diff options
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 26 |
1 files changed, 24 insertions, 2 deletions
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<Box<dyn Component>>, } +impl From<Box<dyn Component>> for EntityComponent +{ + fn from(component: Box<dyn Component>) -> Self + { + Self { + id: component.id(), + name: component.type_name(), + component: Lock::new(component), + } + } +} + #[derive(Debug, Default)] struct ActionQueue { |