Skip to content

Commit 2edfdfe

Browse files
committed
update benches, examples, tests
1 parent b80a99f commit 2edfdfe

File tree

12 files changed

+44
-42
lines changed

12 files changed

+44
-42
lines changed

benches/benches/bevy_ecs/scheduling/schedule.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,19 @@ pub fn empty_schedule_run(criterion: &mut Criterion) {
127127
let mut schedule = Schedule::default();
128128
schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::SingleThreaded);
129129
group.bench_function("SingleThreaded", |bencher| {
130-
bencher.iter(|| schedule.run(&mut app.world));
130+
bencher.iter(|| schedule.run(app.world_mut()));
131131
});
132132

133133
let mut schedule = Schedule::default();
134134
schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::MultiThreaded);
135135
group.bench_function("MultiThreaded", |bencher| {
136-
bencher.iter(|| schedule.run(&mut app.world));
136+
bencher.iter(|| schedule.run(app.world_mut()));
137137
});
138138

139139
let mut schedule = Schedule::default();
140140
schedule.set_executor_kind(bevy_ecs::schedule::ExecutorKind::Simple);
141141
group.bench_function("Simple", |bencher| {
142-
bencher.iter(|| schedule.run(&mut app.world));
142+
bencher.iter(|| schedule.run(app.world_mut()));
143143
});
144144
group.finish();
145145
}

