diff options
Diffstat (limited to 'ecs')
-rw-r--r-- | ecs/src/lib.rs | 24 | ||||
-rw-r--r-- | ecs/src/stats.rs | 10 |
2 files changed, 33 insertions, 1 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 40b2021..452f657 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -23,6 +23,7 @@ use crate::extension::{Collector as ExtensionCollector, Extension}; use crate::lock::{Lock, WriteGuard}; use crate::query::options::Options as QueryOptions; use crate::sole::Sole; +use crate::stats::Stats; use crate::system::{System, TypeErased as TypeErasedSystem}; use crate::tuple::Reduce as TupleReduce; use crate::type_name::TypeName; @@ -36,6 +37,7 @@ pub mod lock; pub mod query; pub mod relationship; pub mod sole; +pub mod stats; pub mod system; pub mod tuple; pub mod type_name; @@ -60,7 +62,13 @@ impl World #[must_use] pub fn new() -> Self { - Self::default() + let mut world = Self::default(); + + world + .add_sole(Stats::default()) + .expect("World already has stats sole"); + + world } /// Creates a new entity with the given components. @@ -267,6 +275,20 @@ impl World if self.stop.load(Ordering::Relaxed) { break; } + + let mut stats_lock = self + .data + .sole_storage + .get::<Stats>() + .expect("No stats sole found") + .write_nonblock() + .expect("Failed to aquire read-write stats sole lock"); + + let stats = stats_lock + .downcast_mut::<Stats>() + .expect("Casting stats sole to Stats type failed"); + + stats.current_tick += 1; } } diff --git a/ecs/src/stats.rs b/ecs/src/stats.rs new file mode 100644 index 0000000..410610f --- /dev/null +++ b/ecs/src/stats.rs @@ -0,0 +1,10 @@ +use ecs_macros::Sole; + +use crate as ecs; + +#[derive(Debug, Default, Sole)] +#[non_exhaustive] +pub struct Stats +{ + pub current_tick: u64, +} |