diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-21 20:05:53 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-22 15:16:01 +0100 |
commit | fe62665b1d62d36ee0839e6bf24e3841ea667da9 (patch) | |
tree | 0533941d2cbbe5bf0a1995a33f05bca37da949fd /ecs/src/query/flexible.rs | |
parent | 76e7e612e7b516bf52b508ae5bb367b1ddc3babc (diff) |
refactor(ecs): replace query options with fieldless terms
Diffstat (limited to 'ecs/src/query/flexible.rs')
-rw-r--r-- | ecs/src/query/flexible.rs | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs index a3e8701..7d24dc9 100644 --- a/ecs/src/query/flexible.rs +++ b/ecs/src/query/flexible.rs @@ -1,10 +1,13 @@ //! Low-level querying. -use std::iter::{repeat_n, Filter, FlatMap, RepeatN, Zip}; +use std::iter::{repeat_n, FlatMap, RepeatN, Zip}; use crate::component::storage::archetype::{Archetype, ArchetypeEntity, EntityIter}; -use crate::component::storage::{ArchetypeRefIter, Storage as ComponentStorage}; +use crate::component::storage::{ + ArchetypeRefIter, + ArchetypeSearchTerms, + Storage as ComponentStorage, +}; use crate::lock::ReadGuard; -use crate::query::options::Options; use crate::query::Terms; use crate::uid::Uid; use crate::{EntityComponent, World}; @@ -21,19 +24,21 @@ impl<'world, 'terms> Query<'world, 'terms> { /// Iterates over the entities matching this query. #[must_use] - pub fn iter<OptionsT: Options>(&self) -> Iter<'_> + pub fn iter(&self) -> Iter<'_> { Iter { iter: self .component_storage - .search_archetypes(self.terms.required_components.as_ref()) + .search_archetypes(ArchetypeSearchTerms { + required_components: &self.terms.required_components, + excluded_components: &self.terms.excluded_components, + }) .flat_map( (|archetype| { repeat_n(archetype, archetype.entity_cnt()) .zip(archetype.entities()) }) as ComponentIterMapFn, - ) - .filter(|(_, entity)| OptionsT::entity_filter(&entity.components)), + ), } } @@ -85,16 +90,11 @@ impl<'query> EntityHandle<'query> #[inline] #[must_use] - pub fn components(&self) -> &'query [EntityComponent] + pub fn get_component(&self, component_uid: Uid) -> Option<&'query EntityComponent> { - &self.entity.components - } + let index = self.archetype.get_index_for_component(component_uid)?; - #[inline] - #[must_use] - pub fn get_component_index(&self, component_uid: Uid) -> Option<usize> - { - self.archetype.get_index_for_component(component_uid) + Some(self.entity.components.get(index).unwrap()) } } @@ -102,14 +102,8 @@ type ComponentIterMapFnOutput<'a> = Zip<RepeatN<&'a Archetype>, EntityIter<'a>>; type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> ComponentIterMapFnOutput<'a>; -type ComponentIterFilterFn = - for<'a, 'b> fn(&'a (&'b Archetype, &'b ArchetypeEntity)) -> bool; - -type QueryEntityIter<'query> = Filter< - FlatMap< - ArchetypeRefIter<'query>, - ComponentIterMapFnOutput<'query>, - ComponentIterMapFn, - >, - ComponentIterFilterFn, +type QueryEntityIter<'query> = FlatMap< + ArchetypeRefIter<'query, 'query>, + ComponentIterMapFnOutput<'query>, + ComponentIterMapFn, >; |