feat(physics): Phase 2 — BuildingPhysics + CheckBuildingTransit
Closes the outdoor→indoor entry path. New BuildingPhysics type holds the per-SortCell BldPortal list + building world transform; PhysicsDataCache caches it (CacheBuilding + GetBuilding); CellTransit.CheckBuildingTransit tests each portal's destination cell via PointInsideCellBsp. PhysicsEngine.ResolveCellId's outdoor branch now hooks CheckBuildingTransit after the terrain-grid lookup: if the matched landcell has a cached building stab, check whether the sphere has crossed into one of its interior EnvCells before returning. GameWindow at landblock-load time iterates LandBlockInfo.Buildings and caches each via PhysicsDataCache.CacheBuilding. The landcell-id derivation uses retail's row-major cell-index formula (gridX * 8 + gridY + 1). Polish items from Subagent B/C reviews folded in: - visited HashSet in FindCellList's BFS (avoids O(N^2) re-enqueue) - ResolveCellId_NoDataCache_ReturnsFallback test (closes coverage gap) - DataCache-asymmetry comment in PhysicsEngine.ResolveCellId - Replaced misleading FindCellList outdoor-branch TODO with explicit note that ResolveCellId bypasses this branch — wired in ResolveCellId directly. - Removed unused 'using DatReaderWriter.Types;' from CellTransit.cs - 2 new CellTransitFindCellListTests integration tests - 1 new CellTransitCheckBuildingTransitTests test (null-CellBSP guard case; happy path deferred to visual verification). Spec: docs/superpowers/specs/2026-05-19-indoor-portal-cell-tracking-design.md Plan: docs/superpowers/plans/2026-05-19-indoor-portal-cell-tracking.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
aad697602e
commit
069534a372
8 changed files with 301 additions and 7 deletions
|
|
@ -20,6 +20,9 @@ public sealed class PhysicsDataCache
|
|||
private readonly ConcurrentDictionary<uint, SetupPhysics> _setup = new();
|
||||
private readonly ConcurrentDictionary<uint, CellPhysics> _cellStruct = new();
|
||||
|
||||
// ── Phase 2: building portal cache for outdoor→indoor entry ───────────
|
||||
private readonly ConcurrentDictionary<uint, BuildingPhysics> _buildings = new();
|
||||
|
||||
/// <summary>
|
||||
/// Extract and cache the physics BSP + polygon data from a GfxObj,
|
||||
/// PLUS always cache a visual AABB from the vertex data regardless of
|
||||
|
|
@ -304,6 +307,31 @@ public sealed class PhysicsDataCache
|
|||
/// </summary>
|
||||
public void RegisterCellStructForTest(uint envCellId, CellPhysics physics)
|
||||
=> _cellStruct[envCellId] = physics;
|
||||
|
||||
/// <summary>
|
||||
/// Indoor walking Phase 2 (2026-05-19). Cache the building portal list
|
||||
/// for an outdoor landcell that contains a building stab. Used by
|
||||
/// <see cref="CellTransit.CheckBuildingTransit"/>.
|
||||
/// </summary>
|
||||
public void CacheBuilding(uint landcellId, IReadOnlyList<BldPortalInfo> portals, Matrix4x4 worldTransform)
|
||||
{
|
||||
if (_buildings.ContainsKey(landcellId)) return;
|
||||
Matrix4x4.Invert(worldTransform, out var inverse);
|
||||
_buildings[landcellId] = new BuildingPhysics
|
||||
{
|
||||
WorldTransform = worldTransform,
|
||||
InverseWorldTransform = inverse,
|
||||
Portals = portals,
|
||||
};
|
||||
}
|
||||
|
||||
public BuildingPhysics? GetBuilding(uint landcellId)
|
||||
=> _buildings.TryGetValue(landcellId, out var b) ? b : null;
|
||||
|
||||
public IReadOnlyCollection<uint> BuildingIds => (IReadOnlyCollection<uint>)_buildings.Keys;
|
||||
|
||||
/// <summary>Test helper, mirrors <see cref="RegisterCellStructForTest"/>.</summary>
|
||||
public void RegisterBuildingForTest(uint landcellId, BuildingPhysics b) => _buildings[landcellId] = b;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue