From 519a73f83848ea668fe79895e6643cff4c5c51be Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 6 Apr 2024 12:30:49 +0200 Subject: feat(ecs): add stopping event loop --- ecs/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ecs/src/lib.rs') diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 339a314..fc97d42 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -26,6 +26,7 @@ use crate::type_name::TypeName; pub mod actions; pub mod component; pub mod event; +pub mod flags; pub mod lock; pub mod system; pub mod tuple; @@ -166,6 +167,16 @@ impl World } self.perform_queued_actions(); + + let flags = self + .data + .flags + .read_nonblock() + .expect("Failed to aquire lock to flags"); + + if flags.stop { + break; + } } } @@ -186,12 +197,27 @@ impl World } } +#[derive(Debug, Default)] +struct WorldFlags +{ + stop: bool, +} + +impl TypeName for WorldFlags +{ + fn type_name(&self) -> &'static str + { + type_name::() + } +} + #[derive(Debug, Default)] pub struct WorldData { events: HashMap>, component_storage: Arc>, action_queue: Lock, + flags: Lock, } #[derive(Debug, Default)] -- cgit v1.2.3-18-g5258