codecraft 0.1.1

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, an immediate-mode UI, audio and gamepad haptics
Documentation
//! Frame timing, published into the ECS world and readable from scenes.
use std::time::Instant;

use crate::ecs::Resource;

/// Seconds elapsed since the last frame and since the app started.
///
/// Updated once per frame by [`crate::AppState::tick_time`].
#[derive(Resource, Clone, Copy, Debug, Default)]
pub struct Time {
    pub delta: f32,
    pub elapsed: f32,
}

/// Drives [`Time`] from the wall clock.
pub struct Clock {
    started: Instant,
    last_frame: Instant,
}

impl Clock {
    pub fn new() -> Self {
        let now = Instant::now();
        Self {
            started: now,
            last_frame: now,
        }
    }

    /// Advances the clock and returns the new [`Time`].
    pub fn tick(&mut self) -> Time {
        let now = Instant::now();
        let delta = now.duration_since(self.last_frame).as_secs_f32();
        self.last_frame = now;
        Time {
            delta,
            elapsed: now.duration_since(self.started).as_secs_f32(),
        }
    }
}

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