summaryrefslogtreecommitdiff
path: root/ecs/src/component
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-04-07 19:19:31 +0200
committerHampusM <hampus@hampusmat.com>2025-04-07 19:19:31 +0200
commit9faa8b8f530f3640e1a604a4888cc3fa7beafd5f (patch)
tree004e75803ac71696db7546676b166875899c58b0 /ecs/src/component
parentf67ccdd0e10cfde6851610d5d96008c8a0a50ab6 (diff)
refactor(ecs): remove TypeName trait
Diffstat (limited to 'ecs/src/component')
-rw-r--r--ecs/src/component/storage.rs20
-rw-r--r--ecs/src/component/storage/archetype.rs6
2 files changed, 9 insertions, 17 deletions
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<dyn Component>),
+ (component_id, component_name, component): (
+ Uid,
+ &'static str,
+ Box<dyn Component>,
+ ),
) -> 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::<Self>()
- }
-}
-
#[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<dyn Component>) -> Self
+ pub fn new(component: Box<dyn Component>, component_name: &'static str) -> Self
{
Self {
- name: component.type_name(),
- component: Lock::new(component),
+ name: component_name,
+ component: Lock::new(component, component_name),
}
}