Add private `SetCurrAndReturn(uint)` helper in PhysicsEngine that looks up the resolved id in `DataCache.CellGraph` and writes `CurrCell` when the cell is present. Wrap the four RESOLVED-id return sites in ResolveCellId: - indoor no-CellBSP return (trust FindCellList) - indoor sphere-overlaps-CellBSP return - outdoor→indoor building-transit return (foreach candidate) - outdoor terrain-grid return The final no-match `return fallbackCellId;` is intentionally NOT wrapped — stale beats null (the caller's seed is preserved unchanged). CurrCell has zero readers in src/ (verified by ripgrep); this is additive write-only, identical observable behavior to W1. One new unit test (CellGraphMembershipTests) proves RED→GREEN. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World.Cells;
|
|
using DatReaderWriter.Types;
|
|
using Xunit;
|
|
using DatEnvCell = DatReaderWriter.DBObjs.EnvCell;
|
|
|
|
namespace AcDream.Core.Tests.Physics;
|
|
|
|
public class CellGraphMembershipTests
|
|
{
|
|
[Fact]
|
|
public void ResolveCellId_Resolved_WritesCurrCellTrackingTheResolvedId()
|
|
{
|
|
var engine = new PhysicsEngine();
|
|
var cache = new PhysicsDataCache();
|
|
engine.DataCache = cache;
|
|
|
|
var cs = new CellStruct {
|
|
VertexArray = new VertexArray { Vertices = new Dictionary<ushort, SWVertex>() },
|
|
Polygons = new Dictionary<ushort, Polygon>(),
|
|
PhysicsBSP = null,
|
|
};
|
|
var dat = new DatEnvCell {
|
|
Flags = (DatReaderWriter.Enums.EnvCellFlags)0,
|
|
CellPortals = new List<DatReaderWriter.Types.CellPortal>(),
|
|
VisibleCells = new List<ushort>(),
|
|
};
|
|
cache.CacheCellStruct(0xA9B40174u, dat, cs, Matrix4x4.Identity); // registers in the graph (W1)
|
|
|
|
uint result = engine.ResolveCellId(new Vector3(0, 0, 0), 0.5f, 0xA9B40174u);
|
|
|
|
// CurrCell tracks whatever id ResolveCellId returned (when that id is in the graph).
|
|
Assert.NotNull(cache.CellGraph.CurrCell);
|
|
Assert.Equal(result, cache.CellGraph.CurrCell!.Id);
|
|
Assert.Equal(0xA9B40174u, cache.CellGraph.CurrCell!.Id);
|
|
}
|
|
}
|