Skip to content

[SOLID] [M8] Replace hardcoded generator registry with comptime GeneratorDescriptor array (covers M9) #792

Description

@MichaelFisher1997

Part of #776 — SOLID architecture debt umbrella.
Phase: P2 · Finding: M8

Problem

modules/world-worldgen/src/registry.zig:24-49 hardcodes all 4 generators in a static GENERATORS array. Adding worldgen-foo requires edits to 6 files (build.zig ×2, registry.zig ×2, root.zig, app.zig). Separately (M9), registry.zig:51-65 redefines a factory signature different from the GeneratorDescriptor.create the API already provides, forcing 4 trivially-delegating wrappers.

Evidence

registry.zig:24-49:

pub const GENERATORS = [_]GeneratorType{
  .{ .id = overworld.descriptor.id, ... .initFn = initOverworld },
  .{ .id = flat_world.descriptor.id, ... .initFn = initFlatWorld },
  ...
};

registry.zig:51-65 — 4 copies of the same delegation:

fn initOverworld(seed, gpa) RegistryError!Generator {
  return overworld.descriptor.create(.{.seed=seed,.allocator=gpa}) catch ...;
}

Fix

Replace GeneratorType/initFn with a comptime array:

pub const DESCRIPTORS = [_]*const GeneratorDescriptor{
  &overworld.descriptor,
  &flat_world.descriptor,
  &shadow_test_world.descriptor,
  &overworld_v2.descriptor,
};

Consumers call DESCRIPTORS[i].create(.{.seed, .allocator}) directly. Deletes the 4 wrappers and unifies the factory signature.

Verification

  • nix develop --command zig build test (includes shader validation)
  • If rendering-touching: capture headless screenshot baseline before/after (-Dskip-present)
  • If behavior-preserving refactor: golden-output test must stay green

Constraints

  • Small reviewable PR targeting dev; conventional commit (refactor: / feat:)
  • Preserve current behavior unless this issue explicitly changes it
  • Keep worker-thread RHI isolation intact (no RHI calls off main thread)

Notes

Resolves M8 + M9 together (they're one logical change). Runtime (world-runtime/src/world.zig:279) already calls registry.createGenerator(index, seed, allocator) — that API can stay, just re-implemented against DESCRIPTORS.

Tracking: #776

Metadata

Metadata

Assignees

No one assigned

    Labels

    automated-auditIssues found by automated opencode audit scansbugSomething isn't workingenhancementNew feature or requestworld

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions