From 799e66c3c92269aef8ba791b9db5661c625dfb95 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Apr 2025 17:39:05 +0200 Subject: refactor(ecs): remove component::Ref trait --- ecs/src/query/term.rs | 53 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'ecs/src/query/term.rs') diff --git a/ecs/src/query/term.rs b/ecs/src/query/term.rs index 597dd1a..2e1ecca 100644 --- a/ecs/src/query/term.rs +++ b/ecs/src/query/term.rs @@ -1,7 +1,12 @@ use std::any::type_name; use std::marker::PhantomData; -use crate::component::{Component, HandleFromEntityComponentRef, Ref as ComponentRef}; +use crate::component::{ + Component, + Handle as ComponentHandle, + HandleFromEntityComponentRef, + HandleMut as ComponentHandleMut, +}; use crate::query::{ TermWithField, TermWithoutField, @@ -48,11 +53,43 @@ where } } -impl TermWithField for Option -where - ComponentRefT: ComponentRef, +impl TermWithField for Option<&ComponentT> +{ + type Field<'a> = Option>; + + fn apply_to_terms_builder( + _terms_builder: &mut TermsBuilder, + ) + { + } + + fn get_field<'world>( + entity_handle: &crate::entity::Handle<'world>, + world: &'world crate::World, + ) -> Self::Field<'world> + { + Some( + ComponentHandle::<'world, ComponentT>::from_entity_component_ref( + Some( + entity_handle + .get_matching_components(ComponentT::id()) + .next()?, + ), + world, + ) + .unwrap_or_else(|err| { + panic!( + "Creating handle to component {} failed: {err}", + type_name::() + ); + }), + ) + } +} + +impl TermWithField for Option<&mut ComponentT> { - type Field<'a> = Option>; + type Field<'a> = Option>; fn apply_to_terms_builder( _terms_builder: &mut TermsBuilder, @@ -66,10 +103,10 @@ where ) -> Self::Field<'world> { Some( - ComponentRefT::Handle::<'world>::from_entity_component_ref( + ComponentHandleMut::<'world, ComponentT>::from_entity_component_ref( Some( entity_handle - .get_matching_components(ComponentRefT::Component::id()) + .get_matching_components(ComponentT::id()) .next()?, ), world, @@ -77,7 +114,7 @@ where .unwrap_or_else(|err| { panic!( "Creating handle to component {} failed: {err}", - type_name::() + type_name::() ); }), ) -- cgit v1.2.3-18-g5258