diff --git a/src/main.rs b/src/main.rs index 71d4705..397a40c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2164,9 +2164,23 @@ app.pending_briefing = briefing_of(&campaign, i); #[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)); + #[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); ui::end_frame(); #[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 { 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 // 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; -// 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"))] struct ShotPlan { load: String, @@ -2188,6 +2203,10 @@ struct ShotPlan { yaw: Option, at: Option<(f32, f32)>, started: Option, + frames: u64, + draw_ms: f64, + report_t: f64, + ff: f32, } #[cfg(not(target_arch = "wasm32"))] @@ -2207,6 +2226,10 @@ impl ShotPlan { Some((a.trim().parse().ok()?, b.trim().parse().ok()?)) }), 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; 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 { app.cam.zoom = z; }