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..4851b38 100644 --- a/client/lib/src/view_thread.rs +++ b/client/lib/src/view_thread.rs @@ -146,6 +146,13 @@ 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 + // for now, print to console every frame + //println!("{} fps", fps); + stopwatch::time("render", || { render(&mut view); // swap buffers