From 8c81e816764e60df5b6f304709259433b734f35c Mon Sep 17 00:00:00 2001 From: Daniel Bearden Date: Sat, 8 Jan 2022 22:36:33 +0000 Subject: [PATCH] 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. --- examples/ecs/ecs_guide.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/ecs/ecs_guide.rs b/examples/ecs/ecs_guide.rs index 7d905ec29bcfc..dd19552684e51 100644 --- a/examples/ecs/ecs_guide.rs +++ b/examples/ecs/ecs_guide.rs @@ -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::().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