Skip to content

[SOLID] [M5] Extract LightingEngine from world_mutation.zig #788

Description

@MichaelFisher1997

Part of #776 — SOLID architecture debt umbrella.
Phase: P1 · Finding: M5

Problem

modules/world-runtime/src/world_mutation.zig:53-92, 137-422 is marketed as 'the single path for block edits' but embeds a complete BFS lighting propagation engine (~285 lines): spreadSkylight, spreadBlockLight, seedSunlightColumn, seedLightFromNeighbors, recomputeLoadedLightingArea, relightAfterBlockRemoval.

Evidence

world_mutation.zig:53-92 — one coordinator doing block-write + GPU signal + flood-fill lighting:

pub fn applyBlockMutation(...) !?MutationResult {
  ...
  data.chunk.setBlock(local.x, local.y, local.z, block);
  if (self.gpu_mesher_active) { ... buf.updateBlock(...); }
  ...
  if (block == .air and old_def.isOpaque() ...) {
    try self.relightAfterBlockRemoval(...);     // BFS engine
  } else if (...) {
    try self.recomputeLoadedLightingArea(...);  // BFS engine
  }
}

Fix

Extract the BFS engine into a LightingEngine module (e.g. modules/world-runtime/src/lighting_engine.zig or world-lighting). The coordinator invokes lightingEngine.afterBlockRemoval(...) / .recomputeArea(...).

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

Behavior-preserving. The lighting algorithm is unchanged — only its home moves.

Tracking: #776

Metadata

Metadata

Assignees

No one assigned

    Labels

    automated-auditIssues found by automated opencode audit scansbugSomething isn't workingenhancementNew feature or requestquestionFurther information is requestedworld

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions