diff --git a/src/simulator/crates/mc-save/src/format.rs b/src/simulator/crates/mc-save/src/format.rs index 949e39dc..7f1c3e48 100644 --- a/src/simulator/crates/mc-save/src/format.rs +++ b/src/simulator/crates/mc-save/src/format.rs @@ -64,6 +64,25 @@ pub struct SaveFile { /// is consistent). #[serde(default)] pub vision_state: Option, + + /// Worldsim continuous side-state (`mc_worldsim` / `mc_ecology`). + /// + /// Carried as opaque JSON so `mc-save` stays decoupled from the ecology + /// crates (mc-save depends only on mc-core). Producers (api-gdext / + /// api-wasm / mc-worldsim) serialize their worldsim side-state — the + /// per-tile eco-damage accumulator (`eco_map: BTreeMap<(u16,u16), + /// TileEcoState>`) and the live fauna population map + /// (`tile_populations: BTreeMap<(i32,i32), Vec>`) — into a + /// single JSON object at save time and restore it on load. + /// + /// Absent in saves produced before this field was added — `#[serde(default)]` + /// reads `None`, in which case the loader rebuilds ecology from scratch via + /// emergence over the first few post-load turns (populations are lost but + /// the game state stays consistent — the same recovery path `EcologyState` + /// documented before round-trip existed). No `SAVE_FORMAT_VERSION` bump, + /// matching how `player_observations` and `vision_state` were added. + #[serde(default)] + pub worldsim_state: Option, } /// Crate-version snapshot captured at save-time. diff --git a/src/simulator/crates/mc-save/src/lib.rs b/src/simulator/crates/mc-save/src/lib.rs index 0c88d41d..6f380b72 100644 --- a/src/simulator/crates/mc-save/src/lib.rs +++ b/src/simulator/crates/mc-save/src/lib.rs @@ -25,6 +25,7 @@ //! grid: GridState::new(4, 4), //! player_observations: std::collections::HashMap::new(), //! vision_state: None, +//! worldsim_state: None, //! }; //! let bytes = save(&file).expect("serialise"); //! let reloaded = load(&bytes).expect("deserialise"); diff --git a/src/simulator/crates/mc-save/tests/round_trip.rs b/src/simulator/crates/mc-save/tests/round_trip.rs index d0d372b1..de2ad431 100644 --- a/src/simulator/crates/mc-save/tests/round_trip.rs +++ b/src/simulator/crates/mc-save/tests/round_trip.rs @@ -26,6 +26,7 @@ fn make_save(cols: i32, rows: i32) -> SaveFile { grid: GridState::new(cols, rows), player_observations: std::collections::HashMap::new(), vision_state: None, + worldsim_state: None, } }