From 75f40d008d8fa0640afd8ab14a0295380217979d Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 21 Jul 2021 21:40:17 +0100 Subject: [PATCH] rename _target_filter --- crates/bevy_ecs/src/query/fetch.rs | 110 ++++++--------------- crates/bevy_ecs/src/query/filter.rs | 102 ++++++------------- crates/bevy_ecs/src/query/iter.rs | 33 +++---- crates/bevy_ecs/src/query/state.rs | 88 ++++++----------- crates/bevy_ecs/src/query/target_filter.rs | 36 +++---- crates/bevy_ecs/src/system/query.rs | 18 ++-- crates/bevy_ecs/src/world/tests.rs | 47 +++++---- examples/ecs/relations_grouping.rs | 4 +- 8 files changed, 152 insertions(+), 286 deletions(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index b3b8a572a2cae7..2a29bd9d7b4557 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -190,20 +190,16 @@ unsafe impl FetchState for EntityState { } #[inline] - fn matches_archetype( - &self, - _archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, _archetype: &Archetype, _: &Self::TargetFilter) -> bool { true } #[inline] - fn matches_table(&self, _table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, _table: &Table, _: &Self::TargetFilter) -> bool { true } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's> Fetch<'w, 's> for EntityFetch { @@ -219,7 +215,7 @@ impl<'w, 's> Fetch<'w, 's> for EntityFetch { unsafe fn init( _world: &World, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -232,7 +228,7 @@ impl<'w, 's> Fetch<'w, 's> for EntityFetch { unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, _tables: &Tables, ) { @@ -240,12 +236,7 @@ impl<'w, 's> Fetch<'w, 's> for EntityFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.entities = table.entities().as_ptr(); } @@ -308,19 +299,15 @@ unsafe impl FetchState for ReadState { } } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } /// The [`Fetch`] of `&T`. @@ -363,7 +350,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ReadFetch { unsafe fn init( world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -388,7 +375,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ReadFetch { unsafe fn set_archetype( &mut self, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables, ) { @@ -405,12 +392,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ReadFetch { } #[inline] - unsafe fn set_table( - &mut self, - state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.table_components = table .get_column(state.component_id, None) .unwrap() @@ -513,19 +495,15 @@ unsafe impl FetchState for WriteState { } } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { @@ -544,7 +522,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { unsafe fn init( world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, last_change_tick: u32, change_tick: u32, ) -> Self { @@ -572,7 +550,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { unsafe fn set_archetype( &mut self, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables, ) { @@ -590,12 +568,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteFetch { } #[inline] - unsafe fn set_table( - &mut self, - state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, state: &Self::State, _: &Self::TargetFilter, table: &Table) { let column = table.get_column(state.component_id, None).unwrap(); self.table_components = column.get_data_ptr().cast::(); self.table_ticks = column.get_ticks_ptr(); @@ -872,7 +845,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ReadRelationFetch { unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables, ) { @@ -882,12 +855,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ReadRelationFetch { self.entities = archetype.entities(); } - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.table_ptr = table; } @@ -1202,7 +1170,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteRelationFetch { unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables, ) { @@ -1212,12 +1180,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WriteRelationFetch { self.entities = archetype.entities(); } - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.table_ptr = table; } @@ -1329,15 +1292,11 @@ unsafe impl FetchState for OptionState { } } - fn matches_archetype( - &self, - _archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, _archetype: &Archetype, _: &Self::TargetFilter) -> bool { true } - fn matches_table(&self, _table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, _table: &Table, _: &Self::TargetFilter) -> bool { true } @@ -1533,19 +1492,15 @@ unsafe impl FetchState for ChangeTrackersState { } } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } /// The [`Fetch`] of [`ChangeTrackers`]. @@ -1579,7 +1534,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { unsafe fn init( world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, last_change_tick: u32, change_tick: u32, ) -> Self { @@ -1607,7 +1562,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { unsafe fn set_archetype( &mut self, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables, ) { @@ -1624,12 +1579,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for ChangeTrackersFetch { } #[inline] - unsafe fn set_table( - &mut self, - state: &Self::State, - _target_filter: &Self::TargetFilter, - table: &Table, - ) { + unsafe fn set_table(&mut self, state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.table_ticks = table .get_column(state.component_id, None) .unwrap() diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index ccf0e99022e228..0e7cdabf7fda84 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -117,19 +117,15 @@ unsafe impl FetchState for WithState { ) { } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's, T: Component> Fetch<'w, 's> for WithFetch { @@ -140,7 +136,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithFetch { unsafe fn init( _world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -156,19 +152,13 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - _table: &Table, - ) { - } + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, _table: &Table) {} #[inline] unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _archetype: &Archetype, _tables: &Tables, ) { @@ -255,19 +245,15 @@ unsafe impl FetchState for WithoutState { ) { } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { !archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { !table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutFetch { @@ -278,7 +264,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutFetch { unsafe fn init( _world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -294,19 +280,13 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - _table: &Table, - ) { - } + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, _table: &Table) {} #[inline] unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _archetype: &Archetype, _tables: &Tables, ) { @@ -421,7 +401,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutRelationFetch { unsafe fn init( _world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -439,19 +419,13 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithoutRelationFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - _table: &Table, - ) { - } + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, _table: &Table) {} #[inline] unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _archetype: &Archetype, _tables: &Tables, ) { @@ -550,7 +524,7 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithRelationFetch { unsafe fn init( _world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -566,19 +540,13 @@ impl<'w, 's, T: Component> Fetch<'w, 's> for WithRelationFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - _table: &Table, - ) { - } + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, _table: &Table) {} #[inline] unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _archetype: &Archetype, _tables: &Tables, ) { @@ -644,23 +612,19 @@ unsafe impl FetchState for WithBundleState { ) { } - fn matches_archetype( - &self, - archetype: &Archetype, - _target_filter: &Self::TargetFilter, - ) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { self.component_ids .iter() .all(|&(component_id, target)| archetype.contains(component_id, target)) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { self.component_ids .iter() .all(|&(component_id, target)| table.has_column(component_id, target)) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's, T: Bundle> Fetch<'w, 's> for WithBundleFetch { @@ -671,7 +635,7 @@ impl<'w, 's, T: Bundle> Fetch<'w, 's> for WithBundleFetch { unsafe fn init( _world: &World, state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _last_change_tick: u32, _change_tick: u32, ) -> Self { @@ -687,19 +651,13 @@ impl<'w, 's, T: Bundle> Fetch<'w, 's> for WithBundleFetch { } #[inline] - unsafe fn set_table( - &mut self, - _state: &Self::State, - _target_filter: &Self::TargetFilter, - _table: &Table, - ) { - } + unsafe fn set_table(&mut self, _state: &Self::State, _: &Self::TargetFilter, _table: &Table) {} #[inline] unsafe fn set_archetype( &mut self, _state: &Self::State, - _target_filter: &Self::TargetFilter, + _: &Self::TargetFilter, _archetype: &Archetype, _tables: &Tables, ) { @@ -957,15 +915,15 @@ macro_rules! impl_tick_filter { } } - fn matches_archetype(&self, archetype: &Archetype, _target_filter: &Self::TargetFilter) -> bool { + fn matches_archetype(&self, archetype: &Archetype, _: &Self::TargetFilter) -> bool { archetype.contains(self.component_id, None) } - fn matches_table(&self, table: &Table, _target_filter: &Self::TargetFilter) -> bool { + fn matches_table(&self, table: &Table, _: &Self::TargetFilter) -> bool { table.has_column(self.component_id, None) } - fn deduplicate_targets(_target_filter: &mut Self::TargetFilter) {} + fn deduplicate_targets(_: &mut Self::TargetFilter) {} } impl<'w, 's, T: Component> Fetch<'w, 's> for $fetch_name { @@ -973,7 +931,7 @@ macro_rules! impl_tick_filter { type Item = bool; type TargetFilter = (); - unsafe fn init(world: &World, state: &Self::State, _target_filter: &Self::TargetFilter, last_change_tick: u32, change_tick: u32) -> Self { + unsafe fn init(world: &World, state: &Self::State, _: &Self::TargetFilter, last_change_tick: u32, change_tick: u32) -> Self { let mut value = Self { storage_type: state.storage_type, table_ticks: ptr::null::>(), @@ -998,13 +956,13 @@ macro_rules! impl_tick_filter { self.storage_type == StorageType::Table } - unsafe fn set_table(&mut self, state: &Self::State, _target_filter: &Self::TargetFilter, table: &Table) { + unsafe fn set_table(&mut self, state: &Self::State, _: &Self::TargetFilter, table: &Table) { self.table_ticks = table .get_column(state.component_id, None).unwrap() .get_ticks_ptr(); } - unsafe fn set_archetype(&mut self, state: &Self::State, _target_filter: &Self::TargetFilter, archetype: &Archetype, tables: &Tables) { + unsafe fn set_archetype(&mut self, state: &Self::State, _: &Self::TargetFilter, archetype: &Archetype, tables: &Tables) { match state.storage_type { StorageType::Table => { self.entity_table_rows = archetype.entity_table_rows().as_ptr(); diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index 828a2e1be2afe4..937f8328f39e94 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -48,14 +48,14 @@ where let fetch = ::init( world, &query_state.fetch_state, - &query_state.current_target_filter.0, + &query_state.current_.0, last_change_tick, change_tick, ); let filter = ::init( world, &query_state.filter_state, - &query_state.current_target_filter.1, + &query_state.current_.1, last_change_tick, change_tick, ); @@ -93,7 +93,7 @@ where self.filter.set_table( &self.query_state.filter_state, - &self.query_state.current_target_filter.1, + &self.query_state.current_.1, table, ); self.current_len = table.len(); @@ -118,7 +118,7 @@ where let archetype = &self.archetypes[*archetype_id]; self.filter.set_archetype( &self.query_state.filter_state, - &self.query_state.current_target_filter.1, + &self.query_state.current_.1, archetype, self.tables, ); @@ -158,12 +158,12 @@ where let table = &self.tables[*table_id]; self.fetch.set_table( &self.query_state.fetch_state, - &self.query_state.current_target_filter.0, + &self.query_state.current_.0, table, ); self.filter.set_table( &self.query_state.filter_state, - &self.query_state.current_target_filter.1, + &self.query_state.current_.1, table, ); self.current_len = table.len(); @@ -187,13 +187,13 @@ where let archetype = &self.archetypes[*archetype_id]; self.fetch.set_archetype( &self.query_state.fetch_state, - &self.query_state.current_target_filter.0, + &self.query_state.current_.0, archetype, self.tables, ); self.filter.set_archetype( &self.query_state.filter_state, - &self.query_state.current_target_filter.1, + &self.query_state.current_.1, archetype, self.tables, ); @@ -483,14 +483,14 @@ where let fetch = ::init( world, &query_state.fetch_state, - &query_state.current_target_filter.0, + &query_state.current_.0, last_change_tick, change_tick, ); let filter = ::init( world, &query_state.filter_state, - &query_state.current_target_filter.1, + &query_state.current_.1, last_change_tick, change_tick, ); @@ -536,14 +536,11 @@ where if self.current_index == self.current_len { let table_id = self.table_id_iter.next()?; let table = &tables[*table_id]; - self.fetch.set_table( - &query_state.fetch_state, - &query_state.current_target_filter.0, - table, - ); + self.fetch + .set_table(&query_state.fetch_state, &query_state.current_.0, table); self.filter.set_table( &query_state.filter_state, - &query_state.current_target_filter.1, + &query_state.current_.1, table, ); self.current_len = table.len(); @@ -568,13 +565,13 @@ where let archetype = &archetypes[*archetype_id]; self.fetch.set_archetype( &query_state.fetch_state, - &query_state.current_target_filter.0, + &query_state.current_.0, archetype, tables, ); self.filter.set_archetype( &query_state.filter_state, - &query_state.current_target_filter.1, + &query_state.current_.1, archetype, tables, ); diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index d3a93569ae3d5d..3262f1b4a87c58 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -33,7 +33,7 @@ where /// If filters have already been added for the relation kind they will be merged with /// the provided filters. #[must_use = "target filters will be unchanged if you do not call `apply_filters`"] - pub fn add_target_filter(mut self, filter: TargetFilter) -> Self + pub fn add_(mut self, filter: TargetFilter) -> Self where QueryTargetFilters: SpecifiesRelation>, @@ -48,7 +48,7 @@ where world, filters, } = self; - state.set_target_filters(world, filters); + state.set_s(world, filters); state } } @@ -71,7 +71,7 @@ where pub(crate) archetype_component_access: Access, pub(crate) component_access: FilteredAccess, - pub(crate) current_target_filter: QueryTargetFilters, + pub(crate) current_: QueryTargetFilters, pub(crate) target_filter_accesses: HashMap, QueryAccessCache>, pub(crate) fetch_state: Q::State, @@ -105,12 +105,12 @@ where filter_state, component_access, - current_target_filter: Default::default(), + current_: Default::default(), target_filter_accesses: HashMap::new(), archetype_component_access: Default::default(), }; - state.set_target_filters(world, QueryTargetFilters::default()); + state.set_s(world, QueryTargetFilters::default()); state.validate_world_and_update_archetypes(world); state } @@ -126,13 +126,11 @@ where } pub fn current_query_access_cache(&self) -> &QueryAccessCache { - self.target_filter_accesses - .get(&self.current_target_filter) - .unwrap() + self.target_filter_accesses.get(&self.current_).unwrap() } - pub fn clear_target_filters(&mut self, world: &World) -> &mut Self { - self.set_target_filters(world, Default::default()); + pub fn clear_s(&mut self, world: &World) -> &mut Self { + self.set_s(world, Default::default()); self } @@ -141,7 +139,7 @@ where /// /// You should call `clear_filter_relations` if you want to reset filters. #[must_use = "target filters will be unchanged if you do not call `apply_filters`"] - pub fn new_target_filters<'a, K: Component, Path>( + pub fn new_s<'a, K: Component, Path>( &mut self, world: &'a World, target_filter: TargetFilter, @@ -155,18 +153,14 @@ where world, filters: QueryTargetFilters::new(), } - .add_target_filter(target_filter) + .add_(target_filter) } - pub(crate) fn set_target_filters( - &mut self, - world: &World, - mut target_filter: QueryTargetFilters, - ) { + pub(crate) fn set_s(&mut self, world: &World, mut target_filter: QueryTargetFilters) { // We deduplicate targets so that `RelationAccess` and `RelationAccessMut` // dont yield aliasing borrows when we have two identical target filters target_filter.deduplicate_targets(); - self.current_target_filter = target_filter.clone(); + self.current_ = target_filter.clone(); self.target_filter_accesses .entry(target_filter) .or_insert(QueryAccessCache { @@ -300,27 +294,27 @@ where let mut fetch = ::init( world, &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, last_change_tick, change_tick, ); let mut filter = ::init( world, &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, last_change_tick, change_tick, ); fetch.set_archetype( &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, archetype, &world.storages().tables, ); filter.set_archetype( &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, archetype, &world.storages().tables, ); @@ -543,14 +537,14 @@ where let mut fetch = ::init( world, &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, last_change_tick, change_tick, ); let mut filter = ::init( world, &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, last_change_tick, change_tick, ); @@ -558,8 +552,8 @@ where let tables = &world.storages().tables; for table_id in self.current_query_access_cache().matched_table_ids.iter() { let table = &tables[*table_id]; - fetch.set_table(&self.fetch_state, &self.current_target_filter.0, table); - filter.set_table(&self.filter_state, &self.current_target_filter.1, table); + fetch.set_table(&self.fetch_state, &self.current_.0, table); + filter.set_table(&self.filter_state, &self.current_.1, table); for table_index in 0..table.len() { if !filter.table_filter_fetch(table_index) { @@ -578,18 +572,8 @@ where .iter() { let archetype = &archetypes[*archetype_id]; - fetch.set_archetype( - &self.fetch_state, - &self.current_target_filter.0, - archetype, - tables, - ); - filter.set_archetype( - &self.filter_state, - &self.current_target_filter.1, - archetype, - tables, - ); + fetch.set_archetype(&self.fetch_state, &self.current_.0, archetype, tables); + filter.set_archetype(&self.filter_state, &self.current_.1, archetype, tables); for archetype_index in 0..archetype.len() { if !filter.archetype_filter_fetch(archetype_index) { @@ -622,14 +606,14 @@ where let fetch = ::init( world, &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, last_change_tick, change_tick, ); let filter = ::init( world, &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, last_change_tick, change_tick, ); @@ -645,29 +629,21 @@ where let mut fetch = ::init( world, &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, last_change_tick, change_tick, ); let mut filter = ::init( world, &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, last_change_tick, change_tick, ); let tables = &world.storages().tables; let table = &tables[*table_id]; - fetch.set_table( - &self.fetch_state, - &self.current_target_filter.0, - table, - ); - filter.set_table( - &self.filter_state, - &self.current_target_filter.1, - table, - ); + fetch.set_table(&self.fetch_state, &self.current_.0, table); + filter.set_table(&self.filter_state, &self.current_.1, table); let len = batch_size.min(table.len() - offset); for table_index in offset..offset + len { if !filter.table_filter_fetch(table_index) { @@ -695,14 +671,14 @@ where let mut fetch = ::init( world, &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, last_change_tick, change_tick, ); let mut filter = ::init( world, &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, last_change_tick, change_tick, ); @@ -710,13 +686,13 @@ where let archetype = &world.archetypes[*archetype_id]; fetch.set_archetype( &self.fetch_state, - &self.current_target_filter.0, + &self.current_.0, archetype, tables, ); filter.set_archetype( &self.filter_state, - &self.current_target_filter.1, + &self.current_.1, archetype, tables, ); diff --git a/crates/bevy_ecs/src/query/target_filter.rs b/crates/bevy_ecs/src/query/target_filter.rs index 6dec158e136af1..5be58e88a724ae 100644 --- a/crates/bevy_ecs/src/query/target_filter.rs +++ b/crates/bevy_ecs/src/query/target_filter.rs @@ -81,7 +81,7 @@ impl QueryTargetFilters { where Self: SpecifiesRelation, { - Self::__add_target_filter(filter, self); + Self::__add_(filter, self); } pub fn deduplicate_targets(&mut self) { @@ -92,7 +92,7 @@ impl QueryTargetFilters { pub trait SpecifiesRelation { type TargetFilter; - fn __add_target_filter(entity: TargetFilter, target_filter: &mut Self::TargetFilter); + fn __add_(entity: TargetFilter, target_filter: &mut Self::TargetFilter); } pub struct Intrinsic; @@ -102,19 +102,13 @@ pub struct InTuple(PhantomData); impl SpecifiesRelation for &Relation { type TargetFilter = <::State as FetchState>::TargetFilter; - fn __add_target_filter( - filter: TargetFilter, - target_filter: &mut smallvec::SmallVec<[Entity; 4]>, - ) { + fn __add_(filter: TargetFilter, target_filter: &mut smallvec::SmallVec<[Entity; 4]>) { target_filter.extend(filter.0.into_iter()); } } impl SpecifiesRelation for &mut Relation { type TargetFilter = <::State as FetchState>::TargetFilter; - fn __add_target_filter( - filter: TargetFilter, - target_filter: &mut smallvec::SmallVec<[Entity; 4]>, - ) { + fn __add_(filter: TargetFilter, target_filter: &mut smallvec::SmallVec<[Entity; 4]>) { target_filter.extend(filter.0.into_iter()); } } @@ -122,19 +116,13 @@ impl SpecifiesRelation for crate::prelude::Without> { type TargetFilter = <::State as FetchState>::TargetFilter; - fn __add_target_filter( - filter: TargetFilter, - target_filter: &mut smallvec::SmallVec<[Entity; 4]>, - ) { + fn __add_(filter: TargetFilter, target_filter: &mut smallvec::SmallVec<[Entity; 4]>) { target_filter.extend(filter.0.into_iter()); } } impl SpecifiesRelation for crate::prelude::With> { type TargetFilter = <::State as FetchState>::TargetFilter; - fn __add_target_filter( - filter: TargetFilter, - target_filter: &mut smallvec::SmallVec<[Entity; 4]>, - ) { + fn __add_(filter: TargetFilter, target_filter: &mut smallvec::SmallVec<[Entity; 4]>) { target_filter.extend(filter.0.into_iter()); } } @@ -149,8 +137,8 @@ where >, { type TargetFilter = Self; - fn __add_target_filter(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { - Q::__add_target_filter(entity, &mut target_filter.0); + fn __add_(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { + Q::__add_(entity, &mut target_filter.0); } } impl SpecifiesRelation> @@ -163,8 +151,8 @@ where >, { type TargetFilter = Self; - fn __add_target_filter(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { - F::__add_target_filter(entity, &mut target_filter.1); + fn __add_(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { + F::__add_(entity, &mut target_filter.1); } } @@ -201,13 +189,13 @@ macro_rules! impl_tuple_inner { ); #[allow(non_snake_case, unused)] - fn __add_target_filter(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { + fn __add_(entity: TargetFilter, target_filter: &mut Self::TargetFilter) { let ( $($head,)* my_thing, $($tail,)* ) = target_filter; - Selected::__add_target_filter(entity, my_thing); + Selected::__add_(entity, my_thing); } } }; diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index 6b9f886193ed0b..428c9b1640567a 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -558,8 +558,8 @@ where .is_empty(self.world, self.last_change_tick, self.change_tick) } - pub fn clear_target_filters(&mut self) -> &mut Self { - self.set_target_filters(Default::default()); + pub fn clear_s(&mut self) -> &mut Self { + self.set_s(Default::default()); self } @@ -568,7 +568,7 @@ where /// /// You should call `clear_filter_relations` if you want to reset filters. #[must_use = "relation filters will be unchanged if you do not call `apply_filters`"] - pub fn new_target_filters( + pub fn new_s( &mut self, filter: TargetFilter, ) -> QueryTargetFiltersBuilder<'_, 'w, Q, F> @@ -580,14 +580,14 @@ where query: self, filters: QueryTargetFilters::new(), } - .add_target_filter(filter) + .add_(filter) } /// Overwrites current relation filters with the provided relation filters /// /// You should prefer `new_filter_relation` over this method - fn set_target_filters(&mut self, target_filter: QueryTargetFilters) -> &mut Self { - self.state.set_target_filters(&self.world, target_filter); + fn set_s(&mut self, target_filter: QueryTargetFilters) -> &mut Self { + self.state.set_s(&self.world, target_filter); self } } @@ -597,7 +597,7 @@ where F::Fetch: FilterFetch, { fn drop(&mut self) { - self.set_target_filters(QueryTargetFilters::new()); + self.set_s(QueryTargetFilters::new()); } } @@ -616,7 +616,7 @@ where /// If filters have already been added for the relation kind they will be merged with /// the provided filters. #[must_use = "target filters will be unchanged if you do not call `apply_filters`"] - pub fn add_target_filter(mut self, filter: TargetFilter) -> Self + pub fn add_(mut self, filter: TargetFilter) -> Self where QueryTargetFilters: SpecifiesRelation>, @@ -627,7 +627,7 @@ where pub fn apply_filters(self) -> &'a mut Query<'b, Q, F> { let Self { query, filters } = self; - query.state.set_target_filters(query.world, filters); + query.state.set_s(query.world, filters); query } } diff --git a/crates/bevy_ecs/src/world/tests.rs b/crates/bevy_ecs/src/world/tests.rs index ee900f5d4ef78d..698370e0687754 100644 --- a/crates/bevy_ecs/src/world/tests.rs +++ b/crates/bevy_ecs/src/world/tests.rs @@ -71,21 +71,21 @@ fn relation_query_raw(storage_type: StorageType) { assert!(matches!(iter.next(), None)); query - .new_target_filters(&world, TargetFilter::::new().target(parent1)) + .new_s(&world, TargetFilter::::new().target(parent1)) .apply_filters(); let mut iter = query.iter_mut(&mut world); assert!(iter.next().unwrap().0 == child1); assert!(matches!(iter.next(), None)); query - .new_target_filters(&world, TargetFilter::::new().target(parent2)) + .new_s(&world, TargetFilter::::new().target(parent2)) .apply_filters(); let mut iter = query.iter_mut(&mut world); assert!(iter.next().unwrap().0 == child2); assert!(matches!(iter.next(), None)); query - .new_target_filters( + .new_s( &world, TargetFilter::::new() .target(parent1) @@ -152,7 +152,7 @@ fn relation_access_raw(storage_type: StorageType) { let mut query = world.query::<(Entity, &Relation)>(); query - .new_target_filters(&world, TargetFilter::::new().target(parent1)) + .new_s(&world, TargetFilter::::new().target(parent1)) .apply_filters(); let mut iter = query.iter(&world); let (child, mut accessor) = iter.next().unwrap(); @@ -170,7 +170,7 @@ fn relation_access_raw(storage_type: StorageType) { assert!(matches!(iter.next(), None)); query - .new_target_filters(&world, TargetFilter::::new().target(parent2)) + .new_s(&world, TargetFilter::::new().target(parent2)) .apply_filters(); let mut iter = query.iter(&world); let (child, mut accessor) = iter.next().unwrap(); @@ -187,7 +187,7 @@ fn relation_access_raw(storage_type: StorageType) { assert!(matches!(accessor.next(), None)); assert!(matches!(iter.next(), None)); - query.clear_target_filters(&world); + query.clear_s(&world); let mut iter = query.iter(&world); // let (child, mut accessor) = iter.next().unwrap(); @@ -285,7 +285,7 @@ fn relation_query_mut_raw(storage_type: StorageType) { let mut query = world.query::<(Entity, &mut Relation, &&str)>(); query - .new_target_filters(&world, TargetFilter::::new().target(target2)) + .new_s(&world, TargetFilter::::new().target(target2)) .apply_filters(); for (_, mut accessor, _) in query.iter_mut(&mut world) { let (_, mut rel) = accessor.single(); @@ -294,7 +294,7 @@ fn relation_query_mut_raw(storage_type: StorageType) { } query - .new_target_filters( + .new_s( &world, TargetFilter::::new() .target(target1) @@ -326,7 +326,7 @@ fn relation_query_mut_raw(storage_type: StorageType) { } assert!(was_targeter1 && was_targeter2); - query.clear_target_filters(&world); + query.clear_s(&world); for (_, accessor, _) in query.iter_mut(&mut world) { for (_, mut rel) in accessor { rel.0 = !rel.0; @@ -458,7 +458,7 @@ fn compiles() { let mut query = world.query::<&u32>(); let borrows = query.iter(&world).collect::>(); - query.clear_target_filters(&world); + query.clear_s(&world); let _borrows2 = query.iter(&world).collect::>(); dbg!(borrows); } @@ -470,7 +470,7 @@ use bevy_ecs::prelude::*; let mut world = World::new(); let mut query = world.query::<&Relation>(); let _borrows = query.iter(&world).collect::>(); -query.clear_target_filters(&world); +query.clear_s(&world); let _borrows2 = query.iter(&world).collect::>(); drop(_borrows); // If this doesn't fail to compile we have unsoundness - Boxy ``` @@ -484,10 +484,7 @@ fn explicit_path() { let target = world.spawn().id(); query - .new_target_filters::>>( - &world, - TargetFilter::new().target(target), - ) + .new_s::>>(&world, TargetFilter::new().target(target)) .apply_filters(); } @@ -498,7 +495,7 @@ fn foo() { let target = world.spawn().id(); query - .new_target_filters(&world, TargetFilter::::new().target(target)) + .new_s(&world, TargetFilter::::new().target(target)) .apply_filters() .for_each(&world, |_| ()) } @@ -555,7 +552,7 @@ fn without_filter_raw(storage_type: StorageType) { let data = world .query_filtered::<(Entity, &String), Without>>() - .new_target_filters(&world, TargetFilter::::new().target(target1)) + .new_s(&world, TargetFilter::::new().target(target1)) .apply_filters() .iter(&world) .collect::>(); @@ -612,12 +609,12 @@ fn relations_dont_yield_components_raw(storage_type: StorageType) { } #[test] -fn duplicated_target_filters() { - duplicated_target_filters_raw(StorageType::SparseSet); - duplicated_target_filters_raw(StorageType::Table); +fn duplicated_s() { + duplicated_s_raw(StorageType::SparseSet); + duplicated_s_raw(StorageType::Table); } -fn duplicated_target_filters_raw(storage_type: StorageType) { +fn duplicated_s_raw(storage_type: StorageType) { let mut world = World::new(); world @@ -632,7 +629,7 @@ fn duplicated_target_filters_raw(storage_type: StorageType) { let mut q = world.query::<&Relation>(); let [relations]: [RelationAccess<_>; 1] = q - .new_target_filters( + .new_s( &world, TargetFilter::::new().target(target).target(target), ) @@ -683,7 +680,7 @@ fn with_filter_raw(storage_type: StorageType) { assert_eq!(e2, has_both); assert_eq!(e3, many_relations); let [e1, e2]: [Entity; 2] = q - .new_target_filters(&world, TargetFilter::::new().target(target1)) + .new_s(&world, TargetFilter::::new().target(target1)) .apply_filters() .iter(&world) .collect::>() @@ -692,7 +689,7 @@ fn with_filter_raw(storage_type: StorageType) { assert_eq!(e1, has_relation); assert_eq!(e2, many_relations); let [e1, e2]: [Entity; 2] = q - .new_target_filters(&world, TargetFilter::::new().target(target2)) + .new_s(&world, TargetFilter::::new().target(target2)) .apply_filters() .iter(&world) .collect::>() @@ -701,7 +698,7 @@ fn with_filter_raw(storage_type: StorageType) { assert_eq!(e1, has_both); assert_eq!(e2, many_relations); let []: [Entity; 0] = q - .new_target_filters(&world, TargetFilter::::new().target(no_relation)) + .new_s(&world, TargetFilter::::new().target(no_relation)) .apply_filters() .iter(&world) .collect::>() diff --git a/examples/ecs/relations_grouping.rs b/examples/ecs/relations_grouping.rs index fdf6e63defe953..48678c95a66289 100644 --- a/examples/ecs/relations_grouping.rs +++ b/examples/ecs/relations_grouping.rs @@ -125,7 +125,7 @@ fn set_group_position( ) { for &group_entity in group_set.0.iter() { let mut iter = bevys - .new_target_filters(TargetFilter::::new().target(group_entity)) + .new_s(TargetFilter::::new().target(group_entity)) .apply_filters() .iter(); @@ -198,7 +198,7 @@ fn move_bevys( let GroupPosition(target_pos) = *groups.get_mut(move_to).unwrap().0; bevys - .new_target_filters(TargetFilter::::new().target(group_entity)) + .new_s(TargetFilter::::new().target(group_entity)) .apply_filters() .iter_mut() .for_each(|(mut transform, target_offset, _)| {