pub struct ChangeTracker { /* private fields */ }Expand description
Tracks which components were added, removed, or modified within a tick.
This is a runtime-only structure (not #[contracttype]) that records
component mutations as they happen. Systems can query the tracker to
skip unchanged entities, improving performance.
§Example
use cougr_core::runtime::ChangeTracker;
use soroban_sdk::symbol_short;
let entity_id = 1;
let mut tracker = ChangeTracker::new();
tracker.record_add(entity_id, symbol_short!("pos"));
if tracker.was_added(entity_id, &symbol_short!("pos")) {
assert_eq!(tracker.change_count(), 1);
}
tracker.clear();
tracker.advance_tick();
assert_eq!(tracker.tick(), 1);Implementations§
Source§impl ChangeTracker
impl ChangeTracker
Sourcepub fn record_add(&mut self, entity_id: EntityId, component_type: Symbol)
pub fn record_add(&mut self, entity_id: EntityId, component_type: Symbol)
Record that a component was added to an entity.
Sourcepub fn record_remove(&mut self, entity_id: EntityId, component_type: Symbol)
pub fn record_remove(&mut self, entity_id: EntityId, component_type: Symbol)
Record that a component was removed from an entity.
Sourcepub fn record_modify(&mut self, entity_id: EntityId, component_type: Symbol)
pub fn record_modify(&mut self, entity_id: EntityId, component_type: Symbol)
Record that a component was modified on an entity.
Sourcepub fn was_added(&self, entity_id: EntityId, component_type: &Symbol) -> bool
pub fn was_added(&self, entity_id: EntityId, component_type: &Symbol) -> bool
Check if a specific component was added to an entity this tick.
Sourcepub fn was_removed(&self, entity_id: EntityId, component_type: &Symbol) -> bool
pub fn was_removed(&self, entity_id: EntityId, component_type: &Symbol) -> bool
Check if a specific component was removed from an entity this tick.
Sourcepub fn was_modified(&self, entity_id: EntityId, component_type: &Symbol) -> bool
pub fn was_modified(&self, entity_id: EntityId, component_type: &Symbol) -> bool
Check if a specific component was modified on an entity this tick.
Sourcepub fn added_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
pub fn added_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
Get all entity IDs that had the given component added this tick.
Sourcepub fn modified_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
pub fn modified_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
Get all entity IDs that had the given component modified this tick.
Sourcepub fn removed_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
pub fn removed_entities_with(&self, component_type: &Symbol) -> Vec<EntityId> ⓘ
Get all entity IDs that had the given component removed this tick.
Sourcepub fn advance_tick(&mut self)
pub fn advance_tick(&mut self)
Advance the tick counter by one.
Sourcepub fn change_count(&self) -> usize
pub fn change_count(&self) -> usize
Returns the total number of recorded changes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ChangeTracker
impl !RefUnwindSafe for ChangeTracker
impl !Send for ChangeTracker
impl !Sync for ChangeTracker
impl Unpin for ChangeTracker
impl UnsafeUnpin for ChangeTracker
impl !UnwindSafe for ChangeTracker
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