diff options
author | HampusM <hampus@hampusmat.com> | 2025-04-09 20:50:14 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-04-10 17:04:40 +0200 |
commit | 94e5e592baea2935af7c94ad44805a09d0e30740 (patch) | |
tree | 358f7496ac40e2a7d7cae10cf04bf25246debdec /ecs/src/query | |
parent | b982b205373f445db9ced7f3cf13c1156ad8a40a (diff) |
feat(ecs): replace Relationship component with pair UID support
Diffstat (limited to 'ecs/src/query')
-rw-r--r-- | ecs/src/query/flexible.rs | 6 | ||||
-rw-r--r-- | ecs/src/query/term.rs | 31 |
2 files changed, 23 insertions, 14 deletions
diff --git a/ecs/src/query/flexible.rs b/ecs/src/query/flexible.rs index 2f0b5e7..3e72b34 100644 --- a/ecs/src/query/flexible.rs +++ b/ecs/src/query/flexible.rs @@ -16,6 +16,7 @@ use crate::World; #[derive(Debug)] pub struct Query<'world, const MAX_TERM_CNT: usize> { + world: &'world World, component_storage: ReadGuard<'world, ComponentStorage>, terms: Terms<MAX_TERM_CNT>, } @@ -27,6 +28,7 @@ impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT> pub fn iter(&self) -> Iter<'_> { Iter { + world: self.world, iter: self .component_storage .search_archetypes(ArchetypeSearchTerms { @@ -45,6 +47,7 @@ impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT> pub(crate) fn new(world: &'world World, terms: Terms<MAX_TERM_CNT>) -> Self { Self { + world, component_storage: world .data .component_storage @@ -57,6 +60,7 @@ impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT> pub struct Iter<'query> { + world: &'query World, iter: QueryEntityIter<'query>, } @@ -68,7 +72,7 @@ impl<'query> Iterator for Iter<'query> { let (archetype, entity) = self.iter.next()?; - Some(EntityHandle::new(archetype, entity)) + Some(EntityHandle::new(self.world, archetype, entity)) } } diff --git a/ecs/src/query/term.rs b/ecs/src/query/term.rs index 78668c5..597dd1a 100644 --- a/ecs/src/query/term.rs +++ b/ecs/src/query/term.rs @@ -8,42 +8,43 @@ use crate::query::{ TermsBuilder, TermsBuilderInterface, }; +use crate::uid::With as WithUid; -pub struct With<ComponentT> +pub struct With<WithUidT> where - ComponentT: Component, + WithUidT: WithUid, { - _pd: PhantomData<ComponentT>, + _pd: PhantomData<WithUidT>, } -impl<ComponentT> TermWithoutField for With<ComponentT> +impl<WithUidT> TermWithoutField for With<WithUidT> where - ComponentT: Component, + WithUidT: WithUid, { fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, ) { - terms_builder.with::<ComponentT>(); + terms_builder.with::<WithUidT>(); } } -pub struct Without<ComponentT> +pub struct Without<WithUidT> where - ComponentT: Component, + WithUidT: WithUid, { - _pd: PhantomData<ComponentT>, + _pd: PhantomData<WithUidT>, } -impl<ComponentT> TermWithoutField for Without<ComponentT> +impl<WithUidT> TermWithoutField for Without<WithUidT> where - ComponentT: Component, + WithUidT: WithUid, { fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, ) { - terms_builder.without::<ComponentT>(); + terms_builder.without::<WithUidT>(); } } @@ -66,7 +67,11 @@ where { Some( ComponentRefT::Handle::<'world>::from_entity_component_ref( - Some(entity_handle.get_component(ComponentRefT::Component::id())?), + Some( + entity_handle + .get_matching_components(ComponentRefT::Component::id()) + .next()?, + ), world, ) .unwrap_or_else(|err| { |