chore(phys): A6.P3 #98 triage — revert neg-poly + bldg-check experiments

Triage step from the plan at C:\Users\erikn\.claude\plans\
i-did-some-work-sharded-acorn.md. Four sessions on issue #98 left the
worktree dirty with ~1352 LOC of mixed work. This commit splits the
work into "keep" (defensible + diagnostic) and "drop" (failed
experiments), then commits the keep set with the drops removed.

Plan asked for three commits (diag / fix / revert); consolidated to one
because the diagnostic emits in TransitionTypes.cs are tightly
interleaved with the multi-sphere CellTransit calls and the CellId
switch. Hunk-level splitting in those files for marginal bisect
granularity didn't justify the misclick risk.

Reverted entirely (failed experiments per slice 7 handoff):
- src/AcDream.Core/Physics/PhysicsDataCache.cs — neg-poly storage
  fields (Stippling, PosSurface, NegSurface, HasNegativeSide,
  IsNegativeSide, NegativeSide).
- src/AcDream.Core/Physics/ShadowObjectRegistry.cs — isBuilding flag
  propagation through Register / ShadowEntry.
- tests/AcDream.Core.Tests/Physics/BSPQueryTests.cs — 165 lines of
  PolygonWithNegativeSide_* tests.
- tests/AcDream.Core.Tests/Physics/ShadowObjectRegistryTests.cs —
  isBuilding propagation tests.
- src/AcDream.Core/World/WorldEntity.cs — IsLandblockBuilding field
  (no consumer once ShadowObjectRegistry.isBuilding is gone).
- src/AcDream.Core/World/LandblockLoader.cs — IsLandblockBuilding=true
  setter on building entities (kept BuildBuildingTerrainCells).
- src/AcDream.App/Rendering/GameWindow.cs — isBuilding: arg passed to
  ShadowObjects.Register.
- src/AcDream.Core/Physics/BSPQuery.cs — TryAdjustWalkableSide /
  IsWalkableAt helpers, their callers, the Path 5 / Path 6 neg-poly
  branch split, the BldgCheck-tied clearCell conditional, and the
  neg-poly ResolveCellPolygons writes.
- src/AcDream.Core/Physics/PhysicsDiagnostics.cs — neg-poly fields
  in the poly-dump format.
- src/AcDream.Core/Physics/TransitionTypes.cs — SpherePath.BldgCheck +
  SpherePath.HitsInteriorCell fields and every consumer, the
  savedBldgCheck try/finally around FindCollisions, and the neg-poly
  format additions to the dump-on-error helper.
- src/AcDream.Core/Physics/CellTransit.cs — FindCellSet overloads
  with hitsInteriorCell out-param and the BuildCellSetAndPickContaining
  out-param threading.

Kept (defensible correctness fixes + diagnostic infrastructure):
- src/AcDream.App/Rendering/GameWindow.cs — render-vs-physics cell
  origin split: the 0.02m render lift no longer leaks into physics
  BSP caching. lb.BuildingTerrainCells threaded into LandblockMesh.Build.
- src/AcDream.Core/World/LoadedLandblock.cs — BuildingTerrainCells
  record field.
- src/AcDream.Core/World/LandblockLoader.cs — BuildBuildingTerrainCells
  (cy*8+cx from LandBlockInfo.Buildings).
- src/AcDream.Core/Terrain/LandblockMesh.cs — hiddenTerrainCells
  param that collapses owned-cell triangles to a zero-area degenerate.
- src/AcDream.App/Streaming/{GpuWorldState,LandblockStreamer}.cs —
  mechanical BuildingTerrainCells threading through LoadedLandblock
  reconstructions.
- src/AcDream.Core/Physics/CellTransit.cs — multi-sphere
  FindTransitCellsSphere variant + multi-sphere AddAllOutsideCells +
  FindCellSet(IReadOnlyList<Sphere>, …) overload + the
  BSPQuery.SphereIntersectsCellBsp call for loaded neighbours. Matches
  retail CObjCell::find_cell_list / CEnvCell::find_transit_cells.
- src/AcDream.Core/Physics/TransitionTypes.cs — multi-sphere FindCellSet
  call site, retail-faithful CellId switch after CheckOtherCells, the
  outdoor-landcell terrain-walkable fallback in CheckOtherCells, and
  the full diagnostic suite ([step-walk], [walkable-nearest],
  [issue98-walkable-detail], [cell-set-summary], LastBspHitPoly
  emits).
- src/AcDream.Core/Physics/PhysicsDiagnostics.cs — ProbeStepWalkEnabled
  gate (ACDREAM_PROBE_STEP_WALK=1) + LogStepWalk helper + FormatVector
  / FormatPlane utilities. All emit-gated.
- src/AcDream.Core/Physics/BSPQuery.cs — diagnostic emits to
  LastBspHitPoly at four sites in SphereIntersectsPolyInternal /
  the placement adjustment path.
- Test files for the kept work: CellTransitFindCellSetTests,
  CellTransitFindTransitCellsSphereTests, PhysicsDiagnosticsTests,
  TransitionCheckOtherCellsTests, LandblockMeshTests,
  LandblockLoaderTests.

Verification:
- dotnet build: green, 0 errors, 3 pre-existing warnings.
- dotnet test: 1156 passed + 8 failed (baseline was 1148 + 8 pre-
  existing; the +8 passing are the new tests for the kept defensible
  work). Same 8 pre-existing failures, no new regressions.

Backup of pre-triage worktree state in stash@{0}.

