diff options
author | HampusM <hampus@hampusmat.com> | 2024-12-09 18:16:50 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-12-09 18:16:50 +0100 |
commit | a318a32eba91cacd71c8f0cb09b49a10d12e96ca (patch) | |
tree | a76848818496a0e22c0f5f061c33ed89ab944999 /ecs/src/component/storage.rs | |
parent | 3553a24c86791f6f4501e3d19fb85f267435cf70 (diff) |
feat(ecs): add action to despawn entity
Diffstat (limited to 'ecs/src/component/storage.rs')
-rw-r--r-- | ecs/src/component/storage.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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, |