summaryrefslogtreecommitdiff
path: root/ecs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-11-02 23:19:10 +0100
committerHampusM <hampus@hampusmat.com>2024-11-02 23:19:10 +0100
commit373a0d53f31b838b3f650a37df39176a31a6c1c4 (patch)
treeadf271c8185dac2de842483358b177b3f06d5103 /ecs
parentf71f967a8d804181038116fe2ad9776c08ddcfbc (diff)
refactor(ecs): make ComponentIter not know entity iter details
Diffstat (limited to 'ecs')
-rw-r--r--ecs/src/query.rs23
1 files changed, 13 insertions, 10 deletions
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::<Comps>());
@@ -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<Map<ArchetypeRefIter<'world>, ComponentIterMapFn>>,
+ ComponentIterFilterFn,
+>;
+
+pub struct ComponentIter<'world, Comps, EntityIter>
+where
+ EntityIter: Iterator<Item = &'world ArchetypeEntity>,
{
world: &'world World,
- entities: Filter<
- Flatten<Map<ArchetypeRefIter<'world>, ComponentIterMapFn>>,
- ComponentIterFilterFn,
- >,
+ entities: EntityIter,
comps_pd: PhantomData<Comps>,
}
-impl<'world, Comps> Iterator for ComponentIter<'world, Comps>
+impl<'world, Comps, EntityIter> Iterator for ComponentIter<'world, Comps, EntityIter>
where
Comps: ComponentSequence + 'world,
+ EntityIter: Iterator<Item = &'world ArchetypeEntity>,
{
type Item = Comps::Refs<'world>;