Fix doc for Added, Changed (#13458)

# Objective

Fixes #13426

## Solution

Correct documentation to describe current behavior

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
SpecificProtagonist 2024-05-21 23:23:24 +02:00 committed by GitHub
parent 151e198d94
commit 6c95d54652
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -765,6 +765,8 @@ impl Components {
/// A value that tracks when a system ran relative to other systems. /// A value that tracks when a system ran relative to other systems.
/// This is used to power change detection. /// This is used to power change detection.
///
/// *Note* that a system that hasn't been run yet has a `Tick` of 0.
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Default, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))] #[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub struct Tick { pub struct Tick {
@ -869,13 +871,15 @@ pub struct ComponentTicks {
} }
impl ComponentTicks { impl ComponentTicks {
/// Returns `true` if the component or resource was added after the system last ran. /// Returns `true` if the component or resource was added after the system last ran
/// (or the system is running for the first time).
#[inline] #[inline]
pub fn is_added(&self, last_run: Tick, this_run: Tick) -> bool { pub fn is_added(&self, last_run: Tick, this_run: Tick) -> bool {
self.added.is_newer_than(last_run, this_run) self.added.is_newer_than(last_run, this_run)
} }
/// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran. /// Returns `true` if the component or resource was added or mutably dereferenced after the system last ran
/// (or the system is running for the first time).
#[inline] #[inline]
pub fn is_changed(&self, last_run: Tick, this_run: Tick) -> bool { pub fn is_changed(&self, last_run: Tick, this_run: Tick) -> bool {
self.changed.is_newer_than(last_run, this_run) self.changed.is_newer_than(last_run, this_run)

View File

@ -514,13 +514,15 @@ macro_rules! impl_tuple_query_filter {
all_tuples!(impl_tuple_query_filter, 0, 15, F); all_tuples!(impl_tuple_query_filter, 0, 15, F);
all_tuples!(impl_or_query_filter, 0, 15, F, S); all_tuples!(impl_or_query_filter, 0, 15, F, S);
/// A filter on a component that only retains results added after the system last ran. /// A filter on a component that only retains results the first time after they have been added.
/// ///
/// A common use for this filter is one-time initialization. /// A common use for this filter is one-time initialization.
/// ///
/// To retain all results without filtering but still check whether they were added after the /// To retain all results without filtering but still check whether they were added after the
/// system last ran, use [`Ref<T>`](crate::change_detection::Ref). /// system last ran, use [`Ref<T>`](crate::change_detection::Ref).
/// ///
/// **Note** that this includes changes that happened before the first time this `Query` was run.
///
/// # Deferred /// # Deferred
/// ///
/// Note, that entity modifications issued with [`Commands`](crate::system::Commands) /// Note, that entity modifications issued with [`Commands`](crate::system::Commands)
@ -716,7 +718,7 @@ impl<T: Component> QueryFilter for Added<T> {
} }
} }
/// A filter on a component that only retains results added or mutably dereferenced after the system last ran. /// A filter on a component that only retains results the first time after they have been added or mutably dereferenced.
/// ///
/// A common use for this filter is avoiding redundant work when values have not changed. /// A common use for this filter is avoiding redundant work when values have not changed.
/// ///
@ -726,6 +728,8 @@ impl<T: Component> QueryFilter for Added<T> {
/// To retain all results without filtering but still check whether they were changed after the /// To retain all results without filtering but still check whether they were changed after the
/// system last ran, use [`Ref<T>`](crate::change_detection::Ref). /// system last ran, use [`Ref<T>`](crate::change_detection::Ref).
/// ///
/// **Note** that this includes changes that happened before the first time this `Query` was run.
///
/// # Deferred /// # Deferred
/// ///
/// Note, that entity modifications issued with [`Commands`](crate::system::Commands) /// Note, that entity modifications issued with [`Commands`](crate::system::Commands)