From 373a0d53f31b838b3f650a37df39176a31a6c1c4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 2 Nov 2024 23:19:10 +0100 Subject: refactor(ecs): make ComponentIter not know entity iter details --- ecs/src/query.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ecs/src/query.rs') diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 944deb1..d0fa872 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -40,9 +40,7 @@ where { /// Iterates over the entities matching this query. #[must_use] - pub fn iter<'this>(&'this self) -> ComponentIter<'world, Comps> - where - 'this: 'world, + pub fn iter(&'world self) -> ComponentIter<'world, Comps, QueryEntityIter<'world>> { #[cfg(feature = "debug")] tracing::debug!("Searching for {}", std::any::type_name::()); @@ -93,7 +91,7 @@ where Comps: ComponentSequence, OptionsT: Options, { - type IntoIter = ComponentIter<'world, Comps>; + type IntoIter = ComponentIter<'world, Comps, QueryEntityIter<'world>>; type Item = Comps::Refs<'world>; fn into_iter(self) -> Self::IntoIter @@ -149,19 +147,24 @@ type ComponentIterMapFn = for<'a> fn(&'a Archetype) -> EntityIter<'a>; type ComponentIterFilterFn = for<'a, 'b> fn(&'a &'b ArchetypeEntity) -> bool; -pub struct ComponentIter<'world, Comps> +type QueryEntityIter<'world> = Filter< + Flatten, ComponentIterMapFn>>, + ComponentIterFilterFn, +>; + +pub struct ComponentIter<'world, Comps, EntityIter> +where + EntityIter: Iterator, { world: &'world World, - entities: Filter< - Flatten, ComponentIterMapFn>>, - ComponentIterFilterFn, - >, + entities: EntityIter, comps_pd: PhantomData, } -impl<'world, Comps> Iterator for ComponentIter<'world, Comps> +impl<'world, Comps, EntityIter> Iterator for ComponentIter<'world, Comps, EntityIter> where Comps: ComponentSequence + 'world, + EntityIter: Iterator, { type Item = Comps::Refs<'world>; -- cgit v1.2.3-18-g5258