From b7f0c2f965a7d460022d157ff149bf1ea498b9b4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 16 Oct 2024 22:15:24 +0200 Subject: feat(ecs): add stats sole containing current tick --- ecs/src/lib.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'ecs/src/lib.rs') 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::() + .expect("No stats sole found") + .write_nonblock() + .expect("Failed to aquire read-write stats sole lock"); + + let stats = stats_lock + .downcast_mut::() + .expect("Casting stats sole to Stats type failed"); + + stats.current_tick += 1; } } -- cgit v1.2.3-18-g5258