added fps counter
This commit is contained in:
+17
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user