summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-10-16 22:15:24 +0200
committerHampusM <hampus@hampusmat.com>2024-10-16 22:15:24 +0200
commitb7f0c2f965a7d460022d157ff149bf1ea498b9b4 (patch)
tree478607d6513479d38e2a288181c931a9dbce4a66 /ecs/src/lib.rs
parent5e232a891c45d84d89f814eee84faeb12df0f052 (diff)
feat(ecs): add stats sole containing current tick
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs24
1 files changed, 23 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;
}
}