summaryrefslogtreecommitdiff
path: root/engine-ecs/src/pair.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src/pair.rs')
-rw-r--r--engine-ecs/src/pair.rs103
1 files changed, 62 insertions, 41 deletions
diff --git a/engine-ecs/src/pair.rs b/engine-ecs/src/pair.rs
index 3668f1b..1168f67 100644
--- a/engine-ecs/src/pair.rs
+++ b/engine-ecs/src/pair.rs
@@ -14,10 +14,11 @@ use crate::entity::{
MatchingComponentIter as EntityMatchingComponentIter,
};
use crate::query::{
- TermWithField as QueryTermWithField,
+ Term as QueryTerm,
TermsBuilder as QueryTermsBuilder,
TermsBuilderInterface,
};
+use crate::tuple::Tuple;
use crate::uid::{PairParams as UidPairParams, Uid, With as WithUid};
use crate::util::impl_multiple;
use crate::{Component, EntityComponentRef, World};
@@ -191,12 +192,13 @@ where
}
}
-impl<Relation, Target> QueryTermWithField for Pair<Relation, &Target>
+impl<'world, Relation, Target> QueryTerm<'world> for Pair<Relation, &Target>
where
Relation: Component,
Target: Component,
{
- type Field<'a> = ComponentHandle<'a, Target>;
+ type AddField<Fields: Tuple> =
+ Fields::WithElementAtEnd<ComponentHandle<'world, Target>>;
fn apply_to_terms_builder<const MAX_TERM_CNT: usize>(
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
@@ -205,31 +207,38 @@ where
terms_builder.present([Pair::<Relation, Target>::uid()]);
}
- fn get_field<'world>(
+ fn add_field<Fields: Tuple>(
entity_handle: &EntityHandle<'world>,
_world: &'world World,
- ) -> Self::Field<'world>
+ fields: Fields,
+ ) -> Self::AddField<Fields>
{
let target_component = entity_handle
.get_matching_components(Pair::<Relation, Target>::uid())
.next()
.expect("Not possible");
- Self::Field::from_entity_component_ref(&target_component).unwrap_or_else(|err| {
- panic!(
- "Creating handle to target component {} failed: {err}",
- type_name::<Target>()
- );
- })
+ let target_component = match ComponentHandle::<Target>::from_entity_component_ref(&target_component) {
+ Ok(target_component) => target_component,
+ Err(err) => {
+ panic!(
+ "Creating handle to target component {} failed: {err}",
+ type_name::<Target>()
+ );
+ }
+ };
+
+ fields.with_elem(target_component)
}
}
-impl<Relation, Target> QueryTermWithField for Pair<Relation, &mut Target>
+impl<'world, Relation, Target> QueryTerm<'world> for Pair<Relation, &mut Target>
where
Relation: Component,
Target: Component,
{
- type Field<'a> = ComponentHandleMut<'a, Target>;
+ type AddField<Fields: Tuple> =
+ Fields::WithElementAtEnd<ComponentHandleMut<'world, Target>>;
fn apply_to_terms_builder<const MAX_TERM_CNT: usize>(
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
@@ -238,35 +247,40 @@ where
terms_builder.present([Pair::<Relation, Target>::uid()]);
}
- fn get_field<'world>(
+ fn add_field<Fields: Tuple>(
entity_handle: &EntityHandle<'world>,
world: &'world World,
- ) -> Self::Field<'world>
+ fields: Fields,
+ ) -> Self::AddField<Fields>
{
let target_component = entity_handle
.get_matching_components(Pair::<Relation, Target>::uid())
.next()
.expect("Not possible");
- Self::Field::from_entity_component_ref(&target_component, world).unwrap_or_else(
- |err| {
+ let target_component = match ComponentHandleMut::<Target>::from_entity_component_ref(&target_component, world) {
+ Ok(target_component) => target_component,
+ Err(err) => {
panic!(
- "Creating handle to target component {} failed: {err}",
+ "Creating mut handle to target component {} failed: {err}",
type_name::<Target>()
);
- },
- )
+ }
+ };
+
+ fields.with_elem(target_component)
}
}
-// TODO: implement QueryTermWithField for Pair<&Relation, Target> (or equivalent)
-// TODO: implement QueryTermWithField for Pair<&mut Relation, Target> (or equivalent)
+// TODO: implement QueryTerm for Pair<&Relation, Target> (or equivalent)
+// TODO: implement QueryTerm for Pair<&mut Relation, Target> (or equivalent)
-impl<Relation> QueryTermWithField for Pair<Relation, Wildcard>
+impl<'world, Relation> QueryTerm<'world> for Pair<Relation, Wildcard>
where
Relation: Component,
{
- type Field<'a> = WithWildcard<'a, Relation, Wildcard>;
+ type AddField<Fields: Tuple> =
+ Fields::WithElementAtEnd<WithWildcard<'world, Relation, Wildcard>>;
fn apply_to_terms_builder<const MAX_TERM_CNT: usize>(
terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
@@ -275,21 +289,24 @@ where
terms_builder.present([Self::uid()]);
}
- fn get_field<'world>(
+ fn add_field<Fields: Tuple>(
entity_handle: &EntityHandle<'world>,
world: &'world World,
- ) -> Self::Field<'world>
+ fields: Fields,
+ ) -> Self::AddField<Fields>
{
let first_matching_comp = entity_handle
.get_matching_components(Self::uid())
.next()
.expect("Not possible");
- WithWildcard {
- world,
- component_ref: first_matching_comp,
- _pd: PhantomData,
- }
+ fields.with_elem(
+ WithWildcard {
+ world,
+ component_ref: first_matching_comp,
+ _pd: PhantomData,
+ }
+ )
}
}
@@ -320,11 +337,12 @@ where
}
}
-impl<Relation> QueryTermWithField for &'_ [Pair<Relation, Wildcard>]
+impl<'world, Relation> QueryTerm<'world> for &[Pair<Relation, Wildcard>]
where
Relation: Component,
{
- type Field<'a> = MultipleWithWildcard<'a, Relation, Wildcard>;
+ type AddField<Fields: Tuple> =
+ Fields::WithElementAtEnd<MultipleWithWildcard<'world, Relation, Wildcard>>;
fn apply_to_terms_builder<const MAX_TERM_CNT: usize>(
_terms_builder: &mut QueryTermsBuilder<MAX_TERM_CNT>,
@@ -332,16 +350,19 @@ where
{
}
- fn get_field<'world>(
+ fn add_field<Fields: Tuple>(
entity_handle: &EntityHandle<'world>,
world: &'world World,
- ) -> Self::Field<'world>
- {
- MultipleWithWildcard {
- entity_handle: entity_handle.clone(),
- world,
- _pd: PhantomData,
- }
+ fields: Fields,
+ ) -> Self::AddField<Fields>
+ {
+ fields.with_elem(
+ MultipleWithWildcard {
+ entity_handle: entity_handle.clone(),
+ world,
+ _pd: PhantomData,
+ }
+ )
}
}