IConverter interface
public interface IConverter Turns a mounted game’s files into one piece of Evil Engine content, such as a texture, a material, a map or a record set. Everything past a converter sees only the converted result, never the game’s own format.
An adapter binds converters to a namespace with AddConverter or AddOwnConverter. When something asks for content of a kind under an id, the pipeline goes through the converters bound to that id’s namespace for that kind, in the order they were bound, and the first whose Accepts returns true runs Convert. The result is cached against every file the converter read, and converted again when one of those files changes.
Quake’s palette and colormap converter, whole:
public sealed class QuakeLumpConverter : IConverter
{
public string Id => "quake.lmp";
public int Version => 1;
public ContentKind Produces => ContentKind.Texture;
public bool Accepts(ConversionContext context)
{
return Lump(context) is { } path && context.Exists(path);
}
public void Convert(ConversionContext context, Stream output)
{
var path = Lump(context) ?? throw new InvalidOperationException($"{context.Id} isn't a palette or colormap.");
var data = context.Read(path).Span;
var palette = path.Value.EndsWith(QuakeMap.Palette, StringComparison.Ordinal);
var size = palette ? 256 * 3 : 256 * Shades;
if (data.Length < size)
throw new QuakeMapException(path.Value, $"is {data.Length} bytes, short of the {size} it needs.");
var texture = Texture.Flat(palette ? TextureFormat.R8G8B8Unorm : TextureFormat.R8Unorm, 256,
palette ? 1 : Shades, data[..size].ToArray()) with
{
Sampling = new TextureSampling(TextureWrap.Clamp, TextureWrap.Clamp, TextureWrap.Clamp, TextureFilter.Nearest,
TextureMipFilter.None)
};
output.Adopt(TextureFile.Write(texture));
}
}
Lump and Shades are the converter’s own helpers, left out here.
- Assembly
- EvilEngine.Conversion
- Commit
- 4ff877b1