From 0d1f3586b2d657d13ed4e9448bd55b4ee564b913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Mon, 22 Jul 2024 20:29:47 +0200 Subject: [PATCH] allow more configuration for showcase from the CLI (#13217) # Objective - The default values hard coded in the showcase script may not make sense depending on your hardware ## Solution - Let them be customised from the CLI --------- Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> Co-authored-by: Alice Cecile Co-authored-by: Rob Parrett --- tools/example-showcase/src/main.rs | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/tools/example-showcase/src/main.rs b/tools/example-showcase/src/main.rs index d0c332008b..2be3b8d62c 100644 --- a/tools/example-showcase/src/main.rs +++ b/tools/example-showcase/src/main.rs @@ -44,13 +44,19 @@ enum Action { /// WGPU backend to use wgpu_backend: Option, - #[arg(long)] - /// Don't stop automatically - manual_stop: bool, + #[arg(long, default_value = "250")] + /// Which frame to automatically stop the example at. + /// + /// This defaults to frame 250. Set it to 0 to not stop the example automatically. + stop_frame: u32, #[arg(long)] - /// Take a screenshot - screenshot: bool, + /// Which frame to take a screenshot at. Set to 0 for no screenshot. + screenshot_frame: u32, + + #[arg(long, default_value = "0.05")] + /// Fixed duration of a frame, in seconds. Only used when taking a screenshot, default to 0.05 + fixed_frame_time: f32, #[arg(long)] /// Running in CI (some adaptation to the code) @@ -138,8 +144,9 @@ fn main() { match cli.action { Action::Run { wgpu_backend, - manual_stop, - screenshot, + stop_frame, + screenshot_frame, + fixed_frame_time, in_ci, ignore_stress_tests, report_details, @@ -171,29 +178,34 @@ fn main() { let mut extra_parameters = vec![]; - match (manual_stop, screenshot) { - (true, true) => { + match (stop_frame, screenshot_frame) { + // When the example does not automatically stop nor take a screenshot. + (0, 0) => (), + // When the example does not automatically stop. + (0, _) => { let mut file = File::create("example_showcase_config.ron").unwrap(); file.write_all( - b"(setup: (fixed_frame_time: Some(0.05)), events: [(100, Screenshot)])", + format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot)])").as_bytes(), ) .unwrap(); extra_parameters.push("--features"); extra_parameters.push("bevy_ci_testing"); } - (true, false) => (), - (false, true) => { + // When the example does not take a screenshot. + (_, 0) => { let mut file = File::create("example_showcase_config.ron").unwrap(); - file.write_all( - b"(setup: (fixed_frame_time: Some(0.05)), events: [(100, Screenshot), (250, AppExit)])", - ) - .unwrap(); + file.write_all(format!("(events: [({stop_frame}, AppExit)])").as_bytes()) + .unwrap(); extra_parameters.push("--features"); extra_parameters.push("bevy_ci_testing"); } - (false, false) => { + // When the example both automatically stops and takes a screenshot. + (_, _) => { let mut file = File::create("example_showcase_config.ron").unwrap(); - file.write_all(b"(events: [(250, AppExit)])").unwrap(); + file.write_all( + format!("(setup: (fixed_frame_time: Some({fixed_frame_time})), events: [({screenshot_frame}, Screenshot), ({stop_frame}, AppExit)])").as_bytes(), + ) + .unwrap(); extra_parameters.push("--features"); extra_parameters.push("bevy_ci_testing"); } @@ -314,7 +326,7 @@ fn main() { cmd = cmd.env("WGPU_BACKEND", backend); } - if !manual_stop || screenshot { + if stop_frame > 0 || screenshot_frame > 0 { cmd = cmd.env("CI_TESTING_CONFIG", "example_showcase_config.ron"); } @@ -329,10 +341,10 @@ fn main() { if (!report_details && result.is_ok()) || (report_details && result.as_ref().unwrap().status.success()) { - if screenshot { + if screenshot_frame > 0 { let _ = fs::create_dir_all(Path::new("screenshots").join(&to_run.category)); let renamed_screenshot = fs::rename( - "screenshot-100.png", + format!("screenshot-{screenshot_frame}.png"), Path::new("screenshots") .join(&to_run.category) .join(format!("{}.png", to_run.technical_name)), @@ -404,7 +416,7 @@ fn main() { .collect::>() .join("\n"), ); - if screenshot { + if screenshot_frame > 0 { let _ = fs::write( format!("{reports_path}/no_screenshots"), no_screenshot_examples