Add prototype FPS counter to HUD

Former-commit-id: 77e22998b71a6d3932271a6b9e815dab3925d5e3
This commit is contained in:
sxv20_ 2019-04-22 17:16:21 +01:00
parent 786dc16092
commit c49a88455a
2 changed files with 14 additions and 4 deletions

View File

@ -20,6 +20,7 @@ widget_ids! {
bag_space_add, bag_space_add,
inventorytest_button, inventorytest_button,
inventorytest_button_label, inventorytest_button_label,
fps_counter,
// Bag and Inventory // Bag and Inventory
bag, bag,
@ -473,7 +474,7 @@ impl Hud {
} }
} }
fn update_layout(&mut self) -> Vec<Event> { fn update_layout(&mut self, tps: f64) -> Vec<Event> {
let mut events = Vec::new(); let mut events = Vec::new();
let ref mut ui_widgets = self.ui.set_widgets(); let ref mut ui_widgets = self.ui.set_widgets();
@ -482,6 +483,15 @@ impl Hud {
const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0); const MANA_COLOR: Color = Color::Rgba(0.42, 0.41, 0.66, 1.0);
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
// Always display an FPS counter
// TODO: move this to a better place
Text::new(&format!("FPS: {:.1}", tps))
.color(Color::Rgba(1.0, 0.0, 0.0, 1.0))
.down_from(self.ids.mmap_frame, 40.0)
.font_id(self.font_opensans)
.font_size(30)
.set(self.ids.fps_counter, ui_widgets);
if self.show_ui { if self.show_ui {
// Add Bag-Space Button // Add Bag-Space Button
if self.inventorytest_button { if self.inventorytest_button {
@ -1603,8 +1613,8 @@ impl Hud {
} }
} }
pub fn maintain(&mut self, renderer: &mut Renderer) -> Vec<Event> { pub fn maintain(&mut self, renderer: &mut Renderer, tps: f64) -> Vec<Event> {
let events = self.update_layout(); let events = self.update_layout(tps);
self.ui.maintain(renderer); self.ui.maintain(renderer);
events events
} }

View File

@ -159,7 +159,7 @@ impl PlayState for SessionState {
// Maintain the scene // Maintain the scene
self.scene.maintain(global_state.window.renderer_mut(), &mut self.client.borrow_mut()); self.scene.maintain(global_state.window.renderer_mut(), &mut self.client.borrow_mut());
// Maintain the UI // Maintain the UI
for event in self.hud.maintain(global_state.window.renderer_mut()) { for event in self.hud.maintain(global_state.window.renderer_mut(), clock.get_tps()) {
match event { match event {
HudEvent::SendMessage(msg) => { HudEvent::SendMessage(msg) => {
// TODO: Handle result // TODO: Handle result