From 9226356b7b54c4c5b036b6fee00bba376245c5f3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 24 Jul 2026 22:32:21 +0200 Subject: feat(engine-ecs): add traversal query term --- engine-ecs/src/component/storage/archetype.rs | 32 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'engine-ecs/src/component/storage') diff --git a/engine-ecs/src/component/storage/archetype.rs b/engine-ecs/src/component/storage/archetype.rs index c5cce10..236bf97 100644 --- a/engine-ecs/src/component/storage/archetype.rs +++ b/engine-ecs/src/component/storage/archetype.rs @@ -107,11 +107,6 @@ impl Archetype EntityIter { iter: self.entities.iter() } } - pub fn entity_cnt(&self) -> usize - { - self.entities.len() - } - pub fn component_cnt(&self) -> usize { self.component_index_lookup.len() @@ -182,6 +177,33 @@ impl Archetype self.contains_component_with_exact_id(component_id) } + pub fn get_matching_component_ids( + &self, + component_id: Uid, + ) -> impl Iterator + use<'_> + { + if component_id.is_pair() && component_id.target() == Uid::wildcard() { + return Either::A( + self.component_ids + .iter() + .filter(move |other_comp_id| { + other_comp_id.is_pair() + && other_comp_id.has_same_relation_as(component_id) + }) + .copied(), + ); + } + + Either::B( + (if self.contains_component_with_exact_id(component_id) { + Some(component_id) + } else { + None + }) + .into_iter(), + ) + } + pub fn contains_component_with_exact_id(&self, component_id: Uid) -> bool { debug_assert!( -- cgit v1.2.3-18-g5258