From 64b0c9d30837442fd5520c3bd6c6bb353de13950 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Tue, 18 Apr 2023 17:04:55 +0100 Subject: [PATCH] Added frame delta time calculation --- src/app.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app.rs b/src/app.rs index 629bbc2..2d83766 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,3 +1,4 @@ +use std::time::Instant; use winit::{ dpi::PhysicalSize, event::{Event, WindowEvent}, @@ -36,6 +37,7 @@ impl App { } pub fn run(mut self) { + let mut last_render_time = Instant::now(); self.event_loop .run(move |event, _, control_flow| match event { Event::WindowEvent { @@ -49,6 +51,9 @@ impl App { self.window.request_redraw(); } Event::RedrawRequested(_) => { + let now = Instant::now(); + let dt = now - last_render_time; + last_render_time = now; self.renderer.render(&self.render_ctx); } _ => {}