pub struct WorldHasher { /* private fields */ }Expand description
The canonical world hash: which state the digest covers, and in what order.
The fold order is pinned in the module docs. An empty hasher digests the entity list alone, which is a real check in a game whose state is its entities, but most callers register the components and resources that decide gameplay:
let mut hasher = WorldHasher::new();
hasher.register::<Height>(|height, hash| hash.f32(height.0));
hasher.register_resource::<Score>(|score, hash| hash.u32(score.0));Implementations§
Source§impl WorldHasher
impl WorldHasher
Sourcepub fn register<C: Component>(
&mut self,
hash_value: impl Fn(&C, &mut Hash64) + Send + Sync + 'static,
) -> &mut Self
pub fn register<C: Component>( &mut self, hash_value: impl Fn(&C, &mut Hash64) + Send + Sync + 'static, ) -> &mut Self
Registers a component: one (entity, value) fold per entity that has it.
Write the value’s fields in a fixed order. A float folds its bits
(hash.f32(value)), so the sign of zero and a NaN payload are covered
exactly; a field left out is a field the digest cannot report.
Sourcepub fn register_hashed<C: Component + Hash>(&mut self) -> &mut Self
pub fn register_hashed<C: Component + Hash>(&mut self) -> &mut Self
register for a component whose own Hash
implementation is yours.
The fold is whatever Hash writes, and every integer writer is pinned by
Hash64, but a Hash impl from std or from a dependency may change
its byte layout in a later release. For a digest a save file or a golden
test pins, write the fields explicitly with
register.
Sourcepub fn register_resource<R: Resource>(
&mut self,
hash_value: impl Fn(&R, &mut Hash64) + Send + Sync + 'static,
) -> &mut Self
pub fn register_resource<R: Resource>( &mut self, hash_value: impl Fn(&R, &mut Hash64) + Send + Sync + 'static, ) -> &mut Self
Registers a resource: a presence byte, then the value hash when it exists.
Presence is state of its own, so a resource missing from one run and present in the other folds differently even when its payload is a zero.
Sourcepub fn register_hashed_resource<R: Resource + Hash>(&mut self) -> &mut Self
pub fn register_hashed_resource<R: Resource + Hash>(&mut self) -> &mut Self
register_resource for a resource whose own
Hash implementation is yours.
Sourcepub fn hash(&self, world: &World) -> u64
pub fn hash(&self, world: &World) -> u64
The canonical digest of world: one number that moves whenever any
registered state moves.
Folds in the order the module docs pin, which is not bevy_ecs’s
iteration order, so a run that reaches the same state through a different
spawn/despawn history digests the same.
Trait Implementations§
Source§impl Clone for WorldHasher
impl Clone for WorldHasher
Auto Trait Implementations§
impl !RefUnwindSafe for WorldHasher
impl !UnwindSafe for WorldHasher
impl Freeze for WorldHasher
impl Send for WorldHasher
impl Sync for WorldHasher
impl Unpin for WorldHasher
impl UnsafeUnpin for WorldHasher
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,
impl<T> ConditionalSend for Twhere
T: Send,
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>, which can then be
downcast into Box<dyn 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>, which 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.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.