perf(physics): cut production traversal to flat assets

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>
This commit is contained in:
Erik 2026-07-25 17:00:04 +02:00
parent d9446030e6
commit 068a06518d
13 changed files with 743 additions and 43 deletions

View file

@ -13,19 +13,30 @@ public sealed class EnvCell : ObjCell
/// <summary>Cell-containment BSP (retail CellStruct.CellBSP). Null =&gt; AABB fallback.</summary>
public CellBSPTree? ContainmentBsp { get; }
/// <summary>
/// Prepared production containment tree. Slice I6 makes this path
/// authoritative while <see cref="ContainmentBsp"/> remains only as the
/// temporary graph referee/test fixture seam.
/// </summary>
public FlatCellContainmentBsp? FlatContainmentBsp { get; }
public EnvCell(uint id, Matrix4x4 worldTransform, Matrix4x4 inverseWorldTransform,
Vector3 localBoundsMin, Vector3 localBoundsMax,
IReadOnlyList<CellPortal> portals, IReadOnlyList<uint> stabList,
bool seenOutside, CellBSPTree? containmentBsp)
bool seenOutside, CellBSPTree? containmentBsp,
FlatCellContainmentBsp? flatContainmentBsp = null)
: base(id, worldTransform, inverseWorldTransform, localBoundsMin, localBoundsMax,
portals, stabList, seenOutside)
{
ContainmentBsp = containmentBsp;
FlatContainmentBsp = flatContainmentBsp;
}
public override bool PointInCell(Vector3 worldPoint)
{
var local = Vector3.Transform(worldPoint, InverseWorldTransform);
if (FlatContainmentBsp is not null)
return FlatBspQuery.PointInsideCellBsp(FlatContainmentBsp, local);
if (ContainmentBsp?.Root is not null)
return BSPQuery.PointInsideCellBsp(ContainmentBsp.Root, local); // BSPQuery.cs:1034
return local.X >= LocalBoundsMin.X && local.X <= LocalBoundsMax.X
@ -40,7 +51,8 @@ public sealed class EnvCell : ObjCell
/// (no +2 cm render lift).
/// </summary>
public static EnvCell FromDat(uint id, DatReaderWriter.DBObjs.EnvCell datCell,
CellStruct cellStruct, Matrix4x4 worldTransform)
CellStruct cellStruct, Matrix4x4 worldTransform,
FlatCellContainmentBsp? flatContainmentBsp = null)
{
Matrix4x4.Invert(worldTransform, out var inverse);
@ -72,7 +84,7 @@ public sealed class EnvCell : ObjCell
bool seenOutside = datCell.Flags.HasFlag(EnvCellFlags.SeenOutside);
return new EnvCell(id, worldTransform, inverse, min, max, portals, stab,
seenOutside, cellStruct.CellBSP);
seenOutside, cellStruct.CellBSP, flatContainmentBsp);
}
private static IReadOnlyList<Vector3> ResolvePortalPolygon(CellStruct cellStruct, ushort polygonId)