Skip to content

Commit 7d9cb1c

Browse files
authored
Remove ChangeTrackers (#7902)
1 parent 3ec764e commit 7d9cb1c

File tree

3 files changed

+3
-272
lines changed

3 files changed

+3
-272
lines changed

crates/bevy_ecs/src/lib.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub use bevy_ptr as ptr;
2525

2626
/// Most commonly used re-exported types.
2727
pub mod prelude {
28-
#[doc(hidden)]
29-
#[allow(deprecated)]
30-
pub use crate::query::ChangeTrackers;
3128
#[doc(hidden)]
3229
#[cfg(feature = "bevy_reflect")]
3330
pub use crate::reflect::{ReflectComponent, ReflectResource};
@@ -1299,33 +1296,6 @@ mod tests {
12991296
.unwrap();
13001297
}
13011298

1302-
#[test]
1303-
#[allow(deprecated)]
1304-
fn trackers_query() {
1305-
use crate::prelude::ChangeTrackers;
1306-
1307-
let mut world = World::default();
1308-
let e1 = world.spawn((A(0), B(0))).id();
1309-
world.spawn(B(0));
1310-
1311-
let mut trackers_query = world.query::<Option<ChangeTrackers<A>>>();
1312-
let trackers = trackers_query.iter(&world).collect::<Vec<_>>();
1313-
let a_trackers = trackers[0].as_ref().unwrap();
1314-
assert!(trackers[1].is_none());
1315-
assert!(a_trackers.is_added());
1316-
assert!(a_trackers.is_changed());
1317-
world.clear_trackers();
1318-
let trackers = trackers_query.iter(&world).collect::<Vec<_>>();
1319-
let a_trackers = trackers[0].as_ref().unwrap();
1320-
assert!(!a_trackers.is_added());
1321-
assert!(!a_trackers.is_changed());
1322-
*world.get_mut(e1).unwrap() = A(1);
1323-
let trackers = trackers_query.iter(&world).collect::<Vec<_>>();
1324-
let a_trackers = trackers[0].as_ref().unwrap();
1325-
assert!(!a_trackers.is_added());
1326-
assert!(a_trackers.is_changed());
1327-
}
1328-
13291299
#[test]
13301300
fn exact_size_query() {
13311301
let mut world = World::default();

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 2 additions & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
archetype::{Archetype, ArchetypeComponentId},
33
change_detection::{Ticks, TicksMut},
4-
component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType, Tick},
4+
component::{Component, ComponentId, ComponentStorage, StorageType, Tick},
55
entity::Entity,
66
query::{Access, DebugCheckedUnwrap, FilteredAccess},
77
storage::{ComponentSparseSet, Table, TableRow},
@@ -37,7 +37,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
3737
/// Wrapping it into an `Option` will increase the query search space, and it will return `None` if an entity doesn't satisfy the `WorldQuery`.
3838
/// - **[`AnyOf`].**
3939
/// Equivalent to wrapping each world query inside it into an `Option`.
40-
/// - **[`ChangeTrackers`].**
40+
/// - **[`Ref`].**
4141
/// Similar to change detection filters but it is used as a query fetch parameter.
4242
/// It exposes methods to check for changes to the wrapped component.
4343
///
@@ -1075,245 +1075,6 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
10751075
/// SAFETY: [`OptionFetch`] is read only because `T` is read only
10761076
unsafe impl<T: ReadOnlyWorldQuery> ReadOnlyWorldQuery for Option<T> {}
10771077

1078-
/// [`WorldQuery`] that tracks changes and additions for component `T`.
1079-
///
1080-
/// Wraps a [`Component`] to track whether the component changed for the corresponding entities in
1081-
/// a query since the last time the system that includes these queries ran.
1082-
///
1083-
/// If you only care about entities that changed or that got added use the
1084-
/// [`Changed`](crate::query::Changed) and [`Added`](crate::query::Added) filters instead.
1085-
///
1086-
/// # Examples
1087-
///
1088-
/// ```
1089-
/// # use bevy_ecs::component::Component;
1090-
/// # use bevy_ecs::query::ChangeTrackers;
1091-
/// # use bevy_ecs::system::IntoSystem;
1092-
/// # use bevy_ecs::system::Query;
1093-
/// #
1094-
/// # #[derive(Component, Debug)]
1095-
/// # struct Name {};
1096-
/// # #[derive(Component)]
1097-
/// # struct Transform {};
1098-
/// #
1099-
/// fn print_moving_objects_system(query: Query<(&Name, ChangeTrackers<Transform>)>) {
1100-
/// for (name, tracker) in &query {
1101-
/// if tracker.is_changed() {
1102-
/// println!("Entity moved: {:?}", name);
1103-
/// } else {
1104-
/// println!("Entity stood still: {:?}", name);
1105-
/// }
1106-
/// }
1107-
/// }
1108-
/// # bevy_ecs::system::assert_is_system(print_moving_objects_system);
1109-
/// ```
1110-
#[deprecated = "`ChangeTrackers<T>` will be removed in bevy 0.11. Use `bevy_ecs::prelude::Ref<T>` instead."]
1111-
pub struct ChangeTrackers<T: Component> {
1112-
pub(crate) component_ticks: ComponentTicks,
1113-
pub(crate) last_run: Tick,
1114-
pub(crate) this_run: Tick,
1115-
marker: PhantomData<T>,
1116-
}
1117-
1118-
#[allow(deprecated)]
1119-
impl<T: Component> Clone for ChangeTrackers<T> {
1120-
fn clone(&self) -> Self {
1121-
*self
1122-
}
1123-
}
1124-
1125-
#[allow(deprecated)]
1126-
impl<T: Component> Copy for ChangeTrackers<T> {}
1127-
1128-
#[allow(deprecated)]
1129-
impl<T: Component> std::fmt::Debug for ChangeTrackers<T> {
1130-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1131-
f.debug_struct("ChangeTrackers")
1132-
.field("component_ticks", &self.component_ticks)
1133-
.field("last_run", &self.last_run)
1134-
.field("this_run", &self.this_run)
1135-
.finish()
1136-
}
1137-
}
1138-
1139-
#[allow(deprecated)]
1140-
impl<T: Component> ChangeTrackers<T> {
1141-
/// Returns true if this component has been added since the last execution of this system.
1142-
pub fn is_added(&self) -> bool {
1143-
self.component_ticks.is_added(self.last_run, self.this_run)
1144-
}
1145-
1146-
/// Returns true if this component has been changed since the last execution of this system.
1147-
pub fn is_changed(&self) -> bool {
1148-
self.component_ticks
1149-
.is_changed(self.last_run, self.this_run)
1150-
}
1151-
}
1152-
1153-
#[doc(hidden)]
1154-
pub struct ChangeTrackersFetch<'w, T> {
1155-
// T::Storage = TableStorage
1156-
table_added: Option<ThinSlicePtr<'w, UnsafeCell<Tick>>>,
1157-
table_changed: Option<ThinSlicePtr<'w, UnsafeCell<Tick>>>,
1158-
// T::Storage = SparseStorage
1159-
sparse_set: Option<&'w ComponentSparseSet>,
1160-
1161-
marker: PhantomData<T>,
1162-
last_run: Tick,
1163-
this_run: Tick,
1164-
}
1165-
1166-
#[allow(deprecated)]
1167-
// SAFETY: `ROQueryFetch<Self>` is the same as `QueryFetch<Self>`
1168-
unsafe impl<T: Component> WorldQuery for ChangeTrackers<T> {
1169-
type Fetch<'w> = ChangeTrackersFetch<'w, T>;
1170-
type Item<'w> = ChangeTrackers<T>;
1171-
type ReadOnly = Self;
1172-
type State = ComponentId;
1173-
1174-
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
1175-
item
1176-
}
1177-
1178-
const IS_DENSE: bool = {
1179-
match T::Storage::STORAGE_TYPE {
1180-
StorageType::Table => true,
1181-
StorageType::SparseSet => false,
1182-
}
1183-
};
1184-
1185-
const IS_ARCHETYPAL: bool = true;
1186-
1187-
unsafe fn init_fetch<'w>(
1188-
world: &'w World,
1189-
&component_id: &ComponentId,
1190-
last_run: Tick,
1191-
this_run: Tick,
1192-
) -> ChangeTrackersFetch<'w, T> {
1193-
ChangeTrackersFetch {
1194-
table_added: None,
1195-
table_changed: None,
1196-
sparse_set: (T::Storage::STORAGE_TYPE == StorageType::SparseSet).then(|| {
1197-
world
1198-
.storages()
1199-
.sparse_sets
1200-
.get(component_id)
1201-
.debug_checked_unwrap()
1202-
}),
1203-
marker: PhantomData,
1204-
last_run,
1205-
this_run,
1206-
}
1207-
}
1208-
1209-
unsafe fn clone_fetch<'w>(fetch: &Self::Fetch<'w>) -> Self::Fetch<'w> {
1210-
ChangeTrackersFetch {
1211-
table_added: fetch.table_added,
1212-
table_changed: fetch.table_changed,
1213-
sparse_set: fetch.sparse_set,
1214-
marker: fetch.marker,
1215-
last_run: fetch.last_run,
1216-
this_run: fetch.this_run,
1217-
}
1218-
}
1219-
1220-
#[inline]
1221-
unsafe fn set_archetype<'w>(
1222-
fetch: &mut ChangeTrackersFetch<'w, T>,
1223-
component_id: &ComponentId,
1224-
_archetype: &'w Archetype,
1225-
table: &'w Table,
1226-
) {
1227-
if Self::IS_DENSE {
1228-
Self::set_table(fetch, component_id, table);
1229-
}
1230-
}
1231-
1232-
#[inline]
1233-
unsafe fn set_table<'w>(
1234-
fetch: &mut ChangeTrackersFetch<'w, T>,
1235-
&id: &ComponentId,
1236-
table: &'w Table,
1237-
) {
1238-
let column = table.get_column(id).debug_checked_unwrap();
1239-
fetch.table_added = Some(column.get_added_ticks_slice().into());
1240-
fetch.table_changed = Some(column.get_changed_ticks_slice().into());
1241-
}
1242-
1243-
#[inline(always)]
1244-
unsafe fn fetch<'w>(
1245-
fetch: &mut Self::Fetch<'w>,
1246-
entity: Entity,
1247-
table_row: TableRow,
1248-
) -> Self::Item<'w> {
1249-
match T::Storage::STORAGE_TYPE {
1250-
StorageType::Table => ChangeTrackers {
1251-
component_ticks: {
1252-
ComponentTicks {
1253-
added: fetch
1254-
.table_added
1255-
.debug_checked_unwrap()
1256-
.get(table_row.index())
1257-
.read(),
1258-
changed: fetch
1259-
.table_changed
1260-
.debug_checked_unwrap()
1261-
.get(table_row.index())
1262-
.read(),
1263-
}
1264-
},
1265-
marker: PhantomData,
1266-
last_run: fetch.last_run,
1267-
this_run: fetch.this_run,
1268-
},
1269-
StorageType::SparseSet => ChangeTrackers {
1270-
component_ticks: fetch
1271-
.sparse_set
1272-
.debug_checked_unwrap()
1273-
.get_ticks(entity)
1274-
.debug_checked_unwrap(),
1275-
marker: PhantomData,
1276-
last_run: fetch.last_run,
1277-
this_run: fetch.this_run,
1278-
},
1279-
}
1280-
}
1281-
1282-
fn update_component_access(&id: &ComponentId, access: &mut FilteredAccess<ComponentId>) {
1283-
assert!(
1284-
!access.access().has_write(id),
1285-
"ChangeTrackers<{}> conflicts with a previous access in this query. Shared access cannot coincide with exclusive access.",
1286-
std::any::type_name::<T>()
1287-
);
1288-
access.add_read(id);
1289-
}
1290-
1291-
fn update_archetype_component_access(
1292-
&id: &ComponentId,
1293-
archetype: &Archetype,
1294-
access: &mut Access<ArchetypeComponentId>,
1295-
) {
1296-
if let Some(archetype_component_id) = archetype.get_archetype_component_id(id) {
1297-
access.add_read(archetype_component_id);
1298-
}
1299-
}
1300-
1301-
fn init_state(world: &mut World) -> ComponentId {
1302-
world.init_component::<T>()
1303-
}
1304-
1305-
fn matches_component_set(
1306-
&id: &ComponentId,
1307-
set_contains_id: &impl Fn(ComponentId) -> bool,
1308-
) -> bool {
1309-
set_contains_id(id)
1310-
}
1311-
}
1312-
1313-
#[allow(deprecated)]
1314-
/// SAFETY: access is read only
1315-
unsafe impl<T: Component> ReadOnlyWorldQuery for ChangeTrackers<T> {}
1316-
13171078
macro_rules! impl_tuple_fetch {
13181079
($(($name: ident, $state: ident)),*) => {
13191080
#[allow(non_snake_case)]

crates/bevy_ecs/src/query/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl_tick_filter!(
596596
/// Bevy does not compare components to their previous values.
597597
///
598598
/// To retain all results without filtering but still check whether they were changed after the
599-
/// system last ran, use [`ChangeTrackers<T>`](crate::query::ChangeTrackers).
599+
/// system last ran, use [`Ref<T>`](crate::change_detection::Ref).
600600
///
601601
/// # Examples
602602
///

0 commit comments

Comments
 (0)