New CellTransit static class ports retail's portal-graph cell traversal:
- FindTransitCellsSphere — indoor portal-neighbour walk
- AddAllOutsideCells — outdoor 24m grid expansion
- FindCellList — top-level driver (BFS through portals;
PointInsideCellBsp for final containment)
PhysicsEngine.ResolveOutdoorCellId renamed to ResolveCellId. Body
rewritten: indoor seeds delegate to CellTransit.FindCellList (portal-
graph BFS + BSP containment test); outdoor seeds keep the landblock
terrain grid lookup from the original implementation (preserving the
L.2e prefix-preservation fix). Signature extended with sphereRadius
parameter (needed by the sphere-vs-portal-plane test). Three call
sites updated (PhysicsEngine x2, TransitionTypes x1).
BSPQuery.PointInsideCellBsp retyped from PhysicsBSPNode? to CellBSPNode?
— the function operates on the cell-BSP tree (CellPhysics.CellBSP.Root
is a CellBSPNode). The previous PhysicsBSPNode typing was dead code, so
retype is safe.
Deletes the Phase D ResolveOutdoorCellIdTests.cs file. New ResolveCellIdTests
covers the equivalent contracts (fallback zero, outdoor seed with no
landblock).
Outdoor->indoor entry (check_building_transit) is stubbed pending the
BuildingPhysics infrastructure landing in the next commit.
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>
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using AcDream.Core.Physics;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.Physics;
|
|
|
|
public class CellTransitAddAllOutsideCellsTests
|
|
{
|
|
[Fact]
|
|
public void SphereWellInsideCell_AddsOneCell()
|
|
{
|
|
// Player at world (12, 12, 0) in landblock 0xA9B40000 → cell (0,0).
|
|
// Landblock origin: 0xA9 = 169 → world X = 169*192 = 32448.
|
|
// 0xB4 = 180 → world Y = 180*192 = 34560.
|
|
// Player needs to be in cell (0,0) RELATIVE to landblock origin:
|
|
// world X = 32448 + 12 = 32460
|
|
// world Y = 34560 + 12 = 34572
|
|
var candidates = new HashSet<uint>();
|
|
CellTransit.AddAllOutsideCells(
|
|
worldSphereCenter: new Vector3(32460f, 34572f, 0f),
|
|
sphereRadius: 0.5f,
|
|
currentCellId: 0xA9B40001u,
|
|
candidates);
|
|
|
|
Assert.Single(candidates);
|
|
Assert.Contains(0xA9B40001u, candidates);
|
|
}
|
|
|
|
[Fact]
|
|
public void SphereAtCellEastBoundary_AddsTwoCells()
|
|
{
|
|
// Player at world (32448 + 23.6, 34560 + 12, 0) — near +X edge of cell (0,0).
|
|
// Sphere reach to localX = 23.6 + 0.5 = 24.1 → cell (1,0) added.
|
|
var candidates = new HashSet<uint>();
|
|
CellTransit.AddAllOutsideCells(
|
|
worldSphereCenter: new Vector3(32448f + 23.6f, 34560f + 12f, 0f),
|
|
sphereRadius: 0.5f,
|
|
currentCellId: 0xA9B40001u,
|
|
candidates);
|
|
|
|
Assert.Equal(2, candidates.Count);
|
|
Assert.Contains(0xA9B40001u, candidates);
|
|
// Cell (1,0): low-16 id = 1 * 8 + 0 + 1 = 9 → 0x0009.
|
|
Assert.Contains(0xA9B40009u, candidates);
|
|
}
|
|
}
|