fix(phys): A6.P3 slice 1 step 2 — strip indoor walkable synthesis
Closes A6.P2 Finding 2 (ContactPlane resynthesis blowup, 250x to ∞x
more CP writes than retail). Indoor branch of Transition.FindEnvCollisions
now matches retail's CEnvCell::find_env_collisions tiny shape (decomp
line 309573): call BSPTREE::find_collisions, return OK. No synthesis,
no per-frame ValidateWalkable call, no per-frame ContactPlane write.
Cross-frame CP retention now flows via:
- Mechanism A: BSPQuery.FindCollisions Path-3 step-down write on
grounded movers (retail-faithful: BSPTREE::step_sphere_down at
acclient_2013_pseudo_c.txt:323711 always writes contact_plane when
it finds a walkable surface — only fires if sphere penetrates floor).
- Mechanism B: per-transition LKCP restore in ValidateTransition
(added in 5aba071) for the Collided/Adjusted/Slid result cases.
- PhysicsEngine.RunTransitionResolve body persist (unchanged).
TryFindIndoorWalkablePlane definition retained for now; deleted in
A6.P4 alongside the #90 sphere-overlap workaround.
Test fix: IndoorContactPlaneRetentionTests sphere position corrected
from 5 cm below the floor (pre-fix arrangement to trigger synthesis)
to exactly on the floor (worldPosZ = floorZ). A grounded sphere at
its natural position does not penetrate the floor polygon, so BSP
Path 5 finds no intersection and returns OK immediately — zero
additional CP writes in 60 frames. Previously the below-floor position
was causing Path 5 → StepSphereUp → DoStepDown → SetContactPlane
every frame (60 writes), not the synthesis path.
Verification:
- IndoorContactPlaneRetentionTests: PASS (was the 9th expected fail;
back to 1148 pass + 8 pre-existing fail).
- Full suite: 1148+420 pass, 8 fail (baseline maintained +1 pass).
- Re-capture verification (scen1/3/5) deferred to Task 6.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5aba071aec
commit
5f7722a3a4
2 changed files with 47 additions and 122 deletions
|
|
@ -1651,104 +1651,29 @@ public sealed class Transition
|
|||
return otherCellsState;
|
||||
// ──────────────────────────────────────────────────────────
|
||||
|
||||
// ── Synthesize indoor walkable contact plane ──────────────
|
||||
// Indoor walking Phase 2 follow-up (2026-05-19). When the BSP
|
||||
// returns OK (no wall collision), the player is standing on a
|
||||
// floor poly inside the cell. We must NOT fall through to
|
||||
// outdoor terrain (SampleTerrainWalkable) — the outdoor terrain
|
||||
// Z is below the indoor floor due to the +0.02f Z-bump applied
|
||||
// for render z-fight prevention. ValidateWalkable would then see
|
||||
// the player 0.5m above the outdoor plane → marks them as
|
||||
// airborne → walkable=False → falling animation, never recovers.
|
||||
// ── Indoor walkable handling — A6.P3 slice 1 (2026-05-22) ─
|
||||
// Retail's CEnvCell::find_env_collisions (decomp
|
||||
// acclient_2013_pseudo_c.txt:309573) returns OK after
|
||||
// BSPTREE::find_collisions returns OK — NO call to
|
||||
// set_contact_plane or any synthesis. ContactPlane is
|
||||
// either:
|
||||
// - Already valid from a previous frame's Path-6 land
|
||||
// write inside BSPQuery.FindCollisions (Mechanism A).
|
||||
// - Restored from LKCP by the per-transition Mechanism B
|
||||
// in Transition.ValidateTransition (added in 5aba071,
|
||||
// Task 4 of this slice).
|
||||
//
|
||||
// Retail: CEnvCell::find_env_collisions returns from the cell
|
||||
// branch with the cell's walkable plane set — no fall-through
|
||||
// to terrain.
|
||||
bool walkableHit = TryFindIndoorWalkablePlane(
|
||||
cellPhysics, localCenter, sphereRadius,
|
||||
out var indoorPlane,
|
||||
out var indoorVertices,
|
||||
out uint hitPolyId);
|
||||
|
||||
if (PhysicsDiagnostics.ProbeIndoorBspEnabled)
|
||||
{
|
||||
if (walkableHit)
|
||||
{
|
||||
// dz = signed gap between foot and synthesized plane.
|
||||
// Plane: N·p + D = 0 ⇒ pZ_on_plane = -D/N.z (for upward-facing planes)
|
||||
// gap = foot.Z - pZ_on_plane = foot.Z - (-D/N.z) = foot.Z + D/N.z
|
||||
float dz = footCenter.Z + indoorPlane.D / indoorPlane.Normal.Z;
|
||||
Console.WriteLine(System.FormattableString.Invariant(
|
||||
$"[indoor-walkable] cell=0x{sp.CheckCellId:X8} wpos=({footCenter.X:F3},{footCenter.Y:F3},{footCenter.Z:F3}) probe={INDOOR_WALKABLE_PROBE_DISTANCE:F2} result=HIT poly=0x{hitPolyId:X4} wn=({indoorPlane.Normal.X:F3},{indoorPlane.Normal.Y:F3},{indoorPlane.Normal.Z:F3}) wD={indoorPlane.D:F3} dz={dz:+0.00;-0.00;+0.00}"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(System.FormattableString.Invariant(
|
||||
$"[indoor-walkable] cell=0x{sp.CheckCellId:X8} wpos=({footCenter.X:F3},{footCenter.Y:F3},{footCenter.Z:F3}) probe={INDOOR_WALKABLE_PROBE_DISTANCE:F2} result=MISS"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!walkableHit && PhysicsDiagnostics.ProbeWalkMissEnabled)
|
||||
{
|
||||
var agg = WalkMissDiagnostic.AggregateNearestWalkable(
|
||||
cellPhysics.Resolved,
|
||||
footLocal: localCenter,
|
||||
floorZ: PhysicsGlobals.FloorZ);
|
||||
|
||||
// Count walkable polys for the line (cheap re-scan; the
|
||||
// probe is opt-in so cost is bounded to MISS frames).
|
||||
int walkableCount = 0;
|
||||
foreach (var kvp in cellPhysics.Resolved)
|
||||
{
|
||||
if (kvp.Value.Plane.Normal.Z >= PhysicsGlobals.FloorZ
|
||||
&& kvp.Value.Vertices.Length >= 3)
|
||||
walkableCount++;
|
||||
}
|
||||
|
||||
// Outdoor terrain probe at the same world XY — the
|
||||
// "would multi-cell iteration have grounded us?" check.
|
||||
var terrain = engine.SampleTerrainWalkable(footCenter.X, footCenter.Y);
|
||||
string terrainPart;
|
||||
if (terrain is null)
|
||||
{
|
||||
terrainPart = "landcell.hasTerrain=false";
|
||||
}
|
||||
else
|
||||
{
|
||||
var tp = terrain.Value.Plane;
|
||||
float terrainZ = -(tp.D + tp.Normal.X * footCenter.X
|
||||
+ tp.Normal.Y * footCenter.Y)
|
||||
/ tp.Normal.Z;
|
||||
float terrainDz = footCenter.Z - terrainZ;
|
||||
terrainPart = System.FormattableString.Invariant(
|
||||
$"landcell.hasTerrain=true landcell.terrainZ={terrainZ:F3} landcell.dz={terrainDz:+0.000;-0.000;+0.000}");
|
||||
}
|
||||
|
||||
string nearestPart = agg.Found
|
||||
? System.FormattableString.Invariant(
|
||||
$"nearest.polyId=0x{agg.PolyId:X4} nearest.containsFootXY={agg.ContainsFootXY} nearest.dz={agg.Dz:+0.000;-0.000;+0.000} nearest.normalZ={agg.NormalZ:F3}")
|
||||
: "nearest=none";
|
||||
|
||||
Console.WriteLine(System.FormattableString.Invariant(
|
||||
$"[walk-miss] cell=0x{sp.CheckCellId:X8} foot.W=({footCenter.X:F3},{footCenter.Y:F3},{footCenter.Z:F3}) foot.L=({localCenter.X:F3},{localCenter.Y:F3},{localCenter.Z:F3}) floorPolyCount={walkableCount} {nearestPart} {terrainPart}"));
|
||||
}
|
||||
|
||||
if (walkableHit)
|
||||
{
|
||||
return ValidateWalkable(
|
||||
footCenter,
|
||||
sphereRadius,
|
||||
indoorPlane,
|
||||
isWater: false,
|
||||
waterDepth: 0f,
|
||||
cellId: sp.CheckCellId,
|
||||
walkableVertices: indoorVertices);
|
||||
}
|
||||
// If no walkable floor was found under the player indoors
|
||||
// (rare — cell with only walls/ceiling), fall through to
|
||||
// outdoor terrain as a defensive backstop. Indoor walking
|
||||
// will report walkable=False until the player moves over a
|
||||
// cell with a proper floor poly.
|
||||
// The old TryFindIndoorWalkablePlane synthesis path is
|
||||
// removed here; the function definition is retained for
|
||||
// now and is deleted in A6.P4 along with the #90
|
||||
// workaround.
|
||||
//
|
||||
// If subsequent visual verification shows first-frame
|
||||
// fall-through (LKCP invalid AND no Path-6 land happens
|
||||
// for a flat-walk-only scenario), A6.P3 slice 2 adds
|
||||
// Mechanism C (retail's frames_stationary_fall flat-CP
|
||||
// synthesis at acclient_2013_pseudo_c.txt:272622+).
|
||||
return TransitionState.OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue