Skip to main content

VirtualTime

Struct VirtualTime 

Source
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: bool

When true, effective_elapsed() always returns 0.

§scale: f64

Speed multiplier. Clamped to [0.0, 8.0].

  • 1.0 = normal
  • 0.5 = half speed
  • 2.0 = double speed
§max_delta: f64

Raw 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: f64

Total virtual time elapsed since engine start. Accumulated by game_loop::tick() each frame.

Implementations§

Source§

impl VirtualTime

Source

pub fn new() -> Self

Create with default settings: unpaused, scale 1.0, max_delta 0.25 s.

Source

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§

Source§

impl Default for VirtualTime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.