The first four posts in this series were backdated to the day the feature they describe actually shipped. This one isn’t: I’m writing it today, months after the fact, going back through the code and naming the patterns that are actually in it. Not the patterns I set out to use. The ones that were there when I went looking.

Factory and Registry, for loading a scene from data

Devlog 4 mentioned that .scene.toml files parse into the same Scene/GameObject graph C# code builds directly. The mechanism is an IComponentFactory per component type, looked up by name in an IComponentRegistry, classic Abstract Factory plus Registry. Most components need no custom parsing at all, so there’s a single generic factory that covers them through reflection:

internal sealed class ReflectionComponentFactory<T> : IComponentFactory where T : Component, new()
{
    public string TypeName => typeof(T).Name;

    public Component Create(IReadOnlyDictionary<string, object?> properties, ISceneLoadContext ctx)
    {
        var component = new T();
        foreach (var (snakeKey, tomlValue) in properties)
        {
            var pascalKey = snakeKey.ToPascalCase();
            var prop = typeof(T).GetProperty(pascalKey);
            if (prop is null || !prop.CanWrite) continue; // (warning logged, elided here)
            prop.SetValue(component, ctx.Converters.Convert(tomlValue, prop.PropertyType, ctx));
        }
        return component;
    }
}

RegisterDefault<T>() wires one of these up per type with a single call; a component with real parsing needs (a door, a light) gets a hand-written IComponentFactory registered instead. The factory doesn’t know it’s building a door versus a light versus a trigger volume. The registry doesn’t know how any one of them is built. Neither has to change when the other grows.

Strategy, for the part the factory delegates

ctx.Converters.Convert(tomlValue, prop.PropertyType, ctx) in that snippet is doing real work: TOML only has a handful of native types, but a component property can be a Vector3, a Quaternion, an enum, a color, or something a plugin defined. ITypeConverterRegistry holds one conversion strategy per target type and picks the right one at the call site, so the factory above never has a type-specific branch in it anywhere. Adding a new convertible type is adding a new converter, not editing the factory that uses it.

A state stack, for scenes

The “Scenes” debug panel listing registered scenes (file_test, spinner, logs, demo1, map_demo, stress_demo, physics_stress, night_temple, and more below the fold) over the running demo1 scene, with “Current: DemoScene1” shown at the top

SceneManager is a push/pop stack of Scene instances, and only the top of the stack receives Update and Render calls. That’s the whole mechanism behind the panel above. Every entry is a registered scene factory, and clicking one pushes a new state onto the stack. It’s the textbook State pattern in its least disguised form, a literal stack of states, because a scene genuinely behaves like one: the global scene underneath (HUD, audio, UI) keeps running, but gameplay logic belongs to whichever scene is on top.

Composite, already covered

The GameObject parent/child tree from devlog 2 is a Composite, every node the same shape, operations like transform propagation and recursive update not caring whether a given GameObject has zero children or fifty. Nothing new to add here except the name.

A Memento, not a Command

The map editor’s undo stack looks, at a glance, like it should be the Command pattern: an action, a way to reverse it. It isn’t. UndoStack pushes and pops full MapDataSnapshot values, entire copies of the map’s state at a point in time, not reversible operations:

public void Push(MapDataSnapshot snap)
{
    _undo.AddLast(snap);
    if (_undo.Count > _capacity) _undo.RemoveFirst();
    _redo.Clear();
}

That’s Memento: the editor doesn’t know or care what changed between two snapshots, only that it can hand you the previous one back. It’s a simpler contract than Command would be (nothing needs an Undo() method, including operations I haven’t written yet), paid for with memory: a capacity of 100 snapshots, oldest dropped on overflow, which is also why there’s a real, filed oddity where undoing past the first snapshot can drop the sole baseline state instead of stopping at it.

What’s already in devlog 2

Dependency injection through DryIoc and the EventBus for decoupled Observer-style notification both got their own section in devlog 2 already, so I won’t repeat them here beyond pointing at it.

That’s the series

Five posts, four real sprint days and one retrospective, covering a PS1-style renderer, a GameObject runtime, portals, procedural rooms, and the handful of named patterns holding the rest of it together. Start from devlog 1 if you landed here first. The code is at codeberg.org/squidd/LyLy.