From 92e95bea53b581196e043b72117dbd881d4eca50 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 23 Jun 2026 00:23:15 +0200 Subject: [PATCH] chore: strip world-load deep-dive diagnostic probes Removes the scenery-frame, building-reach, and stream-resid probes added during the world-load/FPS deep-dive (all root-caused + fixed). Gated-off diagnostics only; no behavior change. The fixes they found remain. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/AcDream.App/Rendering/GameWindow.cs | 80 ----------- src/AcDream.Core/Physics/CellTransit.cs | 21 --- src/AcDream.Core/Physics/PhysicsDataCache.cs | 6 - .../Physics/PhysicsDiagnostics.cs | 135 ------------------ 4 files changed, 242 deletions(-) diff --git a/src/AcDream.App/Rendering/GameWindow.cs b/src/AcDream.App/Rendering/GameWindow.cs index d238c75f..6d78d60b 100644 --- a/src/AcDream.App/Rendering/GameWindow.cs +++ b/src/AcDream.App/Rendering/GameWindow.cs @@ -805,18 +805,6 @@ public sealed class GameWindow : IDisposable private int _liveCenterY; private uint _liveEntityIdCounter = 1_000_000u; // well above any dat-hydrated id - // Trees-in-sky probe (2026-06-22 — REMOVABLE apparatus, see - // PhysicsDiagnostics.ProbeSceneryFrameEnabled). The streaming worker records - // here, per landblock, the _liveCenter it baked scenery against at BUILD time; - // ApplyLoadedTerrainLocked reads it back to compare against the APPLY-time - // center. Written/read only when the probe is on, so this stays empty in - // normal play. - private readonly System.Collections.Concurrent.ConcurrentDictionary - _sceneryBuildCenterByLandblock = new(); - - // Floating-terrain probe throttle (REMOVABLE, see PhysicsDiagnostics.ProbeStreamResidEnabled). - private int _residAuditTick; - // K-fix1 (2026-04-26): cached at startup so per-frame branches are // single-flag reads instead of env-var lookups. True iff // ACDREAM_LIVE=1 was set when the window came up. @@ -6039,13 +6027,6 @@ public sealed class GameWindow : IDisposable (lbY - _liveCenterY) * 192f, 0f); - // Trees-in-sky probe (REMOVABLE): stamp the streaming center this scenery - // was baked against. ApplyLoadedTerrainLocked compares it to the apply-time - // center; a delta is the frame split that floats trees. Capture is the exact - // _liveCenter used in lbOffset above (the worker-thread read). - if (AcDream.Core.Physics.PhysicsDiagnostics.ProbeSceneryFrameEnabled) - _sceneryBuildCenterByLandblock[lb.LandblockId] = (_liveCenterX, _liveCenterY); - // Per-landblock id namespace. Landblock IDs are formatted 0xXXYYFFFF // where XX = landblock X coord (bits 24-31), YY = Y coord (bits 16-23). // Both must go into our ID so landblocks don't collide. @@ -6055,7 +6036,6 @@ public sealed class GameWindow : IDisposable uint lbYByte = (lb.LandblockId >> 16) & 0xFFu; uint sceneryIdBase = 0x80000000u | (lbXByte << 16) | (lbYByte << 8); uint localIndex = 0; - bool loggedStaleZ = false; // trees-in-sky probe: one [scenery-z-stale] line per lb foreach (var spawn in spawns) { @@ -6134,20 +6114,6 @@ public sealed class GameWindow : IDisposable float groundZ = SampleTerrainZ(lb.Heightmap, _heightTable, localX, localY); float finalZ = groundZ + spawn.LocalPosition.Z; - // Trees-in-sky probe (REMOVABLE — strip after verification). Proves the fix: - // compute what the OLD global physics query WOULD have returned and compare - // to the own-heightmap groundZ we now use. A large divergence is the stale- - // neighbor altitude the old code floated scenery to — and no longer does. - if (!loggedStaleZ - && AcDream.Core.Physics.PhysicsDiagnostics.ProbeSceneryFrameEnabled - && _physicsEngine.SampleTerrainZ(worldPx, worldPy) is { } wouldBePhysicsZ - && System.MathF.Abs(wouldBePhysicsZ - groundZ) > 5f) - { - AcDream.Core.Physics.PhysicsDiagnostics.LogSceneryZStale( - lb.LandblockId, worldPx, worldPy, wouldBePhysicsZ, groundZ); - loggedStaleZ = true; - } - // Issue #48 diagnostic. One log line per (spawn, rendered-mesh) // disambiguates H1 (BaseLoc.Z / mesh-zMin per-species), H2 // (physics-vs-bilinear sampler drift), and H3 (DIDDegrade slot 0). @@ -6698,33 +6664,6 @@ public sealed class GameWindow : IDisposable (lbY - _liveCenterY) * 192f, 0f); - // Trees-in-sky probe (REMOVABLE): compare the streaming center this - // landblock's SCENERY was baked against (worker, build time) to the center - // its TERRAIN is being placed against here (render, apply time). A non-zero - // deltaLB is the frame split that floats scenery off its terrain. - if (AcDream.Core.Physics.PhysicsDiagnostics.ProbeSceneryFrameEnabled) - { - var bc = _sceneryBuildCenterByLandblock.TryGetValue(lb.LandblockId, out var c) - ? c : (_liveCenterX, _liveCenterY); - AcDream.Core.Physics.PhysicsDiagnostics.LogSceneryFrame( - lb.LandblockId, bc.Item1, bc.Item2, _liveCenterX, _liveCenterY); - _sceneryBuildCenterByLandblock.TryRemove(lb.LandblockId, out _); - } - - // Floating-terrain probe (REMOVABLE): this landblock is being APPLIED at the - // current center; if its Chebyshev distance from the center exceeds the streaming - // window, it's an in-flight load from a PREVIOUS center applying against the new - // one — it will render far off at the horizon (a floating "terrain trace"). - if (AcDream.Core.Physics.PhysicsDiagnostics.ProbeStreamResidEnabled - && _streamingController is not null) - { - int applyCheby = System.Math.Max( - System.Math.Abs(lbX - _liveCenterX), System.Math.Abs(lbY - _liveCenterY)); - if (applyCheby > _streamingController.FarRadius) - AcDream.Core.Physics.PhysicsDiagnostics.LogApplyOob( - lb.LandblockId, applyCheby, _streamingController.FarRadius, origin.X, origin.Y); - } - // Phase A.5 T15/T16: route through AddLandblockWithMesh — the named // two-tier entry point. Delegates to AddLandblock internally; both // paths share one GPU upload path. @@ -7673,25 +7612,6 @@ public sealed class GameWindow : IDisposable foreach (var entity in rescued) _worldState.AppendLiveEntity(centerLb, entity); } - - // Floating-terrain probe (REMOVABLE): ~2×/sec, list resident landblocks sitting - // OUTSIDE the streaming window (Chebyshev > FarRadius from the current center) — - // stale old-location terrain that never unloaded. Same thread as the Tick above, - // so LoadedLandblockIds is stable. Zero cost when the probe is off. - if (AcDream.Core.Physics.PhysicsDiagnostics.ProbeStreamResidEnabled - && (++_residAuditTick % 30 == 0)) - { - var oob = new List(); - foreach (var id in _worldState.LoadedLandblockIds) - { - int lx = (int)((id >> 24) & 0xFFu), ly = (int)((id >> 16) & 0xFFu); - if (System.Math.Max(System.Math.Abs(lx - _liveCenterX), System.Math.Abs(ly - _liveCenterY)) - > _streamingController.FarRadius) - oob.Add(id); - } - AcDream.Core.Physics.PhysicsDiagnostics.LogResidentAudit( - _liveCenterX, _liveCenterY, _worldState.LoadedLandblockIds.Count, oob); - } } // Drain pending live-session traffic AFTER streaming so any incoming diff --git a/src/AcDream.Core/Physics/CellTransit.cs b/src/AcDream.Core/Physics/CellTransit.cs index 61c7efc6..a5977dd3 100644 --- a/src/AcDream.Core/Physics/CellTransit.cs +++ b/src/AcDream.Core/Physics/CellTransit.cs @@ -859,27 +859,6 @@ public static class CellTransit if (PhysicsDiagnostics.ProbeCellSetEnabled) PhysicsDiagnostics.LogCellSetBuild(currentCellId, worldSphereCenter, candidates); - // Lost-collision probe (REMOVABLE): in a landblock that HAS cached buildings, - // report which of them are reachable from the player's swept candidate set. - // reachable=NO while standing at a wall ⇒ the building IS cached but the - // post-teleport cell resolution excludes its landcell (#145); empty cachedInLb - // ⇒ the landblock's CacheBuilding never ran. One line per walk, near buildings. - if (PhysicsDiagnostics.ProbeBuildingReachEnabled) - { - uint prefix = currentCellId & 0xFFFF0000u; - var cachedInLb = new List(); - foreach (var bid in cache.BuildingIds) - if ((bid & 0xFFFF0000u) == prefix) cachedInLb.Add(bid); - var inSet = new List(); - for (int ci = 0; ci < candidates.Count; ci++) - { - uint cid = candidates.OrderedIds[ci]; - if ((cid & 0xFFFFu) < 0x0100u && cache.GetBuilding(cid) is not null) - inSet.Add(cid); - } - PhysicsDiagnostics.LogBuildingReach(currentCellId, candidates.Count, cachedInLb, inSet); - } - // THE PICK — verbatim CObjCell::find_cell_list containing-cell pick // (pseudo_c:308788-308825): iterate the array IN ORDER from index 0; for each // cell, point_in_cell; set the running result on ANY containing cell; diff --git a/src/AcDream.Core/Physics/PhysicsDataCache.cs b/src/AcDream.Core/Physics/PhysicsDataCache.cs index b3f1044e..7218e016 100644 --- a/src/AcDream.Core/Physics/PhysicsDataCache.cs +++ b/src/AcDream.Core/Physics/PhysicsDataCache.cs @@ -441,12 +441,6 @@ public sealed class PhysicsDataCache public void CacheBuilding(uint landcellId, IReadOnlyList portals, Matrix4x4 worldTransform, uint modelId = 0u) { - // Lost-collision probe (REMOVABLE): record every cache attempt + whether it - // actually took (first-wins) so we can see if/when a landblock's buildings - // get cached after a teleport. - AcDream.Core.Physics.PhysicsDiagnostics.LogBuildingCache( - landcellId, cached: !_buildings.ContainsKey(landcellId)); - if (_buildings.ContainsKey(landcellId)) return; Matrix4x4.Invert(worldTransform, out var inverse); _buildings[landcellId] = new BuildingPhysics diff --git a/src/AcDream.Core/Physics/PhysicsDiagnostics.cs b/src/AcDream.Core/Physics/PhysicsDiagnostics.cs index d75e81ec..1412249c 100644 --- a/src/AcDream.Core/Physics/PhysicsDiagnostics.cs +++ b/src/AcDream.Core/Physics/PhysicsDiagnostics.cs @@ -448,138 +448,6 @@ public static class PhysicsDiagnostics $"[tp-probe] {point,-6} id=0x{id:X8} t={Environment.TickCount64} {extra}")); } - /// - /// Trees-in-sky frame-split probe (2026-06-22 — REMOVABLE apparatus). The - /// streaming worker bakes each landblock's SCENERY world position against the - /// _liveCenter that is current when it BUILDS the landblock, while the - /// render thread positions that landblock's TERRAIN against the - /// _liveCenter that is current when it APPLIES it. A teleport recenters - /// _liveCenter between those two moments, so a landblock built before the - /// recenter and applied after it has its scenery offset from its terrain by - /// deltaLB × 192m in XY — the "arc of trees floating in the sky" after a - /// teleport. When enabled, BuildSceneryEntitiesForStreaming records the - /// build-time center and ApplyLoadedTerrainLocked emits one - /// [scenery-frame] line per landblock comparing build vs apply center; a - /// non-zero deltaLB on a misplaced landblock confirms the mechanism. - /// Initial state from ACDREAM_PROBE_SCENERY_FRAME=1. Zero cost when off. - /// - public static bool ProbeSceneryFrameEnabled { get; set; } = - Environment.GetEnvironmentVariable("ACDREAM_PROBE_SCENERY_FRAME") == "1"; - - /// - /// One [scenery-frame] line. Self-guards on - /// . A non-zero deltaLB means this - /// landblock's scenery was baked against a different streaming center than its - /// terrain was applied against — the trees-in-sky frame split. - /// - public static void LogSceneryFrame( - uint landblockId, int buildCx, int buildCy, int applyCx, int applyCy) - { - if (!ProbeSceneryFrameEnabled) return; - int dx = buildCx - applyCx, dy = buildCy - applyCy; - Console.WriteLine(System.FormattableString.Invariant( - $"[scenery-frame] lb=0x{landblockId:X8} build=({buildCx},{buildCy}) apply=({applyCx},{applyCy}) deltaLB=({dx},{dy}) offsetM=({dx * 192f:F1},{dy * 192f:F1})")); - } - - /// - /// One [scenery-z-stale] line (self-guards on - /// ). Emitted when, at scenery build, the - /// physics-engine terrain sample (SampleTerrainZ, which searches ALL - /// registered landblocks) disagrees materially with the landblock's OWN - /// heightmap. That divergence means the physics query resolved the world point - /// into a STALE neighbor landblock — the previous location's terrain, still - /// registered after a teleport recenter (which removes only the single stale - /// center landblock) until streaming unloads it — and returned ITS height. The - /// scenery is then planted at the old location's altitude: trees-in-sky. The - /// own-heightmap value () is the correct Z. - /// - public static void LogSceneryZStale( - uint landblockId, float worldX, float worldY, float physicsZ, float ownZ) - { - if (!ProbeSceneryFrameEnabled) return; - Console.WriteLine(System.FormattableString.Invariant( - $"[scenery-z-stale] lb=0x{landblockId:X8} world=({worldX:F1},{worldY:F1}) physicsZ={physicsZ:F2} ownZ={ownZ:F2} deltaZ={physicsZ - ownZ:F2}")); - } - - /// - /// Lost-building-collision probe (2026-06-22 — REMOVABLE apparatus). Building - /// WALL collision is the dat-baked PhysicsDataCache.CacheBuilding channel - /// (first-wins, never removed), reached at resolve time only when a candidate - /// landcell in the player's swept cell-walk hits GetBuilding(cellId). When - /// enabled: [bldg-cache] logs each CacheBuilding (CACHED vs first-wins - /// skip) so we can see whether/when a landblock's buildings cache; and - /// [bldg-reach] logs, per cell-walk in a landblock that HAS cached - /// buildings, which of them landed in the player's candidate set - /// (reachable=YES/NO). NO while standing at a wall ⇒ the building is cached - /// but the player's post-teleport cell resolution excludes it (#145 family); - /// empty cachedInLb ⇒ the landblock's CacheBuilding never ran (apply - /// backlog). Initial state from ACDREAM_PROBE_BLDG_REACH=1. - /// - public static bool ProbeBuildingReachEnabled { get; set; } = - Environment.GetEnvironmentVariable("ACDREAM_PROBE_BLDG_REACH") == "1"; - - public static void LogBuildingCache(uint landcellId, bool cached) - { - if (!ProbeBuildingReachEnabled) return; - Console.WriteLine(System.FormattableString.Invariant( - $"[bldg-cache] landcell=0x{landcellId:X8} {(cached ? "CACHED" : "skip(first-wins)")}")); - } - - public static void LogBuildingReach( - uint seedCell, int candidateCount, - IReadOnlyCollection cachedInLb, IReadOnlyCollection inCandidateSet) - { - if (!ProbeBuildingReachEnabled) return; - if (cachedInLb.Count == 0) return; // only interesting in a landblock with buildings - Console.WriteLine(System.FormattableString.Invariant( - $"[bldg-reach] seed=0x{seedCell:X8} cands={candidateCount} cachedInLb=[{HexList(cachedInLb)}] inSet=[{HexList(inCandidateSet)}] reachable={(inCandidateSet.Count > 0 ? "YES" : "NO")}")); - } - - private static string HexList(IReadOnlyCollection ids) - { - var sb = new System.Text.StringBuilder(); - bool first = true; - foreach (var id in ids) - { - if (!first) sb.Append(','); - sb.Append(System.FormattableString.Invariant($"0x{id:X8}")); - first = false; - } - return sb.ToString(); - } - - /// - /// Floating-terrain probe (2026-06-22 — REMOVABLE apparatus). The thin terrain - /// "traces" at the horizon after rapid multi-hop teleporting are landblocks rendering - /// at a STALE world position — their Chebyshev distance from the current streaming - /// center exceeds the window (FarRadius), so their world origin is off by the teleport - /// distance. When enabled: [apply-oob] fires when a landblock is APPLIED while - /// out-of-window (an in-flight load from a PREVIOUS center, applied against the new one); - /// [resid-audit] (throttled) lists every RESIDENT landblock sitting out-of-window - /// (un-cleared old-location terrain that never unloaded). A persistent non-zero - /// outOfWindow count is the floating terrain; whether it arrives via apply-oob or - /// lingers as residents tells us which mechanism. Initial state from - /// ACDREAM_PROBE_STREAM_RESID=1. - /// - public static bool ProbeStreamResidEnabled { get; set; } = - Environment.GetEnvironmentVariable("ACDREAM_PROBE_STREAM_RESID") == "1"; - - public static void LogApplyOob(uint landblockId, int cheby, int farRadius, float ox, float oy) - { - if (!ProbeStreamResidEnabled) return; - Console.WriteLine(System.FormattableString.Invariant( - $"[apply-oob] lb=0x{landblockId:X8} cheby={cheby} (>{farRadius}) origin=({ox:F0},{oy:F0}) — applied OUTSIDE the streaming window (in-flight stale-location apply)")); - } - - public static void LogResidentAudit( - int centerX, int centerY, int residentTotal, IReadOnlyCollection outOfWindow) - { - if (!ProbeStreamResidEnabled) return; - if (outOfWindow.Count == 0) return; // only interesting when stale terrain is resident - Console.WriteLine(System.FormattableString.Invariant( - $"[resid-audit] center=({centerX},{centerY}) resident={residentTotal} outOfWindow={outOfWindow.Count} oob=[{HexList(outOfWindow)}]")); - } - /// /// A6.P3 issue #98 step-walk investigation (2026-05-23). When true, /// emits one [step-walk] line at selected points in the transition @@ -707,9 +575,6 @@ public static class PhysicsDiagnostics ProbeSweptEnabled = false; ProbeStepWalkEnabled = false; ProbeTeleportEnabled = false; - ProbeSceneryFrameEnabled = false; - ProbeBuildingReachEnabled = false; - ProbeStreamResidEnabled = false; // Side-channel fields LastBspHitPoly = null;