steel_core/level_data/game_time.rs
1//! One live simulation counter per domain; persistence belongs to its configured default world.
2//! Domains with persistent worlds require a primary that persists level data.
3//! Legacy absolute timestamps are not rebased when derived worlds adopt the primary clock.
4use std::sync::{
5 Arc,
6 atomic::{AtomicI64, Ordering},
7};
8
9/// Shared game time. World workers only read this counter.
10#[derive(Debug)]
11pub struct GameTime {
12 ticks: AtomicI64,
13}
14
15impl GameTime {
16 pub(super) const fn new(ticks: i64) -> Self {
17 Self {
18 ticks: AtomicI64::new(ticks),
19 }
20 }
21
22 /// Returns the domain's current simulation time.
23 pub fn ticks(&self) -> i64 {
24 self.ticks.load(Ordering::Relaxed)
25 }
26
27 /// Advances the counter once; server coordination must finish all increments before dispatching workers.
28 pub(super) fn advance(&self) {
29 self.ticks.fetch_add(1, Ordering::Relaxed);
30 }
31}
32
33/// Explicit construction authority, independent of serialized field presence.
34#[derive(Clone)]
35pub enum GameTimeSource {
36 /// Initialize from this world's save, or zero for a new world.
37 Primary,
38 /// Ignore this world's obsolete saved time and use the primary's counter.
39 Derived(Arc<GameTime>),
40}