Campaign OVERHAUL S3 chunk 1 fix round 1 (docs/research/2026-09-01-overhaul/
s3-walk-ownership-map.md §11.5), applied on top of 079483bb6 after the
three-lens review. G1-G10, each verified against source and (where the item
adds a pin) mutation-checked.
G1 — the flag-off integration test was vacuous: Collect_TranscriptFlagOff_
ProducesNoConsoleOutput drove ONE frame, and WalkOracleTrace.Parse
structurally discards the last (open) frame, so it passed whether or not
the flag gate worked. Now drives TWO frames and asserts BOTH that Parse
sees zero frames AND that no captured line starts with any of the ten
transcript-kind prefixes (F /P /LS/LC /SC /BLD /DI /DC /EC /OC ) — robust
to unrelated console noise from parallel test classes.
G2 — LC/SC computed LodCellId before testing the flag (~1,300 land-cell
turns/frame of division/modulo/checked-conversion work paid even when the
flag is off). Both OnLandCellTurn and the new OnSortCellTurn now guard the
LodCellId call itself, not just WalkTranscriptDump's internal check.
G3 — the flag-on round trip never exercised LC/SC/BLD (the T2 fixture's
stub 1x1 landscape has zero blocks). New
OutdoorRoot_TranscriptFlagOn_PrintsLandscapeThenLandCellThenSortCellThen
Building_InOrder drives RetailFrameWalk.DrawLandscape directly (the same
deterministic "CY-only" admission technique the existing outdoor LandCell
test uses) over a landscape with one block + one building, and asserts
LS < LC < SC < BLD by position, with the exact cell/building ids.
G4 — the parts/alpha-depth smoke tests asserted FL/PC (Flushes/
DrawCellsSamples) but never AM/PM (MeshAdds/PortalPolyDraws) for the
alpha-depth log, even though PD/DM were already asserted for the parts
log. Added the missing Assert.Contains for MeshAdds and PortalPolyDraws.
G5 — launch-options.md's side-effects column now states the flag off/on
costs explicitly ("one bool read per print site, nothing else" / "one
console line per walk turn, ≈600-800 lines per outdoor frame").
G6 — removed the "DI f4180108... no, a9b4013f" self-correction in
Oh_doorway_still_first_frame_diff's comment; added a one-line note on why
it and Oh_foundry_deep_... stay bespoke Facts rather than folding into the
Theory (no functional reason, just history).
G7 — SC printed from OnLandscapeCellTurn, which RetailFrameWalk.
DrawLandscape calls AFTER DrawBuilding — retail's own order is
LC -> SC -> BLD (terrace-edge.walk.log:2331-2333), not LC -> BLD -> SC.
Fixed by adding IWalkEventSink.OnSortCellTurn, fired at the DrawSortCell
entry point (same alwaysDrawObjects||cellInView gate, before DrawBuilding);
the driver moves its SC print there and OnLandscapeCellTurn no longer
prints one.
G8 — the trailing "OC <viewer land cell>" retail prints once per complete
outdoor frame is GameSky::Draw's weather branch calling
DrawObjCellForDummies(after_sky_cell) @0x005070da, not a walk turn.
RetailPViewPassExecutor.DrawLandscapeSliceLate now prints it at the point
it actually calls RenderWeather; PrintObjectCellTurn's doc, which denied
this line existed, is corrected. New
Oh_terrace_edge_outdoor_frame_ends_with_the_weather_ObjectCellTurn pins
this directly against the OH capture: every complete outdoor frame's last
event is an OC whose cell id equals that same frame's own P-line cell id.
G9 — "EC and OC counts are always exactly equal per pose" was false
(terrace-edge: 12 EC vs 16 OC, the extra 4 being G8's weather OC, which
has no EC counterpart). The visit-scoped/stamp-dedupe conclusion was
right; only the count claim needed fixing. Both doc sites corrected.
G10 — the conformance signature dropped LC/SC/EC/OC entirely, which is
how G7 shipped green: no test ever compared their placement. Recorder now
tracks LC/SC via the new OnLandCellTurn/OnSortCellTurn hooks and derives
EC/OC per DC from PView::DrawCells's own two reverse loops (shell
far-to-near, then object-list far-to-near) — a look-in flood's DC derives
them immediately, the interior root's OWN flood defers to
OnInteriorFloodDrawTurn (verified against cathedral-leak.walk.log:4,1328,
where the root DC's own EC/OC print last). WalkTraceReplayContext.
Signature8 applies the identical derivation to oracle frames and never
produces the trailing weather OC (G8's own dedicated pin covers that
separately, matching the spec's "exclude from the comparison, assert
separately" instruction). Used ONLY for the four OH-capture-rooted
conformance rows (the older FW0 fixtures predate the LC/SC/EC/OC
breakpoints and carry none of those lines).
Applying the eight-kind check surfaced a real, separate bug: WalkLandscape
DatBuilder never set WalkLandBlock.LandblockId, so every LC/SC token any
DAT-built world ever produced read landblockId=0 — latent because the old
four-kind signature filtered LC/SC out. Fixed (one field, test-fixture-
only, no production behavior change). With that fixed, three of the four
OH rows (terrace-edge, cathedral-arrival, foundry-deep) reproduce EXACTLY
at the eight-kind level. Oh_doorway_still_first_frame_diff still diverges
by one extra LC/SC pair (token index 165: replay draws LC:a9c90001|
SC:a9c90001 that retail never does) — a real WalkLandscape.CheckBlocks
visibility question at a ring-2/ring-3 LOD boundary, out of this round's
print-only scope, needing the retail oracle to resolve. Marked
[Trait("Status","KnownFailure")] with the exact position recorded in its
own doc comment, matching TowerAscent's existing pattern — the InstalledDat
lane now shows FOUR known failures (the pre-existing two #383 layout tests
+ TowerAscent, plus this new finding), not three; never weakened the pin
itself.
Mutation checks (all four restored after observing the failure):
- G1: forcing WalkTranscriptDump.Enabled true made
Collect_TranscriptFlagOff_ProducesNoConsoleOutput fail with
"Assert.DoesNotContain() Failure: Filter matched in collection ... Collection:
[\"DI 00000100\", \"DC pv=00000000 ov=1 n=2: 00000100 00000101\", \"LS\", ...]".
- G3: deleting PrintLandCell's Console.WriteLine made the new outdoor test
fail with "expected an LC line".
- G4: making MeshAddPattern unmatchable made all five
Alpha_depth_log_parses_with_nonempty_samples rows fail with
"Assert.Contains() Failure: Filter not matched in collection".
- G7/G10: moving OnSortCellTurn back after DrawBuilding made the
terrace-edge conformance row fail with "walk diverged from retail
(terrace-edge.walk)", first divergence exactly at its first building
(f518002e): expected ...SC:f518002e|BLD:f518002e..., actual
...BLD:f518002e|SC:f518002e....
Gates: hermetic lane 6,816/0 (baseline 6,814 + G3's new test + G8's new
test); InstalledDat lane 244/4 known failures (two pre-existing #383
layout tests + TowerAscent + the new Oh_doorway_still_first_frame_diff
finding, documented above).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
178 lines
8.3 KiB
C#
178 lines
8.3 KiB
C#
using System.Numerics;
|
||
using AcDream.App.Rendering.Walk;
|
||
using DatReaderWriter;
|
||
using DatReaderWriter.DBObjs;
|
||
|
||
namespace AcDream.App.Tests.Rendering.Walk;
|
||
|
||
/// <summary>
|
||
/// Campaign FW1 — assembles the replay world for outdoor/landscape
|
||
/// fixtures: retail's 11×11 viewer-centered block grid (mid_radius 5) in
|
||
/// CAMERA-BLOCK-LOCAL coordinates (the same space the pose origin and the
|
||
/// per-block corner math use), each block with its retail z-slab
|
||
/// (<c>CLandBlock::calc_lighting</c>-adjacent unpack @0x0052f1d0:
|
||
/// max_zval = heightTable[maxByte] + 200, min_zval = heightTable[minByte]
|
||
/// − 1), buildings placed at their landcell indices with landblock-local
|
||
/// transforms offset by the block delta, and every neighbor block's
|
||
/// interior cells merged into one registry.
|
||
/// </summary>
|
||
public static class WalkLandscapeDatBuilder
|
||
{
|
||
public sealed record BuiltWorld(
|
||
WalkLandscape Landscape,
|
||
Dictionary<uint, WalkCell> Cells,
|
||
Dictionary<WalkBuilding, WalkWorldDatAdapter.BuildingEntry> Buildings);
|
||
|
||
/// <summary>The capture client's live landscape grid (dumped 2026-08-30:
|
||
/// LScape mid_radius=25 → a 51×51 grid — the owner's landscape-radius
|
||
/// setting) with the resolution pyramid observed live: side_cell_count 8
|
||
/// in the 3×3 core, 4 at ring 2, 2 at rings 3–4, 1 beyond. Buildings
|
||
/// attach only to full-res blocks (the traces show no BLD beyond ±1).</summary>
|
||
public const int MidRadius = 25;
|
||
|
||
private static int SideCellCountForRing(int ring)
|
||
=> ring <= 1 ? 8 : ring == 2 ? 4 : ring <= 4 ? 2 : 1;
|
||
|
||
/// <summary>Per-frame viewer placement for moving replays (the camera
|
||
/// stays within the anchor block in every moving fixture).</summary>
|
||
public static void SetViewer(WalkLandscape landscape, uint cameraCellId, Vector3 cameraOrigin)
|
||
{
|
||
uint low = cameraCellId & 0xFFFFu;
|
||
if (low >= 1 && low <= 0x40)
|
||
{
|
||
int cellIndex = (int)low - 1;
|
||
landscape.ViewerCellX = cellIndex / 8;
|
||
landscape.ViewerCellY = cellIndex % 8;
|
||
}
|
||
else
|
||
{
|
||
landscape.ViewerCellX = Math.Clamp((int)MathF.Floor(cameraOrigin.X / 24f), 0, 7);
|
||
landscape.ViewerCellY = Math.Clamp((int)MathF.Floor(cameraOrigin.Y / 24f), 0, 7);
|
||
}
|
||
}
|
||
|
||
public static BuiltWorld Build(DatCollection dats, uint cameraCellId, Vector3 cameraOrigin = default)
|
||
{
|
||
Region region = (Region)dats.Get<Region>(0x13000000u)!;
|
||
float[] heightTable = region.LandDefs.LandHeightTable;
|
||
|
||
int cameraBlockX = (int)(cameraCellId >> 24);
|
||
int cameraBlockY = (int)((cameraCellId >> 16) & 0xFF);
|
||
const int midRadius = MidRadius;
|
||
const int midWidth = midRadius * 2 + 1;
|
||
|
||
var landscape = new WalkLandscape
|
||
{
|
||
MidWidth = midWidth,
|
||
Blocks = new WalkLandBlock?[midWidth * midWidth],
|
||
ViewerBlockX = midRadius,
|
||
ViewerBlockY = midRadius,
|
||
};
|
||
uint low = cameraCellId & 0xFFFFu;
|
||
if (low >= 1 && low <= 0x40)
|
||
{
|
||
int cellIndex = (int)low - 1;
|
||
landscape.ViewerCellX = cellIndex / 8;
|
||
landscape.ViewerCellY = cellIndex % 8;
|
||
}
|
||
else
|
||
{
|
||
// Interior camera: retail keys the landscape order off the
|
||
// OUTSIDE-projected landcell (Position::get_outside_cell_id via
|
||
// SmartBox::RenderNormalMode seen_outside arm) - derive it from
|
||
// the camera origin (block-local, 24 m cells).
|
||
landscape.ViewerCellX = Math.Clamp((int)MathF.Floor(cameraOrigin.X / 24f), 0, 7);
|
||
landscape.ViewerCellY = Math.Clamp((int)MathF.Floor(cameraOrigin.Y / 24f), 0, 7);
|
||
}
|
||
|
||
var cells = new Dictionary<uint, WalkCell>();
|
||
var buildings = new Dictionary<WalkBuilding, WalkWorldDatAdapter.BuildingEntry>();
|
||
|
||
for (int gx = 0; gx < midWidth; gx++)
|
||
{
|
||
for (int gy = 0; gy < midWidth; gy++)
|
||
{
|
||
int blockX = cameraBlockX + gx - midRadius;
|
||
int blockY = cameraBlockY + gy - midRadius;
|
||
if (blockX < 0 || blockX > 0xFF || blockY < 0 || blockY > 0xFF)
|
||
continue;
|
||
uint landblockId = (uint)((blockX << 24) | (blockY << 16));
|
||
if (dats.Get<LandBlock>(landblockId | 0xFFFFu) is not LandBlock landBlock)
|
||
continue;
|
||
|
||
byte maxByte = 0, minByte = 255;
|
||
foreach (byte h in landBlock.Height)
|
||
{
|
||
if (h > maxByte) maxByte = h;
|
||
if (h < minByte) minByte = h;
|
||
}
|
||
int ring = Math.Max(Math.Abs(gx - midRadius), Math.Abs(gy - midRadius));
|
||
int sideCellCount = SideCellCountForRing(ring);
|
||
var block = new WalkLandBlock
|
||
{
|
||
// S3 chunk 1 fix round 1 (G10): this field was never
|
||
// set — every LC/SC token this world's blocks ever
|
||
// produced read landblockId=0 (LodCellId's own
|
||
// "(landblockId & 0xFFFF0000) | ..." formula degenerates
|
||
// to a bare 8×8-bucket index), latent because the OLD
|
||
// four-kind Signature filtered LC/SC out entirely; G10's
|
||
// eight-kind comparison is the first thing that ever
|
||
// reads this field back out of a DAT-built world.
|
||
LandblockId = landblockId,
|
||
SideCellCount = sideCellCount,
|
||
MaxZ = heightTable[maxByte] + 200f,
|
||
MinZ = heightTable[minByte] - 1f,
|
||
};
|
||
block.EnsureCellArrays();
|
||
|
||
var blockOffset = new Vector3(
|
||
(gx - midRadius) * WalkLandscape.BlockLength,
|
||
(gy - midRadius) * WalkLandscape.BlockLength,
|
||
0f);
|
||
|
||
if (sideCellCount == 8)
|
||
{
|
||
foreach (WalkWorldDatAdapter.BuildingEntry entry
|
||
in WalkWorldDatAdapter.BuildBuildings(dats, landblockId))
|
||
{
|
||
Matrix4x4 world = entry.WorldTransform
|
||
* Matrix4x4.CreateTranslation(blockOffset);
|
||
Matrix4x4.Invert(world, out Matrix4x4 inverse);
|
||
var placed = new WalkWorldDatAdapter.BuildingEntry(
|
||
entry.Building, world, inverse);
|
||
buildings[entry.Building] = placed;
|
||
int cellIndex = (int)(entry.Building.PositionCellId & 0xFFFFu) - 1;
|
||
if (cellIndex >= 0 && cellIndex < 64)
|
||
block.CellBuildings[cellIndex] = entry.Building;
|
||
|
||
// Retail's loaded-interior rule (CLandBlock::init_buildings
|
||
// @0052fd80 → add_to_stablist → grab_visible_cells): a
|
||
// full-res block loads exactly its buildings' portal
|
||
// stab cells — NOT every interior. The flood halts at
|
||
// unloaded cells (GetVisible null), which is what
|
||
// limits retail's look-in punches to nearby doorways.
|
||
foreach (WalkBldPortal portal in entry.Building.Portals)
|
||
{
|
||
if (portal.OtherCellId != 0xFFFFFFFFu
|
||
&& !cells.ContainsKey(portal.OtherCellId))
|
||
{
|
||
WalkCell? c = WalkWorldDatAdapter.BuildCell(
|
||
dats, portal.OtherCellId, blockOffset);
|
||
if (c is not null) cells[c.CellId] = c;
|
||
}
|
||
foreach (uint stab in portal.StabList)
|
||
{
|
||
if (cells.ContainsKey(stab)) continue;
|
||
WalkCell? c = WalkWorldDatAdapter.BuildCell(
|
||
dats, stab, blockOffset);
|
||
if (c is not null) cells[c.CellId] = c;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
landscape.Blocks[gx * midWidth + gy] = block;
|
||
}
|
||
}
|
||
return new BuiltWorld(landscape, cells, buildings);
|
||
}
|
||
}
|