Skip to content

Commit

Permalink
Thread local example cleanup (#3586)
Browse files Browse the repository at this point in the history
# Objective

Fixes #1917

## Solution

- Change use of "thread local system" wording to "exclusive system".
- Add .exclusive_system() call to example.
  • Loading branch information
dbearden committed Jan 8, 2022
1 parent 4b4dbb0 commit 8c81e81
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions examples/ecs/ecs_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ fn new_player_system(
}
}

// If you really need full, immediate read/write access to the world or resources, you can use a
// "thread local system". These run on the main app thread (hence the name "thread local")
// If you really need full, immediate read/write access to the world or resources, you can use an
// "exclusive system".
// WARNING: These will block all parallel execution of other systems until they finish, so they
// should generally be avoided if you care about performance
// should generally be avoided if you care about performance.
#[allow(dead_code)]
fn thread_local_system(world: &mut World) {
fn exclusive_player_system(world: &mut World) {
// this does the same thing as "new_player_system"
let total_players = world.get_resource_mut::<GameState>().unwrap().total_players;
let should_add_player = {
Expand Down Expand Up @@ -329,6 +329,14 @@ fn main() {
)
.add_system_to_stage(MyStage::BeforeRound, new_round_system)
.add_system_to_stage(MyStage::BeforeRound, new_player_system)
.add_system_to_stage(
MyStage::BeforeRound,
exclusive_player_system.exclusive_system(),
)
// Systems which take `&mut World` as an argument must call `.exclusive_system()`.
// The following will not compile.
//.add_system_to_stage(MyStage::BeforeRound, exclusive_player_system)
//
// We can ensure that game_over system runs after score_check_system using explicit ordering
// constraints First, we label the system we want to refer to using `.label`
// Then, we use either `.before` or `.after` to describe the order we want the relationship
Expand Down

0 comments on commit 8c81e81

Please sign in to comment.