From a318a32eba91cacd71c8f0cb09b49a10d12e96ca Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 9 Dec 2024 18:16:50 +0100 Subject: feat(ecs): add action to despawn entity --- ecs/src/component/storage.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ecs/src/component/storage.rs') diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs index ffd682e..54fa834 100644 --- a/ecs/src/component/storage.rs +++ b/ecs/src/component/storage.rs @@ -79,6 +79,27 @@ impl Storage self.archetypes.get(archetype_index) } + pub fn remove_entity(&mut self, entity_uid: Uid) + { + let Some(archetype_id) = self.entity_archetype_lookup.get(&entity_uid) else { + return; + }; + + let Some(archetype_index) = + self.find_archetype_index_with_entity(*archetype_id, entity_uid) + else { + return; + }; + + let Some(archetype) = self.archetypes.get_mut(archetype_index) else { + return; + }; + + archetype.take_entity(entity_uid); + + self.entity_archetype_lookup.remove(&entity_uid); + } + #[cfg_attr(feature = "debug", tracing::instrument(skip_all))] pub fn push_entity( &mut self, -- cgit v1.2.3-18-g5258