XSharp

Local terrain edits and state restoration

The level loader deliberately shares scene/block templates. Runtime destruction must change a placed cell rather than editing one of those templates. Use Layout.SetMapLocal(position, preparedMap) for that operation. SetMap retains its template-editing semantics for existing construction/editor callers.

The first edit to a placed scene copies its block references; the first edit to a placed block copies its map references. Other cells keep the original nodes. Already prepared maps, tiles, palettes and textures are reused. A rendered copy builds derived geometry once, then refreshes changed blocks. No asset file, ROM, manifest or audio decoder is opened. Derived scene/block nodes are pooled across restores so repeated loads do not continually grow the registries.

BaseEngine.ResolveLevelMap(tilemapName, sourceMapId, background) resolves through the loaded atlas offset. A visible source map zero may follow a reserved transparent slot; adding raw source IDs to the layout registry is therefore incorrect. The lookup validates the source tilemap extent and uses prepared data only.

Igloo destruction and the Penguin demo’s door panels now use placed-map edits. Penguin door coordinates and source map selections are unchanged. The Flame Pillar adapter under development depends on this API for its two floor patches.

State format

New level states begin with xsharp-state:terrain-v4, two JSON arrays of changed placed cells (foreground/background), and the existing session-v3 or combat-v2 payload. Changes contain map IDs and row/column coordinates, never graphics or executable types. All coordinates, IDs and duplicate cells are validated before applying a saved layout patch. Restoring an empty set restores the shared baseline. The existing session-v3/combat-v2/legacy paths remain readable. New terrain-bearing states require an engine which understands this envelope; this does not guarantee arbitrary historical snapshots with different entity types can load.

Validation on 2026-11-17

Fifteen focused map/reader cases passed: isolation across shared scenes and blocks, rendered-copy initialization/refresh, repeated reset/restore without registry growth, invalid saved edits rejected before layout mutation, coordinate/ownership validation, and source map lookup with a reserved atlas slot. The existing Igloo punch test also passed. The separate in-progress Flame Pillar tests are not a completed integration claim for that actor.

The real DX9 Penguin smoke --penguin 0 --local-map-state passed with changes in both layouts, unrelated alias cells preserved, a full state round trip, authored open-door restoration, the previous v3 session envelope accepted and the same 175 prepared audio cache entries. This is a rendering/backend/state smoke, not a full stage playthrough or emulator parity claim.