added fps counter

This commit is contained in:
Piotrek
2021-04-13 11:16:59 +02:00
parent ea58cb8d1c
commit 7a0d14d8d6
+17 -1
View File
@@ -26,6 +26,9 @@ fn main() {
// Create app
let mut app = futures::executor::block_on(App::new(&window));
let mut fps_timer = std::time::Instant::now();
let mut fps_counter = 0;
// Run event loop
events.run(move |e, _, c| {
match e {
@@ -64,9 +67,22 @@ fn main() {
}
// Draw
Event::RedrawRequested(_) => {
// Display FPS
let elapsed = fps_timer.elapsed().as_millis();
if elapsed >= 1000 {
let elapsed_sec = (elapsed as f32) / 1000.0;
let fps = (fps_counter as f32) / elapsed_sec;
println!("FPS: {}", fps);
fps_timer = std::time::Instant::now();
fps_counter = 0;
}
fps_counter += 1;
// Update and Render
app.update();
match app.render() {
Ok(_) => {}
Ok(_) => { }
// Recreate the swap_chain if lost
Err(wgpu::SwapChainError::Lost) => app.resize(None),
// The system is out of memory, we should probably quit