@@ -141,18 +141,16 @@ fn game_over_system(
141
141
// the initial "state" of our game. The only thing that distinguishes a "startup" system from a "normal" system is how it is registered:
142
142
// Startup: app.add_startup_system(startup_system)
143
143
// 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 > ) {
147
145
// Create our game rules resource
148
- resources . insert ( GameRules {
146
+ commands . insert_resource ( GameRules {
149
147
max_rounds : 10 ,
150
148
winning_score : 4 ,
151
149
max_players : 4 ,
152
150
} ) ;
153
151
154
152
// 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 ! [
156
154
(
157
155
Player {
158
156
name: "Alice" . to_string( ) ,
@@ -168,7 +166,6 @@ fn startup_system(world: &mut World, resources: &mut Resources) {
168
166
] ) ;
169
167
170
168
// set the total players to "2"
171
- let mut game_state = resources. get_mut :: < GameState > ( ) . unwrap ( ) ;
172
169
game_state. total_players = 2 ;
173
170
}
174
171
@@ -201,8 +198,6 @@ fn new_player_system(
201
198
// These run on the main app thread (hence the name "thread local")
202
199
// WARNING: These will block all parallel execution of other systems until they finish, so they should generally be avoided if you
203
200
// 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!
206
201
#[ allow( dead_code) ]
207
202
fn thread_local_system ( world : & mut World , resources : & mut Resources ) {
208
203
// this does the same thing as "new_player_system"
@@ -259,7 +254,7 @@ fn main() {
259
254
. init_resource :: < GameState > ( )
260
255
// Startup systems run exactly once BEFORE all other systems. These are generally used for
261
256
// app initialization code (ex: adding entities and resources)
262
- . add_startup_system ( startup_system. thread_local_system ( ) )
257
+ . add_startup_system ( startup_system. system ( ) )
263
258
// my_system.system() calls converts normal rust functions into ECS systems:
264
259
. add_system ( print_message_system. system ( ) )
265
260
//
0 commit comments