use std::time::Instant;
use crate::core::color::Color;
use crate::core::window::Window;
use crate::core::mouse::Mouse;
pub struct Config {
pub title: String,
pub width: u32,
pub height: u32,
pub background_color: Color,
}
impl Default for Config {
fn default() -> Config {
Config {
title: format!("d7engine {}", env!("CARGO_PKG_VERSION")),
width: 1270,
height: 700,
background_color: Color::grey(44),
}
}
}
pub trait Runtime {
fn load(&mut self);
fn update(&mut self, draw: &Draw);
}
pub struct Draw {
pub performance: Performance,
pub window: Window,
pub mouse: Mouse,
pub keys: Vec<String>,
}
#[derive(Clone)]
pub struct Performance {
last_frame: Instant,
fps: f32,
delta: f32,
}
impl Performance {
pub fn new() -> Performance {
let last_frame = Instant::now();
let fps = 0.0;
let delta = 0.0;
Performance { last_frame, fps, delta }
}
pub fn frame(&mut self) {
let elapsed = self.last_frame.elapsed();
self.last_frame = Instant::now();
self.fps = 1_000_000_000.0 / elapsed.as_nanos() as f32;
self.delta = 1.0 / self.fps;
}
pub fn fps(&self) -> f32 {
self.fps
}
pub fn delta(&self) -> f32 {
self.delta
}
}