Make prepared flat BSP data authoritative for gameplay while retaining the parsed graph only as an exact sampled referee. Fail production publication when collision package data is genuinely absent, keep idempotent already-cached publication valid, and move cell membership, floor lookup, camera diagnostics, and live/static shape bounds onto the flat representation. Validated by 8,402 Release tests, a strict dense-Arwic connected gate with 46,309/46,309 exact referee matches, and graceful shutdown. Co-authored-by: Codex <codex@openai.com>
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using System.Numerics;
|
|
using AcDream.Core.Physics;
|
|
using AcDream.Core.World.Cells;
|
|
using DatReaderWriter.Enums;
|
|
using DatReaderWriter.Types;
|
|
using Xunit;
|
|
using UcgCellPortal = AcDream.Core.World.Cells.CellPortal;
|
|
|
|
namespace AcDream.Core.Tests.World.Cells;
|
|
|
|
public class EnvCellTests
|
|
{
|
|
private static EnvCell Make(Vector3 min, Vector3 max, Matrix4x4? transform = null)
|
|
{
|
|
var t = transform ?? Matrix4x4.Identity;
|
|
Matrix4x4.Invert(t, out var inv);
|
|
return new EnvCell(0xA9B40174u, t, inv, min, max,
|
|
System.Array.Empty<UcgCellPortal>(), System.Array.Empty<uint>(),
|
|
seenOutside: false, containmentBsp: null);
|
|
}
|
|
|
|
[Fact]
|
|
public void PointInCell_NullBsp_Aabb_InsideIsTrue()
|
|
=> Assert.True(Make(new Vector3(0,0,0), new Vector3(10,10,10)).PointInCell(new Vector3(5,5,5)));
|
|
|
|
[Fact]
|
|
public void PointInCell_NullBsp_Aabb_OutsideIsFalse()
|
|
=> Assert.False(Make(new Vector3(0,0,0), new Vector3(10,10,10)).PointInCell(new Vector3(20,5,5)));
|
|
|
|
[Fact]
|
|
public void PointInCell_TransformsWorldToLocalBeforeTesting()
|
|
{
|
|
var c = Make(new Vector3(0,0,0), new Vector3(10,10,10), Matrix4x4.CreateTranslation(100,0,0));
|
|
Assert.True(c.PointInCell(new Vector3(105,5,5)));
|
|
Assert.False(c.PointInCell(new Vector3(5,5,5)));
|
|
}
|
|
|
|
[Fact]
|
|
public void PointInCell_PreparedContainmentIsAuthoritative()
|
|
{
|
|
var graphRoot = new CellBSPNode
|
|
{
|
|
Type = BSPNodeType.BPIn,
|
|
SplittingPlane = new Plane(Vector3.UnitX, -1f),
|
|
PosNode = new CellBSPNode { Type = BSPNodeType.Leaf },
|
|
};
|
|
var flatRoot = new CellBSPNode
|
|
{
|
|
Type = BSPNodeType.Leaf,
|
|
LeafIndex = 1,
|
|
};
|
|
FlatCellContainmentBsp flat =
|
|
FlatCollisionAssetBuilder.FlattenCellContainmentBsp(flatRoot);
|
|
var cell = new EnvCell(
|
|
0xA9B4_0174u,
|
|
Matrix4x4.Identity,
|
|
Matrix4x4.Identity,
|
|
-Vector3.One,
|
|
Vector3.One,
|
|
Array.Empty<UcgCellPortal>(),
|
|
Array.Empty<uint>(),
|
|
seenOutside: false,
|
|
containmentBsp: new CellBSPTree { Root = graphRoot },
|
|
flatContainmentBsp: flat);
|
|
|
|
Assert.True(cell.PointInCell(Vector3.Zero));
|
|
Assert.False(BSPQuery.PointInsideCellBsp(graphRoot, Vector3.Zero));
|
|
}
|
|
}
|