From 35cd9c52467ddada1f86a4b7fda2fd1801d94b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:27:25 +0100 Subject: [PATCH 1/6] allow multiple wave from cli --- examples/tools/bevymark.rs | 45 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index ac3c975438693..eb6773c64eaf8 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -1,4 +1,5 @@ use bevy::{ + core::FixedTimestep, diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, }; @@ -43,30 +44,44 @@ fn main() { .add_system(movement_system) .add_system(collision_system) .add_system(counter_system) + .add_system_set( + SystemSet::new() + .with_run_criteria(FixedTimestep::step(0.2)) + .with_system(scheduled_spawne), + ) .run(); } -struct BirdTexture(Handle); +struct BirdScheduled { + wave: u128, + per_wave: u128, +} -fn setup( +fn scheduled_spawne( mut commands: Commands, windows: Res, + mut scheduled: ResMut, mut counter: ResMut, - asset_server: Res, + bird_texture: Res, ) { - let texture = asset_server.load("branding/icon.png"); - if let Some(initial_count) = std::env::args() - .nth(1) - .and_then(|arg| arg.parse::().ok()) - { + if scheduled.wave > 0 { + counter.color = Color::rgb(random(), random(), random()); spawn_birds( &mut commands, &windows, &mut counter, - initial_count, - texture.clone_weak(), + scheduled.per_wave, + bird_texture.0.clone_weak(), ); + scheduled.wave -= 1; } +} + +struct BirdTexture(Handle); + +fn setup(mut commands: Commands, asset_server: Res) { + let texture = asset_server.load("branding/icon.png"); + commands.spawn_bundle(OrthographicCameraBundle::new_2d()); commands.spawn_bundle(UiCameraBundle::default()); commands.spawn_bundle(TextBundle { @@ -120,6 +135,16 @@ fn setup( }); commands.insert_resource(BirdTexture(texture)); + commands.insert_resource(BirdScheduled { + per_wave: std::env::args() + .nth(1) + .and_then(|arg| arg.parse::().ok()) + .unwrap_or_default(), + wave: std::env::args() + .nth(2) + .and_then(|arg| arg.parse::().ok()) + .unwrap_or(1), + }); } fn mouse_handler( From 889797b4f98aa95d992b747feda096e134875899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:49:45 +0100 Subject: [PATCH 2/6] make sure birds don't go off screen --- examples/tools/bevymark.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index eb6773c64eaf8..3662db99530c4 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -235,6 +235,9 @@ fn collision_system(windows: Res, mut bird_query: Query<(&mut Bird, &Tr if y_vel < 0. && y_pos - HALF_BIRD_SIZE < -half_height { bird.velocity.y = -y_vel; } + if y_pos + HALF_BIRD_SIZE > half_height && y_vel > 0.0 { + bird.velocity.y = 0.0; + } } } From d282b8632c55ffbb78258496dc5d30fb74897a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Fri, 17 Dec 2021 13:54:24 +0100 Subject: [PATCH 3/6] typo Co-Authored-By: bjorn3 --- examples/tools/bevymark.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 3662db99530c4..6a4ca642aa55b 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -47,7 +47,7 @@ fn main() { .add_system_set( SystemSet::new() .with_run_criteria(FixedTimestep::step(0.2)) - .with_system(scheduled_spawne), + .with_system(scheduled_spawner), ) .run(); } @@ -57,7 +57,7 @@ struct BirdScheduled { per_wave: u128, } -fn scheduled_spawne( +fn scheduled_spawner( mut commands: Commands, windows: Res, mut scheduled: ResMut, From 3a0f4b050928293e06080b573e2b394dfe20fd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:23:20 +0100 Subject: [PATCH 4/6] spawn the first wave in white to hit both pipelines --- examples/tools/bevymark.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 6a4ca642aa55b..2f630565084e9 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -65,7 +65,6 @@ fn scheduled_spawner( bird_texture: Res, ) { if scheduled.wave > 0 { - counter.color = Color::rgb(random(), random(), random()); spawn_birds( &mut commands, &windows, @@ -73,6 +72,7 @@ fn scheduled_spawner( scheduled.per_wave, bird_texture.0.clone_weak(), ); + counter.color = Color::rgb(random(), random(), random()); scheduled.wave -= 1; } } From c9062a29f194ba7bde85c839564063cc5be7f99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:24:54 +0100 Subject: [PATCH 5/6] remove dead code --- examples/tools/bevymark.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 2f630565084e9..b99e756ebad7e 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -3,7 +3,7 @@ use bevy::{ diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, }; -use rand::{random, Rng}; +use rand::random; const BIRDS_PER_SECOND: u32 = 10000; const _BASE_COLOR: Color = Color::rgb(5.0, 5.0, 5.0); @@ -255,15 +255,3 @@ fn counter_system( } }; } - -/// Generate a color modulation -/// -/// Because there is no `Mul for Color` instead `[f32; 3]` is -/// used. -fn _gen_color(rng: &mut impl Rng) -> [f32; 3] { - let r = rng.gen_range(0.2..1.0); - let g = rng.gen_range(0.2..1.0); - let b = rng.gen_range(0.2..1.0); - let v = Vec3::new(r, g, b); - v.normalize().into() -} From 3664b7335b4d55e14b20a1f8b187b85004a8de30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <8672791+mockersf@users.noreply.github.com> Date: Sat, 18 Dec 2021 19:01:18 +0100 Subject: [PATCH 6/6] squeeze a little more perfs --- examples/tools/bevymark.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index b99e756ebad7e..290fdf42594aa 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -72,7 +72,7 @@ fn scheduled_spawner( scheduled.per_wave, bird_texture.0.clone_weak(), ); - counter.color = Color::rgb(random(), random(), random()); + counter.color = Color::rgb_linear(random(), random(), random()); scheduled.wave -= 1; } } @@ -156,7 +156,7 @@ fn mouse_handler( mut counter: ResMut, ) { if mouse_button_input.just_released(MouseButton::Left) { - counter.color = Color::rgb(random(), random(), random()); + counter.color = Color::rgb_linear(random(), random(), random()); } if mouse_button_input.pressed(MouseButton::Left) { @@ -166,7 +166,7 @@ fn mouse_handler( &windows, &mut counter, spawn_count, - bird_texture.0.clone(), + bird_texture.0.clone_weak(), ); } }