From aeed1b1ff3e34fe719a2f7e6097584b99a673ded Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 7 Jun 2025 20:23:34 +0200 Subject: refactor(ecs): make entity::Handle not hold world reference --- ecs/src/entity.rs | 9 ++------- ecs/src/pair.rs | 2 +- ecs/src/query/flexible.rs | 4 +--- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'ecs/src') 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)) } } -- cgit v1.2.3-18-g5258