mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
Add last_changed_tick and added_tick to ComponentTicks (#8803)
# Objective EntityRef::get_change_ticks mentions that ComponentTicks is useful to create change detection for your own runtime. However, ComponentTicks doesn't even expose enough data to create something that implements DetectChanges. Specifically, we need to be able to extract the last change tick. ## Solution We add a method to get the last change tick. We also add a method to get the added tick. ## Changelog - Add `last_changed_tick` and `added_tick` to `ComponentTicks`
This commit is contained in:
parent
f135535cd6
commit
f07bb3c449
1 changed files with 14 additions and 2 deletions
|
@ -744,18 +744,30 @@ pub struct ComponentTicks {
|
|||
}
|
||||
|
||||
impl ComponentTicks {
|
||||
#[inline]
|
||||
/// Returns `true` if the component was added after the system last ran.
|
||||
#[inline]
|
||||
pub fn is_added(&self, last_run: Tick, this_run: Tick) -> bool {
|
||||
self.added.is_newer_than(last_run, this_run)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns `true` if the component was added or mutably dereferenced after the system last ran.
|
||||
#[inline]
|
||||
pub fn is_changed(&self, last_run: Tick, this_run: Tick) -> bool {
|
||||
self.changed.is_newer_than(last_run, this_run)
|
||||
}
|
||||
|
||||
/// Returns the tick recording the time this component was most recently changed.
|
||||
#[inline]
|
||||
pub fn last_changed_tick(&self) -> Tick {
|
||||
self.changed
|
||||
}
|
||||
|
||||
/// Returns the tick recording the time this component was added.
|
||||
#[inline]
|
||||
pub fn added_tick(&self) -> Tick {
|
||||
self.added
|
||||
}
|
||||
|
||||
pub(crate) fn new(change_tick: Tick) -> Self {
|
||||
Self {
|
||||
added: change_tick,
|
||||
|
|
Loading…
Add table
Reference in a new issue