mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Thread local example cleanup (#3586)
# Objective Fixes #1917 ## Solution - Change use of "thread local system" wording to "exclusive system". - Add .exclusive_system() call to example.
This commit is contained in:
parent
4b4dbb021f
commit
8c81e81676
1 changed files with 12 additions and 4 deletions
|
@ -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 = {
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue