pub struct VirtualTime {
pub paused: bool,
pub scale: f64,
pub max_delta: f64,
pub elapsed: f64,
}Expand description
Virtual time controls: pause, speed scaling, and max-delta clamping.
Insert this resource to gain time control. If absent, the game loop uses raw host elapsed (backward compatible).
§Example
use galeon_engine::VirtualTime;
let mut vt = VirtualTime::new();
assert!((vt.effective_elapsed(0.5) - 0.25).abs() < f64::EPSILON); // clamped to max_delta
vt.paused = true;
assert_eq!(vt.effective_elapsed(1.0), 0.0);
vt.paused = false;
vt.scale = 2.0;
assert!((vt.effective_elapsed(0.1) - 0.2).abs() < f64::EPSILON);Fields§
§paused: boolWhen true, effective_elapsed() always returns 0.
scale: f64Speed multiplier. Clamped to [0.0, 8.0].
- 1.0 = normal
- 0.5 = half speed
- 2.0 = double speed
max_delta: f64Raw elapsed is clamped to this value before scaling. Prevents death spirals when the host delivers a huge frame delta (e.g., tab was backgrounded). Default: 0.25 s.
elapsed: f64Total virtual time elapsed since engine start.
Accumulated by game_loop::tick() each frame.
Implementations§
Source§impl VirtualTime
impl VirtualTime
Sourcepub fn effective_elapsed(&self, raw: f64) -> f64
pub fn effective_elapsed(&self, raw: f64) -> f64
Transform raw host elapsed into virtual elapsed.
Returns 0.0 when paused. Otherwise clamps raw to max_delta,
then multiplies by scale (clamped to [0.0, 8.0]).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VirtualTime
impl RefUnwindSafe for VirtualTime
impl Send for VirtualTime
impl Sync for VirtualTime
impl Unpin for VirtualTime
impl UnsafeUnpin for VirtualTime
impl UnwindSafe for VirtualTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more