diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-16 20:13:22 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-16 20:13:22 +0200 |
commit | 7d218b2525f90dfedcae02f3b3d0d2f7b9c99bd2 (patch) | |
tree | bc9523b82d138a7048ff583dd75e0a8c26fe5e6b /ecs/src/query.rs | |
parent | 0f7811f3cba24c8a5927d5bcdfb30dd94de87102 (diff) |
feat(ecs): make relationships creatable without reference to world
Diffstat (limited to 'ecs/src/query.rs')
-rw-r--r-- | ecs/src/query.rs | 16 |
1 files changed, 11 insertions, 5 deletions
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<Lock<ComponentStorage>>) -> 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<Other: SystemParam<'world>>() -> 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<Map<ArchetypeRefIter<'world>, ComponentIterMapFn>>, ComponentIterFilterFn, @@ -163,6 +168,7 @@ where { Some(Comps::from_components( self.entities.next()?.components().iter(), + self.world, )) } } |