dm2-saves: SaveFile::tile_at / set_tile_type_attr transpose coordinates (row-major indexing into column-major map_data) #171
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
SaveFile::tile_at(sksave.rs:744) andSaveFile::set_tile_type_attr(sksave.rs:767) compute themap_dataindex asbut the on-disk tile grid is column-major (
tiles[x * height + y]), as documented indm2-dungeon(dungeon.rs, "column-major", with a dedicatedtile_at_is_column_majortest) and used consistently by every other consumer:object_place.rs:680and:857(map_offset + x * height + y)records.rsTileChainWalker(tile_record_link,chain_head_index)linkage.rsvalidate_linkageImpact
Public tile reads and edits are transposed for any tile with
x != y, and on non-square maps the index can land inside a neighboring map's data block. A caller that inspects a tile viatile_atand then acts on it via theobject_placeAPIs operates on two different tiles. Existing coverage (tests/tile_edit.rs) only probes(0, 0)— the one coordinate where the transposition is invisible.Fix
Switch both functions to
map_offset + x * height + yand extendtile_edit.rswith an asymmetric coordinate (and ideally a cross-check againstTileChainWalker/ adm2-dungeonMapBodyread of the same tile).Fixed by #209 (merged into
main).