Skip to content

System::check_change_tick and similar methods take CheckChangeTicks #19600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
62d3f7d
System::check_change_tick and similar methods take CheckChangeTicks
urben1680 Jun 12, 2025
a9202ce
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 12, 2025
2bd5f85
Update check_change_ticks.md
urben1680 Jun 12, 2025
ead5972
rename Tick get method of CheckChangeTicks
urben1680 Jun 12, 2025
db96322
Merge branch 'system-check-tick_takes_CheckChangeTicks' of https://gi…
urben1680 Jun 12, 2025
b6d921e
Update crates/bevy_ecs/src/component.rs
urben1680 Jun 12, 2025
40a4b41
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 12, 2025
72a7a9e
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 13, 2025
2462985
modified migration guide
urben1680 Jun 13, 2025
052688d
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 13, 2025
09be3eb
modified migration guide
urben1680 Jun 13, 2025
63f7070
Merge branch 'system-check-tick_takes_CheckChangeTicks' of https://gi…
urben1680 Jun 13, 2025
e0d6d24
Update crates/bevy_ecs/src/component.rs
urben1680 Jun 13, 2025
2b7ea28
make World::check_change_ticks return CheckChangeTicks option
urben1680 Jun 13, 2025
4d0a014
Update crates/bevy_ecs/src/observer/mod.rs
urben1680 Jun 13, 2025
68d522b
Update crates/bevy_ecs/src/world/deferred_world.rs
urben1680 Jun 13, 2025
cb036e6
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 13, 2025
4fcfc9a
Merge branch 'main' into system-check-tick_takes_CheckChangeTicks
urben1680 Jun 13, 2025
727db3b
Update release-content/migration-guides/check_change_ticks.md
urben1680 Jun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2381,12 +2381,12 @@ impl Tick {
///
/// Returns `true` if wrapping was performed. Otherwise, returns `false`.
#[inline]
pub fn check_tick(&mut self, tick: Tick) -> bool {
let age = tick.relative_to(*self);
pub fn check_tick(&mut self, check: CheckChangeTicks) -> bool {
let age = check.present_tick().relative_to(*self);
// This comparison assumes that `age` has not overflowed `u32::MAX` before, which will be true
// so long as this check always runs before that can happen.
if age.get() > Self::MAX.get() {
*self = tick.relative_to(Self::MAX);
*self = check.present_tick().relative_to(Self::MAX);
true
} else {
false
Expand Down Expand Up @@ -2415,16 +2415,16 @@ impl Tick {
/// struct CustomSchedule(Schedule);
///
/// # let mut world = World::new();
/// world.add_observer(|tick: On<CheckChangeTicks>, mut schedule: ResMut<CustomSchedule>| {
/// schedule.0.check_change_ticks(tick.get());
/// world.add_observer(|check: On<CheckChangeTicks>, mut schedule: ResMut<CustomSchedule>| {
/// schedule.0.check_change_ticks(*check);
/// });
/// ```
#[derive(Debug, Clone, Copy, Event)]
pub struct CheckChangeTicks(pub(crate) Tick);

impl CheckChangeTicks {
/// Get the `Tick` that can be used as the parameter of [`Tick::check_tick`].
pub fn get(self) -> Tick {
/// Get the present `Tick` that other ticks get compared to.
pub fn present_tick(self) -> Tick {
self.0
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub use unique_vec::{UniqueEntityEquivalentVec, UniqueEntityVec};
use crate::{
archetype::{ArchetypeId, ArchetypeRow},
change_detection::MaybeLocation,
component::Tick,
component::{CheckChangeTicks, Tick},
storage::{SparseSetIndex, TableId, TableRow},
};
use alloc::vec::Vec;
Expand Down Expand Up @@ -1216,9 +1216,9 @@ impl Entities {
}

#[inline]
pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for meta in &mut self.meta {
meta.spawned_or_despawned.at.check_tick(change_tick);
meta.spawned_or_despawned.at.check_tick(check);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/schedule/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use self::multi_threaded::{MainThreadExecutor, MultiThreadedExecutor};
use fixedbitset::FixedBitSet;

use crate::{
component::{ComponentId, Tick},
component::{CheckChangeTicks, ComponentId, Tick},
error::{BevyError, ErrorContext, Result},
prelude::{IntoSystemSet, SystemSet},
query::FilteredAccessSet,
Expand Down Expand Up @@ -204,7 +204,7 @@ impl System for ApplyDeferred {
FilteredAccessSet::new()
}

fn check_change_tick(&mut self, _change_tick: Tick) {}
fn check_change_tick(&mut self, _check: CheckChangeTicks) {}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
vec![SystemTypeSet::<Self>::new().intern()]
Expand Down
15 changes: 8 additions & 7 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use thiserror::Error;
#[cfg(feature = "trace")]
use tracing::info_span;

use crate::component::CheckChangeTicks;
use crate::{
component::{ComponentId, Components, Tick},
component::{ComponentId, Components},
prelude::Component,
query::FilteredAccessSet,
resource::Resource,
Expand Down Expand Up @@ -112,7 +113,7 @@ impl Schedules {
/// Iterates the change ticks of all systems in all stored schedules and clamps any older than
/// [`MAX_CHANGE_AGE`](crate::change_detection::MAX_CHANGE_AGE).
/// This prevents overflow and thus prevents false positives.
pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
#[cfg(feature = "trace")]
let _all_span = info_span!("check stored schedule ticks").entered();
#[cfg_attr(
Expand All @@ -127,7 +128,7 @@ impl Schedules {
let name = format!("{label:?}");
#[cfg(feature = "trace")]
let _one_span = info_span!("check schedule ticks", name = &name).entered();
schedule.check_change_ticks(change_tick);
schedule.check_change_ticks(check);
}
}

Expand Down Expand Up @@ -559,22 +560,22 @@ impl Schedule {
/// Iterates the change ticks of all systems in the schedule and clamps any older than
/// [`MAX_CHANGE_AGE`](crate::change_detection::MAX_CHANGE_AGE).
/// This prevents overflow and thus prevents false positives.
pub fn check_change_ticks(&mut self, change_tick: Tick) {
pub fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for SystemWithAccess { system, .. } in &mut self.executable.systems {
if !is_apply_deferred(system) {
system.check_change_tick(change_tick);
system.check_change_tick(check);
}
}

for conditions in &mut self.executable.system_conditions {
for system in conditions {
system.condition.check_change_tick(change_tick);
system.condition.check_change_tick(check);
}
}

for conditions in &mut self.executable.set_conditions {
for system in conditions {
system.condition.check_change_tick(change_tick);
system.condition.check_change_tick(check);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ecs/src/storage/resource.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
change_detection::{MaybeLocation, MutUntyped, TicksMut},
component::{ComponentId, ComponentTicks, Components, Tick, TickCells},
component::{CheckChangeTicks, ComponentId, ComponentTicks, Components, Tick, TickCells},
storage::{blob_vec::BlobVec, SparseSet},
};
use alloc::string::String;
Expand Down Expand Up @@ -298,9 +298,9 @@ impl<const SEND: bool> ResourceData<SEND> {
}
}

pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
self.added_ticks.get_mut().check_tick(change_tick);
self.changed_ticks.get_mut().check_tick(change_tick);
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
self.added_ticks.get_mut().check_tick(check);
self.changed_ticks.get_mut().check_tick(check);
}
}

Expand Down Expand Up @@ -393,9 +393,9 @@ impl<const SEND: bool> Resources<SEND> {
})
}

pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for info in self.resources.values_mut() {
info.check_change_ticks(change_tick);
info.check_change_ticks(check);
}
}
}
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/storage/sparse_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
change_detection::MaybeLocation,
component::{ComponentId, ComponentInfo, ComponentTicks, Tick, TickCells},
component::{CheckChangeTicks, ComponentId, ComponentInfo, ComponentTicks, Tick, TickCells},
entity::{Entity, EntityRow},
storage::{Column, TableRow},
};
Expand Down Expand Up @@ -360,8 +360,8 @@ impl ComponentSparseSet {
}
}

pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
self.dense.check_change_ticks(change_tick);
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
self.dense.check_change_ticks(check);
}
}

Expand Down Expand Up @@ -650,9 +650,9 @@ impl SparseSets {
}
}

pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for set in self.sets.values_mut() {
set.check_change_ticks(change_tick);
set.check_change_ticks(check);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_ecs/src/storage/table/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,20 @@ impl ThinColumn {
/// # Safety
/// `len` is the actual length of this column
#[inline]
pub(crate) unsafe fn check_change_ticks(&mut self, len: usize, change_tick: Tick) {
pub(crate) unsafe fn check_change_ticks(&mut self, len: usize, check: CheckChangeTicks) {
for i in 0..len {
// SAFETY:
// - `i` < `len`
// we have a mutable reference to `self`
unsafe { self.added_ticks.get_unchecked_mut(i) }
.get_mut()
.check_tick(change_tick);
.check_tick(check);
// SAFETY:
// - `i` < `len`
// we have a mutable reference to `self`
unsafe { self.changed_ticks.get_unchecked_mut(i) }
.get_mut()
.check_tick(change_tick);
.check_tick(check);
}
}

Expand Down Expand Up @@ -646,12 +646,12 @@ impl Column {
}

#[inline]
pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for component_ticks in &mut self.added_ticks {
component_ticks.get_mut().check_tick(change_tick);
component_ticks.get_mut().check_tick(check);
}
for component_ticks in &mut self.changed_ticks {
component_ticks.get_mut().check_tick(change_tick);
component_ticks.get_mut().check_tick(check);
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/storage/table/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
change_detection::MaybeLocation,
component::{ComponentId, ComponentInfo, ComponentTicks, Components, Tick},
component::{CheckChangeTicks, ComponentId, ComponentInfo, ComponentTicks, Components, Tick},
entity::Entity,
query::DebugCheckedUnwrap,
storage::{blob_vec::BlobVec, ImmutableSparseSet, SparseSet},
Expand Down Expand Up @@ -629,11 +629,11 @@ impl Table {
}

/// Call [`Tick::check_tick`] on all of the ticks in the [`Table`]
pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
let len = self.entity_count() as usize;
for col in self.columns.values_mut() {
// SAFETY: `len` is the actual length of the column
unsafe { col.check_change_ticks(len, change_tick) };
unsafe { col.check_change_ticks(len, check) };
}
}

Expand Down Expand Up @@ -793,9 +793,9 @@ impl Tables {
}
}

pub(crate) fn check_change_ticks(&mut self, change_tick: Tick) {
pub(crate) fn check_change_ticks(&mut self, check: CheckChangeTicks) {
for table in &mut self.tables {
table.check_change_ticks(change_tick);
table.check_change_ticks(check);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/adapter_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ where
self.system.initialize(world)
}

fn check_change_tick(&mut self, change_tick: crate::component::Tick) {
self.system.check_change_tick(change_tick);
fn check_change_tick(&mut self, check: crate::component::CheckChangeTicks) {
self.system.check_change_tick(check);
}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/system/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::{borrow::Cow, format, vec::Vec};
use core::marker::PhantomData;

use crate::{
component::{ComponentId, Tick},
component::{CheckChangeTicks, ComponentId, Tick},
prelude::World,
query::FilteredAccessSet,
schedule::InternedSystemSet,
Expand Down Expand Up @@ -200,9 +200,9 @@ where
a_access
}

fn check_change_tick(&mut self, change_tick: Tick) {
self.a.check_change_tick(change_tick);
self.b.check_change_tick(change_tick);
fn check_change_tick(&mut self, check: CheckChangeTicks) {
self.a.check_change_tick(check);
self.b.check_change_tick(check);
}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
Expand Down Expand Up @@ -406,9 +406,9 @@ where
a_access
}

fn check_change_tick(&mut self, change_tick: Tick) {
self.a.check_change_tick(change_tick);
self.b.check_change_tick(change_tick);
fn check_change_tick(&mut self, check: CheckChangeTicks) {
self.a.check_change_tick(check);
self.b.check_change_tick(check);
}

fn default_system_sets(&self) -> Vec<InternedSystemSet> {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/system/exclusive_function_system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
component::{ComponentId, Tick},
component::{CheckChangeTicks, ComponentId, Tick},
query::FilteredAccessSet,
schedule::{InternedSystemSet, SystemSet},
system::{
Expand Down Expand Up @@ -177,10 +177,10 @@ where
}

#[inline]
fn check_change_tick(&mut self, change_tick: Tick) {
fn check_change_tick(&mut self, check: CheckChangeTicks) {
check_system_change_tick(
&mut self.system_meta.last_run,
change_tick,
check,
self.system_meta.name.as_ref(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
component::{ComponentId, Tick},
component::{CheckChangeTicks, ComponentId, Tick},
prelude::FromWorld,
query::FilteredAccessSet,
schedule::{InternedSystemSet, SystemSet},
Expand Down Expand Up @@ -708,10 +708,10 @@ where
}

#[inline]
fn check_change_tick(&mut self, change_tick: Tick) {
fn check_change_tick(&mut self, check: CheckChangeTicks) {
check_system_change_tick(
&mut self.system_meta.last_run,
change_tick,
check,
self.system_meta.name.as_ref(),
);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/system/observer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::{borrow::Cow, vec::Vec};
use core::marker::PhantomData;

use crate::{
component::{ComponentId, Tick},
component::{CheckChangeTicks, ComponentId, Tick},
error::Result,
never::Never,
prelude::{Bundle, On},
Expand Down Expand Up @@ -161,8 +161,8 @@ where
}

#[inline]
fn check_change_tick(&mut self, change_tick: Tick) {
self.observer.check_change_tick(change_tick);
fn check_change_tick(&mut self, check: CheckChangeTicks) {
self.observer.check_change_tick(check);
}

#[inline]
Expand Down
Loading