From 22668f3c0f27178103484fc8ff02240f00386ba8 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Sun, 7 May 2017 20:33:35 -0400 Subject: [PATCH] Add FPS counter. --- main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.rs b/main.rs index 37fc5a5..b492676 100644 --- a/main.rs +++ b/main.rs @@ -14,6 +14,7 @@ use glutin::Event::KeyboardInput; use glutin::VirtualKeyCode; use mandelwow_lib::*; use std::f32::consts::PI; +use std::time::{Duration, Instant}; #[cfg(target_os = "emscripten")] use std::os::raw::{c_int, c_void}; @@ -125,6 +126,10 @@ fn main() { } } + let mut frame_cnt = 0; + let mut last_report_time = Instant::now(); + let mut last_report_frame_cnt = 0; + set_main_loop_callback(|| { camera.update(); let perspview = camera.get_perspview(); @@ -218,6 +223,16 @@ fn main() { } } + frame_cnt += 1; + let now = Instant::now(); + if now - last_report_time > Duration::from_secs(10) { + let fps = (frame_cnt - last_report_frame_cnt) as f32 / + (now - last_report_time).as_secs() as f32; + println!("fps={}", fps); + last_report_time = now; + last_report_frame_cnt = frame_cnt; + } + support::Action::Continue }); } -- 2.25.1