From 811c643753d713e55af94443bf5de35c0e325787 Mon Sep 17 00:00:00 2001 From: acerix Date: Wed, 20 Jan 2016 21:16:41 -0500 Subject: [PATCH 1/4] Add piston's fps_counter --- client/lib/Cargo.toml | 1 + client/lib/src/view.rs | 7 +++++++ client/lib/src/view_thread.rs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/client/lib/Cargo.toml b/client/lib/Cargo.toml index d8da8d7..1a13d43 100755 --- a/client/lib/Cargo.toml +++ b/client/lib/Cargo.toml @@ -22,6 +22,7 @@ sdl2 = "0.9.*" sdl2-sys = "0.6.*" thread-scoped = "*" time = "*" +fps_counter = "*" [dependencies.playform-common] path = "../../common" diff --git a/client/lib/src/view.rs b/client/lib/src/view.rs index bd72cf0..403181b 100644 --- a/client/lib/src/view.rs +++ b/client/lib/src/view.rs @@ -1,5 +1,7 @@ //! The state associated with perceiving the world state. +extern crate fps_counter; + use cgmath; use cgmath::Vector2; use std; @@ -44,6 +46,9 @@ pub struct T<'a> { #[allow(missing_docs)] pub show_hud: bool, + + /// A counter of frames per second + pub fps_counter: fps_counter::FPSCounter, } impl<'a> T<'a> { @@ -129,6 +134,8 @@ impl<'a> T<'a> { }, show_hud: true, + + fps_counter: fps_counter::FPSCounter::new(), } } } diff --git a/client/lib/src/view_thread.rs b/client/lib/src/view_thread.rs index 50fd9c4..3b1441a 100644 --- a/client/lib/src/view_thread.rs +++ b/client/lib/src/view_thread.rs @@ -146,6 +146,12 @@ pub fn view_thread( let renders = render_timer.update(time::precise_time_ns()); if renders > 0 { + + let fps = view.fps_counter.tick(); + + // TODO: display in client + //println!("{}", fps); + stopwatch::time("render", || { render(&mut view); // swap buffers From 3e7f7b98ee61787520e14becef294be33fe7524f Mon Sep 17 00:00:00 2001 From: acerix Date: Mon, 1 Feb 2016 19:59:23 -0500 Subject: [PATCH 2/4] actually output the fps count to fix "unused variable" --- client/lib/src/view_thread.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/lib/src/view_thread.rs b/client/lib/src/view_thread.rs index 3b1441a..c0d1030 100644 --- a/client/lib/src/view_thread.rs +++ b/client/lib/src/view_thread.rs @@ -150,8 +150,9 @@ pub fn view_thread( let fps = view.fps_counter.tick(); // TODO: display in client - //println!("{}", fps); - + // for now, print to console every frame + println!("{} fps", fps); + stopwatch::time("render", || { render(&mut view); // swap buffers From 4bbc4f1a1f7927493807adc5334d011c5fba0de0 Mon Sep 17 00:00:00 2001 From: acerix Date: Mon, 1 Feb 2016 20:54:31 -0500 Subject: [PATCH 3/4] Since fps is not used yet, silence the warning instead of displaying it every frame --- client/lib/src/view_thread.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/src/view_thread.rs b/client/lib/src/view_thread.rs index c0d1030..aeebb0a 100644 --- a/client/lib/src/view_thread.rs +++ b/client/lib/src/view_thread.rs @@ -147,11 +147,11 @@ pub fn view_thread( let renders = render_timer.update(time::precise_time_ns()); if renders > 0 { - let fps = view.fps_counter.tick(); + let _fps = view.fps_counter.tick(); // TODO: display in client // for now, print to console every frame - println!("{} fps", fps); + //println!("{} fps", fps); stopwatch::time("render", || { render(&mut view); From c8ad41c5d7ae6eb6eeca0292b2a2ba7ce95ed255 Mon Sep 17 00:00:00 2001 From: acerix Date: Mon, 1 Feb 2016 20:55:59 -0500 Subject: [PATCH 4/4] fix tab instead of spaces --- client/lib/src/view_thread.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/src/view_thread.rs b/client/lib/src/view_thread.rs index aeebb0a..4851b38 100644 --- a/client/lib/src/view_thread.rs +++ b/client/lib/src/view_thread.rs @@ -150,7 +150,7 @@ pub fn view_thread( let _fps = view.fps_counter.tick(); // TODO: display in client - // for now, print to console every frame + // for now, print to console every frame //println!("{} fps", fps); stopwatch::time("render", || {