Repository navigation
Nauvis terrain matches the game on every pixel: expression_in_range's real form (#521) - #523
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
The game's builder (NoiseExpressions::expressionInRange, read from the 2.1.23 binary with Ghidra) folds center = (from + to) / 2 and half = (to - from) / 2 into constants and evaluates half - |value - center| per dim, then the multiplier, the cap, and a min across dims starting from +inf. That equals min(value - from, to - value) in exact math, which we computed, but rounds differently in f32. A probe at the last differing Nauvis pixel, (229, -19), read the game's aux, moisture, elevation and the four grass noise layers: all matched ours. The center form then reproduces the game's grass scores at all 36 values in the 3x3 around it; the edge form matched 11. - Nauvis terrain against the game's preview: 1 -> 0 differing pixels. - The last-pixel diagnostics: grass-1 now wins by 28 ULPs on the grid kernel, and both scores are within half an ULP of the game's on the point kernel (grass-1 bit-exact). - A unit test pins the game's grass-1 score at (229, -19) and checks the edge form misses it. The zero-dimension case now returns the builder's starting +inf (unreachable: the game needs at least one dim). - Tier 2: 114 Nauvis rows re-recorded (the 19 land tiles). The 404-sample expression_in_range fixture is still exact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
Every land tile is box + noise_layer_noise(N), one f32 add in the game. The catalog added in f64 and never rounded. With the center-form box from the commit before, both grass scores at the last Nauvis pixel, (229, -19), now equal the game's bit for bit on the point kernel, and the test asserts that directly. The grid-kernel gap for grass-1 over grass-3 is 27 ULPs (was 28). Tier 2: the 19 land-tile rows re-recorded. Tier 3 and the Nauvis terrain count (0) do not move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
water_base(max_elevation, influence) is shared by the Nauvis water tiles and Fulgora's four oil-ocean tiles. Both now round each step in the Lua's order: the headroom, the product with the influence, and on Fulgora the 50 * mask * water_base * max(...) chain and deep-2's scale. Measured: Nauvis deepwater and water rows move in tier 2. Nothing on Fulgora moves: its terrain count stays 20 pixels and no Fulgora tier-2 row changes, so the ocean arithmetic is not the cause of #453. Kept because it is how the game evaluates these tiles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
scripts/probes/expression-in-range-form reads the game's aux, moisture, elevation, grass noise layers and grass scores at (229, -19) and its 3x3, then rebuilds each score from the game's own inputs in both forms. 2.1.23 build 87750: center form 36 of 36 exact, edge form 11. It writes nothing to the repo; it is what makes the unit test's pinned numbers repeatable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
ef16af3 to
7b1684b
Compare
All 19 tile ranges from tiles-vulcanus.lua, plus mountain_lava_spots, now evaluate one f32 operation at a time in the Lua's order, with each non-exact literal (0.05, 0.3, 0.15, 0.85, 0.35, 0.2, 0.8, 0.25, 0.6, 0.66, 0.01, 0.1, 1.95, 0.95, 0.4, 1.8) narrowed first. Each range's final sum is rounded too. A private range_select_base_f32 holds the f32 form of clamp(min(input - from, to - input) / slope, lo, hi); the shared f64 helper is left alone. Vulcanus tile ranges use no expression_in_range builtin, so the center/half-width form (#523) does not apply. Tier 1: tile argmax 374/381, saves-surface-seed 368/381 and lava classification 49/49 with 0 mismatches do not move. The last-pixel argmax gap moves 19,301 -> 19,300 ULPs. On the point kernel warm stays exact to the game and cracks moves -60,387 -> -60,388 ULPs (grid shift 627 -> 628). The 60k cracks gap is not step rounding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
Stacked on #522. Its base is
nauvis-f32-fields, so this diff shows only the four commits below. Merge #522 first.The Nauvis terrain preview now matches the game's own preview on every pixel: 0 of 1,048,576 differ, down from 1.
What was wrong
After #522, the last differing pixel was (229, -19): we drew grass-3 and the game drew grass-1. A new probe read the game's own values at that tile. Its aux, moisture, elevation and the four grass noise layers all matched ours bit for bit, so the inputs were not the problem. The scores built from them were.
The cause was
expression_in_range, the builtin that turns aux and moisture into a tile's score. We computed each dimension asmin(value - from, to - value). Ghidra on the 2.1.23 binary (NoiseExpressions::expressionInRange) shows the game builds it differently:The two are equal in exact math. In f32 they are not, because
value - centersubtracts a far-away number and rounds differently. The existing 404-point fixture could not see this: its ranges are centred on 0 or have exact f32 bounds, where both forms agree.The evidence
From
scripts/probes/expression-in-range-form, which rebuilds each grass score from the game's own inputs at the pixel and its 8 neighbours:Because every input is the game's, only the form can separate the two, so this check could have gone either way.
Commits
expression_in_rangein the center form. Nauvis terrain 1 -> 0. A unit test pins the game's grass-1 score at (229, -19) and checks the old form misses it. 114 Nauvis tier-2 rows (the 19 land tiles) re-recorded. The 404-point fixture stays exact.box + noise_layerrounded to f32. With this, both grass scores equal the game's bit for bit on the point kernel, and the test asserts that directly.water_baseand Fulgora's ocean test in f32. Nauvis water rows move. Nothing on Fulgora moves: its terrain count stays 20 and no Fulgora row changes. So the ocean arithmetic is not Fulgora terrain: factorio.extm.dev misses 4 pixels to our 22, and the sets do not overlap #453's cause. Kept because it is how the game evaluates these tiles.Only Nauvis tiles call
expression_in_rangein the game's Lua, so no other planet's tiles change.Checks
cargo test(fmw-noise): 537 passed.pnpm vp test, full suite, after each commit: green once the Nauvis tier-2 section was re-recorded.pnpm run verifyon the head: exit 0 in 6m26s on hammond.cargo denyskipped there (not installed); CI runs it.#400's table is updated for the new Nauvis count. #521 tracks the remaining f64 arithmetic.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Kd6o1cBoAGaJ1FoYPm6arC
Summary by CodeRabbit
Bug Fixes
Documentation