|
1 | 1 | use crate::{
|
2 | 2 | archetype::{Archetype, ArchetypeComponentId},
|
3 | 3 | change_detection::{Ticks, TicksMut},
|
4 |
| - component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType, Tick}, |
| 4 | + component::{Component, ComponentId, ComponentStorage, StorageType, Tick}, |
5 | 5 | entity::Entity,
|
6 | 6 | query::{Access, DebugCheckedUnwrap, FilteredAccess},
|
7 | 7 | storage::{ComponentSparseSet, Table, TableRow},
|
@@ -37,7 +37,7 @@ use std::{cell::UnsafeCell, marker::PhantomData};
|
37 | 37 | /// Wrapping it into an `Option` will increase the query search space, and it will return `None` if an entity doesn't satisfy the `WorldQuery`.
|
38 | 38 | /// - **[`AnyOf`].**
|
39 | 39 | /// Equivalent to wrapping each world query inside it into an `Option`.
|
40 |
| -/// - **[`ChangeTrackers`].** |
| 40 | +/// - **[`Ref`].** |
41 | 41 | /// Similar to change detection filters but it is used as a query fetch parameter.
|
42 | 42 | /// It exposes methods to check for changes to the wrapped component.
|
43 | 43 | ///
|
@@ -1075,245 +1075,6 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
|
1075 | 1075 | /// SAFETY: [`OptionFetch`] is read only because `T` is read only
|
1076 | 1076 | unsafe impl<T: ReadOnlyWorldQuery> ReadOnlyWorldQuery for Option<T> {}
|
1077 | 1077 |
|
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 |
| - |
1317 | 1078 | macro_rules! impl_tuple_fetch {
|
1318 | 1079 | ($(($name: ident, $state: ident)),*) => {
|
1319 | 1080 | #[allow(non_snake_case)]
|
|
0 commit comments