From 2edfdfe2b8c64f98fdaa1ad36552b0cc1085929d Mon Sep 17 00:00:00 2001 From: Cameron <51241057+maniwani@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:38:59 -0700 Subject: [PATCH] update benches, examples, tests --- .../benches/bevy_ecs/scheduling/schedule.rs | 6 ++--- examples/2d/mesh2d_manual.rs | 2 +- examples/app/custom_loop.rs | 2 +- examples/ecs/custom_schedule.rs | 4 ++-- examples/ecs/system_stepping.rs | 24 +++++++++---------- examples/games/stepping.rs | 2 +- .../shader/compute_shader_game_of_life.rs | 2 +- examples/shader/post_processing.rs | 4 ++-- examples/shader/texture_binding_array.rs | 4 ++-- examples/stress_tests/many_lights.rs | 2 +- examples/time/time.rs | 10 ++++---- tests/how_to_test_systems.rs | 24 ++++++++++--------- 12 files changed, 44 insertions(+), 42 deletions(-) diff --git a/benches/benches/bevy_ecs/scheduling/schedule.rs b/benches/benches/bevy_ecs/scheduling/schedule.rs index dc7068325e6ca9..0930d8e122b0fe 100644 --- a/benches/benches/bevy_ecs/scheduling/schedule.rs +++ b/benches/benches/bevy_ecs/scheduling/schedule.rs @@ -127,19 +127,19 @@ pub fn empty_schedule_run(criterion: &mut Criterion) { let mut schedule = Schedule::default(); schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::SingleThreaded); group.bench_function("SingleThreaded", |bencher| { - bencher.iter(|| schedule.run(&mut app.world)); + bencher.iter(|| schedule.run(app.world_mut())); }); let mut schedule = Schedule::default(); schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::MultiThreaded); group.bench_function("MultiThreaded", |bencher| { - bencher.iter(|| schedule.run(&mut app.world)); + bencher.iter(|| schedule.run(app.world_mut())); }); let mut schedule = Schedule::default(); schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::Simple); group.bench_function("Simple", |bencher| { - bencher.iter(|| schedule.run(&mut app.world)); + bencher.iter(|| schedule.run(app.world_mut())); }); group.finish(); } diff --git a/examples/2d/mesh2d_manual.rs b/examples/2d/mesh2d_manual.rs index 25af819323cb7d..860bea5d606706 100644 --- a/examples/2d/mesh2d_manual.rs +++ b/examples/2d/mesh2d_manual.rs @@ -285,7 +285,7 @@ pub const COLORED_MESH2D_SHADER_HANDLE: Handle = impl Plugin for ColoredMesh2dPlugin { fn build(&self, app: &mut App) { // Load our custom shader - let mut shaders = app.world.resource_mut::>(); + let mut shaders = app.world_mut().resource_mut::>(); shaders.insert( &COLORED_MESH2D_SHADER_HANDLE, Shader::from_wgsl(COLORED_MESH2D_SHADER, file!()), diff --git a/examples/app/custom_loop.rs b/examples/app/custom_loop.rs index 17f70ae9f6d389..3d76bed2dff915 100644 --- a/examples/app/custom_loop.rs +++ b/examples/app/custom_loop.rs @@ -11,7 +11,7 @@ fn my_runner(mut app: App) { println!("Type stuff into the console"); for line in io::stdin().lines() { { - let mut input = app.world.resource_mut::(); + let mut input = app.world_mut().resource_mut::(); input.0 = line.unwrap(); } app.update(); diff --git a/examples/ecs/custom_schedule.rs b/examples/ecs/custom_schedule.rs index f85da26e8fed97..564d00f401cca0 100644 --- a/examples/ecs/custom_schedule.rs +++ b/examples/ecs/custom_schedule.rs @@ -33,14 +33,14 @@ fn main() { // // Note that we modify `MainScheduleOrder` directly in `main` and not in a startup system. The reason for this is // that the `MainScheduleOrder` cannot be modified from systems that are run as part of the `Main` schedule. - let mut main_schedule_order = app.world.resource_mut::(); + let mut main_schedule_order = app.world_mut().resource_mut::(); main_schedule_order.insert_after(Update, SingleThreadedUpdate); // Adding a custom startup schedule works similarly, but needs to use `insert_startup_after` // instead of `insert_after`. app.add_schedule(Schedule::new(CustomStartup)); - let mut main_schedule_order = app.world.resource_mut::(); + let mut main_schedule_order = app.world_mut().resource_mut::(); main_schedule_order.insert_startup_after(PreStartup, CustomStartup); app.add_systems(SingleThreadedUpdate, single_threaded_update_system) diff --git a/examples/ecs/system_stepping.rs b/examples/ecs/system_stepping.rs index 0732e76eb0ee27..a4e4437362e9ef 100644 --- a/examples/ecs/system_stepping.rs +++ b/examples/ecs/system_stepping.rs @@ -54,7 +54,7 @@ fn main() { * Stepping::continue_frame() is called * System has been configured to always run"# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.add_schedule(Update).enable(); app.update(); @@ -65,7 +65,7 @@ fn main() { Stepping, step means run the next system across all the schedules that have been added to the Stepping resource."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.step_frame(); app.update(); @@ -89,7 +89,7 @@ fn main() { case, we previously performed a step, running one system in Update. This continue will cause all remaining systems in Update to run."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.continue_frame(); app.update(); @@ -102,7 +102,7 @@ fn main() { systems."# ); for _ in 0..4 { - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.step_frame(); app.update(); } @@ -116,10 +116,10 @@ fn main() { execute all systems in the frame. Stepping::always_run() allows us to granularly allow systems to run when stepping is enabled."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.always_run(Update, update_system_two); for _ in 0..3 { - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.step_frame(); app.update(); } @@ -132,7 +132,7 @@ fn main() { Stepping::never_run() allows us to disable systems while Stepping is enabled."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.never_run(Update, update_system_two); stepping.continue_frame(); app.update(); @@ -155,14 +155,14 @@ fn main() { During the final continue pre_update_system() and update_system_three() run."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.set_breakpoint(Update, update_system_two); stepping.continue_frame(); app.update(); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.step_frame(); app.update(); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.continue_frame(); app.update(); @@ -172,7 +172,7 @@ fn main() { through all systems Result: All systems will run"# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.clear_breakpoint(Update, update_system_two); stepping.continue_frame(); app.update(); @@ -184,7 +184,7 @@ fn main() { call Stepping::step_frame() or Stepping::continue_frame() to run systems in the Update schedule."# ); - let mut stepping = app.world.resource_mut::(); + let mut stepping = app.world_mut().resource_mut::(); stepping.disable(); app.update(); } diff --git a/examples/games/stepping.rs b/examples/games/stepping.rs index 05e7081e5d3ab1..61918c330dce65 100644 --- a/examples/games/stepping.rs +++ b/examples/games/stepping.rs @@ -36,7 +36,7 @@ impl Plugin for SteppingPlugin { // We need an independent schedule so we have access to all other // schedules through the `Stepping` resource app.init_schedule(DebugSchedule); - let mut order = app.world.resource_mut::(); + let mut order = app.world_mut().resource_mut::(); order.insert_after(Update, DebugSchedule); // create our stepping resource diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 95751be4e36635..21b5cc92c44793 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -84,7 +84,7 @@ impl Plugin for GameOfLifeComputePlugin { prepare_bind_group.in_set(RenderSet::PrepareBindGroups), ); - let mut render_graph = render_app.world.resource_mut::(); + let mut render_graph = render_app.world_mut().resource_mut::(); render_graph.add_node(GameOfLifeLabel, GameOfLifeNode::default()); render_graph.add_node_edge(GameOfLifeLabel, bevy::render::graph::CameraDriverLabel); } diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index 7760d07963145c..b3b7330bca8fe7 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -59,7 +59,7 @@ impl Plugin for PostProcessPlugin { )); // We need to get the render app from the main app - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; @@ -97,7 +97,7 @@ impl Plugin for PostProcessPlugin { fn finish(&self, app: &mut App) { // We need to get the render app from the main app - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/examples/shader/texture_binding_array.rs b/examples/shader/texture_binding_array.rs index 6332beda6f1c63..252172f5838ae1 100644 --- a/examples/shader/texture_binding_array.rs +++ b/examples/shader/texture_binding_array.rs @@ -33,11 +33,11 @@ impl Plugin for GpuFeatureSupportChecker { fn build(&self, _app: &mut App) {} fn finish(&self, app: &mut App) { - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; - let render_device = render_app.world.resource::(); + let render_device = render_app.world().resource::(); // Check if the device support the required feature. If not, exit the example. // In a real application, you should setup a fallback for the missing feature diff --git a/examples/stress_tests/many_lights.rs b/examples/stress_tests/many_lights.rs index 4157869197d67d..b9134c42c4f5e1 100644 --- a/examples/stress_tests/many_lights.rs +++ b/examples/stress_tests/many_lights.rs @@ -157,7 +157,7 @@ struct LogVisibleLights; impl Plugin for LogVisibleLights { fn build(&self, app: &mut App) { - let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { + let Some(render_app) = app.get_sub_app_mut(RenderApp) else { return; }; diff --git a/examples/time/time.rs b/examples/time/time.rs index 01e5eefa1b07b7..c473f9fa213753 100644 --- a/examples/time/time.rs +++ b/examples/time/time.rs @@ -45,29 +45,29 @@ fn runner(mut app: App) { } "f" => { println!("FAST: setting relative speed to 2x"); - app.world + app.world_mut() .resource_mut::>() .set_relative_speed(2.0); } "n" => { println!("NORMAL: setting relative speed to 1x"); - app.world + app.world_mut() .resource_mut::>() .set_relative_speed(1.0); } "s" => { println!("SLOW: setting relative speed to 0.5x"); - app.world + app.world_mut() .resource_mut::>() .set_relative_speed(0.5); } "p" => { println!("PAUSE: pausing virtual clock"); - app.world.resource_mut::>().pause(); + app.world_mut().resource_mut::>().pause(); } "u" => { println!("UNPAUSE: resuming virtual clock"); - app.world.resource_mut::>().unpause(); + app.world_mut().resource_mut::>().unpause(); } "q" => { println!("QUITTING!"); diff --git a/tests/how_to_test_systems.rs b/tests/how_to_test_systems.rs index b71e5471bd1e16..f14a14a60eba9d 100644 --- a/tests/how_to_test_systems.rs +++ b/tests/how_to_test_systems.rs @@ -62,7 +62,7 @@ fn did_hurt_enemy() { // Setup test entities let enemy_id = app - .world + .world_mut() .spawn(Enemy { hit_points: 5, score_value: 3, @@ -73,8 +73,8 @@ fn did_hurt_enemy() { app.update(); // Check resulting changes - assert!(app.world.get::(enemy_id).is_some()); - assert_eq!(app.world.get::(enemy_id).unwrap().hit_points, 4); + assert!(app.world().get::(enemy_id).is_some()); + assert_eq!(app.world().get::(enemy_id).unwrap().hit_points, 4); } #[test] @@ -93,7 +93,7 @@ fn did_despawn_enemy() { // Setup test entities let enemy_id = app - .world + .world_mut() .spawn(Enemy { hit_points: 1, score_value: 1, @@ -104,10 +104,10 @@ fn did_despawn_enemy() { app.update(); // Check enemy was despawned - assert!(app.world.get::(enemy_id).is_none()); + assert!(app.world().get::(enemy_id).is_none()); // Get `EnemyDied` event reader - let enemy_died_events = app.world.resource::>(); + let enemy_died_events = app.world().resource::>(); let mut enemy_died_reader = enemy_died_events.get_reader(); let enemy_died = enemy_died_reader.read(enemy_died_events).next().unwrap(); @@ -132,16 +132,18 @@ fn spawn_enemy_using_input_resource() { app.update(); // Check resulting changes, one entity has been spawned with `Enemy` component - assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1); + assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1); // Clear the `just_pressed` status for all `KeyCode`s - app.world.resource_mut::>().clear(); + app.world_mut() + .resource_mut::>() + .clear(); // Run systems app.update(); // Check resulting changes, no new entity has been spawned - assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1); + assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1); } #[test] @@ -159,7 +161,7 @@ fn update_score_on_event() { app.add_systems(Update, update_score); // Send an `EnemyDied` event - app.world + app.world_mut() .resource_mut::>() .send(EnemyDied(3)); @@ -167,5 +169,5 @@ fn update_score_on_event() { app.update(); // Check resulting changes - assert_eq!(app.world.resource::().0, 3); + assert_eq!(app.world().resource::().0, 3); }