diff options
author | HampusM <hampus@hampusmat.com> | 2025-03-18 13:21:46 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-03-18 13:21:46 +0100 |
commit | 7a7d3a350b22b5555c27debff6fee4fc6100fa38 (patch) | |
tree | 9eb96f2563264f51691e2a06a7b95f8b39904d18 /ecs/src/query/flexible.rs | |
parent | ee7c0cb713891ae480407f56823289f3fe3b9807 (diff) |
Diffstat (limited to 'ecs/src/query/flexible.rs')
-rw-r--r-- | ecs/src/query/flexible.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs index 3bb8fd6..c42ec25 100644 --- a/ecs/src/query/flexible.rs +++ b/ecs/src/query/flexible.rs @@ -1,5 +1,5 @@ //! Low-level querying. -use std::iter::{repeat_n, Filter, Flatten, Map, RepeatN, Zip}; +use std::iter::{repeat_n, Filter, FlatMap, RepeatN, Zip}; use crate::component::storage::archetype::{Archetype, ArchetypeEntity, EntityIter}; use crate::component::storage::{ArchetypeRefIter, Storage as ComponentStorage}; @@ -30,19 +30,18 @@ where { /// Iterates over the entities matching this query. #[must_use] - pub fn iter<'query, OptionsT: Options>(&'query self) -> Iter<'query> + pub fn iter<OptionsT: Options>(&self) -> Iter<'_> { Iter { iter: self .component_storage - .search_archetypes(&self.comp_metadata.as_ref()) - .map( + .search_archetypes(self.comp_metadata.as_ref()) + .flat_map( (|archetype| { repeat_n(archetype, archetype.entity_cnt()) .zip(archetype.entities()) }) as ComponentIterMapFn, ) - .flatten() .filter(|(_, entity)| OptionsT::entity_filter(&entity.components)), } } @@ -110,31 +109,39 @@ impl<'query> EntityHandle<'query> { /// Returns the [`Uid`] of this entity. #[inline] + #[must_use] pub fn uid(&self) -> Uid { self.entity.uid } #[inline] + #[must_use] pub fn components(&self) -> &'query [EntityComponent] { &self.entity.components } #[inline] + #[must_use] pub fn get_component_index(&self, component_uid: Uid) -> Option<usize> { self.archetype.get_index_for_component(component_uid) } } -type ComponentIterMapFn = - for<'a> fn(&'a Archetype) -> Zip<RepeatN<&'a Archetype>, EntityIter<'a>>; +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< - Flatten<Map<ArchetypeRefIter<'query>, ComponentIterMapFn>>, + FlatMap< + ArchetypeRefIter<'query>, + ComponentIterMapFnOutput<'query>, + ComponentIterMapFn, + >, ComponentIterFilterFn, >; |