From 7276f9c72f53f02820c3238f72d099221daf7afd Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 8 Apr 2025 17:19:30 +0200 Subject: refactor(ecs): replace optional components with Option query term --- ecs/src/component.rs | 118 +-------------------------------------------------- 1 file changed, 1 insertion(+), 117 deletions(-) (limited to 'ecs/src/component.rs') diff --git a/ecs/src/component.rs b/ecs/src/component.rs index f4c29ae..49265b3 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -51,21 +51,6 @@ pub trait Component: SystemInput + Any /// Returns the component UID of a component event for this component. fn get_event_uid(&self, event_kind: ComponentEventKind) -> Uid; - - /// Returns whether the component `self` is optional. - fn self_is_optional(&self) -> bool - { - false - } - - /// Returns whether this component is optional. - #[must_use] - fn is_optional() -> bool - where - Self: Sized, - { - false - } } impl dyn Component @@ -94,46 +79,6 @@ impl Debug for dyn Component } } -impl Component for Option -where - ComponentT: Component, - for<'a> Option>: HandleFromEntityComponentRef<'a>, - for<'a> Option>: HandleFromEntityComponentRef<'a>, -{ - type Component = ComponentT; - type Handle<'component> = Option>; - type HandleMut<'component> = Option>; - - fn id() -> Uid - { - ComponentT::id() - } - - fn name(&self) -> &'static str - { - type_name::() - } - - fn get_event_uid(&self, event_kind: ComponentEventKind) -> Uid - { - match event_kind { - ComponentEventKind::Removed => ComponentRemovedEvent::::id(), - } - } - - fn self_is_optional(&self) -> bool - { - true - } - - fn is_optional() -> bool - { - true - } -} - -impl SystemInput for Option where ComponentT: Component {} - /// A sequence of components. pub trait Sequence { @@ -180,24 +125,14 @@ where pub struct Metadata { pub id: Uid, - pub is_optional: bool, } impl Metadata { - #[must_use] - pub fn new_non_optional(id: Uid) -> Self - { - Self { id, is_optional: false } - } - #[must_use] pub fn of() -> Self { - Self { - id: ComponentT::id(), - is_optional: ComponentT::is_optional(), - } + Self { id: ComponentT::id() } } } @@ -257,31 +192,6 @@ impl<'comp, ComponentT: Component> HandleFromEntityComponentRef<'comp> } } -impl<'comp, ComponentT> HandleFromEntityComponentRef<'comp> - for Option> -where - ComponentT: Component, -{ - type Error = HandleError; - - fn from_entity_component_ref( - entity_component_ref: Option>, - _world: &'comp World, - ) -> Result - { - entity_component_ref - .map(|entity_comp| { - Ok(Handle::new( - entity_comp - .component() - .read_nonblock() - .map_err(AcquireComponentLockFailed)?, - )) - }) - .transpose() - } -} - impl Deref for Handle<'_, ComponentT> { type Target = ComponentT; @@ -337,31 +247,6 @@ impl<'comp, ComponentT: Component> HandleFromEntityComponentRef<'comp> } } -impl<'comp, ComponentT> HandleFromEntityComponentRef<'comp> - for Option> -where - ComponentT: Component, -{ - type Error = HandleError; - - fn from_entity_component_ref( - entity_component_ref: Option>, - _world: &'comp World, - ) -> Result - { - entity_component_ref - .map(|entity_comp| { - Ok(HandleMut::new( - entity_comp - .component() - .write_nonblock() - .map_err(AcquireComponentLockFailed)?, - )) - }) - .transpose() - } -} - impl Deref for HandleMut<'_, ComponentT> { type Target = ComponentT; @@ -422,7 +307,6 @@ macro_rules! inner { #( Metadata { id: IntoComp~I::Component::id(), - is_optional: IntoComp~I::Component::is_optional(), }, )* ] -- cgit v1.2.3-18-g5258