From: Bernie Innocenti Date: Mon, 8 May 2017 00:33:35 +0000 (-0400) Subject: Add FPS counter. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=22668f3c0f27178103484fc8ff02240f00386ba8;p=mandelwow.git Add FPS counter. --- 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 }); }