Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added screenshot function and workflow for krypta #72

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
47 changes: 41 additions & 6 deletions examples/krypta.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,8 +34,8 @@ pub struct Movable;
fn main()
{
// Basic setup.
App::new()
.insert_resource(ClearColor(Color::srgba_u8(0, 0, 0, 0)))
let mut app = App::new();
app.insert_resource(ClearColor(Color::srgba_u8(0, 0, 0, 0)))
.add_plugins((
DefaultPlugins
.set(AssetPlugin {
Expand Down Expand Up @@ -74,8 +79,12 @@ fn main()
.register_type::<LightPassParams>()
.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)]
Expand Down Expand Up @@ -970,7 +979,8 @@ fn system_camera_zoom(
mut cameras: Query<&mut OrthographicProjection, With<SpriteCamera>>,
time: Res<Time>,
mut scroll_event_reader: EventReader<MouseWheel>,
) {
)
{
let mut projection_delta = 0.;

for event in scroll_event_reader.read() {
Expand All @@ -985,4 +995,29 @@ 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<Time>,
main_window: Query<Entity, With<PrimaryWindow>>,
mut screenshot_manager: ResMut<ScreenshotManager>,
mut exit: EventWriter<AppExit>,
mut screenshot_requested: Local<bool>,
)
{
const SCREENSHOT_AFTER_SECONDS: f32 = 10.0;

if time.elapsed_seconds() > SCREENSHOT_AFTER_SECONDS && !*screenshot_requested {
// take screenshot
screenshot_manager
.save_screenshot_to_disk(main_window.single(), "./screenshot.png")
.unwrap();
*screenshot_requested = true;
}

if *screenshot_requested && Path::new("./screenshot.png").exists() {
// exit
exit.send(AppExit::Success);
}
}
8 changes: 4 additions & 4 deletions src/gi/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ pub struct AssetUtil;

impl AssetUtil
{
pub fn gi(l: &'static str) -> AssetPath
pub fn gi(l: &'static str) -> AssetPath<'static>
{
AssetPath::parse("gi/target").with_label(l.to_owned())
}
pub fn camera(l: &'static str) -> AssetPath
pub fn camera(l: &'static str) -> AssetPath<'static>
{
AssetPath::parse("camera/target").with_label(l.to_owned())
}
pub fn material(l: &'static str) -> AssetPath
pub fn material(l: &'static str) -> AssetPath<'static>
{
AssetPath::parse("material").with_label(l.to_owned())
}
pub fn mesh(l: &'static str) -> AssetPath
pub fn mesh(l: &'static str) -> AssetPath<'static>
{
AssetPath::parse("mesh").with_label(l.to_owned())
}
Expand Down
Loading