From a832582c002c0f51dc5e7a5e0b7c73495df505d2 Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Sun, 25 Dec 2022 00:18:25 +0000 Subject: [PATCH] Add a basic example for system ordering (#7017) # Objective Fix #5653. ## Solution - Add an example of how systems can be ordered from within a stage. - Update some docs from before #4224 --- crates/bevy_ecs/src/system/mod.rs | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 0dcc806c6d44ab..be66144b4a6a8a 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -41,9 +41,35 @@ //! //! - **System Stages:** They determine hard execution synchronization boundaries inside of //! which systems run in parallel by default. -//! - **Labeling:** First, systems are labeled upon creation by calling `.label()`. Then, -//! methods such as `.before()` and `.after()` are appended to systems to determine -//! execution order in respect to other systems. +//! - **Labels:** Systems may be ordered within a stage using the methods `.before()` and `.after()`, +//! which order systems based on their [`SystemLabel`]s. Each system is implicitly labeled with +//! its `fn` type, and custom labels may be added by calling `.label()`. +//! +//! [`SystemLabel`]: crate::schedule::SystemLabel +//! +//! ## Example +//! +//! ``` +//! # use bevy_ecs::prelude::*; +//! # let mut app = SystemStage::single_threaded(); +//! // Prints "Hello, World!" each frame. +//! app +//! .add_system(print_first.before(print_mid)) +//! .add_system(print_mid) +//! .add_system(print_last.after(print_mid)); +//! # let mut world = World::new(); +//! # app.run(&mut world); +//! +//! fn print_first() { +//! print!("Hello"); +//! } +//! fn print_mid() { +//! print!(", "); +//! } +//! fn print_last() { +//! println!("World!"); +//! } +//! ``` //! //! # System parameter list //! Following is the complete list of accepted types as system parameters: