#119-residual ROOT CAUSE: the +0.02 m render lift leaked into the portal-visibility graph - horizontal portals side-culled anyone standing on them

The live capture pinned it end to end. BuildInteriorEntitiesForStreaming
lifts the render-side cell transform +0.02 m Z (shell z-fighting vs
terrain - a DRAW concern) and passed that LIFTED transform to
BuildLoadedCell, so every plane in the visibility graph sat 2 cm high.
The portal side test's in-plane window is +-10 mm: an eye standing ON a
floor containing a HORIZONTAL portal (the tower's deck lip 010A->0107,
stair landings, cellar mouths) sits 0-10 mm above the TRUE plane = 10-20
mm BELOW the lifted plane -> outside the window -> the cell behind the
portal side-culled out of the flood. Captured live at the stair top:
root=0xAAB3010A eye z=126.803 vs the portal plane at 126.80, flood=1,
0x0107 (the whole tower interior incl. the staircase) dropped WHILE THE
GAZE LOOKED STRAIGHT AT IT - "stairs disappear and you can walk on
them", and the roof/edge flap as the gaze swung the marginal admissions.
Vertical doorways were immune (the lift slides their planes along
themselves) - exactly why this hit stairs/decks/floors and not doors.

Chase chain (the apparatus did all the work): [viewer] print-on-change
probe with eye@mm -> the user's climb capture -> [viewer-diff] naming
the dropped cells per flip -> headless replay of the exact captured
(eye,fwd) frame: healthy UNLIFTED, reproduces ONLY with the production
lift -> gate-by-gate diagnostic (side test dot=+0.003 unlifted vs
-0.017 lifted; clip + rescue exonerated; knife-edge z-sweep all-stable,
killing the float-chaos theory).

