Skip to content

Commit

Permalink
Fix last_changed() and set_last_changed() for MutUntyped (bevye…
Browse files Browse the repository at this point in the history
…ngine#7619)

# Objective

Continuation of bevyengine#7560.

`MutUntyped::last_changed` and `set_last_changed` do not behave as described in their docs.

## Solution

Fix them using the same approach that was used for `Mut<>` in bevyengine#7560.
  • Loading branch information
JoJoJet authored and myreprise1 committed Feb 15, 2023
1 parent 6acf2c2 commit c053c42
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ macro_rules! change_detection_mut_impl {
}

#[inline]
fn set_last_changed(&mut self, last_change_tick: u32) {
fn set_last_changed(&mut self, last_changed: u32) {
self.ticks
.changed
.set_changed(last_change_tick);
.set_changed(last_changed);
}

#[inline]
Expand Down Expand Up @@ -242,9 +242,6 @@ macro_rules! impl_methods {
/// This is useful if you have `&mut
#[doc = stringify!($name)]
/// <T>`, but you need a `Mut<T>`.
///
/// Note that calling [`DetectChangesMut::set_last_changed`] on the returned value
/// will not affect the original.
pub fn reborrow(&mut self) -> Mut<'_, $target> {
Mut {
value: self.value,
Expand Down Expand Up @@ -607,9 +604,6 @@ impl<'a> MutUntyped<'a> {

/// Returns a [`MutUntyped`] with a smaller lifetime.
/// This is useful if you have `&mut MutUntyped`, but you need a `MutUntyped`.
///
/// Note that calling [`DetectChangesMut::set_last_changed`] on the returned value
/// will not affect the original.
#[inline]
pub fn reborrow(&mut self) -> MutUntyped {
MutUntyped {
Expand Down Expand Up @@ -667,7 +661,7 @@ impl<'a> DetectChanges for MutUntyped<'a> {

#[inline]
fn last_changed(&self) -> u32 {
self.ticks.last_change_tick
self.ticks.changed.tick
}
}

Expand All @@ -680,8 +674,8 @@ impl<'a> DetectChangesMut for MutUntyped<'a> {
}

#[inline]
fn set_last_changed(&mut self, last_change_tick: u32) {
self.ticks.last_change_tick = last_change_tick;
fn set_last_changed(&mut self, last_changed: u32) {
self.ticks.changed.set_changed(last_changed);
}

#[inline]
Expand Down

0 comments on commit c053c42

Please sign in to comment.