Skip to content

Extensibility

shmellyorc edited this page Sep 13, 2026 · 7 revisions

Extensibility

VOID was built around extend, don't modify.

The goal is to let your game replace important behavior without forking the engine.

Common Extension Points

Area Extension Point Use It For
Graphics backend IRendererBackend Vulkan, Direct3D, another OpenGL backend, custom renderer
GPU device/resources IGraphicsDevice and graphics resource interfaces Backend-specific buffers, textures, shaders, targets
Assets IAsset New asset types
Asset sources IMount Network, custom archives, generated content, mod folders
Atlas packing IAtlasPacker Different rectangle packing strategy
Logging ILogSink Database, telemetry, remote logs, custom format
Batching IBatcher / BaseBatcher Specialized draw collection
Render targets IRenderTarget Custom render-surface behavior
Save data ContentTypeWriterReader<T> Custom serialized types
Type discovery [Discoverable] Registries, tools, gameplay modules, plugin systems

Custom Renderer

Register a renderer without changing VOID:

var settings = GameSettings.Instance
    .SetRenderer(() => new MyRenderer())
    .Build();

A backend implements IRendererBackend, provides an IGraphicsDevice, and receives IRendererContext during initialization.

See Custom Renderers for the complete practical guide.

Custom Asset Type

Implement IAsset, then register the file extensions and factory with AssetManager.

Example shape:

public sealed class DialogueAsset : IAsset
{
    public uint Id { get; }
    public string Tag { get; }
    public byte[] Data { get; }

    public bool IsValid { get; private set; }
    public AssetType Type => AssetType.Normal;
    public DateTime LastAccessTime { get; private set; }

    public DialogueAsset(
        uint id,
        byte[] data,
        string tag)
    {
        Id = id;
        Data = data;
        Tag = tag;
        LastAccessTime = DateTime.Now;
    }

    public void Load()
    {
        // Parse Data.
        LastAccessTime = DateTime.Now;
        IsValid = true;
    }

    public void Unload()
    {
        IsValid = false;
    }

    public void Dispose()
    {
        Unload();
    }
}

Register it:

AssetManager.Instance.RegisterAssetType<DialogueAsset>(
    new[] { ".dialogue" },
    (id, data, tag) =>
        new DialogueAsset(id, data, tag));

Load it normally:

var dialogue =
    AssetManager.Instance.Load<DialogueAsset>(
        "Dialogue/intro.dialogue");

Custom Asset Mount

An IMount supplies files to AssetManager.

public sealed class MemoryMount : IMount
{
    private readonly Dictionary<string, byte[]> _files = new();

    public string Name => "Memory";

    public bool HasFile(string virtualPath)
        => _files.ContainsKey(virtualPath);

    public byte[] ReadFile(string virtualPath)
        => _files.TryGetValue(virtualPath, out var data)
            ? data
            : throw new FileNotFoundException(virtualPath);
}

Put it at the front of the search order:

AssetManager.Instance.AddMountToStart(
    new MemoryMount());

Mount order matters. The first mount containing a requested virtual path wins.

Custom Atlas Packer

Custom atlas packers own allocation geometry only. VOID handles pixel uploads and renderer resources.

A packer selected through SetAtlasPacker must expose a public (int width, int height) constructor:

public sealed class MyPacker : IAtlasPacker
{
    private readonly int _width;
    private readonly int _height;

    public MyPacker(int width, int height)
    {
        _width = width;
        _height = height;
    }

    public bool TryPack(
        int width,
        int height,
        out Rect2 packedRect)
    {
        packedRect = default;
        return false;
    }

    public void Free(Rect2 rect)
    {
    }

    public List<(Rect2 OldRect, Rect2 NewRect)> Defrag()
    {
        return [];
    }

    public void Clear()
    {
    }

    public float Fragmentation => 0f;
    public int UsedSpace => 0;
    public int TotalSpace => _width * _height;
}

Select it:

GameSettings.Instance
    .SetAtlasPacker(typeof(MyPacker));

Fragmentation is free-space fragmentation, not unused percentage. See Atlas Manager → Creating a Custom Packer for the current contract.

Custom Log Sink

public sealed class DatabaseSink : ILogSink
{
    public void Write(LogEntry entry)
    {
        // Store or forward the entry.
    }
}

Register it:

Logger.Instance.AddSink(
    new DatabaseSink());

Discover Your Own Systems

The discovery helper does not require a VOID-specific plugin interface.

Define an interface that belongs to your game:

public interface IGameplayModule
{
    void Initialize();
}

Implement it:

[Discoverable(
    Name = "Weather",
    Category = "Gameplay",
    Priority = 10)]
public sealed class WeatherModule : IGameplayModule
{
    public void Initialize()
    {
    }
}

Find all matching modules:

IReadOnlyList<Type> moduleTypes =
    DiscoverableHelper.FindAll<IGameplayModule>();

Create them:

foreach (Type type in moduleTypes)
{
    IGameplayModule module =
        InstanceHelper.CreateInstanceFromType<IGameplayModule>(
            type,
            null);

    module?.Initialize();
}

This is useful for registries and plugin-style systems without coupling those systems to VOID internals.

See Discoverable System and Instance Helper.

No Engine Fork Required

The intended pattern is:

VOID interface / extension point
        ↓
your implementation
        ↓
registration through the public API

Keep your project-specific behavior in your project. That makes engine updates much easier to take.


Back to Home

Clone this wiki locally