Debug FPS display with rendering backend info

This commit is contained in:
Richard Zink committed 2026-11-05 07:21:37 +01:00
1 parent ee7b76fa6a
commit 07371cc893
8 files changed
+133 -4

No files matched your search

+35 -2
View File
@@ -394,6 +394,8 @@ struct App {
ws_id: i32,
match_mode: bool,
coop: bool,
fps: f32,
renderer: String,
}
impl App {
@@ -600,7 +602,7 @@ async fn main() {
let seed = (miniquad::date::now() * 1000.0) as u32 | 1;
// behind the title menu: the endless bridge battle
let (game, cam) = Game::new_demo(seed);
let mut app = App { game, cam, settings, seed, status: None, recorded: false, client: MatchClient::new(), ws_id: 0, match_mode: false, coop: false };
let mut app = App { game, cam, settings, seed, status: None, recorded: false, client: MatchClient::new(), ws_id: 0, match_mode: false, coop: false, fps: 0.0, renderer: platform::renderer() };
menu.progress = platform::storage_get(PROGRESS_KEY).and_then(|s| serde_json::from_str(&s).ok()).unwrap_or_default();
app.game.hints = app.settings.hints;
let mut inp = Input { ldown: None, rdown: None, rlast: (0.0, 0.0), rdrag: false, mlast: None, minimap_drag: false, tlast: None, touch_world: false, inspect: None };
@@ -614,8 +616,11 @@ async fn main() {
let mut cache_t = 0.0f32;
loop {
let dt = get_frame_time().min(0.1);
let raw_dt = get_frame_time();
let dt = raw_dt.min(0.1);
let now = get_time();
let fps_now = 1.0 / raw_dt.max(0.001);
app.fps = if app.fps <= 0.0 { fps_now } else { app.fps + (fps_now - app.fps) * 0.08 };
let mut settings_changed = false;
// ---------------- touch or mouse: which interface is active
@@ -1423,4 +1428,32 @@ fn draw_frame(app: &mut App, gfx: &Gfx, r3d: &mut R3d, ui: &mut Ui, menu: &mut M
if !touch {
ui.draw_cursor(gfx, &app.game, now, blocked);
}
if app.settings.debug_fps {
draw_debug_fps(app, gfx);
}
}
fn draw_debug_fps(app: &App, gfx: &Gfx) {
ui::begin_ui();
let scale = ui::SMALL().max(1.0);
let fps = app.fps.max(0.0).round() as i32;
let renderer = {
let r = app.renderer.trim();
if r.is_empty() {
if cfg!(target_arch = "wasm32") {
"WebGL"
} else {
"OpenGL"
}
} else {
r
}
};
let max_cols = (((ui::sw() - 6.0) / ui::CW()).floor() as i32).max(12) as usize;
let line: String = format!("{} FPS {}", fps, renderer).chars().take(max_cols).collect();
let w = gfx.measure(&line, scale);
let x = (ui::sw() - w - 2.0).max(2.0);
let y = 2.0;
draw_rectangle(x - 2.0, y - 2.0, w + 4.0, scale * 10.0 + 4.0, Color::from_rgba(0, 0, 0, 150));
gfx.text(&line, x, y, scale, GOLD);
}