examples/2d/mesh2d_manual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pub const COLORED_MESH2D_SHADER_HANDLE: Handle<Shader> =
285285
impl Plugin for ColoredMesh2dPlugin {
286286
fn build(&self, app: &mut App) {
287287
// Load our custom shader
288-
let mut shaders = app.world.resource_mut::<Assets<Shader>>();
288+
let mut shaders = app.world_mut().resource_mut::<Assets<Shader>>();
289289
shaders.insert(
290290
&COLORED_MESH2D_SHADER_HANDLE,
291291
Shader::from_wgsl(COLORED_MESH2D_SHADER, file!()),

examples/app/custom_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn my_runner(mut app: App) {
1111
println!("Type stuff into the console");
1212
for line in io::stdin().lines() {
1313
{
14-
let mut input = app.world.resource_mut::<Input>();
14+
let mut input = app.world_mut().resource_mut::<Input>();
1515
input.0 = line.unwrap();
1616
}
1717
app.update();

examples/ecs/custom_schedule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ fn main() {
3333
//
3434
// Note that we modify `MainScheduleOrder` directly in `main` and not in a startup system. The reason for this is
3535
// that the `MainScheduleOrder` cannot be modified from systems that are run as part of the `Main` schedule.
36-
let mut main_schedule_order = app.world.resource_mut::<MainScheduleOrder>();
36+
let mut main_schedule_order = app.world_mut().resource_mut::<MainScheduleOrder>();
3737
main_schedule_order.insert_after(Update, SingleThreadedUpdate);
3838

3939
// Adding a custom startup schedule works similarly, but needs to use `insert_startup_after`
4040
// instead of `insert_after`.
4141
app.add_schedule(Schedule::new(CustomStartup));
4242

43-
let mut main_schedule_order = app.world.resource_mut::<MainScheduleOrder>();
43+
let mut main_schedule_order = app.world_mut().resource_mut::<MainScheduleOrder>();
4444
main_schedule_order.insert_startup_after(PreStartup, CustomStartup);
4545

4646
app.add_systems(SingleThreadedUpdate, single_threaded_update_system)

examples/ecs/system_stepping.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn main() {
5454
* Stepping::continue_frame() is called
5555
* System has been configured to always run"#
5656
);
57-
let mut stepping = app.world.resource_mut::<Stepping>();
57+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
5858
stepping.add_schedule(Update).enable();
5959
app.update();
6060

@@ -65,7 +65,7 @@ fn main() {
6565
Stepping, step means run the next system across all the schedules
6666
that have been added to the Stepping resource."#
6767
);
68-
let mut stepping = app.world.resource_mut::<Stepping>();
68+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
6969
stepping.step_frame();
7070
app.update();
7171

@@ -89,7 +89,7 @@ fn main() {
8989
case, we previously performed a step, running one system in Update.
9090
This continue will cause all remaining systems in Update to run."#
9191
);
92-
let mut stepping = app.world.resource_mut::<Stepping>();
92+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
9393
stepping.continue_frame();
9494
app.update();
9595

@@ -102,7 +102,7 @@ fn main() {
102102
systems."#
103103
);
104104
for _ in 0..4 {
105-
let mut stepping = app.world.resource_mut::<Stepping>();
105+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
106106
stepping.step_frame();
107107
app.update();
108108
}
@@ -116,10 +116,10 @@ fn main() {
116116
execute all systems in the frame. Stepping::always_run() allows
117117
us to granularly allow systems to run when stepping is enabled."#
118118
);
119-
let mut stepping = app.world.resource_mut::<Stepping>();
119+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
120120
stepping.always_run(Update, update_system_two);
121121
for _ in 0..3 {
122-
let mut stepping = app.world.resource_mut::<Stepping>();
122+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
123123
stepping.step_frame();
124124
app.update();
125125
}
@@ -132,7 +132,7 @@ fn main() {
132132
Stepping::never_run() allows us to disable systems while Stepping
133133
is enabled."#
134134
);
135-
let mut stepping = app.world.resource_mut::<Stepping>();
135+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
136136
stepping.never_run(Update, update_system_two);
137137
stepping.continue_frame();
138138
app.update();
@@ -155,14 +155,14 @@ fn main() {
155155
During the final continue pre_update_system() and
156156
update_system_three() run."#
157157
);
158-
let mut stepping = app.world.resource_mut::<Stepping>();
158+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
159159
stepping.set_breakpoint(Update, update_system_two);
160160
stepping.continue_frame();
161161
app.update();
162-
let mut stepping = app.world.resource_mut::<Stepping>();
162+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
163163
stepping.step_frame();
164164
app.update();
165-
let mut stepping = app.world.resource_mut::<Stepping>();
165+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
166166
stepping.continue_frame();
167167
app.update();
168168

@@ -172,7 +172,7 @@ fn main() {
172172
through all systems
173173
Result: All systems will run"#
174174
);
175-
let mut stepping = app.world.resource_mut::<Stepping>();
175+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
176176
stepping.clear_breakpoint(Update, update_system_two);
177177
stepping.continue_frame();
178178
app.update();
@@ -184,7 +184,7 @@ fn main() {
184184
call Stepping::step_frame() or Stepping::continue_frame() to run
185185
systems in the Update schedule."#
186186
);
187-
let mut stepping = app.world.resource_mut::<Stepping>();
187+
let mut stepping = app.world_mut().resource_mut::<Stepping>();
188188
stepping.disable();
189189
app.update();
190190
}

examples/games/stepping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Plugin for SteppingPlugin {
3636
// We need an independent schedule so we have access to all other
3737
// schedules through the `Stepping` resource
3838
app.init_schedule(DebugSchedule);
39-
let mut order = app.world.resource_mut::<MainScheduleOrder>();
39+
let mut order = app.world_mut().resource_mut::<MainScheduleOrder>();
4040
order.insert_after(Update, DebugSchedule);
4141

4242
// create our stepping resource

examples/shader/compute_shader_game_of_life.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Plugin for GameOfLifeComputePlugin {
8484
prepare_bind_group.in_set(RenderSet::PrepareBindGroups),
8585
);
8686

87-
let mut render_graph = render_app.world.resource_mut::<RenderGraph>();
87+
let mut render_graph = render_app.world_mut().resource_mut::<RenderGraph>();
8888
render_graph.add_node(GameOfLifeLabel, GameOfLifeNode::default());
8989
render_graph.add_node_edge(GameOfLifeLabel, bevy::render::graph::CameraDriverLabel);
9090
}

examples/shader/post_processing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Plugin for PostProcessPlugin {
5959
));
6060

6161
// We need to get the render app from the main app
62-
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
62+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
6363
return;
6464
};
6565

@@ -97,7 +97,7 @@ impl Plugin for PostProcessPlugin {
9797

9898
fn finish(&self, app: &mut App) {
9999
// We need to get the render app from the main app
100-
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
100+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
101101
return;
102102
};
103103

examples/shader/texture_binding_array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ impl Plugin for GpuFeatureSupportChecker {
3333
fn build(&self, _app: &mut App) {}
3434

3535
fn finish(&self, app: &mut App) {
36-
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
36+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
3737
return;
3838
};
3939

40-
let render_device = render_app.world.resource::<RenderDevice>();
40+
let render_device = render_app.world().resource::<RenderDevice>();
4141

4242
// Check if the device support the required feature. If not, exit the example.
4343
// In a real application, you should setup a fallback for the missing feature

examples/stress_tests/many_lights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct LogVisibleLights;
157157

158158
impl Plugin for LogVisibleLights {
159159
fn build(&self, app: &mut App) {
160-
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
160+
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
161161
return;
162162
};
163163

examples/time/time.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ fn runner(mut app: App) {
4545
}
4646
"f" => {
4747
println!("FAST: setting relative speed to 2x");
48-
app.world
48+
app.world_mut()
4949
.resource_mut::<Time<Virtual>>()
5050
.set_relative_speed(2.0);
5151
}
5252
"n" => {
5353
println!("NORMAL: setting relative speed to 1x");
54-
app.world
54+
app.world_mut()
5555
.resource_mut::<Time<Virtual>>()
5656
.set_relative_speed(1.0);
5757
}
5858
"s" => {
5959
println!("SLOW: setting relative speed to 0.5x");
60-
app.world
60+
app.world_mut()
6161
.resource_mut::<Time<Virtual>>()
6262
.set_relative_speed(0.5);
6363
}
6464
"p" => {
6565
println!("PAUSE: pausing virtual clock");
66-
app.world.resource_mut::<Time<Virtual>>().pause();
66+
app.world_mut().resource_mut::<Time<Virtual>>().pause();
6767
}
6868
"u" => {
6969
println!("UNPAUSE: resuming virtual clock");
70-
app.world.resource_mut::<Time<Virtual>>().unpause();
70+
app.world_mut().resource_mut::<Time<Virtual>>().unpause();
7171
}
7272
"q" => {
7373
println!("QUITTING!");

tests/how_to_test_systems.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn did_hurt_enemy() {
6262

6363
// Setup test entities
6464
let enemy_id = app
65-
.world
65+
.world_mut()
6666
.spawn(Enemy {
6767
hit_points: 5,
6868
score_value: 3,
@@ -73,8 +73,8 @@ fn did_hurt_enemy() {
7373
app.update();
7474

7575
// Check resulting changes
76-
assert!(app.world.get::<Enemy>(enemy_id).is_some());
77-
assert_eq!(app.world.get::<Enemy>(enemy_id).unwrap().hit_points, 4);
76+
assert!(app.world().get::<Enemy>(enemy_id).is_some());
77+
assert_eq!(app.world().get::<Enemy>(enemy_id).unwrap().hit_points, 4);
7878
}
7979

8080
#[test]
@@ -93,7 +93,7 @@ fn did_despawn_enemy() {
9393

9494
// Setup test entities
9595
let enemy_id = app
96-
.world
96+
.world_mut()
9797
.spawn(Enemy {
9898
hit_points: 1,
9999
score_value: 1,
@@ -104,10 +104,10 @@ fn did_despawn_enemy() {
104104
app.update();
105105

106106
// Check enemy was despawned
107-
assert!(app.world.get::<Enemy>(enemy_id).is_none());
107+
assert!(app.world().get::<Enemy>(enemy_id).is_none());
108108

109109
// Get `EnemyDied` event reader
110-
let enemy_died_events = app.world.resource::<Events<EnemyDied>>();
110+
let enemy_died_events = app.world().resource::<Events<EnemyDied>>();
111111
let mut enemy_died_reader = enemy_died_events.get_reader();
112112
let enemy_died = enemy_died_reader.read(enemy_died_events).next().unwrap();
113113

@@ -132,16 +132,18 @@ fn spawn_enemy_using_input_resource() {
132132
app.update();
133133

134134
// Check resulting changes, one entity has been spawned with `Enemy` component
135-
assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1);
135+
assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1);
136136

137137
// Clear the `just_pressed` status for all `KeyCode`s
138-
app.world.resource_mut::<ButtonInput<KeyCode>>().clear();
138+
app.world_mut()
139+
.resource_mut::<ButtonInput<KeyCode>>()
140+
.clear();
139141

140142
// Run systems
141143
app.update();
142144

143145
// Check resulting changes, no new entity has been spawned
144-
assert_eq!(app.world.query::<&Enemy>().iter(&app.world).len(), 1);
146+
assert_eq!(app.world_mut().query::<&Enemy>().iter(app.world()).len(), 1);
145147
}
146148

147149
#[test]
@@ -159,13 +161,13 @@ fn update_score_on_event() {
159161
app.add_systems(Update, update_score);
160162

161163
// Send an `EnemyDied` event
162-
app.world
164+
app.world_mut()
163165
.resource_mut::<Events<EnemyDied>>()
164166
.send(EnemyDied(3));
165167

166168
// Run systems
167169
app.update();
168170

169171
// Check resulting changes
170-
assert_eq!(app.world.resource::<Score>().0, 3);
172+
assert_eq!(app.world().resource::<Score>().0, 3);
171173
}

0 commit comments

Comments
 (0)