Skip to content

Commit 5cd67f7

Browse files
authored
Change the ecs_guide example so it doesn't make it seem like startup systems have to be thread local (#759)
1 parent 9cc6368 commit 5cd67f7

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

examples/ecs/ecs_guide.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,16 @@ fn game_over_system(
141141
// the initial "state" of our game. The only thing that distinguishes a "startup" system from a "normal" system is how it is registered:
142142
// Startup: app.add_startup_system(startup_system)
143143
// Normal: app.add_system(normal_system)
144-
// This startup system needs direct access to the ECS World and Resources, which makes it a "thread local system".
145-
// That being said, startup systems can use any of the system forms we've covered. We will also cover thread local systems more in a bit.
146-
fn startup_system(world: &mut World, resources: &mut Resources) {
144+
fn startup_system(mut commands: Commands, mut game_state: ResMut<GameState>) {
147145
// Create our game rules resource
148-
resources.insert(GameRules {
146+
commands.insert_resource(GameRules {
149147
max_rounds: 10,
150148
winning_score: 4,
151149
max_players: 4,
152150
});
153151

154152
// Add some players to our world. Players start with a score of 0 ... we want our game to be fair!
155-
world.spawn_batch(vec![
153+
commands.spawn_batch(vec![
156154
(
157155
Player {
158156
name: "Alice".to_string(),
@@ -168,7 +166,6 @@ fn startup_system(world: &mut World, resources: &mut Resources) {
168166
]);
169167

170168
// set the total players to "2"
171-
let mut game_state = resources.get_mut::<GameState>().unwrap();
172169
game_state.total_players = 2;
173170
}
174171

@@ -201,8 +198,6 @@ fn new_player_system(
201198
// These run on the main app thread (hence the name "thread local")
202199
// WARNING: These will block all parallel execution of other systems until they finish, so they should generally be avoided if you
203200
// care about performance
204-
// NOTE: You may notice that this function signature looks exactly like the "startup_system" above.
205-
// Thats because they are both thread local!
206201
#[allow(dead_code)]
207202
fn thread_local_system(world: &mut World, resources: &mut Resources) {
208203
// this does the same thing as "new_player_system"
@@ -259,7 +254,7 @@ fn main() {
259254
.init_resource::<GameState>()
260255
// Startup systems run exactly once BEFORE all other systems. These are generally used for
261256
// app initialization code (ex: adding entities and resources)
262-
.add_startup_system(startup_system.thread_local_system())
257+
.add_startup_system(startup_system.system())
263258
// my_system.system() calls converts normal rust functions into ECS systems:
264259
.add_system(print_message_system.system())
265260
//

0 commit comments

Comments
 (0)