From d50a2f6e63c25adf3b64652310c423717bd3966f Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 16 Jun 2024 13:17:57 +0200 Subject: refactor(ecs): add component ID struct --- ecs/src/query.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'ecs/src/query.rs') diff --git a/ecs/src/query.rs b/ecs/src/query.rs index de6c832..a2edc4d 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -1,4 +1,4 @@ -use std::any::{type_name, Any, TypeId}; +use std::any::{type_name, Any}; use std::collections::HashSet; use std::iter::{Flatten, Map}; use std::marker::PhantomData; @@ -7,6 +7,7 @@ use std::sync::{Arc, Weak}; use crate::component::storage::Archetype; use crate::component::{ + Id as ComponentId, IsOptional as ComponentIsOptional, Sequence as ComponentSequence, }; @@ -43,7 +44,7 @@ where ComponentIter { entities: self .component_storage - .find_entities(&Comps::type_ids()) + .find_entities(&Comps::ids()) .unwrap_or_else(|| panic!("Could not find {:?}", type_name::())) .iter() .map((|archetype| archetype.components.as_slice()) as ComponentIterMapFn) @@ -124,9 +125,7 @@ where fn get_comparable() -> Box { - Box::new(QueryComponentIds { - component_type_ids: Comps::type_ids(), - }) + Box::new(QueryComponentIds { component_ids: Comps::ids() }) } fn handle_pre_run(world_data: &WorldData) @@ -143,7 +142,7 @@ where ); component_storage_lock.add_archetype_lookup_entry( - &Comps::type_ids() + &Comps::ids() .into_iter() .filter_map(|(component_id, is_optional)| { if is_optional == ComponentIsOptional::Yes { @@ -242,7 +241,7 @@ where #[derive(Debug)] struct QueryComponentIds { - component_type_ids: Vec<(TypeId, ComponentIsOptional)>, + component_ids: Vec<(ComponentId, ComponentIsOptional)>, } impl QueryComponentIds @@ -251,15 +250,13 @@ impl QueryComponentIds where OtherComps: ComponentSequence, { - let other_component_type_ids = OtherComps::type_ids() + let other_ids = OtherComps::ids() .into_iter() - .map(|(type_id, _)| type_id) - .collect::>(); + .map(|(id, _)| id) + .collect::>(); - self.component_type_ids + self.component_ids .iter() - .all(|(component_type_id, _)| { - other_component_type_ids.contains(component_type_id) - }) + .all(|(id, _)| other_ids.contains(id)) } } -- cgit v1.2.3-18-g5258