diff options
| author | HampusM <hampus@hampusmat.com> | 2026-10-30 05:24:39 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-10-30 05:52:42 +0100 |
| commit | 723f48d8e008d216978b8ed7d70499c972cc5a1c (patch) | |
| tree | cdb997249bb0188c35c92c0a68a7c8d91ac222fd /engine-ecs/src/query | |
| parent | 5828e00dbe274391a05772380910f82996908b7d (diff) | |
refactor(engine-ecs): replace uid::WithUid* traits with new component traits
Diffstat (limited to 'engine-ecs/src/query')
| -rw-r--r-- | engine-ecs/src/query/term.rs | 113 |
1 files changed, 100 insertions, 13 deletions
diff --git a/engine-ecs/src/query/term.rs b/engine-ecs/src/query/term.rs index 980ee87..f5fd531 100644 --- a/engine-ecs/src/query/term.rs +++ b/engine-ecs/src/query/term.rs @@ -5,7 +5,9 @@ use crate::component::{ Component, Handle as ComponentHandle, HandleMut as ComponentHandleMut, + WithAssociatedId as _, }; +use crate::pair::{Pair, Wildcard}; use crate::query::{ FoundByTraversal, SearchResult, @@ -17,19 +19,61 @@ use crate::query::{ Traversal, TraversalKind, }; -use crate::uid::With as WithUid; use crate::World; -pub struct With<WithUidT> +pub struct With<T> +{ + _pd: PhantomData<T>, +} + +impl<'query, ComponentT: Component> Term<'query> for With<ComponentT> +{ + type Fields = (); + + fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( + terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, + _term_metadata: TermMetadata, + ) + { + terms_builder.present([ComponentT::id()]); + } + + fn fields( + _world: &'query World, + _search_result: &SearchResult<'query, '_>, + _term_metadata: TermMetadata, + ) -> Self::Fields + { + } +} + +impl<'query, Relation, Target> Term<'query> for With<Pair<Relation, Target>> where - WithUidT: WithUid, + Relation: Component, + Target: Component, { - _pd: PhantomData<WithUidT>, + type Fields = (); + + fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( + terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, + _term_metadata: TermMetadata, + ) + { + terms_builder.present([Pair::<Relation, Target>::id()]); + } + + fn fields( + _world: &'query World, + _search_result: &SearchResult<'query, '_>, + _term_metadata: TermMetadata, + ) -> Self::Fields + { + } } -impl<'query, WithUidT> Term<'query> for With<WithUidT> +impl<'query, Relation> Term<'query> for With<Pair<Relation, Wildcard>> where - WithUidT: WithUid, + Relation: Component, { type Fields = (); @@ -38,7 +82,7 @@ where _term_metadata: TermMetadata, ) { - terms_builder.present([WithUidT::uid()]); + terms_builder.present([Pair::<Relation, Wildcard>::id()]); } fn fields( @@ -50,16 +94,59 @@ where } } -pub struct Without<WithUidT> +pub struct Without<T> +{ + _pd: PhantomData<T>, +} + +impl<'query, ComponentT: Component> Term<'query> for Without<ComponentT> +{ + type Fields = (); + + fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( + terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, + _term_metadata: TermMetadata, + ) + { + terms_builder.absent([ComponentT::id()]); + } + + fn fields( + _world: &'query World, + _search_result: &SearchResult<'query, '_>, + _term_metadata: TermMetadata, + ) -> Self::Fields + { + } +} + +impl<'query, Relation, Target> Term<'query> for Without<Pair<Relation, Target>> where - WithUidT: WithUid, + Relation: Component, + Target: Component, { - _pd: PhantomData<WithUidT>, + type Fields = (); + + fn apply_to_terms_builder<const MAX_TERM_CNT: usize>( + terms_builder: &mut TermsBuilder<MAX_TERM_CNT>, + _term_metadata: TermMetadata, + ) + { + terms_builder.absent([Pair::<Relation, Target>::id()]); + } + + fn fields( + _world: &'query World, + _search_result: &SearchResult<'query, '_>, + _term_metadata: TermMetadata, + ) -> Self::Fields + { + } } -impl<'query, WithUidT> Term<'query> for Without<WithUidT> +impl<'query, Relation> Term<'query> for Without<Pair<Relation, Wildcard>> where - WithUidT: WithUid, + Relation: Component, { type Fields = (); @@ -68,7 +155,7 @@ where _term_metadata: TermMetadata, ) { - terms_builder.absent([WithUidT::uid()]); + terms_builder.absent([Pair::<Relation, Wildcard>::id()]); } fn fields( |
