telltale_vm/clock.rs
1//! Deterministic simulation clock.
2
3use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6/// Deterministic simulation clock.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct SimClock {
9 /// Logical tick counter (increments once per scheduler round).
10 pub tick: u64,
11 /// Simulated time.
12 pub time: Duration,
13 /// Duration advanced per tick.
14 pub tick_duration: Duration,
15}
16
17impl SimClock {
18 /// Create a new clock starting at tick 0/time 0.
19 #[must_use]
20 pub fn new(tick_duration: Duration) -> Self {
21 Self {
22 tick: 0,
23 time: Duration::from_secs(0),
24 tick_duration,
25 }
26 }
27
28 /// Advance the clock by one tick.
29 pub fn advance(&mut self) {
30 self.tick += 1;
31 self.time += self.tick_duration;
32 }
33}