pub struct WorldSnapshot {
pub entities: Vec<EntitySnapshot>,
pub resources: Vec<ResourceSnapshot>,
pub timestamp: f64,
pub version: u32,
pub metadata: HashMap<String, String>,
}Expand description
A complete serialized snapshot of the world state at a point in time.
This is the primary unit passed to the save/load pipeline and the checkpoint manager.
Fields§
§entities: Vec<EntitySnapshot>All entity snapshots.
resources: Vec<ResourceSnapshot>All resource snapshots.
timestamp: f64When this snapshot was taken, in seconds since some epoch (game time).
version: u32Schema version — used to detect incompatible save files.
metadata: HashMap<String, String>Free-form metadata (level name, player name, etc.).
Implementations§
Source§impl WorldSnapshot
impl WorldSnapshot
Sourcepub fn with_timestamp(self, ts: f64) -> Self
pub fn with_timestamp(self, ts: f64) -> Self
Create a snapshot with a specific timestamp.
Sourcepub fn add_entity(
&mut self,
entity_id: u64,
components: HashMap<String, SerializedValue>,
)
pub fn add_entity( &mut self, entity_id: u64, components: HashMap<String, SerializedValue>, )
Add or replace an entity snapshot.
Sourcepub fn add_entity_snapshot(&mut self, snapshot: EntitySnapshot)
pub fn add_entity_snapshot(&mut self, snapshot: EntitySnapshot)
Add an entity snapshot directly.
Sourcepub fn add_resource(
&mut self,
type_name: impl Into<String>,
value: SerializedValue,
)
pub fn add_resource( &mut self, type_name: impl Into<String>, value: SerializedValue, )
Add or replace a resource snapshot.
Sourcepub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)
Set a metadata key.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Number of entity snapshots.
Sourcepub fn resource_count(&self) -> usize
pub fn resource_count(&self) -> usize
Number of resource snapshots.
Sourcepub fn get_entity(&self, id: u64) -> Option<&EntitySnapshot>
pub fn get_entity(&self, id: u64) -> Option<&EntitySnapshot>
Find an entity snapshot by id.
Sourcepub fn get_entity_mut(&mut self, id: u64) -> Option<&mut EntitySnapshot>
pub fn get_entity_mut(&mut self, id: u64) -> Option<&mut EntitySnapshot>
Find a mutable entity snapshot by id.
Sourcepub fn get_resource(&self, type_name: &str) -> Option<&ResourceSnapshot>
pub fn get_resource(&self, type_name: &str) -> Option<&ResourceSnapshot>
Find a resource snapshot by type name.
Sourcepub fn remove_entity(&mut self, id: u64) -> bool
pub fn remove_entity(&mut self, id: u64) -> bool
Remove an entity by id. Returns true if it was found.
Sourcepub fn merge(&mut self, other: &WorldSnapshot)
pub fn merge(&mut self, other: &WorldSnapshot)
Merge other into self. Entities and resources in other override self.
Sourcepub fn diff(&self, other: &WorldSnapshot) -> SnapshotDiff
pub fn diff(&self, other: &WorldSnapshot) -> SnapshotDiff
Compute the changes from self (old) to other (new).
Sourcepub fn apply_diff(&mut self, diff: &SnapshotDiff)
pub fn apply_diff(&mut self, diff: &SnapshotDiff)
Apply a SnapshotDiff to produce an updated snapshot.
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 moreSource§impl Debug for WorldSnapshot
impl Debug for WorldSnapshot
Auto Trait Implementations§
impl Freeze for WorldSnapshot
impl RefUnwindSafe for WorldSnapshot
impl Send for WorldSnapshot
impl Sync for WorldSnapshot
impl Unpin for WorldSnapshot
impl UnsafeUnpin for WorldSnapshot
impl UnwindSafe for WorldSnapshot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.