wasm: a save's live dungeon as layout and chips #482
Labels
No labels
area/ci-release
area/cli
area/docs
area/dungeon
area/ftl
area/graphics
area/gui
area/music
area/saves
area/tooling
port/amiga
port/dos
port/fm-towns
port/mac
port/pc98
port/sega-cd
priority/high
priority/low
priority/medium
type/bug
type/chore
type/docs
type/feature
type/research
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jqueuniet/dm2-tools#482
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?
A save holds the live dungeon: its own
map_dataand object chains, with doors opened, creatures moved or killed, items dropped.DungeonFile.levelLayoutandlevelChipsonly read dungeon.dat, so a browser cannot show the save's state.Wanted on
SaveGame(with context):levelLayout(level)andlevelChips(level, options), same JSON asDungeonFile's, read from the save's state and its graphics.dat. dm2-magicmap draws from aDungeon, so this likely needs one built over the save'smap_dataand objects.The web editor shows this in its Dungeon tab when a save is open, beside dungeon.dat as shipped, and later edits on it: party, doors, floor items, creatures.
#482 — a save's live dungeon as layout and chips
Intent
A save holds the live dungeon: doors opened, creatures moved or killed, items
dropped.
DungeonFile.levelLayout/levelChipsonly readdungeon.dat. Theweb editor's Dungeon tab wants the same views of an open save, beside the
shipped dungeon, and later of its edits (party, doors, floor items, creatures).
Goals
SaveGame.levelLayout(level, options)andSaveGame.levelChips(level, options)(wasm), same JSON asDungeonFile's, drawn from the save's stateand the
GraphicsArchivethe save keeps.dm2_save_game_level_layout,_level_chips): bindingsfeatures land on both.
stream overlay included (user's call). Stale creatures, wrong door states and
missing dropped items are all failures.
SaveGameshow in the next call.Non-goals
mapLayout/mapChips/mapPng/levelPngonSaveGame(trivial toadd later on the same base).
DungeonFile's.NoContext.Anti-goals
dm2-magicmapto know about saves. It draws aDungeon; we give itone.
dm2-savesinternals fromdm2-convertor the bindings:convert calls one
dm2-savesAPI.How: a dungeon.dat image of the live state
The save's raw sections are dungeon.dat's sections in the same order
(
docs/formats/dungeon-dat.md§ File body layout):dungeon_stateis the play-time header (SgWordsmaps all 44 bytes), so thesection sizes match. The image parses with the existing
Dungeon::parse, anddm2-convertwraps it in aDungeonFileto reuselevel_layout/level_chipsunchanged.The overlay replays the engine's load (
DM2_READ_SKSAVE_DUNGEON, SKWINSPXsksvgame.cpp; per-tile loop ~L1180–1320,READ_RECORD_CHECKCODE~L830–960)from the decoded
RecordStream, perTileChain:floor_bits, mask 0x08 pit / 0x07 door / 0x04 trick wall /0x08 detail-less teleporter):
SUPPRESS_READER(tile, mask, …, argflag=false)merges, so
tile = (tile & !mask) | (bits & mask)atmap_offset + x * height + y. Mask selection is the decoder's(
decode_tile_chains); reuse it, don't restate it.existing_chain_reads): zip with the same step listthe decoder walked (
static_overlay_steps, Beta pair-fold included) to geteach read's
(rec_type, rec_index). Body merges byte-wise with the mask thedecoder used (
select_object_mask(tile_chain_body_mask(…))):rec = (rec & !mask) | body.actuator_extrareplacesw_02bits 7..15(
w_02 = (w_02 & 0x7f) | (v << 7)), in the save's byte order, before thebody merge (engine order).
appended_records): the engine frees the raw dynamictail and allocates fresh records from the stream. We instead use R≡C
(
docs/formats/save-placement-linkage.md): the raw chain's dynamic tail,in order, is the stream's
appended_records. Walk it withTileChainWalkerand write eachCheckcodeRecord's body into its raw slot,keeping the raw link words (
next_oid; possession head of types 4/9/14).Recurse
sub_recordsonto the raw possession chain the same way. Sidefields the stream carries apart from
data(creatureai_spec_flags,chest class) go back into their bytes as
read_chaintakes them out; useCheckcodeRecord::decode_object's view of the record where it alreadydoes so. A count or type mismatch between the raw chain and the stream is
an error, never a silent partial image.
Back-link teleporter tiles (
should_read_chain == false) are left as raw, likethe engine.
Where it lives
dm2-saves:SaveDump::live_dungeon(&self, map_info: &DungeonMapInfo) -> Result<Vec<u8>, JsonError>(name is the builder's call), full dumps only(
WrongVariantotherwise). Built fromraw+record_stream, no bitstreamre-encode. Walker map info from the save's
map_data(
SaveFile::save_map_infologic).dm2-convert:SaveGame::level_layout(level, &LayoutOptions)andlevel_chips(level, &ChipsOptions), reusingDungeonFile's option types.Each call builds the image and a
DungeonFilefrom it: no cache, so editsshow at once. A cache invalidated on edit is the builder's call if a call
proves slow on the 4 MB DOS dump; measure first.
dm2-wasm/dm2-ffi: thin wrappers, doc comments as onDungeonFile.TS option types are
LayoutOptions/ChipsOptions.crates/dm2-wasm/README.md,CHANGELOG.md: document the two methods.Tests
Fixtures:
dos-en/saves/sksave*.dat,mac-us/saves/*,dos-en-betasaves.levelLayout/levelChipssucceed for every level of everyfixture save.
from raw
map_data, and a tile whose creature/item set differs fromdungeon.dat, show the save's state (pick concrete tiles while building).SaveGameedit touches the map yet (allare held-item edits), so test at the
dm2-saveslevel:add_objecton aSaveFileFull→SaveDump::full→ image shows the item.NoContext.dm2_save_game_*calls.Left to the builder
Function names, error variant names, internal module split, test tile picks,
whether a no-overlay helper is exposed for tests.