diff options
author | HampusM <hampus@hampusmat.com> | 2024-05-19 21:12:07 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-05-19 21:14:55 +0200 |
commit | 9863b431950c681225f8774af244a56adbd18937 (patch) | |
tree | c487a12b9a7b4d362687d9fa065748af1f12cca8 /ecs/src/lib.rs | |
parent | 355a19e630de61397bf70b69b7ab2356318be2b8 (diff) |
feat(ecs): add support for optional query components
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 009ff21..c2fc9c7 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -10,7 +10,11 @@ use std::sync::Arc; use std::vec::Drain; use crate::actions::Action; -use crate::component::{Component, Sequence as ComponentSequence}; +use crate::component::{ + Component, + IsOptional as ComponentIsOptional, + Sequence as ComponentSequence, +}; use crate::event::{Event, Id as EventId, Ids, Sequence as EventSequence}; use crate::extension::{Collector as ExtensionCollector, Extension}; use crate::lock::Lock; @@ -281,7 +285,7 @@ impl ComponentStorage fn find_entity_with_components( &self, start_index: usize, - component_type_ids: &[TypeId], + component_type_ids: &[(TypeId, ComponentIsOptional)], ) -> Option<(usize, &Entity)> { // TODO: This is a really dumb and slow way to do this. Refactor the world @@ -294,9 +298,13 @@ impl ComponentStorage .map(|component| component.id) .collect::<HashSet<_>>(); - if component_type_ids.iter().all(|component_type_id| { - entity_components.contains(component_type_id) - }) { + if component_type_ids + .iter() + .filter(|(_, is_optional)| *is_optional == ComponentIsOptional::No) + .all(|(component_type_id, _)| { + entity_components.contains(component_type_id) + }) + { return true; } |