From ee69aa92802ba9f5becd533465ca1639cb670ace Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 11 Aug 2024 21:48:31 +0200 Subject: feat(ecs): add action to add component(s) to entity --- ecs/src/lib.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'ecs/src/lib.rs') diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 34d6b7b..df65cb3 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -71,7 +71,7 @@ impl World .component_storage .write_nonblock() .expect("Failed to acquire read-write component storage lock") - .push_entity(components.into_vec()); + .push_entity(EntityUid::new_unique(), components.into_vec()); entity_uid } @@ -158,7 +158,17 @@ impl World "Failed to acquire read-write component storage lock", ); - component_storage_lock.push_entity(components); + component_storage_lock + .push_entity(EntityUid::new_unique(), components); + } + Action::AddComponents(entity_uid, components) => { + let mut component_storage_lock = + self.data.component_storage.write_nonblock().expect( + "Failed to acquire read-write component storage lock", + ); + + component_storage_lock + .add_components_to_entity(entity_uid, components); } Action::Stop => { self.stop.store(true, Ordering::Relaxed); @@ -226,6 +236,18 @@ pub struct EntityComponent pub component: Lock>, } +impl From> for EntityComponent +{ + fn from(component: Box) -> Self + { + Self { + id: component.id(), + name: component.type_name(), + component: Lock::new(component), + } + } +} + #[derive(Debug, Default)] struct ActionQueue { -- cgit v1.2.3-18-g5258