summaryrefslogtreecommitdiff
path: root/ecs/src/query.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-06-16 13:17:57 +0200
committerHampusM <hampus@hampusmat.com>2024-06-16 13:17:57 +0200
commitd50a2f6e63c25adf3b64652310c423717bd3966f (patch)
tree3edf4ee3d1eec93a52a8de4fdc5a7be5c487c711 /ecs/src/query.rs
parent69d90ece7f54996f0f51fc120a38d37717c5248e (diff)
refactor(ecs): add component ID struct
Diffstat (limited to 'ecs/src/query.rs')
-rw-r--r--ecs/src/query.rs25
1 files changed, 11 insertions, 14 deletions
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::<Comps>()))
.iter()
.map((|archetype| archetype.components.as_slice()) as ComponentIterMapFn)
@@ -124,9 +125,7 @@ where
fn get_comparable() -> Box<dyn Any>
{
- 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::<HashSet<TypeId>>();
+ .map(|(id, _)| id)
+ .collect::<HashSet<_>>();
- 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))
}
}