From 6038a5b701ee9ea3bd3b5da50d7d06930cd9a270 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 6 Apr 2024 15:35:51 +0200 Subject: refactor(ecs): make stopping into a action --- ecs/src/actions.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ecs/src/actions.rs') diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index ea4837a..a5aaf0c 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -26,6 +26,20 @@ impl<'world> Actions<'world> .expect("Failed to aquire read-write action queue lock") .push(Action::Spawn(components.into_vec())); } + + /// Adds stopping the loop in [`Engine::event_loop`] at the next oppertune time to the + /// action queue. + /// + /// # Panics + /// Will panic if a mutable internal lock cannot be acquired. + pub fn stop(&mut self) + { + self.world_data + .action_queue + .write_nonblock() + .expect("Failed to aquire read-write action queue lock") + .push(Action::Stop); + } } unsafe impl<'world> SystemParam<'world> for Actions<'world> @@ -66,6 +80,7 @@ unsafe impl<'world> SystemParam<'world> for Actions<'world> pub(crate) enum Action { Spawn(Vec>), + Stop, } struct Comparable; -- cgit v1.2.3-18-g5258