summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine-ecs/src/component/storage.rs26
-rw-r--r--engine-ecs/src/lib.rs4
-rw-r--r--engine-ecs/src/pair.rs6
-rw-r--r--engine-ecs/src/query.rs82
-rw-r--r--engine-ecs/src/query/flexible.rs4
-rw-r--r--engine-ecs/src/query/term.rs4
6 files changed, 49 insertions, 77 deletions
diff --git a/engine-ecs/src/component/storage.rs b/engine-ecs/src/component/storage.rs
index e77cfa3..a4944c7 100644
--- a/engine-ecs/src/component/storage.rs
+++ b/engine-ecs/src/component/storage.rs
@@ -27,8 +27,8 @@ mod graph;
#[derive(Debug)]
pub struct ArchetypeSearchTerms<'a>
{
- pub required_components: &'a [Uid],
- pub excluded_components: &'a [Uid],
+ pub present: &'a [Uid],
+ pub absent: &'a [Uid],
}
impl ArchetypeSearchTerms<'_>
@@ -40,10 +40,10 @@ impl ArchetypeSearchTerms<'_>
|| (comp_id.is_pair() && comp_id.target() != Uid::wildcard())
);
- let is_found = self.excluded_components.binary_search(&comp_id).is_ok();
+ let is_found = self.absent.binary_search(&comp_id).is_ok();
if !is_found && comp_id.is_pair() {
- return self.excluded_components.iter().any(|excluded_comp_id| {
+ return self.absent.iter().any(|excluded_comp_id| {
excluded_comp_id.is_pair()
&& excluded_comp_id.has_same_relation_as(comp_id)
&& excluded_comp_id.target() == Uid::wildcard()
@@ -55,8 +55,8 @@ impl ArchetypeSearchTerms<'_>
fn contains_conflicting(&self) -> bool
{
- self.excluded_components.iter().any(|excluded_comp_id| {
- self.required_components
+ self.absent.iter().any(|excluded_comp_id| {
+ self.present
.binary_search(excluded_comp_id)
.is_ok()
})
@@ -64,7 +64,7 @@ impl ArchetypeSearchTerms<'_>
fn archetype_contains_all_required(&self, archetype: &Archetype) -> bool
{
- self.required_components
+ self.present
.iter()
.all(|comp_id| archetype.contains_matching_component(*comp_id))
}
@@ -85,7 +85,7 @@ impl Storage
search_terms: ArchetypeSearchTerms<'search_terms>,
) -> ArchetypeRefIter<'_, 'search_terms>
{
- let archetype_id = ArchetypeId::new(search_terms.required_components);
+ let archetype_id = ArchetypeId::new(search_terms.present);
if search_terms.contains_conflicting() {
return ArchetypeRefIter {
@@ -102,14 +102,14 @@ impl Storage
self.imaginary_archetypes
.borrow_mut()
.push(ImaginaryArchetype {
- id: ArchetypeId::new(search_terms.required_components.iter().filter(
+ id: ArchetypeId::new(search_terms.present.iter().filter(
|required_comp_id| {
!required_comp_id.is_pair()
|| required_comp_id.target() != Uid::wildcard()
},
)),
component_ids: search_terms
- .required_components
+ .present
.iter()
.copied()
.filter(|required_comp_id| {
@@ -406,7 +406,7 @@ impl Storage
.get_node_by_id(node_id)
.expect("Graph node found through DFS doesn't exist");
- if node.archetype().component_cnt() < search_terms.required_components.len() {
+ if node.archetype().component_cnt() < search_terms.present.len() {
continue;
}
@@ -693,8 +693,8 @@ impl ArchetypeRefIter<'_, '_>
{
self.storage
.find_all_archetype_with_comps(&ArchetypeSearchTerms {
- required_components: imaginary_archetype_comps,
- excluded_components: &[],
+ present: imaginary_archetype_comps,
+ absent: &[],
})
.into_iter()
.filter_map(|found_id| {
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index f0e3e36..3a867ba 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -497,7 +497,7 @@ impl World
{
let phase_query = self.flexible_query(
QueryTerms::<2>::builder()
- .with_required([
+ .present([
Phase::id(),
Pair::builder()
.relation::<ChildOf>()
@@ -726,7 +726,7 @@ impl World
let query = Query::<(&SystemComponent,)>::from_flexible_query(
self.flexible_query(
QueryTerms::<QUERY_MAX_TERM_CNT>::builder()
- .with_required([SystemComponent::id(), event_id])
+ .present([SystemComponent::id(), event_id])
.build(),
),
);
diff --git a/engine-ecs/src/pair.rs b/engine-ecs/src/pair.rs
index cede364..3668f1b 100644
--- a/engine-ecs/src/pair.rs
+++ b/engine-ecs/src/pair.rs
@@ -202,7 +202,7 @@ where
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with_required([Pair::<Relation, Target>::uid()]);
+ terms_builder.present([Pair::<Relation, Target>::uid()]);
}
fn get_field<'world>(
@@ -235,7 +235,7 @@ where
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with_required([Pair::<Relation, Target>::uid()]);
+ terms_builder.present([Pair::<Relation, Target>::uid()]);
}
fn get_field<'world>(
@@ -272,7 +272,7 @@ where
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with_required([Self::uid()]);
+ terms_builder.present([Self::uid()]);
}
fn get_field<'world>(
diff --git a/engine-ecs/src/query.rs b/engine-ecs/src/query.rs
index 16e7b99..1b7bf43 100644
--- a/engine-ecs/src/query.rs
+++ b/engine-ecs/src/query.rs
@@ -11,7 +11,7 @@ use crate::component::{
use crate::entity::Handle as EntityHandle;
use crate::query::flexible::{Iter as FlexibleQueryIter, Query as FlexibleQuery};
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
-use crate::uid::{Uid, With as WithUid};
+use crate::uid::Uid;
use crate::util::array_vec::ArrayVec;
use crate::util::Array;
use crate::World;
@@ -168,8 +168,8 @@ where
#[derive(Debug)]
pub struct Terms<const MAX_TERM_CNT: usize>
{
- required_components: ArrayVec<Uid, MAX_TERM_CNT>,
- excluded_components: ArrayVec<Uid, MAX_TERM_CNT>,
+ present: ArrayVec<Uid, MAX_TERM_CNT>,
+ absent: ArrayVec<Uid, MAX_TERM_CNT>,
}
impl<const MAX_TERM_CNT: usize> Terms<MAX_TERM_CNT>
@@ -184,20 +184,16 @@ impl<const MAX_TERM_CNT: usize> Terms<MAX_TERM_CNT>
#[must_use]
pub struct TermsBuilder<const MAX_TERM_CNT: usize>
{
- required_components: ArrayVec<Uid, MAX_TERM_CNT>,
- excluded_components: ArrayVec<Uid, MAX_TERM_CNT>,
+ present: ArrayVec<Uid, MAX_TERM_CNT>,
+ absent: ArrayVec<Uid, MAX_TERM_CNT>,
}
#[allow(clippy::return_self_not_must_use)]
pub trait TermsBuilderInterface
{
- fn with<WithUidT: WithUid>(self) -> Self;
+ fn present(self, ids: impl Array<Uid>) -> Self;
- fn without<WithUidT: WithUid>(self) -> Self;
-
- fn with_required(self, ids: impl Array<Uid>) -> Self;
-
- fn without_ids(self, ids: impl Array<Uid>) -> Self;
+ fn absent(self, ids: impl Array<Uid>) -> Self;
}
macro_rules! impl_terms_builder {
@@ -218,54 +214,30 @@ macro_rules! impl_terms_builder {
impl_terms_builder! {
#[allow(unused_mut)]
- fn with<WithUidT: WithUid>(mut self) -> Self
- {
- let insert_index = self.required_components
- .partition_point(|id| *id <= WithUidT::uid());
-
- self.required_components
- .insert(insert_index, WithUidT::uid());
-
- self
- }
-
- #[allow(unused_mut)]
- fn without<WithUidT: WithUid>(mut self) -> Self
- {
- let insert_index = self.excluded_components
- .partition_point(|id| *id <= WithUidT::uid());
-
- self.excluded_components
- .insert(insert_index, WithUidT::uid());
-
- self
- }
-
- #[allow(unused_mut)]
- fn with_required(mut self, mut ids: impl Array<Uid>) -> Self
+ fn present(mut self, mut ids: impl Array<Uid>) -> Self
{
if !ids.as_ref().is_sorted() {
ids.as_mut().sort();
}
- if self.required_components.is_empty() {
- self.required_components.extend(ids);
+ if self.present.is_empty() {
+ self.present.extend(ids);
return self;
}
let mut id_iter = ids.into_iter();
while let Some(id) = id_iter.next() {
- let insert_index = self.required_components
+ let insert_index = self.present
.partition_point(|other_id| *other_id <= id);
- if insert_index == self.required_components.len() {
- self.required_components.extend([id].into_iter().chain(id_iter));
+ if insert_index == self.present.len() {
+ self.present.extend([id].into_iter().chain(id_iter));
return self;
}
- self.required_components
+ self.present
.insert(insert_index, id);
}
@@ -274,30 +246,30 @@ impl_terms_builder! {
}
#[allow(unused_mut)]
- fn without_ids(mut self, mut ids: impl Array<Uid>) -> Self
+ fn absent(mut self, mut ids: impl Array<Uid>) -> Self
{
if !ids.as_ref().is_sorted() {
ids.as_mut().sort();
}
- if self.excluded_components.is_empty() {
- self.excluded_components.extend(ids);
+ if self.absent.is_empty() {
+ self.absent.extend(ids);
return self;
}
let mut id_iter = ids.into_iter();
while let Some(id) = id_iter.next() {
- let insert_index = self.excluded_components
+ let insert_index = self.absent
.partition_point(|other_id| *other_id <= id);
- if insert_index == self.excluded_components.len() {
- self.excluded_components.extend([id].into_iter().chain(id_iter));
+ if insert_index == self.absent.len() {
+ self.absent.extend([id].into_iter().chain(id_iter));
return self;
}
- self.excluded_components
+ self.absent
.insert(insert_index, id);
}
@@ -311,12 +283,12 @@ impl<const MAX_TERM_CNT: usize> TermsBuilder<MAX_TERM_CNT>
#[must_use]
pub fn build(self) -> Terms<MAX_TERM_CNT>
{
- debug_assert!(self.required_components.is_sorted());
- debug_assert!(self.excluded_components.is_sorted());
+ debug_assert!(self.present.is_sorted());
+ debug_assert!(self.absent.is_sorted());
Terms {
- required_components: self.required_components,
- excluded_components: self.excluded_components,
+ present: self.present,
+ absent: self.absent,
}
}
}
@@ -350,7 +322,7 @@ impl<ComponentT: Component> TermWithField for &ComponentT
terms_builder: &mut TermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with::<ComponentT>();
+ terms_builder.present([ComponentT::id()]);
}
fn get_field<'world>(
@@ -391,7 +363,7 @@ impl<ComponentT: Component> TermWithField for &mut ComponentT
terms_builder: &mut TermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with::<ComponentT>();
+ terms_builder.present([ComponentT::id()]);
}
fn get_field<'world>(
diff --git a/engine-ecs/src/query/flexible.rs b/engine-ecs/src/query/flexible.rs
index 936ab82..66d62c6 100644
--- a/engine-ecs/src/query/flexible.rs
+++ b/engine-ecs/src/query/flexible.rs
@@ -27,8 +27,8 @@ impl<'world, const MAX_TERM_CNT: usize> Query<'world, MAX_TERM_CNT>
.data
.component_storage
.search_archetypes(ArchetypeSearchTerms {
- required_components: &self.terms.required_components,
- excluded_components: &self.terms.excluded_components,
+ present: &self.terms.present,
+ absent: &self.terms.absent
})
.flat_map(
(|archetype| {
diff --git a/engine-ecs/src/query/term.rs b/engine-ecs/src/query/term.rs
index 0683918..7c4503a 100644
--- a/engine-ecs/src/query/term.rs
+++ b/engine-ecs/src/query/term.rs
@@ -29,7 +29,7 @@ where
terms_builder: &mut TermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.with::<WithUidT>();
+ terms_builder.present([WithUidT::uid()]);
}
}
@@ -48,7 +48,7 @@ where
terms_builder: &mut TermsBuilder<MAX_TERM_CNT>,
)
{
- terms_builder.without::<WithUidT>();
+ terms_builder.absent([WithUidT::uid()]);
}
}