A6.P3 #98 is still open; this is the apparatus-prep step, not a fix.
Next: cell-dump probe (Step 2 of the plan).
This commit is contained in:
Erik 2026-05-23 15:11:49 +02:00
parent 111aa3e59d
commit 35b37dfb5f
16 changed files with 930 additions and 58 deletions

View file

@ -378,6 +378,23 @@ public static class PhysicsDiagnostics
public static bool ProbePlacementFailEnabled { get; set; } =
Environment.GetEnvironmentVariable("ACDREAM_PROBE_PLACEMENT_FAIL") == "1";
/// <summary>
/// A6.P3 issue #98 step-walk investigation (2026-05-23). When true,
/// emits one <c>[step-walk]</c> line at selected points in the transition
/// sub-step loop and step-down probe. The line records requested vs
/// adjusted offset, current/check sphere position, cell id, walk interp,
/// contact planes, and walkable flags so a cellar-ramp capture can answer
/// whether forward motion is being projected into rising Z or lost before
/// the placement check.
///
/// <para>
/// Initial state from <c>ACDREAM_PROBE_STEP_WALK=1</c>. One-shot
/// diagnostic; no DebugPanel mirror until the root cause is identified.
/// </para>
/// </summary>
public static bool ProbeStepWalkEnabled { get; set; } =
Environment.GetEnvironmentVariable("ACDREAM_PROBE_STEP_WALK") == "1";
/// <summary>
/// Side-channel populated by <c>BSPQuery.SphereIntersectsSolidInternal</c>
/// at the leaf where it returns true. Either
@ -549,6 +566,82 @@ public static class PhysicsDiagnostics
primaryCellId, otherCellId, bspResult, halted));
}
/// <summary>
/// Emit one <c>[step-walk]</c> line for issue #98's cellar-ramp
/// investigation. Caller MUST guard with
/// <c>if (!ProbeStepWalkEnabled) return;</c> before calling.
/// </summary>
public static void LogStepWalk(
string site,
int stepIndex,
int stepCount,
SpherePath sp,
CollisionInfo ci,
ObjectInfo oi,
Vector3 requestedOffset,
Vector3 adjustedOffset,
TransitionState? state = null,
string? detail = null)
{
var culture = System.Globalization.CultureInfo.InvariantCulture;
var checkDelta = sp.CheckPos - sp.CurPos;
string stateText = state.HasValue ? state.Value.ToString() : "n/a";
string stepText = stepIndex >= 0 && stepCount > 0
? string.Format(culture, "{0}/{1}", stepIndex + 1, stepCount)
: "-";
Console.WriteLine(string.Format(culture,
"[step-walk] site={0} step={1} state={2} " +
"cur=({3:F4},{4:F4},{5:F4}) check=({6:F4},{7:F4},{8:F4}) " +
"delta=({9:F4},{10:F4},{11:F4}) cell=0x{12:X8}->0x{13:X8} " +
"req=({14:F4},{15:F4},{16:F4}) adj=({17:F4},{18:F4},{19:F4}) " +
"winterp={20:F4} stepUp={21} stepDown={22} insert={23} " +
"oi=0x{24:X} contact={25} onWalkable={26} " +
"cp={27} lkcp={28} hit={29} slide={30} walkPoly={31} lastWalkPoly={32}{33}",
site, stepText, stateText,
sp.CurPos.X, sp.CurPos.Y, sp.CurPos.Z,
sp.CheckPos.X, sp.CheckPos.Y, sp.CheckPos.Z,
checkDelta.X, checkDelta.Y, checkDelta.Z,
sp.CurCellId, sp.CheckCellId,
requestedOffset.X, requestedOffset.Y, requestedOffset.Z,
adjustedOffset.X, adjustedOffset.Y, adjustedOffset.Z,
sp.WalkInterp,
sp.StepUp, sp.StepDown, sp.InsertType,
(uint)oi.State, oi.Contact, oi.OnWalkable,
FormatPlane(ci.ContactPlaneValid, ci.ContactPlane, ci.ContactPlaneCellId, ci.ContactPlaneIsWater),
FormatPlane(ci.LastKnownContactPlaneValid, ci.LastKnownContactPlane, ci.LastKnownContactPlaneCellId, ci.LastKnownContactPlaneIsWater),
FormatVector(ci.CollisionNormalValid, ci.CollisionNormal),
FormatVector(ci.SlidingNormalValid, ci.SlidingNormal),
sp.HasWalkablePolygon, sp.HasLastWalkablePolygon,
string.IsNullOrEmpty(detail) ? string.Empty : " " + detail));
}
private static string FormatVector(bool valid, Vector3 value)
{
if (!valid)
return "n/a";
return string.Format(System.Globalization.CultureInfo.InvariantCulture,
"({0:F4},{1:F4},{2:F4})",
value.X, value.Y, value.Z);
}
private static string FormatPlane(bool valid, Plane plane, uint cellId, bool isWater)
{
if (!valid)
return "n/a";
float zAtOrigin = MathF.Abs(plane.Normal.Z) > PhysicsGlobals.EPSILON
? -plane.D / plane.Normal.Z
: float.NaN;
return string.Format(System.Globalization.CultureInfo.InvariantCulture,
"cell=0x{0:X8},water={1},n=({2:F4},{3:F4},{4:F4}),d={5:F4},z0={6:F4}",
cellId, isWater,
plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D,
zAtOrigin);
}
public static void LogCpBoolWrite(string field, bool oldValue, bool newValue)
{
var caller = GetCpCallerName();