diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 3802af55dd349d..609ca15c014b06 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -138,14 +138,14 @@ macro_rules! change_detection_impl { fn is_added(&self) -> bool { self.ticks .added - .is_older_than(self.ticks.last_change_tick, self.ticks.change_tick) + .is_newer_than(self.ticks.last_change_tick, self.ticks.change_tick) } #[inline] fn is_changed(&self) -> bool { self.ticks .changed - .is_older_than(self.ticks.last_change_tick, self.ticks.change_tick) + .is_newer_than(self.ticks.last_change_tick, self.ticks.change_tick) } #[inline] @@ -653,14 +653,14 @@ impl<'a> DetectChanges for MutUntyped<'a> { fn is_added(&self) -> bool { self.ticks .added - .is_older_than(self.ticks.last_change_tick, self.ticks.change_tick) + .is_newer_than(self.ticks.last_change_tick, self.ticks.change_tick) } #[inline] fn is_changed(&self) -> bool { self.ticks .changed - .is_older_than(self.ticks.last_change_tick, self.ticks.change_tick) + .is_newer_than(self.ticks.last_change_tick, self.ticks.change_tick) } #[inline] diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index 6121de200144ed..745c75df6ff89b 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -596,8 +596,10 @@ impl Tick { } #[inline] - /// Returns `true` if the tick is older than the system last's run. - pub fn is_older_than(&self, last_change_tick: u32, change_tick: u32) -> bool { + /// Returns `true` if this `Tick` occurred since the system's `last_change_tick`. + /// + /// `change_tick` is the current tick of the system, used as a reference to help deal with wraparound. + pub fn is_newer_than(&self, last_change_tick: u32, change_tick: u32) -> bool { // This works even with wraparound because the world tick (`change_tick`) is always "newer" than // `last_change_tick` and `self.tick`, and we scan periodically to clamp `ComponentTicks` values // so they never get older than `u32::MAX` (the difference would overflow). @@ -670,13 +672,13 @@ impl ComponentTicks { #[inline] /// Returns `true` if the component was added after the system last ran. pub fn is_added(&self, last_change_tick: u32, change_tick: u32) -> bool { - self.added.is_older_than(last_change_tick, change_tick) + self.added.is_newer_than(last_change_tick, change_tick) } #[inline] /// Returns `true` if the component was added or mutably dereferenced after the system last ran. pub fn is_changed(&self, last_change_tick: u32, change_tick: u32) -> bool { - self.changed.is_older_than(last_change_tick, change_tick) + self.changed.is_newer_than(last_change_tick, change_tick) } pub(crate) fn new(change_tick: u32) -> Self { diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index a067acbd89932e..a9e831c2c9c9f4 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -509,7 +509,7 @@ macro_rules! impl_tick_filter { .debug_checked_unwrap() .get(table_row.index()) .deref() - .is_older_than(fetch.last_change_tick, fetch.change_tick) + .is_newer_than(fetch.last_change_tick, fetch.change_tick) } StorageType::SparseSet => { let sparse_set = &fetch @@ -518,7 +518,7 @@ macro_rules! impl_tick_filter { $get_sparse_set(sparse_set, entity) .debug_checked_unwrap() .deref() - .is_older_than(fetch.last_change_tick, fetch.change_tick) + .is_newer_than(fetch.last_change_tick, fetch.change_tick) } } }