refactor(physics): remove parsed collision graphs
Publish prepared GfxObj, Setup, CellStruct, and EnvCell collision records without retaining their parsed DAT BSP, polygon, vertex, or shape graphs. Strip temporary physics bundles at stable world commit, keep graph traversal only as an explicit test/tooling oracle, and report graph residency from actual retained fields. Validated by 115 focused collision/streaming tests, a zero-warning Release build, and 8,413 passing Release tests with five pre-existing skips. Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
parent
feb80a67d9
commit
82f8d4f82e
18 changed files with 923 additions and 104 deletions
|
|
@ -87,6 +87,82 @@ public sealed class EnvCell : ObjCell
|
|||
seenOutside, cellStruct.CellBSP, flatContainmentBsp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build the production cell-graph record from package-prepared collision
|
||||
/// arrays. No parsed DAT CellStruct/BSP/polygon/vertex graph is retained.
|
||||
/// </summary>
|
||||
public static EnvCell FromPrepared(
|
||||
uint id,
|
||||
Matrix4x4 worldTransform,
|
||||
FlatCellStructureCollisionAsset structure,
|
||||
FlatEnvCellTopology topology)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(structure);
|
||||
ArgumentNullException.ThrowIfNull(topology);
|
||||
Matrix4x4.Invert(worldTransform, out Matrix4x4 inverse);
|
||||
|
||||
Vector3 min = new(float.MaxValue);
|
||||
Vector3 max = new(float.MinValue);
|
||||
IncludeVertices(
|
||||
structure.PhysicsBsp.PolygonTable.Vertices,
|
||||
ref min,
|
||||
ref max);
|
||||
IncludeVertices(
|
||||
structure.PortalPolygons.Vertices,
|
||||
ref min,
|
||||
ref max);
|
||||
if (min.X == float.MaxValue)
|
||||
{
|
||||
min = Vector3.Zero;
|
||||
max = Vector3.Zero;
|
||||
}
|
||||
|
||||
var portals = new List<CellPortal>(topology.Portals.Length);
|
||||
for (int i = 0; i < topology.Portals.Length; i++)
|
||||
{
|
||||
FlatEnvCellPortal portal = topology.Portals[i];
|
||||
FlatCollisionPolygon polygon =
|
||||
structure.PortalPolygons.Polygons[portal.PolygonIndex];
|
||||
var vertices = new Vector3[polygon.VertexRange.Count];
|
||||
structure.PortalPolygons.Vertices.AsSpan(
|
||||
polygon.VertexRange.Start,
|
||||
polygon.VertexRange.Count).CopyTo(vertices);
|
||||
portals.Add(new CellPortal(
|
||||
// Preserve FromDat's existing representation exactly. CellGraph
|
||||
// portal-ID normalization is a separate behavioral concern and
|
||||
// must not be changed by this graph-residency cleanup.
|
||||
portal.OtherCellId,
|
||||
otherPortalId: 0,
|
||||
portal.PolygonId,
|
||||
portal.Flags,
|
||||
vertices));
|
||||
}
|
||||
|
||||
return new EnvCell(
|
||||
id,
|
||||
worldTransform,
|
||||
inverse,
|
||||
min,
|
||||
max,
|
||||
portals,
|
||||
topology.VisibleCellIds,
|
||||
topology.SeenOutside,
|
||||
containmentBsp: null,
|
||||
structure.ContainmentBsp);
|
||||
}
|
||||
|
||||
private static void IncludeVertices(
|
||||
System.Collections.Immutable.ImmutableArray<Vector3> vertices,
|
||||
ref Vector3 min,
|
||||
ref Vector3 max)
|
||||
{
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
min = Vector3.Min(min, vertices[i]);
|
||||
max = Vector3.Max(max, vertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static IReadOnlyList<Vector3> ResolvePortalPolygon(CellStruct cellStruct, ushort polygonId)
|
||||
{
|
||||
if (!cellStruct.Polygons.TryGetValue(polygonId, out var poly) || poly.VertexIds.Count < 3)
|
||||
|
|
|
|||
|
|
@ -26,4 +26,17 @@ public sealed record PhysicsDatBundle(
|
|||
new Dictionary<uint, DatEnvironment>(),
|
||||
new Dictionary<uint, Setup>(),
|
||||
new Dictionary<uint, GfxObj>());
|
||||
|
||||
/// <summary>
|
||||
/// Drops parsed collision-bearing GfxObj and Environment/CellStruct graphs
|
||||
/// after their immutable package assets have been resolved. The remaining
|
||||
/// records are the small publication facts still consumed by building,
|
||||
/// placement, and static-light owners.
|
||||
/// </summary>
|
||||
public PhysicsDatBundle WithoutCollisionGraphs() => new(
|
||||
Info,
|
||||
EnvCells,
|
||||
Empty.Environments,
|
||||
Setups,
|
||||
Empty.GfxObjs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue