codecraft 0.2.0

A minimalist 3D game engine built on parts of Bevy (ECS, color) with wgpu and winit: OpenPBR materials, clustered lighting, a yakui-drawn UI, audio and gamepad haptics; its binary maps any folder, and the symbols of its Rust files, as a 3D wall of boxes
Documentation
//! Frame timing, published into the ECS world and readable from scenes.
use std::time::Instant;

use crate::ecs::Resource;

/// Seconds since the last frame and since the app started.
#[derive(Resource, Clone, Copy, Debug, Default)]
pub struct Time {
    pub delta: f32,
    pub elapsed: f32,
}

pub struct Clock {
    started: Instant,
    last_frame: Instant,
}

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

    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()
    }
}