From d39b5c44a1184cc865a91b2c314b93f448c4e52e Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 20 May 2022 01:20:16 +0100 Subject: [PATCH 1/3] do the thing --- crates/bevy_ecs/macros/src/fetch.rs | 7 +-- crates/bevy_ecs/src/archetype.rs | 5 ++ crates/bevy_ecs/src/query/fetch.rs | 73 +++++++---------------- crates/bevy_ecs/src/query/filter.rs | 40 ++++--------- crates/bevy_ecs/src/query/state.rs | 8 ++- crates/bevy_ecs/src/storage/sparse_set.rs | 4 ++ crates/bevy_ecs/src/storage/table.rs | 4 ++ 7 files changed, 52 insertions(+), 89 deletions(-) diff --git a/crates/bevy_ecs/macros/src/fetch.rs b/crates/bevy_ecs/macros/src/fetch.rs index f7d0433306e5b..b46e597142056 100644 --- a/crates/bevy_ecs/macros/src/fetch.rs +++ b/crates/bevy_ecs/macros/src/fetch.rs @@ -279,12 +279,9 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream { #(self.#field_idents.update_archetype_component_access(_archetype, _access);)* } - fn matches_archetype(&self, _archetype: &#path::archetype::Archetype) -> bool { - true #(&& self.#field_idents.matches_archetype(_archetype))* - } + fn matches_component_set(&self, _component_set: &#path::storage::SparseArray<#path::component::ComponentId, usize>) -> bool { + true #(&& self.#field_idents.matches_component_set(_component_set))* - fn matches_table(&self, _table: &#path::storage::Table) -> bool { - true #(&& self.#field_idents.matches_table(_table))* } } }; diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index ab33119a93be6..e7791744a5a15 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -221,6 +221,11 @@ impl Archetype { self.components.indices() } + #[inline] + pub fn component_ids(&self) -> &SparseArray { + self.components.sparse_array() + } + #[inline] pub fn edges(&self) -> &Edges { &self.edges diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index ff2a629277502..e1798ba176f9d 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -4,7 +4,7 @@ use crate::{ component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType}, entity::Entity, query::{debug_checked_unreachable, Access, FilteredAccess}, - storage::{ComponentSparseSet, Table, Tables}, + storage::{ComponentSparseSet, SparseArray, Table, Tables}, world::{Mut, World}, }; use bevy_ecs_macros::all_tuples; @@ -431,8 +431,7 @@ pub unsafe trait FetchState: Send + Sync + Sized { archetype: &Archetype, access: &mut Access, ); - fn matches_archetype(&self, archetype: &Archetype) -> bool; - fn matches_table(&self, table: &Table) -> bool; + fn matches_component_set(&self, component_set: &SparseArray) -> bool; } /// A fetch that is read only. @@ -480,12 +479,7 @@ unsafe impl FetchState for EntityState { } #[inline] - fn matches_archetype(&self, _archetype: &Archetype) -> bool { - true - } - - #[inline] - fn matches_table(&self, _table: &Table) -> bool { + fn matches_component_set(&self, _component_set: &SparseArray) -> bool { true } } @@ -588,12 +582,8 @@ unsafe impl FetchState for ReadState { } } - fn matches_archetype(&self, archetype: &Archetype) -> bool { - archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + component_set.contains(self.component_id) } } @@ -825,12 +815,8 @@ unsafe impl FetchState for WriteState { } } - fn matches_archetype(&self, archetype: &Archetype) -> bool { - archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + component_set.contains(self.component_id) } } @@ -1105,17 +1091,13 @@ unsafe impl FetchState for OptionState { archetype: &Archetype, access: &mut Access, ) { - if self.state.matches_archetype(archetype) { + if self.state.matches_component_set(archetype.component_ids()) { self.state .update_archetype_component_access(archetype, access); } } - fn matches_archetype(&self, _archetype: &Archetype) -> bool { - true - } - - fn matches_table(&self, _table: &Table) -> bool { + fn matches_component_set(&self, _component_set: &SparseArray) -> bool { true } } @@ -1153,7 +1135,7 @@ impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch { archetype: &'w Archetype, tables: &'w Tables, ) { - self.matches = state.state.matches_archetype(archetype); + self.matches = state.state.matches_component_set(archetype.component_ids()); if self.matches { self.fetch.set_archetype(&state.state, archetype, tables); } @@ -1161,7 +1143,7 @@ impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch { #[inline] unsafe fn set_table(&mut self, state: &Self::State, table: &'w Table) { - self.matches = state.state.matches_table(table); + self.matches = state.state.matches_component_set(table.component_ids()); if self.matches { self.fetch.set_table(&state.state, table); } @@ -1297,12 +1279,8 @@ unsafe impl FetchState for ChangeTrackersState { } } - fn matches_archetype(&self, archetype: &Archetype) -> bool { - archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + component_set.contains(self.component_id) } } @@ -1551,14 +1529,9 @@ macro_rules! impl_tuple_fetch { $($name.update_archetype_component_access(_archetype, _access);)* } - fn matches_archetype(&self, _archetype: &Archetype) -> bool { - let ($($name,)*) = self; - true $(&& $name.matches_archetype(_archetype))* - } - - fn matches_table(&self, _table: &Table) -> bool { + fn matches_component_set(&self, _component_set: &SparseArray) -> bool { let ($($name,)*) = self; - true $(&& $name.matches_table(_table))* + true $(&& $name.matches_component_set(_component_set))* } } @@ -1618,7 +1591,7 @@ macro_rules! impl_anytuple_fetch { let ($($name,)*) = &mut self.0; let ($($state,)*) = &_state.0; $( - $name.1 = $state.matches_archetype(_archetype); + $name.1 = $state.matches_component_set(_archetype.component_ids()); if $name.1 { $name.0.set_archetype($state, _archetype, _tables); } @@ -1630,7 +1603,7 @@ macro_rules! impl_anytuple_fetch { let ($($name,)*) = &mut self.0; let ($($state,)*) = &_state.0; $( - $name.1 = $state.matches_table(_table); + $name.1 = $state.matches_component_set(_table.component_ids()); if $name.1 { $name.0.set_table($state, _table); } @@ -1699,20 +1672,14 @@ macro_rules! impl_anytuple_fetch { fn update_archetype_component_access(&self, _archetype: &Archetype, _access: &mut Access) { let ($($name,)*) = &self.0; $( - if $name.matches_archetype(_archetype) { + if $name.matches_component_set(_archetype.component_ids()) { $name.update_archetype_component_access(_archetype, _access); } )* } - - fn matches_archetype(&self, _archetype: &Archetype) -> bool { - let ($($name,)*) = &self.0; - false $(|| $name.matches_archetype(_archetype))* - } - - fn matches_table(&self, _table: &Table) -> bool { + fn matches_component_set(&self, _component_set: &SparseArray) -> bool { let ($($name,)*) = &self.0; - false $(|| $name.matches_table(_table))* + false $(|| $name.matches_component_set(_component_set))* } } diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index 36dc70844eff8..82a09ff399041 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -6,7 +6,7 @@ use crate::{ debug_checked_unreachable, Access, Fetch, FetchState, FilteredAccess, QueryFetch, ROQueryFetch, WorldQuery, WorldQueryGats, }, - storage::{ComponentSparseSet, Table, Tables}, + storage::{ComponentSparseSet, SparseArray, Table, Tables}, world::World, }; use bevy_ecs_macros::all_tuples; @@ -90,12 +90,8 @@ unsafe impl FetchState for WithState { ) { } - fn matches_archetype(&self, archetype: &Archetype) -> bool { - archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + component_set.contains(self.component_id) } } @@ -232,13 +228,8 @@ unsafe impl FetchState for WithoutState { _access: &mut Access, ) { } - - fn matches_archetype(&self, archetype: &Archetype) -> bool { - !archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - !table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + !component_set.contains(self.component_id) } } @@ -390,7 +381,7 @@ macro_rules! impl_query_filter_tuple { let ($($filter,)*) = &mut self.0; let ($($state,)*) = &state.0; $( - $filter.matches = $state.matches_table(table); + $filter.matches = $state.matches_component_set(table.component_ids()); if $filter.matches { $filter.fetch.set_table($state, table); } @@ -402,7 +393,7 @@ macro_rules! impl_query_filter_tuple { let ($($filter,)*) = &mut self.0; let ($($state,)*) = &state.0; $( - $filter.matches = $state.matches_archetype(archetype); + $filter.matches = $state.matches_component_set(archetype.component_ids()); if $filter.matches { $filter.fetch.set_archetype($state, archetype, tables); } @@ -477,14 +468,9 @@ macro_rules! impl_query_filter_tuple { $($filter.update_archetype_component_access(archetype, access);)* } - fn matches_archetype(&self, archetype: &Archetype) -> bool { + fn matches_component_set(&self, _component_set: &SparseArray) -> bool { let ($($filter,)*) = &self.0; - false $(|| $filter.matches_archetype(archetype))* - } - - fn matches_table(&self, table: &Table) -> bool { - let ($($filter,)*) = &self.0; - false $(|| $filter.matches_table(table))* + false $(|| $filter.matches_component_set(_component_set))* } } @@ -564,12 +550,8 @@ macro_rules! impl_tick_filter { } } - fn matches_archetype(&self, archetype: &Archetype) -> bool { - archetype.contains(self.component_id) - } - - fn matches_table(&self, table: &Table) -> bool { - table.has_column(self.component_id) + fn matches_component_set(&self, component_set: &SparseArray) -> bool { + component_set.contains(self.component_id) } } diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index ae23c1c512e8e..7db4e0e86607f 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -115,8 +115,12 @@ impl QueryState { /// Creates a new [`Archetype`]. pub fn new_archetype(&mut self, archetype: &Archetype) { - if self.fetch_state.matches_archetype(archetype) - && self.filter_state.matches_archetype(archetype) + if self + .fetch_state + .matches_component_set(archetype.component_ids()) + && self + .filter_state + .matches_component_set(archetype.component_ids()) { self.fetch_state .update_archetype_component_access(archetype, &mut self.archetype_component_access); diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index e21a4f4723c14..2bd2cf5abd2ca 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -370,6 +370,10 @@ impl SparseSet { pub fn values_mut(&mut self) -> impl Iterator { self.dense.iter_mut() } + + pub fn sparse_array(&self) -> &SparseArray { + &self.sparse + } } pub trait SparseSetIndex: Clone + PartialEq + Eq + Hash { diff --git a/crates/bevy_ecs/src/storage/table.rs b/crates/bevy_ecs/src/storage/table.rs index 755644998decf..fbdd1cc151f51 100644 --- a/crates/bevy_ecs/src/storage/table.rs +++ b/crates/bevy_ecs/src/storage/table.rs @@ -405,6 +405,10 @@ impl Table { column.clear(); } } + + pub fn component_ids(&self) -> &super::SparseArray { + self.columns.sparse_array() + } } /// A collection of [`Table`] storages, indexed by [`TableId`] From fb967a065115d564672cb207880ee7b23a13b807 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 20 May 2022 01:31:28 +0100 Subject: [PATCH 2/3] a --- crates/bevy_ecs/src/query/fetch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index e1798ba176f9d..041dc2e78bae2 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -421,7 +421,7 @@ pub trait Fetch<'world>: Sized { /// /// Implementor must ensure that [`FetchState::update_component_access`] and /// [`FetchState::update_archetype_component_access`] exactly reflects the results of -/// [`FetchState::matches_archetype`], [`FetchState::matches_table`], [`Fetch::archetype_fetch`], and +/// [`FetchState::matches_component_set`], [`Fetch::archetype_fetch`], and /// [`Fetch::table_fetch`]. pub unsafe trait FetchState: Send + Sync + Sized { fn init(world: &mut World) -> Self; From 30a168f943bf92ab4434d6c9e4c50ec6cca8526a Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 21 May 2022 00:13:40 +0100 Subject: [PATCH 3/3] review discussion avoidance --- crates/bevy_ecs/macros/src/fetch.rs | 4 +- crates/bevy_ecs/src/archetype.rs | 5 --- crates/bevy_ecs/src/query/fetch.rs | 47 +++++++++++++---------- crates/bevy_ecs/src/query/filter.rs | 22 +++++------ crates/bevy_ecs/src/query/state.rs | 4 +- crates/bevy_ecs/src/storage/sparse_set.rs | 4 -- crates/bevy_ecs/src/storage/table.rs | 4 -- 7 files changed, 42 insertions(+), 48 deletions(-) diff --git a/crates/bevy_ecs/macros/src/fetch.rs b/crates/bevy_ecs/macros/src/fetch.rs index b46e597142056..50adea5691e2e 100644 --- a/crates/bevy_ecs/macros/src/fetch.rs +++ b/crates/bevy_ecs/macros/src/fetch.rs @@ -279,8 +279,8 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream { #(self.#field_idents.update_archetype_component_access(_archetype, _access);)* } - fn matches_component_set(&self, _component_set: &#path::storage::SparseArray<#path::component::ComponentId, usize>) -> bool { - true #(&& self.#field_idents.matches_component_set(_component_set))* + fn matches_component_set(&self, _set_contains_id: &impl Fn(#path::component::ComponentId) -> bool) -> bool { + true #(&& self.#field_idents.matches_component_set(_set_contains_id))* } } diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index e7791744a5a15..ab33119a93be6 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -221,11 +221,6 @@ impl Archetype { self.components.indices() } - #[inline] - pub fn component_ids(&self) -> &SparseArray { - self.components.sparse_array() - } - #[inline] pub fn edges(&self) -> &Edges { &self.edges diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 041dc2e78bae2..fafd634f8a464 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -4,7 +4,7 @@ use crate::{ component::{Component, ComponentId, ComponentStorage, ComponentTicks, StorageType}, entity::Entity, query::{debug_checked_unreachable, Access, FilteredAccess}, - storage::{ComponentSparseSet, SparseArray, Table, Tables}, + storage::{ComponentSparseSet, Table, Tables}, world::{Mut, World}, }; use bevy_ecs_macros::all_tuples; @@ -431,7 +431,7 @@ pub unsafe trait FetchState: Send + Sync + Sized { archetype: &Archetype, access: &mut Access, ); - fn matches_component_set(&self, component_set: &SparseArray) -> bool; + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool; } /// A fetch that is read only. @@ -479,7 +479,7 @@ unsafe impl FetchState for EntityState { } #[inline] - fn matches_component_set(&self, _component_set: &SparseArray) -> bool { + fn matches_component_set(&self, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { true } } @@ -582,8 +582,8 @@ unsafe impl FetchState for ReadState { } } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + set_contains_id(self.component_id) } } @@ -815,8 +815,8 @@ unsafe impl FetchState for WriteState { } } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + set_contains_id(self.component_id) } } @@ -1091,13 +1091,16 @@ unsafe impl FetchState for OptionState { archetype: &Archetype, access: &mut Access, ) { - if self.state.matches_component_set(archetype.component_ids()) { + if self + .state + .matches_component_set(&|id| archetype.contains(id)) + { self.state .update_archetype_component_access(archetype, access); } } - fn matches_component_set(&self, _component_set: &SparseArray) -> bool { + fn matches_component_set(&self, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { true } } @@ -1135,7 +1138,9 @@ impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch { archetype: &'w Archetype, tables: &'w Tables, ) { - self.matches = state.state.matches_component_set(archetype.component_ids()); + self.matches = state + .state + .matches_component_set(&|id| archetype.contains(id)); if self.matches { self.fetch.set_archetype(&state.state, archetype, tables); } @@ -1143,7 +1148,9 @@ impl<'w, T: Fetch<'w>> Fetch<'w> for OptionFetch { #[inline] unsafe fn set_table(&mut self, state: &Self::State, table: &'w Table) { - self.matches = state.state.matches_component_set(table.component_ids()); + self.matches = state + .state + .matches_component_set(&|id| table.has_column(id)); if self.matches { self.fetch.set_table(&state.state, table); } @@ -1279,8 +1286,8 @@ unsafe impl FetchState for ChangeTrackersState { } } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + set_contains_id(self.component_id) } } @@ -1529,9 +1536,9 @@ macro_rules! impl_tuple_fetch { $($name.update_archetype_component_access(_archetype, _access);)* } - fn matches_component_set(&self, _component_set: &SparseArray) -> bool { + fn matches_component_set(&self, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { let ($($name,)*) = self; - true $(&& $name.matches_component_set(_component_set))* + true $(&& $name.matches_component_set(_set_contains_id))* } } @@ -1591,7 +1598,7 @@ macro_rules! impl_anytuple_fetch { let ($($name,)*) = &mut self.0; let ($($state,)*) = &_state.0; $( - $name.1 = $state.matches_component_set(_archetype.component_ids()); + $name.1 = $state.matches_component_set(&|id| _archetype.contains(id)); if $name.1 { $name.0.set_archetype($state, _archetype, _tables); } @@ -1603,7 +1610,7 @@ macro_rules! impl_anytuple_fetch { let ($($name,)*) = &mut self.0; let ($($state,)*) = &_state.0; $( - $name.1 = $state.matches_component_set(_table.component_ids()); + $name.1 = $state.matches_component_set(&|id| _table.has_column(id)); if $name.1 { $name.0.set_table($state, _table); } @@ -1672,14 +1679,14 @@ macro_rules! impl_anytuple_fetch { fn update_archetype_component_access(&self, _archetype: &Archetype, _access: &mut Access) { let ($($name,)*) = &self.0; $( - if $name.matches_component_set(_archetype.component_ids()) { + if $name.matches_component_set(&|id| _archetype.contains(id)) { $name.update_archetype_component_access(_archetype, _access); } )* } - fn matches_component_set(&self, _component_set: &SparseArray) -> bool { + fn matches_component_set(&self, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { let ($($name,)*) = &self.0; - false $(|| $name.matches_component_set(_component_set))* + false $(|| $name.matches_component_set(_set_contains_id))* } } diff --git a/crates/bevy_ecs/src/query/filter.rs b/crates/bevy_ecs/src/query/filter.rs index 82a09ff399041..c973765be6bb8 100644 --- a/crates/bevy_ecs/src/query/filter.rs +++ b/crates/bevy_ecs/src/query/filter.rs @@ -6,7 +6,7 @@ use crate::{ debug_checked_unreachable, Access, Fetch, FetchState, FilteredAccess, QueryFetch, ROQueryFetch, WorldQuery, WorldQueryGats, }, - storage::{ComponentSparseSet, SparseArray, Table, Tables}, + storage::{ComponentSparseSet, Table, Tables}, world::World, }; use bevy_ecs_macros::all_tuples; @@ -90,8 +90,8 @@ unsafe impl FetchState for WithState { ) { } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + set_contains_id(self.component_id) } } @@ -228,8 +228,8 @@ unsafe impl FetchState for WithoutState { _access: &mut Access, ) { } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - !component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + !set_contains_id(self.component_id) } } @@ -381,7 +381,7 @@ macro_rules! impl_query_filter_tuple { let ($($filter,)*) = &mut self.0; let ($($state,)*) = &state.0; $( - $filter.matches = $state.matches_component_set(table.component_ids()); + $filter.matches = $state.matches_component_set(&|id| table.has_column(id)); if $filter.matches { $filter.fetch.set_table($state, table); } @@ -393,7 +393,7 @@ macro_rules! impl_query_filter_tuple { let ($($filter,)*) = &mut self.0; let ($($state,)*) = &state.0; $( - $filter.matches = $state.matches_component_set(archetype.component_ids()); + $filter.matches = $state.matches_component_set(&|id| archetype.contains(id)); if $filter.matches { $filter.fetch.set_archetype($state, archetype, tables); } @@ -468,9 +468,9 @@ macro_rules! impl_query_filter_tuple { $($filter.update_archetype_component_access(archetype, access);)* } - fn matches_component_set(&self, _component_set: &SparseArray) -> bool { + fn matches_component_set(&self, _set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { let ($($filter,)*) = &self.0; - false $(|| $filter.matches_component_set(_component_set))* + false $(|| $filter.matches_component_set(_set_contains_id))* } } @@ -550,8 +550,8 @@ macro_rules! impl_tick_filter { } } - fn matches_component_set(&self, component_set: &SparseArray) -> bool { - component_set.contains(self.component_id) + fn matches_component_set(&self, set_contains_id: &impl Fn(ComponentId) -> bool) -> bool { + set_contains_id(self.component_id) } } diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 7db4e0e86607f..fd8ec31e48710 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -117,10 +117,10 @@ impl QueryState { pub fn new_archetype(&mut self, archetype: &Archetype) { if self .fetch_state - .matches_component_set(archetype.component_ids()) + .matches_component_set(&|id| archetype.contains(id)) && self .filter_state - .matches_component_set(archetype.component_ids()) + .matches_component_set(&|id| archetype.contains(id)) { self.fetch_state .update_archetype_component_access(archetype, &mut self.archetype_component_access); diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index 2bd2cf5abd2ca..e21a4f4723c14 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -370,10 +370,6 @@ impl SparseSet { pub fn values_mut(&mut self) -> impl Iterator { self.dense.iter_mut() } - - pub fn sparse_array(&self) -> &SparseArray { - &self.sparse - } } pub trait SparseSetIndex: Clone + PartialEq + Eq + Hash { diff --git a/crates/bevy_ecs/src/storage/table.rs b/crates/bevy_ecs/src/storage/table.rs index fbdd1cc151f51..755644998decf 100644 --- a/crates/bevy_ecs/src/storage/table.rs +++ b/crates/bevy_ecs/src/storage/table.rs @@ -405,10 +405,6 @@ impl Table { column.clear(); } } - - pub fn component_ids(&self) -> &super::SparseArray { - self.columns.sparse_array() - } } /// A collection of [`Table`] storages, indexed by [`TableId`]