feat(render): Phase A8 RR4 — wire BuildingRegistry into landblock load

LoadedCell.BuildingId (init + internal setter) — set exactly once at
    landblock load time by BuildingLoader; null when the cell isn't
    part of any building (outdoor surface cells; dungeon cells not
    enumerated in LandBlockInfo.Buildings).

  GameWindow landblock-load path: builds BuildingRegistry from
    LandBlockInfo.Buildings; stamps each cell's BuildingId; stores the
    registry on _buildingRegistries[landblockId] (GameWindow-level dict)
    for render-frame lookups. Note: LoadedLandblock is AcDream.Core.World
    (a sealed record) — adding an App-type field there would violate
    Code Structure Rule #2, so the registry is stored in a new
    GameWindow-level dictionary instead. Cleanup wired in both
    removeTerrain lambdas (OnLoad + OnResize paths).

  drainedCells dict: the existing _pendingCells drain loop is extended
    to also build a local CellId→LoadedCell dict; BuildingLoader.Build
    uses this dict for the stamping pass so no second iteration is needed.

  New BuildingLoaderTest verifies the stamping path. 5 BuildingLoader
  tests total (4 from RR3 + 1 new).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-05-27 11:13:48 +02:00
parent f125fdb220
commit f8d0499d8b
4 changed files with 93 additions and 4 deletions

View file

@ -85,4 +85,46 @@ public class BuildingLoaderTests
foreach (var b in reg.All()) ids.Add(b.BuildingId);
Assert.Equal(new SortedSet<uint> { 1, 2 }, ids); // sequential 1, 2
}
[Fact]
public void Build_StampsLoadedCellBuildingId()
{
// Fixture: minimal LoadedCell instances representing 2 cottage cells.
var cell150 = new AcDream.App.Rendering.LoadedCell
{
CellId = 0xA9B40150u,
Portals = new List<AcDream.App.Rendering.CellPortalInfo>(),
PortalPolygons = new List<Vector3[]>(),
WorldTransform = Matrix4x4.Identity,
InverseWorldTransform = Matrix4x4.Identity,
LocalBoundsMin = new Vector3(-5, -5, -5),
LocalBoundsMax = new Vector3(5, 5, 5),
ClipPlanes = new List<AcDream.App.Rendering.PortalClipPlane>(),
};
var cell151 = new AcDream.App.Rendering.LoadedCell
{
CellId = 0xA9B40151u,
Portals = new List<AcDream.App.Rendering.CellPortalInfo>(),
PortalPolygons = new List<Vector3[]>(),
WorldTransform = Matrix4x4.Identity,
InverseWorldTransform = Matrix4x4.Identity,
LocalBoundsMin = new Vector3(-5, -5, -5),
LocalBoundsMax = new Vector3(5, 5, 5),
ClipPlanes = new List<AcDream.App.Rendering.PortalClipPlane>(),
};
var cells = new Dictionary<uint, AcDream.App.Rendering.LoadedCell>
{
{ 0xA9B40150u, cell150 },
{ 0xA9B40151u, cell151 },
};
var info = MakeInfo((0x02000123u, new[] { 0x0150u, 0x0151u }));
var reg = BuildingLoader.Build(info, 0xA9B40000u, cells);
Assert.Equal(1, reg.Count);
var b = System.Linq.Enumerable.First(reg.All());
// Both cells stamped with the building id:
Assert.Equal(b.BuildingId, cell150.BuildingId);
Assert.Equal(b.BuildingId, cell151.BuildingId);
}
}