From ff548b962c93c255cb79e3e0aa7c34e42530ef97 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 19 May 2026 21:22:40 +0200 Subject: [PATCH] refactor(physics): expose hitPolyId from FindWalkableInternal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a ref ushort hitPolyId parameter to FindWalkableInternal so callers can identify which polygon was hit. The leaf branch already iterates foreach (ushort polyId in node.Polygons); this surfaces it. No behavior change. Existing callers (StepSphereDown, Path 4 Collide) pass a discard local. The new BSPQuery.FindWalkableSphere wrapper (next commit) will consume it. Prep for indoor walkable-plane BSP port — see spec docs/superpowers/specs/2026-05-19-indoor-walkable-plane-bsp-port-design.md --- src/AcDream.Core/Physics/BSPQuery.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/AcDream.Core/Physics/BSPQuery.cs b/src/AcDream.Core/Physics/BSPQuery.cs index 55dc792..c58594e 100644 --- a/src/AcDream.Core/Physics/BSPQuery.cs +++ b/src/AcDream.Core/Physics/BSPQuery.cs @@ -652,6 +652,7 @@ public static class BSPQuery Vector3 movement, Vector3 up, ref ResolvedPolygon? hitPoly, + ref ushort hitPolyId, ref bool changed) { if (node is null) return; @@ -673,6 +674,7 @@ public static class BSPQuery { changed = true; hitPoly = poly; + hitPolyId = polyId; } } return; @@ -686,22 +688,22 @@ public static class BSPQuery if (dist >= reach) { FindWalkableInternal(node.PosNode, resolved, path, validPos, movement, up, - ref hitPoly, ref changed); + ref hitPoly, ref hitPolyId, ref changed); return; } if (dist <= -reach) { FindWalkableInternal(node.NegNode, resolved, path, validPos, movement, up, - ref hitPoly, ref changed); + ref hitPoly, ref hitPolyId, ref changed); return; } // Straddles. FindWalkableInternal(node.PosNode, resolved, path, validPos, movement, up, - ref hitPoly, ref changed); + ref hitPoly, ref hitPolyId, ref changed); FindWalkableInternal(node.NegNode, resolved, path, validPos, movement, up, - ref hitPoly, ref changed); + ref hitPoly, ref hitPolyId, ref changed); } // ------------------------------------------------------------------------- @@ -1103,9 +1105,10 @@ public static class BSPQuery var validPos = new CollisionSphere(checkPos); bool changed = false; ResolvedPolygon? polyHit = null; + ushort _polyId = 0; // step-down doesn't need the id, but the signature requires it FindWalkableInternal(root, resolved, path, validPos, movement, up, - ref polyHit, ref changed); + ref polyHit, ref _polyId, ref changed); if (changed && polyHit is not null) { @@ -1487,10 +1490,11 @@ public static class BSPQuery { var validPos = new CollisionSphere(sphere0); ResolvedPolygon? hitPoly = null; + ushort _hitPolyId = 0; // Path 4 doesn't need the id bool changed = false; FindWalkableInternal(root, resolved, path, validPos, movement, localSpaceZ, - ref hitPoly, ref changed); + ref hitPoly, ref _hitPolyId, ref changed); if (changed && hitPoly is not null) {