checkpoint(render): preserve pre-overhaul investigation state

This commit is contained in:
Erik 2026-09-01 18:04:24 +02:00
parent e880860291
commit b3b7d922f1
45 changed files with 3168 additions and 619 deletions

View file

@ -276,8 +276,7 @@ public sealed class LightManagerTests
LightSource[] expected = FullSortOracle(
registered,
Vector3.Zero,
visibleCells: null);
Vector3.Zero);
manager.BuildPointLightSnapshot(Vector3.Zero);
Assert.Equal(expected, manager.PointSnapshot);
@ -324,23 +323,15 @@ public sealed class LightManagerTests
manager.Register(light);
}
IReadOnlySet<uint>? visibleCells = scenario % 2 == 0
? new HashSet<uint>
{
0xAAAA0101u,
0xAAAA0103u,
}
: null;
Vector3 player = new(
random.Next(-4, 5),
random.Next(-4, 5),
random.Next(-2, 3));
LightSource[] expected = FullSortOracle(
registered,
player,
visibleCells);
player);
manager.BuildPointLightSnapshot(player, visibleCells);
manager.BuildPointLightSnapshot(player);
Assert.Equal(expected, manager.PointSnapshot);
}
@ -369,15 +360,12 @@ public sealed class LightManagerTests
registered.Add(light);
manager.Register(light);
}
IReadOnlySet<uint> visibleCells =
new HashSet<uint> { fountainRoom, corridor };
Vector3 player = new(4.25f, -1.5f, 0.7f);
LightSource[] expected = FullSortOracle(
registered,
player,
visibleCells);
player);
manager.BuildPointLightSnapshot(player, visibleCells);
manager.BuildPointLightSnapshot(player);
Assert.Equal(LightManager.MaxGlobalLights, manager.PointSnapshot.Count);
Assert.Equal(expected, manager.PointSnapshot);
@ -415,71 +403,11 @@ public sealed class LightManagerTests
Assert.Equal(0, allocated);
}
// ── Visible-cell scoping (A7.L1, 2026-07-09 — the Town Network starvation fix) ──
// BuildPointLightSnapshot's player-nearest cap sorts by raw Euclidean distance,
// which is not a reliable proxy for "same room" in a dense, maze-like hub: a
// fixture on the other side of a wall can be geometrically closer than the
// player's own room's torches. The Town Network fountain room (463 registered
// fixtures, cap 128) went dark because far-denser, closer-in-a-straight-line
// corridor fixtures won the cap over the room's own lights. Filtering candidacy
// by the frame's actual visible-cell set (the render already computes this)
// fixes it without touching the distance-sort anchor (still the PLAYER, per the
// #176 correction — camera anchoring is what caused the earlier flicker).
[Fact]
public void BuildPointLightSnapshot_VisibleCellScoping_RoomLightsSurviveOverEuclideanCloserInvisibleCell()
public void BuildPointLightSnapshot_UsesAllResidentLights()
{
var mgr = new LightManager();
// A different, NOT-visible cell packed with fixtures that are, in raw
// straight-line distance, closer to the player than the room's own
// torches (e.g. a corridor on the other side of a wall).
const uint otherCellId = 0xAAAA0102u;
for (int i = 0; i < LightManager.MaxGlobalLights + 50; i++)
mgr.Register(MakePoint(new Vector3(1f + i * 0.001f, 1f, 0), range: 5f, ownerId: (uint)(i + 1), cellId: otherCellId));
// The player's own room: a handful of torches, each FARTHER in raw
// distance than every "other cell" fixture above, but the only cell
// actually visible from the player's viewpoint this frame.
const uint roomCellId = 0xAAAA0101u;
var roomTorches = new LightSource[5];
for (int i = 0; i < roomTorches.Length; i++)
{
roomTorches[i] = MakePoint(new Vector3(50f + i, 0, 0), range: 15f, cellId: roomCellId);
mgr.Register(roomTorches[i]);
}
var visibleCells = new HashSet<uint> { roomCellId };
mgr.BuildPointLightSnapshot(playerWorldPos: Vector3.Zero, visibleCells);
foreach (var torch in roomTorches)
Assert.Contains(torch, mgr.PointSnapshot);
}
[Fact]
public void BuildPointLightSnapshot_VisibleCellScoping_CellLessLightAlwaysIncluded()
{
// The viewer fill light (CellId==0) must survive scoping unconditionally —
// retail's per-frame add_dynamic_light(&viewer_light, ...) is unconditional
// (LightManager.UpdateViewerLight's doc comment).
var mgr = new LightManager();
var viewerFill = MakePoint(new Vector3(0, 0, 2), range: 15f, cellId: 0u);
mgr.Register(viewerFill);
var otherRoom = MakePoint(new Vector3(2, 0, 0), range: 5f, cellId: 0xBEEFu);
mgr.Register(otherRoom);
var visibleCells = new HashSet<uint> { 0xF00Du }; // neither light's cell
mgr.BuildPointLightSnapshot(Vector3.Zero, visibleCells);
Assert.Contains(viewerFill, mgr.PointSnapshot);
Assert.DoesNotContain(otherRoom, mgr.PointSnapshot);
}
[Fact]
public void BuildPointLightSnapshot_NoVisibleCellsArg_UnscopedLegacyBehavior()
{
// Outdoor / no-clipRoot callers omit visibleCells — every registered lit
// light stays a candidate, exactly the pre-A7.L1 behavior.
// Retail walks the resident EnvCell registry. A camera-root transition
// cannot make either resident cell stop contributing candidates.
var mgr = new LightManager();
mgr.Register(MakePoint(new Vector3(1, 0, 0), 5f, cellId: 0xAAAAu));
mgr.Register(MakePoint(new Vector3(2, 0, 0), 5f, cellId: 0xBBBBu));
@ -685,8 +613,7 @@ public sealed class LightManagerTests
private static LightSource[] FullSortOracle(
IReadOnlyList<LightSource> registered,
Vector3 player,
IReadOnlySet<uint>? visibleCells)
Vector3 player)
{
var ranked = new List<OracleRank>();
for (int index = 0; index < registered.Count; index++)
@ -694,13 +621,6 @@ public sealed class LightManagerTests
LightSource light = registered[index];
if (!light.IsLit || light.Kind == LightKind.Directional)
continue;
if (visibleCells is not null
&& light.CellId != 0
&& !visibleCells.Contains(light.CellId))
{
continue;
}
ranked.Add(new OracleRank(
light,
Vector3.DistanceSquared(light.WorldPosition, player)));