summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-04-27 14:58:48 +0200
committerHampusM <hampus@hampusmat.com>2026-04-27 14:58:48 +0200
commitddbf984fb7187f42322e214504e0dde76e4efd8d (patch)
tree29e92df3198a6b9eb2cf7501bb4ee829ea7f5200 /ecs/src
parent5f93b02dc787bbda41ce9213d1a418ecea8c61a3 (diff)
feat(ecs): add logging when component is removed
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/component/storage.rs12
-rw-r--r--ecs/src/component/storage/archetype.rs15
2 files changed, 23 insertions, 4 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index a8711c5..d974967 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -339,7 +339,8 @@ impl Storage
.remove_entity(entity_uid)
.expect("Entity should exist in archetype");
- entity.remove_component(component_id, archetype_node.archetype());
+ let removed_component =
+ entity.remove_component(component_id, archetype_node.archetype());
self.graph
.get_node_by_id_mut(remove_edge_id)
@@ -350,6 +351,13 @@ impl Storage
self.entity_archetype_lookup
.insert(entity_uid, remove_edge_id);
+ tracing::debug!(
+ entity_id = %entity_uid,
+ component_id = %component_id,
+ component_name = removed_component.name(),
+ "Removed component from entity"
+ );
+
Ok(())
}
@@ -757,8 +765,8 @@ struct ImaginaryArchetype
#[cfg(test)]
mod tests
{
- use crate::component::storage::archetype::Id as ArchetypeId;
use crate::component::storage::Storage;
+ use crate::component::storage::archetype::Id as ArchetypeId;
use crate::uid::{Kind as UidKind, Uid};
#[test]
diff --git a/ecs/src/component/storage/archetype.rs b/ecs/src/component/storage/archetype.rs
index d96632e..a7fe7ed 100644
--- a/ecs/src/component/storage/archetype.rs
+++ b/ecs/src/component/storage/archetype.rs
@@ -287,13 +287,17 @@ impl Entity
&self.components
}
- pub fn remove_component(&mut self, component_id: Uid, archetype: &Archetype)
+ pub fn remove_component(
+ &mut self,
+ component_id: Uid,
+ archetype: &Archetype,
+ ) -> EntityComponent
{
let index = archetype
.get_index_for_component(component_id)
.expect("Archetype should contain component");
- self.components.remove(index);
+ self.components.remove(index)
}
pub fn insert_component(
@@ -315,6 +319,7 @@ impl Entity
pub struct EntityComponent
{
component: Lock<Box<dyn Any>>,
+ name: &'static str,
}
impl EntityComponent
@@ -323,6 +328,7 @@ impl EntityComponent
{
Self {
component: Lock::new(component, component_name),
+ name: component_name,
}
}
@@ -330,6 +336,11 @@ impl EntityComponent
{
&self.component
}
+
+ pub fn name(&self) -> &str
+ {
+ self.name
+ }
}
/// Archetype ID.