From 61ce6ce0a603384b07ede2d149f6ec0542a2d03e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 16 Jun 2024 19:30:27 +0200 Subject: fix(ecs): update archetype lookups when entity is spawned with Actions --- ecs/src/lib.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'ecs/src/lib.rs') diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index e427150..42cdef3 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -142,12 +142,29 @@ impl World .drain(..) { match action { - Action::Spawn(components) => self - .data - .component_storage - .write_nonblock() - .expect("Failed to acquire read-write component storage lock") - .push_entity(components), + Action::Spawn(components) => { + { + let mut component_storage_lock = + self.data.component_storage.write_nonblock().expect( + "Failed to acquire read-write component storage lock", + ); + + component_storage_lock.push_entity(components); + } + + for system in &self.systems { + unsafe { + system.prepare(&self.data); + } + } + + let mut component_storage_lock = + self.data.component_storage.write_nonblock().expect( + "Failed to acquire read-write component storage lock", + ); + + component_storage_lock.make_archetype_lookup_entries(); + } Action::Stop => { self.stop.store(true, Ordering::Relaxed); } -- cgit v1.2.3-18-g5258