Self test: fast forward and drawing times

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Opus 5.5 committed 2026-11-08 00:56:26 +01:00
1 parent 7e2e638e05
commit 7972e8ad1b
1 file changed
+30 -1
+30 -1
View File
@@ -2164,9 +2164,23 @@ app.pending_briefing = briefing_of(&campaign, i);
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
let shot_now = shot.as_mut().and_then(|p| p.before_frame(&mut app, &mut ui, &mut menu, &mut r3d, now)); let shot_now = shot.as_mut().and_then(|p| p.before_frame(&mut app, &mut ui, &mut menu, &mut r3d, now));
#[cfg(not(target_arch = "wasm32"))]
let draw_t0 = std::time::Instant::now();
draw_frame(&mut app, &gfx, &mut r3d, &mut ui, &mut menu, &cloud, &inp, (mx, my), touch_mode, now); draw_frame(&mut app, &gfx, &mut r3d, &mut ui, &mut menu, &cloud, &inp, (mx, my), touch_mode, now);
ui::end_frame(); ui::end_frame();
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
if let Some(p) = shot.as_mut() {
// the self test reports the time drawing takes (without waiting for the screen)
p.frames += 1;
p.draw_ms += draw_t0.elapsed().as_secs_f64() * 1000.0;
if now - p.report_t >= 2.0 {
println!("self test: {:.1} s, {} frames, drawing {:.2} ms per frame, {} units, {} particles", now - p.started.unwrap_or(now), p.frames, p.draw_ms / p.frames.max(1) as f64, app.game.ents.len(), app.game.parts.len());
p.frames = 0;
p.draw_ms = 0.0;
p.report_t = now;
}
}
#[cfg(not(target_arch = "wasm32"))]
if let Some(path) = shot_now { if let Some(path) = shot_now {
shot_capture(&path); shot_capture(&path);
} }
@@ -2177,7 +2191,8 @@ app.pending_briefing = briefing_of(&campaign, i);
// ---- self test and screenshots (desktop): DC_SHOT=demo or a savegame file starts it right // ---- self test and screenshots (desktop): DC_SHOT=demo or a savegame file starts it right
// away, DC_SHOT_STYLE=hd|pixel picks the graphics style (not saved), DC_SHOT_AFTER seconds later // away, DC_SHOT_STYLE=hd|pixel picks the graphics style (not saved), DC_SHOT_AFTER seconds later
// (default 10) the screen goes to DC_SHOT_OUT (default /tmp/dc-shot.png) and the game ends; // (default 10) the screen goes to DC_SHOT_OUT (default /tmp/dc-shot.png) and the game ends;
// DC_SHOT_ZOOM sets the camera zoom, DC_SHOT_YAW its turn, DC_SHOT_AT=x,z where it looks // DC_SHOT_ZOOM sets the camera zoom, DC_SHOT_YAW its turn, DC_SHOT_AT=x,z where it looks;
// DC_SHOT_FF=seconds runs the game that long at once before (a screen that is off gives few frames)
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
struct ShotPlan { struct ShotPlan {
load: String, load: String,
@@ -2188,6 +2203,10 @@ struct ShotPlan {
yaw: Option<f32>, yaw: Option<f32>,
at: Option<(f32, f32)>, at: Option<(f32, f32)>,
started: Option<f64>, started: Option<f64>,
frames: u64,
draw_ms: f64,
report_t: f64,
ff: f32,
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@@ -2207,6 +2226,10 @@ impl ShotPlan {
Some((a.trim().parse().ok()?, b.trim().parse().ok()?)) Some((a.trim().parse().ok()?, b.trim().parse().ok()?))
}), }),
started: None, started: None,
frames: 0,
draw_ms: 0.0,
report_t: 0.0,
ff: num("DC_SHOT_FF").unwrap_or(0.0),
}) })
} }
@@ -2229,6 +2252,12 @@ impl ShotPlan {
} }
menu.page = None; menu.page = None;
ui.show_help = false; ui.show_help = false;
// fast forward: the game's own steps, without drawing
let mut left = self.ff;
while left > 0.0 {
app.game.update(0.05);
left -= 0.05;
}
if let Some(z) = self.zoom { if let Some(z) = self.zoom {
app.cam.zoom = z; app.cam.zoom = z;
} }