Bindings: Dungeon handle for dungeon.dat and the magic map #443

Closed
opened 2026-10-30 23:28:23 +01:00 by jqueuniet · 0 comments
Owner

Follow-up to #440. The dungeon.dat bindings are free functions that each detect and parse the dungeon, and the magic-map ones also parse graphics.dat (8.6 MB on DOS), on every call. Rendering every map or level of a dungeon re-parses both files once per call; through wasm, both files are also copied into WASM memory each time.

Proposal

The #440 shape for dungeons:

  • A Dungeon handle (wasm class, opaque FFI Dm2Dungeon *, Python class), built once from the bytes.
  • Methods with one options object each, as GraphicsArchive:
Method Options Replaces
toJson() — dungeon_to_json
skprojectJson() — dungeon_skproject_json
mapLayout(map) / levelLayout(level) — dungeon_map_layout_json / dungeon_level_layout_json
mapPng(map, graphics) / levelPng(level, graphics) scale (1), creatures (true), fill (true) dungeon_map_png / dungeon_level_png
mapChips(map, graphics) / levelChips(level, graphics) fill (true), language (en) dungeon_map_chips_json / dungeon_level_chips_json
  • The magic-map methods take a GraphicsArchive, not bytes, so neither file is parsed per call.
  • Remove the replaced free functions. dungeon_from_json stays free: it builds bytes from JSON and parses no dungeon.
  • As in #440: one PR adding the handle (additive), one removing the free functions.

Acceptance

  • Outputs byte-identical to the current functions for the same arguments.
  • Rendering every DOS level through one Dungeon and one GraphicsArchive is measurably faster than through the free functions in wasm (numbers in the PR).
  • Adding an option changes no signature.

Out of scope

The save editor functions (save_to_json_full, save_from_json_full, save_inventory_json, save_container_*, save_item_*, item_catalog_json, skill_title_json) also re-parse graphics.dat (and dungeon.dat) per call; taking these handles instead is a separate issue.

https://claude.ai/code/session_01SnENBXnZbhNNrojZT5jbJ7

Follow-up to #440. The `dungeon.dat` bindings are free functions that each detect and parse the dungeon, and the magic-map ones also parse `graphics.dat` (8.6 MB on DOS), on every call. Rendering every map or level of a dungeon re-parses both files once per call; through wasm, both files are also copied into WASM memory each time. ## Proposal The #440 shape for dungeons: - A `Dungeon` handle (wasm class, opaque FFI `Dm2Dungeon *`, Python class), built once from the bytes. - Methods with one options object each, as `GraphicsArchive`: | Method | Options | Replaces | |---|---|---| | `toJson()` | — | `dungeon_to_json` | | `skprojectJson()` | — | `dungeon_skproject_json` | | `mapLayout(map)` / `levelLayout(level)` | — | `dungeon_map_layout_json` / `dungeon_level_layout_json` | | `mapPng(map, graphics)` / `levelPng(level, graphics)` | `scale` (1), `creatures` (`true`), `fill` (`true`) | `dungeon_map_png` / `dungeon_level_png` | | `mapChips(map, graphics)` / `levelChips(level, graphics)` | `fill` (`true`), `language` (`en`) | `dungeon_map_chips_json` / `dungeon_level_chips_json` | - The magic-map methods take a `GraphicsArchive`, not bytes, so neither file is parsed per call. - Remove the replaced free functions. `dungeon_from_json` stays free: it builds bytes from JSON and parses no dungeon. - As in #440: one PR adding the handle (additive), one removing the free functions. ## Acceptance - Outputs byte-identical to the current functions for the same arguments. - Rendering every DOS level through one `Dungeon` and one `GraphicsArchive` is measurably faster than through the free functions in wasm (numbers in the PR). - Adding an option changes no signature. ## Out of scope The save editor functions (`save_to_json_full`, `save_from_json_full`, `save_inventory_json`, `save_container_*`, `save_item_*`, `item_catalog_json`, `skill_title_json`) also re-parse `graphics.dat` (and `dungeon.dat`) per call; taking these handles instead is a separate issue. https://claude.ai/code/session_01SnENBXnZbhNNrojZT5jbJ7
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools#443
No description provided.