fix(physics): validate retail cell containment roots

This commit is contained in:
Erik 2026-07-31 14:48:26 +02:00
parent 7716c2ee89
commit 3e0f3b6206
23 changed files with 429 additions and 197 deletions

View file

@ -107,8 +107,13 @@ public sealed class PhysicsDataCacheProductionTests
var structure = new FlatCellStructureCollisionAsset(
physicsBsp,
new FlatCellContainmentBsp(
-1,
ImmutableArray<FlatCellBspNode>.Empty),
0,
ImmutableArray.Create(new FlatCellBspNode(
BSPNodeType.Leaf,
default,
-1,
-1,
0))),
FlatPolygonTable.Empty);
var topology = new FlatEnvCellTopology(
ImmutableArray<FlatEnvCellPortal>.Empty,
@ -162,7 +167,7 @@ public sealed class PhysicsDataCacheProductionTests
}
[Fact]
public void ProductionCellPublication_PreservesLoadedCellWithEmptyRoots()
public void ProductionCellPublication_RejectsRootlessContainment_ThenAllowsValidRetry()
{
const uint cellId = 0xA9B4_0174u;
PhysicsDataCache cache = PhysicsDataCache.CreateProduction();
@ -190,18 +195,33 @@ public sealed class PhysicsDataCacheProductionTests
structure,
topology);
CellPhysics loaded = Assert.IsType<CellPhysics>(
cache.GetCellStruct(cellId));
Assert.Null(cache.GetCellStruct(cellId));
Assert.Null(cache.CellGraph.GetVisible(cellId));
Assert.Equal(0, cache.FlatCellStructCount);
Assert.Equal(0, cache.FlatEnvCellCount);
var validContainment = new FlatCellContainmentBsp(
0,
ImmutableArray.Create(new FlatCellBspNode(
BSPNodeType.Leaf,
default,
-1,
-1,
0)));
cache.CacheCellStruct(
cellId,
new EnvCell(),
Matrix4x4.Identity,
new FlatCellStructureCollisionAsset(
emptyPhysics,
validContainment,
FlatPolygonTable.Empty),
topology);
CellPhysics loaded = Assert.IsType<CellPhysics>(cache.GetCellStruct(cellId));
Assert.False(CollisionTraversal.HasPhysics(cache, loaded));
Assert.True(CollisionTraversal.HasCellContainment(cache, loaded));
Assert.True(CollisionTraversal.PointInsideCell(
cache,
loaded,
new Vector3(10_000f, -10_000f, 500f)));
var graphCell = Assert.IsType<AcDream.Core.World.Cells.EnvCell>(
cache.CellGraph.GetVisible(cellId));
Assert.True(graphCell.PointInCell(
new Vector3(10_000f, -10_000f, 500f)));
Assert.NotNull(cache.CellGraph.GetVisible(cellId));
Assert.Equal(1, cache.CellStructCount);
Assert.Equal(1, cache.FlatCellStructCount);
Assert.Equal(0, cache.GraphCellStructCount);