From 70c7d745f918dd23343599963a619539f4f880cb Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 1 Aug 2024 12:36:35 +0200 Subject: refactor(ecs): add & use component metadata struct --- ecs/src/query.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'ecs/src/query.rs') diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 2c52206..bc98ac0 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -9,11 +9,7 @@ use crate::component::storage::{ ArchetypeRefIter, Storage as ComponentStorage, }; -use crate::component::{ - Id as ComponentId, - IsOptional as ComponentIsOptional, - Sequence as ComponentSequence, -}; +use crate::component::{Metadata as ComponentMetadata, Sequence as ComponentSequence}; use crate::lock::{Lock, ReadGuard}; use crate::query::options::Options; use crate::system::{ @@ -52,7 +48,7 @@ where ComponentIter { entities: self .component_storage - .find_entities(&Comps::ids()) + .find_entities(Comps::metadata()) .map((|archetype| archetype.components.as_slice()) as ComponentIterMapFn) .flatten() .filter(|components| OptionsT::entity_filter(*components)), @@ -124,7 +120,7 @@ where fn get_comparable() -> Box { - Box::new(QueryComponentIds { component_ids: Comps::ids() }) + Box::new(QueryComponentIds { component_ids: Comps::metadata() }) } fn prepare(world_data: &WorldData) @@ -140,18 +136,7 @@ where std::any::type_name::() ); - component_storage_lock.add_archetype_lookup_entry( - &Comps::ids() - .into_iter() - .filter_map(|(component_id, is_optional)| { - if is_optional == ComponentIsOptional::Yes { - return None; - } - - Some(component_id) - }) - .collect::>(), - ); + component_storage_lock.add_archetype_lookup_entry(Comps::metadata()); } } @@ -183,7 +168,7 @@ where #[derive(Debug)] struct QueryComponentIds { - component_ids: Vec<(ComponentId, ComponentIsOptional)>, + component_ids: Vec, } impl QueryComponentIds @@ -192,13 +177,13 @@ impl QueryComponentIds where OtherComps: ComponentSequence, { - let other_ids = OtherComps::ids() + let other_ids = OtherComps::metadata() .into_iter() - .map(|(id, _)| id) + .map(|component_metadata| component_metadata.id) .collect::>(); self.component_ids .iter() - .all(|(id, _)| other_ids.contains(id)) + .all(|component_metadata| other_ids.contains(&component_metadata.id)) } } -- cgit v1.2.3-18-g5258