Added frame delta time calculation

This commit is contained in:
Jarrod Doyle 2023-04-18 17:04:55 +01:00
parent 528f866311
commit 64b0c9d308
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 5 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use std::time::Instant;
use winit::{ use winit::{
dpi::PhysicalSize, dpi::PhysicalSize,
event::{Event, WindowEvent}, event::{Event, WindowEvent},
@ -36,6 +37,7 @@ impl App {
} }
pub fn run(mut self) { pub fn run(mut self) {
let mut last_render_time = Instant::now();
self.event_loop self.event_loop
.run(move |event, _, control_flow| match event { .run(move |event, _, control_flow| match event {
Event::WindowEvent { Event::WindowEvent {
@ -49,6 +51,9 @@ impl App {
self.window.request_redraw(); self.window.request_redraw();
} }
Event::RedrawRequested(_) => { Event::RedrawRequested(_) => {
let now = Instant::now();
let dt = now - last_render_time;
last_render_time = now;
self.renderer.render(&self.render_ctx); self.renderer.render(&self.render_ctx);
} }
_ => {} _ => {}