summaryrefslogtreecommitdiff
path: root/ecs/src/query.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-19 21:12:07 +0200
committerHampusM <hampus@hampusmat.com>2024-05-19 21:14:55 +0200
commit9863b431950c681225f8774af244a56adbd18937 (patch)
treec487a12b9a7b4d362687d9fa065748af1f12cca8 /ecs/src/query.rs
parent355a19e630de61397bf70b69b7ab2356318be2b8 (diff)
feat(ecs): add support for optional query components
Diffstat (limited to 'ecs/src/query.rs')
-rw-r--r--ecs/src/query.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/ecs/src/query.rs b/ecs/src/query.rs
index 683dde7..61e2797 100644
--- a/ecs/src/query.rs
+++ b/ecs/src/query.rs
@@ -3,7 +3,10 @@ use std::collections::HashSet;
use std::marker::PhantomData;
use std::sync::{Arc, Weak};
-use crate::component::Sequence as ComponentSequence;
+use crate::component::{
+ IsOptional as ComponentIsOptional,
+ Sequence as ComponentSequence,
+};
use crate::lock::{Lock, ReadGuard};
use crate::system::{
NoInitParamFlag as NoInitSystemParamFlag,
@@ -184,7 +187,7 @@ pub struct ComponentIter<'world, Comps>
{
component_storage: &'world ComponentStorage,
current_entity_index: usize,
- component_type_ids: Vec<TypeId>,
+ component_type_ids: Vec<(TypeId, ComponentIsOptional)>,
comps_pd: PhantomData<Comps>,
}
@@ -216,7 +219,7 @@ where
#[derive(Debug)]
struct QueryComponentIds
{
- component_type_ids: Vec<TypeId>,
+ component_type_ids: Vec<(TypeId, ComponentIsOptional)>,
}
impl QueryComponentIds
@@ -227,10 +230,13 @@ impl QueryComponentIds
{
let other_component_type_ids = OtherComps::type_ids()
.into_iter()
+ .map(|(type_id, _)| type_id)
.collect::<HashSet<TypeId>>();
self.component_type_ids
.iter()
- .all(|component_type_id| other_component_type_ids.contains(component_type_id))
+ .all(|(component_type_id, _)| {
+ other_component_type_ids.contains(component_type_id)
+ })
}
}