aboutsummaryrefslogtreecommitdiff
path: root/pixel-client/src/profiler.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-25 17:37:49 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-25 17:37:49 +0200
commit5bf5a200ada9ba03ca2a12c1503318a97166d7c7 (patch)
tree0936ea088efd11eaee00a88dcb368e7271fb985b /pixel-client/src/profiler.rs
parent3403fc2d55f510c29bf7e74d85433801cd99cbbc (diff)
downloadhurrycurry-5bf5a200ada9ba03ca2a12c1503318a97166d7c7.tar
hurrycurry-5bf5a200ada9ba03ca2a12c1503318a97166d7c7.tar.bz2
hurrycurry-5bf5a200ada9ba03ca2a12c1503318a97166d7c7.tar.zst
pc: show fps
Diffstat (limited to 'pixel-client/src/profiler.rs')
-rw-r--r--pixel-client/src/profiler.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/pixel-client/src/profiler.rs b/pixel-client/src/profiler.rs
new file mode 100644
index 00000000..8d3f4689
--- /dev/null
+++ b/pixel-client/src/profiler.rs
@@ -0,0 +1,60 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+use crate::render::{sprite::SpriteDraw, Renderer};
+use hurrycurry_protocol::glam::Vec2;
+use std::time::Instant;
+
+pub struct ProfilerOverlay {
+ frames: usize,
+ fps_timer_start: Instant,
+ fps: f32,
+}
+
+impl ProfilerOverlay {
+ pub fn new() -> Self {
+ Self {
+ fps: 0.,
+ fps_timer_start: Instant::now(),
+ frames: 0,
+ }
+ }
+ pub fn update(&mut self, renderer: &mut Renderer) {
+ self.frames += 1;
+
+ let t = self.fps_timer_start.elapsed();
+
+ if t.as_secs_f32() > 0.2 {
+ self.fps = self.frames as f32 / t.as_secs_f32();
+ self.frames = 0;
+ self.fps_timer_start += t;
+ }
+ let size = renderer.draw_text(
+ Vec2::ZERO,
+ &format!("FPS: {:.0}", self.fps),
+ 0.3,
+ Some([255, 150, 255, 255]),
+ );
+ renderer.draw_ui(SpriteDraw::screen(
+ renderer.misc_textures.solid,
+ i32::MAX - 1,
+ Vec2::ZERO,
+ size,
+ Some([0, 0, 0, 200]),
+ ))
+ }
+}