fix: lift the 64-upgrader wall, save format v3 - #16
Merged
Conversation
MAX_UPGRADERS was 64 because Item.upgraded_mask (the "which upgraders have already lifted this ore" set) was a single u64. That made the 65th upgrader in the WHOLE world a silent rejection, with MAX_ENTITIES at 10000 and the largest region at 128x128. The cap sat in the middle of the intended late game. The mask is now u64[UPGRADER_WORDS] and the cap is 256. An ore's mask goes 8 -> 32 bytes, so items[1024] grows 48KB -> 72KB, against the 512KB of grids already in World. The word/bit split lives in mask_test/mask_set/mask_clear and is not open-coded anywhere, because an id >= 64 in the old `(u64)1 << id` is undefined rather than visibly wrong. Save format v3. v1 and v2 files still load: the two bitmaps were one u64 there, and the only ids such a file can name are 0..63, so they widen into word 0. This is the first change to the byte layout, so it is the first version the reader branches on. Two latent load bugs on the same path, fixed here: An upgrader_id was never validated on load. A corrupt file with an id past the cap shifted out of range the first time an ore touched that upgrader. It now fails the load. An upgrader dropped by the placement check (off-grid or occupied cell) leaked its id forever, because the id bitmap was restored wholesale from the file. The bitmap is now rebuilt from the upgraders that actually land, so it describes exactly the world that exists. A duplicate id fails the load rather than gating two upgraders on one bit. Covered by a headless probe: 256 place and the 257th is rejected, an upgrader with an id past word 0 lifts the ceiling exactly once and climbs on re-pass, a v3 file round-trips bits in all four words, a real v2 file written by the pre-change binary still loads with its masks in word 0, and a corrupt id fails.
This was referenced Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MAX_UPGRADERSwas 64 becauseItem.upgraded_mask(the "which upgraders have already lifted this ore" set) was a singleu64. The 65th upgrader in the whole world was a silent rejection, withMAX_ENTITIESat 10000 and the largest region at 128x128 = 16384 cells. Upgraders are the game's core verb, so the cap was a design wall sitting in the middle of the intended late game.The change
u64 upgraded_mask[UPGRADER_WORDS], cap 256. An ore's mask goes 8 -> 32 bytes, soitems[1024]grows 48KB -> 72KB, against the 512KB of grids already inWorldmask_test/mask_set/mask_clearin world.c. Not open-coded anywhere: the old(u64)1 << idis undefined for an id >= 64, not visibly wrong, which is exactly the bug a naive widening leaves behindu64there and the only ids such a file can name are 0..63, so they widen into word 0. This is the first change to the byte layout, so it is the first version the reader actually branches onTwo latent load bugs on the same path, fixed here
upgrader_idwas never validated on load, so a corrupt file with an id past the cap shifted out of range the first time an ore touched that upgraderVerification
Headless probe over world.c + save.c:
./nob releaseand./nob gameclean under-Wall -Wextra; release binary runs without a crash.Note: this changes the layout of
ItemandWorld, so a running./nob hotneeds a full restart, not a reload.