pub struct TrackedWorld { /* private fields */ }Expand description
A wrapper around SimpleWorld that automatically records component changes.
Similar to HookedWorld, but instead of firing callbacks, it records changes
in a ChangeTracker for later querying by systems.
§Example
use cougr_core::{SimpleWorld, runtime::TrackedWorld};
use soroban_sdk::{symbol_short, Bytes, Env};
let env = Env::default();
let world = SimpleWorld::new(&env);
let mut tracked = TrackedWorld::new(world);
let e1 = tracked.spawn_entity();
tracked.add_component(e1, symbol_short!("pos"), Bytes::new(&env));
assert!(tracked.tracker().was_added(e1, &symbol_short!("pos")));Implementations§
Source§impl TrackedWorld
impl TrackedWorld
Sourcepub fn new(world: SimpleWorld) -> Self
pub fn new(world: SimpleWorld) -> Self
Wrap a SimpleWorld with a new change tracker.
Sourcepub fn world(&self) -> &SimpleWorld
pub fn world(&self) -> &SimpleWorld
Access the underlying SimpleWorld.
Sourcepub fn world_mut(&mut self) -> &mut SimpleWorld
pub fn world_mut(&mut self) -> &mut SimpleWorld
Mutably access the underlying SimpleWorld.
Sourcepub fn tracker(&self) -> &ChangeTracker
pub fn tracker(&self) -> &ChangeTracker
Access the change tracker.
Sourcepub fn tracker_mut(&mut self) -> &mut ChangeTracker
pub fn tracker_mut(&mut self) -> &mut ChangeTracker
Mutably access the change tracker (e.g. to clear it).
Sourcepub fn into_inner(self) -> SimpleWorld
pub fn into_inner(self) -> SimpleWorld
Consume the wrapper and return the inner SimpleWorld.
Sourcepub fn spawn_entity(&mut self) -> EntityId
pub fn spawn_entity(&mut self) -> EntityId
Spawn a new entity (delegates to SimpleWorld).
Sourcepub fn add_component(
&mut self,
entity_id: EntityId,
component_type: Symbol,
data: Bytes,
)
pub fn add_component( &mut self, entity_id: EntityId, component_type: Symbol, data: Bytes, )
Add a component, recording the change.
Sourcepub fn add_component_with_storage(
&mut self,
entity_id: EntityId,
component_type: Symbol,
data: Bytes,
storage: ComponentStorage,
)
pub fn add_component_with_storage( &mut self, entity_id: EntityId, component_type: Symbol, data: Bytes, storage: ComponentStorage, )
Add a component with explicit storage kind, recording the change.
Sourcepub fn remove_component(
&mut self,
entity_id: EntityId,
component_type: &Symbol,
) -> bool
pub fn remove_component( &mut self, entity_id: EntityId, component_type: &Symbol, ) -> bool
Remove a component, recording the change.
Sourcepub fn get_component(
&self,
entity_id: EntityId,
component_type: &Symbol,
) -> Option<Bytes>
pub fn get_component( &self, entity_id: EntityId, component_type: &Symbol, ) -> Option<Bytes>
Get a component (delegates to SimpleWorld).
Sourcepub fn has_component(
&self,
entity_id: EntityId,
component_type: &Symbol,
) -> bool
pub fn has_component( &self, entity_id: EntityId, component_type: &Symbol, ) -> bool
Check if an entity has a component (delegates to SimpleWorld).
Sourcepub fn despawn_entity(&mut self, entity_id: EntityId)
pub fn despawn_entity(&mut self, entity_id: EntityId)
Despawn an entity, recording removals for each component.
Auto Trait Implementations§
impl Freeze for TrackedWorld
impl !RefUnwindSafe for TrackedWorld
impl !Send for TrackedWorld
impl !Sync for TrackedWorld
impl Unpin for TrackedWorld
impl UnsafeUnpin for TrackedWorld
impl !UnwindSafe for TrackedWorld
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, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
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.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more