Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add piston's fps_counter #176

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sdl2 = "0.9.*"
sdl2-sys = "0.6.*"
thread-scoped = "*"
time = "*"
fps_counter = "*"

[dependencies.playform-common]
path = "../../common"
Expand Down
7 changes: 7 additions & 0 deletions client/lib/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! The state associated with perceiving the world state.

extern crate fps_counter;

use cgmath;
use cgmath::Vector2;
use std;
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -129,6 +134,8 @@ impl<'a> T<'a> {
},

show_hud: true,

fps_counter: fps_counter::FPSCounter::new(),
}
}
}
7 changes: 7 additions & 0 deletions client/lib/src/view_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ pub fn view_thread<Recv0, Recv1, UpdateServer>(

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
Expand Down