Skip to content

Commit

Permalink
Merge pull request #57 from indiv0/feat-display-fps-in-window
Browse files Browse the repository at this point in the history
Display Rendering Debug Info in Window
  • Loading branch information
indiv0 committed May 15, 2016
2 parents 1555858 + 1a590c1 commit 3e88676
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions assets/localization/en_CA.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"colonize_window_title": "Colonize",
"debug_render_info": "Render Info",
"gamescene_welcome_text": "Welcome to Colonize!",
"gamescene_debug_cursor": "Mouse Cursor",
"gamescene_debug_camera": "Camera",
Expand Down
22 changes: 17 additions & 5 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Game<B, E, G, W>
G: Graphics<Texture=B::Texture>,
W: AdvancedWindow + Window,
{
config: Rc<Config>,
localization: Rc<Localization>,
fps_counter: fps_counter::FPSCounter,
scene_manager: SceneManager<B, E, G>,
Expand All @@ -52,15 +53,16 @@ impl<B, E, G, W> Game<B, E, G, W>

let events = window.events().ups(config.ups).max_fps(config.max_fps);

Self::new_internal(events, localization, scene_manager, window)
Self::new_internal(events, config, localization, scene_manager, window)
}

fn new_internal(events: WindowEvents, localization: Rc<Localization>, scene_manager: SceneManager<B, E, G>, window: W) -> Self {
fn new_internal(events: WindowEvents, config: Rc<Config>, localization: Rc<Localization>, scene_manager: SceneManager<B, E, G>, window: W) -> Self {
Game {
events: events,
fps_counter: fps_counter::FPSCounter::new(),
scene_manager: scene_manager,
window: window,
config: config,
localization: localization,
}
}
Expand All @@ -84,15 +86,25 @@ impl<W> Game<GlBackend, Event<W::Event>, GlGraphics, W>
let end_time = time::precise_time_ns();

let fps = self.fps_counter.tick();
let title = format!(
let fps_info = format!(
"{}: {:.2}{unit_millisecond} @ {} {unit_fps}",
self.localization.colonize_window_title,
self.localization.debug_render_info,
(end_time - start_time) as f64 / 1e6,
fps,
unit_millisecond=self.localization.util_unit_millisecond,
unit_fps=self.localization.util_unit_fps,
);
self.window.set_title(title);

gl.draw(args.viewport(), |c, gl| {
use graphics::{Text, Transformed};

Text::new(self.config.font_size).draw(
&fps_info,
glyph_cache,
&c.draw_state,
c.transform.trans(10.0, 25.0),
gl);
});
},
_ => {
self.scene_manager.handle_event(&e);
Expand Down
3 changes: 3 additions & 0 deletions src/localization.in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pub struct Localization {
/// Colonize - Window title
pub colonize_window_title: String,
/// Debug - Render Info
pub debug_render_info: String,
/// GameScene - Welcome text
pub gamescene_welcome_text: String,
/// GameScene - Debug - Cursor
Expand Down Expand Up @@ -29,6 +31,7 @@ pub struct Localization {
#[derive(Deserialize, Serialize)]
struct ParsedLocalization {
colonize_window_title: Option<String>,
debug_render_info: Option<String>,
gamescene_welcome_text: Option<String>,
gamescene_debug_cursor: Option<String>,
gamescene_debug_camera: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions src/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ create_type_parsing_impls! {
Localization,
ParsedLocalization,
colonize_window_title, "Colonize".to_owned();
debug_render_info, "Render Info".to_owned();
gamescene_welcome_text, "Welcome to Colonize!".to_owned();
gamescene_debug_cursor, "Mouse Cursor".to_owned();
gamescene_debug_camera, "Camera".to_owned();
Expand Down

0 comments on commit 3e88676

Please sign in to comment.