From 9faa8b8f530f3640e1a604a4888cc3fa7beafd5f Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 7 Apr 2025 19:19:31 +0200 Subject: refactor(ecs): remove TypeName trait --- ecs/src/component/storage.rs | 20 ++++++-------------- ecs/src/component/storage/archetype.rs | 6 +++--- 2 files changed, 9 insertions(+), 17 deletions(-) (limited to 'ecs/src/component') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index 0a6382b..14aa191 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -1,4 +1,3 @@ -use std::any::type_name; use std::array::IntoIter as ArrayIter; use std::cell::RefCell; use std::vec::IntoIter as VecIntoIter; @@ -18,7 +17,6 @@ use crate::component::storage::graph::{ Graph, }; use crate::component::Component; -use crate::type_name::TypeName; use crate::uid::{Kind as UidKind, Uid}; use crate::util::{BorrowedOrOwned, Either, StreamingIterator, VecExt}; @@ -161,11 +159,13 @@ impl Storage pub fn add_entity_component( &mut self, entity_uid: Uid, - component: (Uid, Box), + (component_id, component_name, component): ( + Uid, + &'static str, + Box, + ), ) -> Result<(), Error> { - let (component_id, component) = component; - debug_assert!( !component.self_is_optional(), "Adding a optional component to a entity is not supported" @@ -244,7 +244,7 @@ impl Storage entity.insert_component( component_id, - ArchetypeEntityComponent::new(component), + ArchetypeEntityComponent::new(component, component_name), add_edge_archetype, ); @@ -393,14 +393,6 @@ impl Storage } } -impl TypeName for Storage -{ - fn type_name(&self) -> &'static str - { - type_name::() - } -} - #[cfg(feature = "vizoxide")] impl Storage { diff --git a/ecs/src/component/storage/archetype.rs b/ecs/src/component/storage/archetype.rs index 5306cf9..8d48e13 100644 --- a/ecs/src/component/storage/archetype.rs +++ b/ecs/src/component/storage/archetype.rs @@ -215,11 +215,11 @@ pub struct EntityComponent impl EntityComponent { - pub fn new(component: Box) -> Self + pub fn new(component: Box, component_name: &'static str) -> Self { Self { - name: component.type_name(), - component: Lock::new(component), + name: component_name, + component: Lock::new(component, component_name), } } -- cgit v1.2.3-18-g5258