From e4443fe4dc26cf04ab819ec94297ed0bddffbac3 Mon Sep 17 00:00:00 2001 From: tigerplush <64077786+tigerplush@users.noreply.github.com> Date: Tue, 3 Sep 2024 19:01:34 +0200 Subject: [PATCH 1/4] added screenshot function and workflow for krypta --- .github/workflows/perf.yml | 34 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + examples/krypta.rs | 40 +++++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/perf.yml diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml new file mode 100644 index 0000000..584355f --- /dev/null +++ b/.github/workflows/perf.yml @@ -0,0 +1,34 @@ +name: Performance Check +permissions: read-all + +on: workflow_dispatch + +env: + CARGO_TERM_COLOR: always + +jobs: + performance: + name: Performance Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: clippy, rustfmt + + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev + + - name: Cargo Build Krypta Example + run: cargo run --release --example krypta --features benchmark + + - name: ls + run: ls -la + + - uses: actions/upload-artifact@v4 + with: + name: upload screenshot + path: ./screenshot.png diff --git a/Cargo.toml b/Cargo.toml index f7b7f0c..de224be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ readme = "README.md" [features] default = ["egui"] egui = ["dep:bevy-inspector-egui"] +benchmark = ["default"] [dependencies] bevy = { version = "0.14.1", default-features = false, features = [ diff --git a/examples/krypta.rs b/examples/krypta.rs index 008b906..dc949b1 100644 --- a/examples/krypta.rs +++ b/examples/krypta.rs @@ -1,8 +1,13 @@ +#[cfg(feature = "benchmark")] +use std::path::Path; + use bevy::color::palettes; use bevy::input::mouse::MouseWheel; use bevy::prelude::*; use bevy::render::camera::RenderTarget; use bevy::render::texture::{ImageFilterMode, ImageSamplerDescriptor}; +#[cfg(feature = "benchmark")] +use bevy::render::view::screenshot::ScreenshotManager; use bevy::render::view::RenderLayers; use bevy::sprite::MaterialMesh2dBundle; use bevy::window::PrimaryWindow; @@ -29,7 +34,8 @@ pub struct Movable; fn main() { // Basic setup. - App::new() + let mut app = App::new(); + app .insert_resource(ClearColor(Color::srgba_u8(0, 0, 0, 0))) .add_plugins(( DefaultPlugins @@ -74,8 +80,12 @@ fn main() .register_type::() .add_systems(Startup, setup.after(setup_post_processing_camera)) .add_systems(Update, (system_move_camera, system_camera_zoom)) - .add_systems(Update, system_control_mouse_light.after(system_move_camera)) - .run(); + .add_systems(Update, system_control_mouse_light.after(system_move_camera)); + + #[cfg(feature = "benchmark")] + app.add_systems(Update, take_screenshot); + + app.run(); } #[allow(clippy::identity_op)] @@ -985,4 +995,28 @@ fn system_camera_zoom( camera.scale = (camera.scale - projection_delta * time.delta_seconds()) .clamp(CAMERA_SCALE_BOUNDS.0, CAMERA_SCALE_BOUNDS.1); } +} + +#[cfg(feature = "benchmark")] +fn take_screenshot( + time: Res