summaryrefslogtreecommitdiff
path: root/ecs/src/actions.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-06 15:35:51 +0200
committerHampusM <hampus@hampusmat.com>2024-04-06 16:09:25 +0200
commit6038a5b701ee9ea3bd3b5da50d7d06930cd9a270 (patch)
tree4b00618fd6f8290006dcedb92f15bde20cba93ce /ecs/src/actions.rs
parent97f973d685baf389dcde08044dd3dfb7ba556050 (diff)
refactor(ecs): make stopping into a action
Diffstat (limited to 'ecs/src/actions.rs')
-rw-r--r--ecs/src/actions.rs15
1 files changed, 15 insertions, 0 deletions
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<Box<dyn Component>>),
+ Stop,
}
struct Comparable;