shadow_engine_2d 2.0.1

A modern, high-performance 2D game engine built in Rust with ECS, physics, particles, audio, and more
Documentation
use std::time::{Duration, Instant};

pub struct Time {
    start: Instant,
    last_update: Instant,
    delta: Duration,
    elapsed: Duration,
}

impl Time {
    pub fn new() -> Self {
        let now = Instant::now();
        Self {
            start: now,
            last_update: now,
            delta: Duration::ZERO,
            elapsed: Duration::ZERO,
        }
    }

    pub fn update(&mut self) {
        let now = Instant::now();
        self.delta = now - self.last_update;
        self.elapsed = now - self.start;
        self.last_update = now;
    }

    pub fn delta(&self) -> f32 {
        self.delta.as_secs_f32()
    }

    pub fn delta_duration(&self) -> Duration {
        self.delta
    }

    pub fn elapsed(&self) -> f32 {
        self.elapsed.as_secs_f32()
    }

    pub fn elapsed_duration(&self) -> Duration {
        self.elapsed
    }
}

impl Default for Time {
    fn default() -> Self {
        Self::new()
    }
}