From 9863b431950c681225f8774af244a56adbd18937 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 May 2024 21:12:07 +0200 Subject: feat(ecs): add support for optional query components --- ecs/src/query.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ecs/src/query.rs') 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, + component_type_ids: Vec<(TypeId, ComponentIsOptional)>, comps_pd: PhantomData, } @@ -216,7 +219,7 @@ where #[derive(Debug)] struct QueryComponentIds { - component_type_ids: Vec, + 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::>(); 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) + }) } } -- cgit v1.2.3-18-g5258