Fix: BuildLoadedCell receives the PHYSICS (unlifted) transform; the
drawn shells keep their lift. The seal/punch fans (which read the
visibility LoadedCell's WorldTransform) now stamp TRUE depth - MORE
consistent with the unlifted terrain they protect.

Pins: CapturedTopOfStairs_MainCellStaysInFlood - arm 1 (unlifted =
post-fix production) asserts the main cell admitted at the captured
frame; arm 2 (lifted) is the mechanism canary asserting the drop, with
instructions if it ever starts passing. Plus the gate-by-gate
diagnostic + knife-edge sweep as the investigation record.

Also this session: Issue127FloodFlipReplayTests (the captured 4 cm
outdoor flip pair replays STABLE across fovs/pre-gate arms - the
outdoor churn is NOT the flood math; remaining #127 = distant-building
admission churn, lower priority now that the tower-cell drops are
explained by the lift), and the [viewer-diff] probe (per-flip added/
removed cell naming - keep, it found this).

Suites: App 242+1skip, Core 1422+2skip, UI 420, Net 294.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-11 19:26:06 +02:00
parent cd12d3dbbc
commit f35cb8b164
4 changed files with 448 additions and 4 deletions

View file

@ -247,6 +247,176 @@ public class TowerAscentReplayTests
$"{flips.Count} root ping-pongs along a monotone ascent — knife-edge root decisions (see output)");
}
/// <summary>
/// THE captured top-of-stairs vanish (flap-diff-capture.log, live user
/// pan): root=0xAAB3010A (the roof-lip cell), eye 3 mm above its floor
/// portal plane, gazing DOWN at the staircase — and the flood admitted
/// ONLY {010A}: 0x0107 (the whole tower interior, staircase included)
/// dropped while being looked straight at. Exact production inputs:
/// eye=(301.448,-128.448,126.803) fwd=(-0.9361,-0.2459,-0.2514)
/// eye=(301.371,-128.401,126.807) fwd=(-0.8938,-0.3596,-0.2678)
/// The 010A→0107 portal is HORIZONTAL at z≈126.8 — the eye rides within
/// millimetres of its plane at the stair top, knife-edge projection
/// territory (the #120 family's geometry, admission-side).
/// </summary>
[Theory]
[InlineData(301.448f, -128.448f, 126.803f, -0.9361f, -0.2459f, -0.2514f)]
[InlineData(301.371f, -128.401f, 126.807f, -0.8938f, -0.3596f, -0.2678f)]
public void CapturedTopOfStairs_MainCellStaysInFlood(
float ex, float ey, float ez, float fx, float fy, float fz)
{
var datDir = CornerFloodReplayTests.ResolveDatDir();
if (datDir is null) { _out.WriteLine("SKIP: dats unavailable"); return; }
using var dats = new DatCollection(datDir, DatAccessType.Read);
var cells = Issue120ReciprocalPingPongTests.LoadAllInteriorCells(dats, Landblock);
Func<uint, LoadedCell?> lookup = id => cells.TryGetValue(id, out var c) ? c : null;
// The capture is A9B4-anchored world; the loaded cells are AAB3-local
// (LoadCell without offset). AAB3 = A9B4 + (1,-1) blocks → local =
// world - (192,-192,0).
var eye = new Vector3(ex - 192f, ey + 192f, ez);
var fwd = Vector3.Normalize(new Vector3(fx, fy, fz));
// ROOT CAUSE (found via this capture): production fed BuildLoadedCell
// the +0.02 m RENDER-LIFTED transform ("keep the small render lift out
// of physics", GameWindow:5567) — the visibility graph's HORIZONTAL
// portal planes all sat 2 cm high, so an eye standing on the deck
// (3 mm above the TRUE plane) was 17 mm BELOW the lifted plane —
// outside the side test's ±10 mm in-plane window → 010A→0107
// side-culled → the staircase vanished while walkable. FIXED: the
// visibility LoadedCell now gets the PHYSICS (unlifted) transform.
//
// Arm 1 (unlifted = post-fix production): the main cell must be
// admitted. Arm 2 (lifted = the old bug, kept as the mechanism
// canary): the main cell is dropped — if this arm ever starts
// PASSING, the in-plane window has changed enough to absorb a 2 cm
// lift; re-evaluate both this canary and the no-lift rule.
foreach (bool lift in new[] { false, true })
{
var armCells = lift ? new Dictionary<uint, LoadedCell>() : cells;
if (lift)
{
var datDir2 = CornerFloodReplayTests.ResolveDatDir()!;
using var dats2 = new DatCollection(datDir2, DatAccessType.Read);
var lbi = dats2.Get<DatReaderWriter.DBObjs.LandBlockInfo>(Landblock | 0xFFFEu)!;
for (uint low = 0x0100u; low < 0x0100u + lbi.NumCells; low++)
{
try { armCells[Landblock | low] = CornerFloodReplayTests.LoadCell(dats2, Landblock | low, new Vector3(0f, 0f, 0.02f)); }
catch (InvalidOperationException) { }
}
}
Func<uint, LoadedCell?> armLookup = id => armCells.TryGetValue(id, out var c) ? c : null;
var root = armCells[Landblock | 0x010Au];
foreach (float fov in new[] { MathF.PI / 3f, 1.2f, MathF.PI / 2f })
{
var view = Matrix4x4.CreateLookAt(eye, eye + fwd * 3f, Vector3.UnitZ);
var proj = Matrix4x4.CreatePerspectiveFieldOfView(fov, 1280f / 720f, 0.1f, 5000f);
var pv = PortalVisibilityBuilder.Build(root, eye, armLookup, view * proj);
bool hasMain = pv.CellViews.ContainsKey(MainCell);
_out.WriteLine(FormattableString.Invariant(
$"lift={lift} fov={fov:F2}: flood={pv.OrderedVisibleCells.Count} hasMain={hasMain}"));
if (!lift)
Assert.True(hasMain,
$"fov={fov:F2}: the tower main cell 0x{MainCell:X8} is NOT in the flood from the roof-lip root (unlifted = post-fix production)");
else
Assert.False(hasMain,
$"fov={fov:F2}: the LIFTED canary unexpectedly admits the main cell — the in-plane window now absorbs a 2 cm lift; re-evaluate the canary + the no-lift rule");
}
}
}
/// <summary>
/// Gate-by-gate diagnosis of the captured drop: for the 010A→0107 portal
/// at the exact captured eye/gaze, print each admission gate's verdict —
/// side test (CameraOnInteriorSide replica), homogeneous clip vs the
/// full-screen view (ProjectToClip + ClipToRegion, the forward-hop
/// pipeline), and the eye-in-opening rescue inputs (perp distance +
/// footprint containment).
/// </summary>
[Fact]
public void Diagnostic_TopOfStairs_GateByGate()
{
var datDir = CornerFloodReplayTests.ResolveDatDir();
if (datDir is null) { _out.WriteLine("SKIP: dats unavailable"); return; }
using var dats = new DatCollection(datDir, DatAccessType.Read);
var cells = Issue120ReciprocalPingPongTests.LoadAllInteriorCells(dats, Landblock);
var root = cells[Landblock | 0x010Au];
// capture eye converted to the cells' AAB3-local frame (world - (192,-192,0))
var eye = new Vector3(301.448f - 192f, -128.448f + 192f, 126.803f);
var fwd = Vector3.Normalize(new Vector3(-0.9361f, -0.2459f, -0.2514f));
var view = Matrix4x4.CreateLookAt(eye, eye + fwd * 3f, Vector3.UnitZ);
var proj = Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 3f, 1280f / 720f, 0.1f, 5000f);
var viewProj = view * proj;
for (int i = 0; i < root.Portals.Count; i++)
{
var portal = root.Portals[i];
var poly = i < root.PortalPolygons.Count ? root.PortalPolygons[i] : null;
_out.WriteLine($"portal[{i}] -> 0x{portal.OtherCellId:X4} polyLen={poly?.Length ?? -1}");
if (poly is null || poly.Length < 3) continue;
// gate 1: side test (CameraOnInteriorSide replica, ε=0.01 in-plane-allowed)
string side = "no-plane(allow)";
if (i < root.ClipPlanes.Count && root.ClipPlanes[i].Normal.LengthSquared() >= 1e-8f)
{
var plane = root.ClipPlanes[i];
var localCam = Vector3.Transform(eye, root.InverseWorldTransform);
float dot = Vector3.Dot(plane.Normal, localCam) + plane.D;
bool pass = plane.InsideSide == 0 ? dot >= -0.01f : dot <= 0.01f;
side = FormattableString.Invariant($"dot={dot:F4} insideSide={plane.InsideSide} -> {(pass ? "TRAVERSE" : "CULL")}");
}
_out.WriteLine($" side: {side}");
// gate 2: homogeneous clip vs the full-screen view
var clip = PortalProjection.ProjectToClip(poly, root.WorldTransform, viewProj);
var fullScreen = new[] { new Vector2(-1f, -1f), new Vector2(1f, -1f), new Vector2(1f, 1f), new Vector2(-1f, 1f) };
var region = clip.Length >= 3 ? PortalProjection.ClipToRegion(clip, fullScreen) : Array.Empty<Vector2>();
_out.WriteLine($" clip: projVerts={clip.Length} regionVerts={region.Length}");
// gate 3: rescue inputs — perp distance to the portal plane + the
// perpendicular foot inside the opening's footprint
var centroid = Vector3.Zero;
foreach (var v in poly) centroid += Vector3.Transform(v, root.WorldTransform);
centroid /= poly.Length;
var n0 = Vector3.Transform(poly[0], root.WorldTransform);
var n1 = Vector3.Transform(poly[1], root.WorldTransform);
var n2 = Vector3.Transform(poly[2], root.WorldTransform);
var planeN = Vector3.Normalize(Vector3.Cross(n1 - n0, n2 - n0));
float perp = MathF.Abs(Vector3.Dot(planeN, eye - centroid));
_out.WriteLine(FormattableString.Invariant(
$" rescue: perpDist={perp:F4} centroid=({centroid.X:F2},{centroid.Y:F2},{centroid.Z:F2}) planeN=({planeN.X:F2},{planeN.Y:F2},{planeN.Z:F2})"));
}
// knife-edge sweep: the probe rounds the eye to mm — sweep z within the
// rounding envelope and count clip flips for the 010A→0107 portal. A
// chaotic 6↔0 region inside ±2 mm proves the live drop is the same
// frame at sub-mm precision.
{
var poly = root.PortalPolygons[0];
var fullScreen = new[] { new Vector2(-1f, -1f), new Vector2(1f, -1f), new Vector2(1f, 1f), new Vector2(-1f, 1f) };
int flips = 0;
bool? prev = null;
var results = new System.Text.StringBuilder();
for (int i = -20; i <= 20; i++)
{
var e2 = eye with { Z = eye.Z + i * 0.0002f };
var v2 = Matrix4x4.CreateLookAt(e2, e2 + fwd * 3f, Vector3.UnitZ);
var vp2 = v2 * proj;
var clip2 = PortalProjection.ProjectToClip(poly, root.WorldTransform, vp2);
var region2 = clip2.Length >= 3 ? PortalProjection.ClipToRegion(clip2, fullScreen) : Array.Empty<Vector2>();
bool ok = region2.Length >= 3;
if (prev.HasValue && ok != prev.Value) flips++;
prev = ok;
results.Append(ok ? '1' : '0');
}
_out.WriteLine($" knife-edge sweep (z ±4 mm, 0.2 mm steps): {results} flips={flips}");
}
}
/// <summary>Full per-step table for the investigation record.</summary>
[Fact]
public void Diagnostic_TowerAscent_PerStepTable()