Skip to main content

WorldSnapshot

Struct WorldSnapshot 

Source
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: u32

Schema 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: u64

Current simulation tick.

§dt: f64

Time 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: Metrics

Global metrics at snapshot time.

§metric_tags: MetricTags

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: f64

Ticks per second (for TimeAdapter reconstruction).

§hall_calls: Vec<HallCall>

All pending hall calls across every stop. Absent in legacy snapshots.

§arrival_log: ArrivalLog

Rolling 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: ArrivalLogRetention

Retention 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

Source

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

Source§

fn clone(&self) -> WorldSnapshot

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorldSnapshot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WorldSnapshot

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for WorldSnapshot

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,