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/lib.rs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'ecs/src/lib.rs') diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 5273b67..1c4e44f 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -7,6 +7,7 @@ use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ops::RangeBounds; use std::slice::Iter as SliceIter; +use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Weak}; use std::vec::Drain; @@ -26,7 +27,6 @@ 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; @@ -53,6 +53,7 @@ pub struct World { systems: Vec, data: WorldData, + stop: AtomicBool, } impl World @@ -160,6 +161,9 @@ impl World .collect(), }); } + Action::Stop => { + self.stop.store(true, Ordering::Relaxed); + } } } } @@ -179,13 +183,7 @@ impl World self.perform_queued_actions(); - let flags = self - .data - .flags - .read_nonblock() - .expect("Failed to aquire lock to flags"); - - if flags.stop { + if self.stop.load(Ordering::Relaxed) { break; } } @@ -208,27 +206,12 @@ 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