diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-01 12:36:35 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-01 12:36:35 +0200 |
commit | 70c7d745f918dd23343599963a619539f4f880cb (patch) | |
tree | 076779b4364649fcea76ce07a6cd1d6b8d6956f2 /ecs/src/query.rs | |
parent | a5c45dab18399461aff5dc13c471ea6c5ec80c34 (diff) |
refactor(ecs): add & use component metadata struct
Diffstat (limited to 'ecs/src/query.rs')
-rw-r--r-- | ecs/src/query.rs | 31 |
1 files changed, 8 insertions, 23 deletions
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<dyn Any> { - 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::<Comps>() ); - 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::<Vec<_>>(), - ); + 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<ComponentMetadata>, } 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::<HashSet<_>>(); self.component_ids .iter() - .all(|(id, _)| other_ids.contains(id)) + .all(|component_metadata| other_ids.contains(&component_metadata.id)) } } |