Rewrite part of Commands rustdoc (#11141)

- Explain it is flushed in the same schedule run (was not obvious to me)
- Point to `apply_deferred` example
- Remove mentions of `System::apply_deferred` and
`Schedule::apply_deferred` which are probably too low level for the most
users

Co-authored-by: James Liu <contact@jamessliu.com>
This commit is contained in:
Stepan Koltsov 2024-03-05 09:52:48 +00:00 committed by GitHub
parent ee2fdc094c
commit 70b70cd323
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 9 deletions

View File

@ -93,9 +93,20 @@ impl SystemSchedule {
} }
/// Instructs the executor to call [`System::apply_deferred`](crate::system::System::apply_deferred) /// Instructs the executor to call [`System::apply_deferred`](crate::system::System::apply_deferred)
/// on the systems that have run but not applied their [`Deferred`](crate::system::Deferred) system parameters (like [`Commands`](crate::prelude::Commands)) or other system buffers. /// on the systems that have run but not applied their [`Deferred`](crate::system::Deferred) system parameters
/// (like [`Commands`](crate::prelude::Commands)) or other system buffers.
/// ///
/// **Notes** /// ## Scheduling
///
/// `apply_deferred` systems are scheduled *by default*
/// - later in the same schedule run (for example, if a system with `Commands` param
/// is scheduled in `Update`, all the changes will be visible in `PostUpdate`)
/// - between systems with dependencies if the dependency
/// [has deferred buffers](crate::system::System::has_deferred)
/// (if system `bar` directly or indirectly depends on `foo`, and `foo` uses `Commands` param,
/// changes to the world in `foo` will be visible in `bar`)
///
/// ## Notes
/// - This function (currently) does nothing if it's called manually or wrapped inside a [`PipeSystem`](crate::system::PipeSystem). /// - This function (currently) does nothing if it's called manually or wrapped inside a [`PipeSystem`](crate::system::PipeSystem).
/// - Modifying a [`Schedule`](super::Schedule) may change the order buffers are applied. /// - Modifying a [`Schedule`](super::Schedule) may change the order buffers are applied.
#[doc(alias = "apply_system_buffers")] #[doc(alias = "apply_system_buffers")]

View File

@ -17,11 +17,7 @@ use std::marker::PhantomData;
/// ///
/// Since each command requires exclusive access to the `World`, /// Since each command requires exclusive access to the `World`,
/// all queued commands are automatically applied in sequence /// all queued commands are automatically applied in sequence
/// when the [`apply_deferred`] system runs. /// when the `apply_deferred` system runs (see [`apply_deferred`] documentation for more details).
///
/// The command queue of an individual system can also be manually applied
/// by calling [`System::apply_deferred`].
/// Similarly, the command queue of a schedule can be manually applied via [`Schedule::apply_deferred`].
/// ///
/// Each command can be used to modify the [`World`] in arbitrary ways: /// Each command can be used to modify the [`World`] in arbitrary ways:
/// * spawning or despawning entities /// * spawning or despawning entities
@ -67,9 +63,7 @@ use std::marker::PhantomData;
/// # } /// # }
/// ``` /// ```
/// ///
/// [`System::apply_deferred`]: crate::system::System::apply_deferred
/// [`apply_deferred`]: crate::schedule::apply_deferred /// [`apply_deferred`]: crate::schedule::apply_deferred
/// [`Schedule::apply_deferred`]: crate::schedule::Schedule::apply_deferred
#[derive(SystemParam)] #[derive(SystemParam)]
pub struct Commands<'w, 's> { pub struct Commands<'w, 's> {
queue: Deferred<'s, CommandQueue>, queue: Deferred<'s, CommandQueue>,