From 7d218b2525f90dfedcae02f3b3d0d2f7b9c99bd2 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 16 Aug 2024 20:13:22 +0200 Subject: feat(ecs): make relationships creatable without reference to world --- ecs/src/query.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ecs/src/query.rs') diff --git a/ecs/src/query.rs b/ecs/src/query.rs index ea61640..06633bc 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -2,7 +2,6 @@ use std::any::Any; use std::collections::HashSet; use std::iter::{Filter, Flatten, Map}; use std::marker::PhantomData; -use std::sync::Arc; use crate::component::storage::{ Archetype, @@ -13,7 +12,7 @@ use crate::component::storage::{ }; use crate::component::{Metadata as ComponentMetadata, Sequence as ComponentSequence}; use crate::entity::Uid as EntityUid; -use crate::lock::{Lock, ReadGuard}; +use crate::lock::ReadGuard; use crate::query::options::Options; use crate::system::{ NoInitParamFlag as NoInitSystemParamFlag, @@ -29,6 +28,7 @@ pub struct Query<'world, Comps, OptionsT = ()> where Comps: ComponentSequence, { + world: &'world World, component_storage: ReadGuard<'world, ComponentStorage>, _pd: PhantomData<(Comps, OptionsT)>, } @@ -49,6 +49,7 @@ where #[allow(clippy::map_flatten)] ComponentIter { + world: self.world, entities: self .component_storage .find_entities(Comps::metadata()) @@ -72,10 +73,13 @@ where ) } - pub(crate) fn new(component_storage: &'world Arc>) -> Self + pub(crate) fn new(world: &'world World) -> Self { Self { - component_storage: component_storage + world, + component_storage: world + .data + .component_storage .read_nonblock() .expect("Failed to acquire read-only component storage lock"), _pd: PhantomData, @@ -118,7 +122,7 @@ where world: &'world World, ) -> Self { - Self::new(&world.data.component_storage) + Self::new(&world) } fn is_compatible>() -> bool @@ -146,6 +150,7 @@ type ComponentIterFilterFn = for<'a, 'b> fn(&'a &'b ArchetypeEntity) -> bool; pub struct ComponentIter<'world, Comps> { + world: &'world World, entities: Filter< Flatten, ComponentIterMapFn>>, ComponentIterFilterFn, @@ -163,6 +168,7 @@ where { Some(Comps::from_components( self.entities.next()?.components().iter(), + self.world, )) } } -- cgit v1.2.3-18-g5258