Skip to content

Commit deb90e5

Browse files
add {read,last,increment}_change_tick to interiormutableworld
1 parent f157113 commit deb90e5

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

crates/bevy_ecs/src/world/interior_mutable_world.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ impl<'w> InteriorMutableWorld<'w> {
119119
&self.0.bundles
120120
}
121121

122+
/// Reads the current change tick of this world.
123+
#[inline]
124+
pub fn read_change_tick(&self) -> u32 {
125+
self.0.read_change_tick()
126+
}
127+
128+
#[inline]
129+
pub fn last_change_tick(&self) -> u32 {
130+
self.0.last_change_tick()
131+
}
132+
133+
#[inline]
134+
pub fn increment_change_tick(&self) -> u32 {
135+
self.0.increment_change_tick()
136+
}
137+
122138
/// Retrieves an [`InteriorMutableEntityRef`] that exposes read and write operations for the given `entity`.
123139
/// Similar to the [`InteriorMutableWorld`], you are in charge of making sure that no aliasing rules are violated.
124140
pub fn get_entity(&self, entity: Entity) -> Option<InteriorMutableEntityRef<'w>> {
@@ -206,7 +222,7 @@ impl<'w> InteriorMutableWorld<'w> {
206222
// - index is in-bounds because the column is initialized and non-empty
207223
// - the caller promises that no other reference to the ticks of the same row can exist at the same time
208224
let ticks = unsafe {
209-
TicksMut::from_tick_cells(ticks, self.0.last_change_tick(), self.0.read_change_tick())
225+
TicksMut::from_tick_cells(ticks, self.last_change_tick(), self.read_change_tick())
210226
};
211227

212228
Some(MutUntyped {
@@ -250,7 +266,7 @@ impl<'w> InteriorMutableWorld<'w> {
250266
// - This caller ensures that nothing aliases `ticks`.
251267
// - index is in-bounds because the column is initialized and non-empty
252268
let ticks = unsafe {
253-
TicksMut::from_tick_cells(ticks, self.0.last_change_tick(), self.0.read_change_tick())
269+
TicksMut::from_tick_cells(ticks, self.last_change_tick(), self.read_change_tick())
254270
};
255271

256272
Some(Mut {
@@ -283,11 +299,7 @@ impl<'w> InteriorMutableWorld<'w> {
283299
value: unsafe { ptr.assert_unique().deref_mut() },
284300
// SAFETY: caller ensures unique access
285301
ticks: unsafe {
286-
TicksMut::from_tick_cells(
287-
ticks,
288-
self.0.last_change_tick(),
289-
self.0.read_change_tick(),
290-
)
302+
TicksMut::from_tick_cells(ticks, self.last_change_tick(), self.read_change_tick())
291303
},
292304
})
293305
}
@@ -393,10 +405,7 @@ impl<'w> InteriorMutableEntityRef<'w> {
393405
pub unsafe fn get_mut<T: Component>(&self) -> Option<Mut<'w, T>> {
394406
// SAFETY: same safety requirements
395407
unsafe {
396-
self.get_mut_using_ticks(
397-
self.world.0.last_change_tick(),
398-
self.world.0.read_change_tick(),
399-
)
408+
self.get_mut_using_ticks(self.world.last_change_tick(), self.world.read_change_tick())
400409
}
401410
}
402411

@@ -487,8 +496,8 @@ impl<'w> InteriorMutableEntityRef<'w> {
487496
value: value.assert_unique(),
488497
ticks: TicksMut::from_tick_cells(
489498
cells,
490-
self.world.0.last_change_tick,
491-
self.world.0.read_change_tick(),
499+
self.world.last_change_tick(),
500+
self.world.read_change_tick(),
492501
),
493502
})
494503
}

0 commit comments

Comments
 (0)