pub fn structure_view(sim: &Simulation) -> Vec<f64>Expand description
The structural snapshot as one flat number array.
Header (STRUCTURE_HEADER slots): the tower revision, the room count, the
run count, the shaft count, the highest and the lowest floor any unit
stands on with floor 1 always counted (so 1 on an empty tower), read from
the tower’s cached floor bounds (Tower::floor_bounds, which
highest_floor and lowest_floor answer from), then the game mode and
the Modern calendar as codes (layout::MODES, layout::CALENDARS) and
the seed the tower was founded with (rng.initial_seed, a u32, whole in
an f64), all three fixed when the tower was founded and carried here so
a host reads them with the structure it reads at load. Then the rooms
(ROOM_RECORD each: id, kind code, floor, x, width), in the order of the
rooms index: the room in slot k is the one a dynamic frame’s record with
slot k describes. Then the floor and lobby tiles as runs (RUN_RECORD
each: kind code, floor, x, width, count, then the five frame fields every
tile of the run holds), ordered by floor and then x, so every tile is in
exactly one run, and maximal: no run continues the one before it. A run
carries no ids: a host that needs a tile’s id asks for the unit at its
floor and x. Then every transport (SHAFT_FIXED plus its skipped floors:
id, kind code, x, width, bottom, top, cars, the skip count, then the
skipped floors as the save carries them).
A field belongs here only if every write to it moves the revision. The
tiles’ frame fields are here on the strength of the view freshness test
(oracle_tests.rs), which fails if one changes with the revision still.
A host reads it when it starts on an engine (a load or an attach builds a new tower, whose revision starts over) and whenever the frame header’s tower revision moves. The unit count, which the dynamic frame’s reader also keys on, moves only with the revision.
One pass over the units (the runs) and one over the rooms index, plus a
sort of the runs when a floor was built in several drags (at most
run_limit of them; a list more scattered than that is read off the
grid in one more pass); the floor bounds and the rooms index are the
tower’s per-revision caches, shared with every other reader. The output
is allocated once, after the walk, at its size. A read for each
revision, too slow for each frame.