summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-06-07 20:23:34 +0200
committerHampusM <hampus@hampusmat.com>2025-06-07 20:23:34 +0200
commitaeed1b1ff3e34fe719a2f7e6097584b99a673ded (patch)
tree98158913fa3d1482358a21426bcbbf4312afe02f
parentcaf56d34449b471169b7c71eddabad230449dfe3 (diff)
refactor(ecs): make entity::Handle not hold world reference
-rw-r--r--ecs/src/entity.rs9
-rw-r--r--ecs/src/pair.rs2
-rw-r--r--ecs/src/query/flexible.rs4
3 files changed, 4 insertions, 11 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs
index 196bd01..4496a2b 100644
--- a/ecs/src/entity.rs
+++ b/ecs/src/entity.rs
@@ -19,7 +19,6 @@ use crate::{EntityComponentRef, World};
#[derive(Debug)]
pub struct Handle<'a>
{
- _world: &'a World,
archetype: &'a Archetype,
entity: &'a ArchetypeEntity,
}
@@ -97,13 +96,9 @@ impl<'a> Handle<'a>
}
}
- pub(crate) fn new(
- world: &'a World,
- archetype: &'a Archetype,
- entity: &'a ArchetypeEntity,
- ) -> Self
+ pub(crate) fn new(archetype: &'a Archetype, entity: &'a ArchetypeEntity) -> Self
{
- Self { _world: world, archetype, entity }
+ Self { archetype, entity }
}
}
diff --git a/ecs/src/pair.rs b/ecs/src/pair.rs
index 2055d5e..4ff4995 100644
--- a/ecs/src/pair.rs
+++ b/ecs/src/pair.rs
@@ -140,7 +140,7 @@ impl Handle<'_>
unreachable!();
};
- Some(EntityHandle::new(self.world, archetype, archetype_entity))
+ Some(EntityHandle::new(archetype, archetype_entity))
}
}
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs
index 6d65ee0..add30b0 100644
--- a/ecs/src/query/flexible.rs
+++ b/ecs/src/query/flexible.rs
@@ -22,7 +22,6 @@ impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT>
pub fn iter(&self) -> Iter<'_>
{
Iter {
- world: self.world,
iter: self
.world
.data
@@ -59,7 +58,6 @@ impl<'query, const MAX_TERM_CNT: usize> IntoIterator for &'query Query<'_, MAX_T
pub struct Iter<'query>
{
- world: &'query World,
iter: QueryEntityIter<'query>,
}
@@ -71,7 +69,7 @@ impl<'query> Iterator for Iter<'query>
{
let (archetype, entity) = self.iter.next()?;
- Some(EntityHandle::new(self.world, archetype, entity))
+ Some(EntityHandle::new(archetype, entity))
}
}