Added frame delta time calculation
This commit is contained in:
parent
528f866311
commit
64b0c9d308
|
@ -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);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Reference in New Issue