pub struct WorldSnapshot {Show 13 fields
pub version: u32,
pub tick: u64,
pub dt: f64,
pub entities: Vec<EntitySnapshot>,
pub groups: Vec<GroupSnapshot>,
pub stop_lookup: BTreeMap<StopId, usize>,
pub metrics: Metrics,
pub metric_tags: MetricTags,
pub extensions: BTreeMap<String, BTreeMap<EntityId, String>>,
pub ticks_per_second: f64,
pub hall_calls: Vec<HallCall>,
pub arrival_log: ArrivalLog,
pub arrival_log_retention: ArrivalLogRetention,
}Expand description
Serializable snapshot of the entire simulation state.
Capture via Simulation::snapshot()
and restore via WorldSnapshot::restore(). The game chooses the serde format
(RON, JSON, bincode, etc.).
Determinism: the map fields below all use BTreeMap instead of
HashMap so postcard/RON/JSON serialize entries in a deterministic
(key-sorted) order. With HashMap, two snapshots of the same sim
taken in different processes produced different bytes, defeating
content-addressed caching and bit-equality replay (#254).
Extension components are included (via extensions); games must
register types via register_ext before restore() to materialize them.
Custom resources inserted via world.insert_resource are NOT
snapshotted — only the built-in MetricTags resource is captured
in metric_tags. Games using custom resources must save and restore
them out-of-band (#296).
Fields§
§version: u32Schema version of this snapshot. Bumped on incompatible changes
to the snapshot layout. Loading a snapshot whose version differs
from the current crate’s expected version returns
SimError::SnapshotVersion.
Legacy snapshots default to 0 (#295).
tick: u64Current simulation tick.
dt: f64Time delta per tick.
entities: Vec<EntitySnapshot>All entities indexed by position in this vec.
EntityIds are regenerated on restore.
groups: Vec<GroupSnapshot>Elevator groups (references into entities by index).
stop_lookup: BTreeMap<StopId, usize>Stop ID → entity index mapping. BTreeMap for deterministic
snapshot bytes across processes (#254).
metrics: MetricsGlobal metrics at snapshot time.
Per-tag metric accumulators and entity-tag associations.
extensions: BTreeMap<String, BTreeMap<EntityId, String>>Serialized extension component data: name → (EntityId → RON string).
Both maps are BTreeMap for deterministic snapshot bytes (#254).
ticks_per_second: f64Ticks per second (for TimeAdapter reconstruction).
hall_calls: Vec<HallCall>All pending hall calls across every stop. Absent in legacy snapshots.
arrival_log: ArrivalLogRolling per-stop arrival log. Empty in legacy snapshots; on
restore the log’s (tick, stop) entries have their stop IDs
remapped through id_remap so they line up with the newly
allocated entity IDs.
arrival_log_retention: ArrivalLogRetentionRetention window for the arrival log (ticks). Captured so a
host-configured value (e.g. via
Simulation::set_arrival_log_retention_ticks) survives
snapshot round-trip; legacy snapshots default to
DEFAULT_ARRIVAL_WINDOW_TICKS.
Implementations§
Source§impl WorldSnapshot
impl WorldSnapshot
Sourcepub fn restore(
self,
custom_strategy_factory: Option<&'_ dyn Fn(&str) -> Option<Box<dyn DispatchStrategy>>>,
) -> Result<Simulation, SimError>
pub fn restore( self, custom_strategy_factory: Option<&'_ dyn Fn(&str) -> Option<Box<dyn DispatchStrategy>>>, ) -> Result<Simulation, SimError>
Restore a simulation from this snapshot.
Built-in strategies (Scan, Look, NearestCar, ETD) are auto-restored.
For Custom strategies, provide a factory function that maps strategy
names to instances. Pass None if only using built-in strategies.
§Errors
Returns SimError::UnresolvedCustomStrategy
if a snapshot group uses a Custom strategy and the factory returns None.
To restore extension components, call
Simulation::load_extensions_with
on the returned simulation.
Trait Implementations§
Source§impl Clone for WorldSnapshot
impl Clone for WorldSnapshot
Source§fn clone(&self) -> WorldSnapshot
fn clone(&self) -> WorldSnapshot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more