Replace World::read_change_ticks with World::change_ticks within bevy_ecs crate (#6816)
# Objective - Fixes #6812. ## Solution - Replaced `World::read_change_ticks` with `World::change_ticks` within `bevy_ecs` crate in places where `World` references were mutable. ---
This commit is contained in:
parent
17480b2d89
commit
eff632dac8
@ -276,15 +276,9 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
entity: Entity,
|
entity: Entity,
|
||||||
) -> Result<Q::Item<'w>, QueryEntityError> {
|
) -> Result<Q::Item<'w>, QueryEntityError> {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe { self.get_unchecked_manual(world, entity, world.last_change_tick(), change_tick) }
|
||||||
self.get_unchecked_manual(
|
|
||||||
world,
|
|
||||||
entity,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the query results for the given array of [`Entity`].
|
/// Returns the query results for the given array of [`Entity`].
|
||||||
@ -333,15 +327,11 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
) -> Result<[Q::Item<'w>; N], QueryEntityError> {
|
) -> Result<[Q::Item<'w>; N], QueryEntityError> {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
|
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: method requires exclusive world access
|
// SAFETY: method requires exclusive world access
|
||||||
// and world has been validated via update_archetypes
|
// and world has been validated via update_archetypes
|
||||||
unsafe {
|
unsafe {
|
||||||
self.get_many_unchecked_manual(
|
self.get_many_unchecked_manual(world, entities, world.last_change_tick(), change_tick)
|
||||||
world,
|
|
||||||
entities,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,10 +515,11 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
/// Returns an [`Iterator`] over the query results for the given [`World`].
|
/// Returns an [`Iterator`] over the query results for the given [`World`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter_mut<'w, 's>(&'s mut self, world: &'w mut World) -> QueryIter<'w, 's, Q, F> {
|
pub fn iter_mut<'w, 's>(&'s mut self, world: &'w mut World) -> QueryIter<'w, 's, Q, F> {
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
self.iter_unchecked_manual(world, world.last_change_tick(), world.read_change_tick())
|
self.iter_unchecked_manual(world, world.last_change_tick(), change_tick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,14 +602,11 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
&'s mut self,
|
&'s mut self,
|
||||||
world: &'w mut World,
|
world: &'w mut World,
|
||||||
) -> QueryCombinationIter<'w, 's, Q, F, K> {
|
) -> QueryCombinationIter<'w, 's, Q, F, K> {
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
self.iter_combinations_unchecked_manual(
|
self.iter_combinations_unchecked_manual(world, world.last_change_tick(), change_tick)
|
||||||
world,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,14 +653,10 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
EntityList::Item: Borrow<Entity>,
|
EntityList::Item: Borrow<Entity>,
|
||||||
{
|
{
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: Query has unique world access.
|
// SAFETY: Query has unique world access.
|
||||||
unsafe {
|
unsafe {
|
||||||
self.iter_many_unchecked_manual(
|
self.iter_many_unchecked_manual(entities, world, world.last_change_tick(), change_tick)
|
||||||
entities,
|
|
||||||
world,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,15 +781,11 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
/// `iter_mut()` method, but cannot be chained like a normal [`Iterator`].
|
/// `iter_mut()` method, but cannot be chained like a normal [`Iterator`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn for_each_mut<'w, FN: FnMut(Q::Item<'w>)>(&mut self, world: &'w mut World, func: FN) {
|
pub fn for_each_mut<'w, FN: FnMut(Q::Item<'w>)>(&mut self, world: &'w mut World, func: FN) {
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
self.for_each_unchecked_manual(
|
self.for_each_unchecked_manual(world, func, world.last_change_tick(), change_tick);
|
||||||
world,
|
|
||||||
func,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,6 +853,7 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
batch_size: usize,
|
batch_size: usize,
|
||||||
func: FN,
|
func: FN,
|
||||||
) {
|
) {
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
@ -881,7 +862,7 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
batch_size,
|
batch_size,
|
||||||
func,
|
func,
|
||||||
world.last_change_tick(),
|
world.last_change_tick(),
|
||||||
world.read_change_tick(),
|
change_tick,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1195,14 +1176,9 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
|
|||||||
) -> Result<Q::Item<'w>, QuerySingleError> {
|
) -> Result<Q::Item<'w>, QuerySingleError> {
|
||||||
self.update_archetypes(world);
|
self.update_archetypes(world);
|
||||||
|
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: query has unique world access
|
// SAFETY: query has unique world access
|
||||||
unsafe {
|
unsafe { self.get_single_unchecked_manual(world, world.last_change_tick(), change_tick) }
|
||||||
self.get_single_unchecked_manual(
|
|
||||||
world,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a query result when there is exactly one entity matching the query.
|
/// Returns a query result when there is exactly one entity matching the query.
|
||||||
@ -1293,7 +1269,7 @@ mod tests {
|
|||||||
|
|
||||||
// These don't matter for the test
|
// These don't matter for the test
|
||||||
let last_change_tick = world.last_change_tick();
|
let last_change_tick = world.last_change_tick();
|
||||||
let change_tick = world.read_change_tick();
|
let change_tick = world.change_tick();
|
||||||
|
|
||||||
// It's best to test get_many_unchecked_manual directly,
|
// It's best to test get_many_unchecked_manual directly,
|
||||||
// as it is shared and unsafe
|
// as it is shared and unsafe
|
||||||
|
|||||||
@ -930,15 +930,12 @@ pub(crate) unsafe fn get_mut_by_id(
|
|||||||
location: EntityLocation,
|
location: EntityLocation,
|
||||||
component_id: ComponentId,
|
component_id: ComponentId,
|
||||||
) -> Option<MutUntyped> {
|
) -> Option<MutUntyped> {
|
||||||
|
let change_tick = world.change_tick();
|
||||||
// SAFETY: world access is unique, entity location and component_id required to be valid
|
// SAFETY: world access is unique, entity location and component_id required to be valid
|
||||||
get_component_and_ticks(world, component_id, entity, location).map(|(value, ticks)| {
|
get_component_and_ticks(world, component_id, entity, location).map(|(value, ticks)| {
|
||||||
MutUntyped {
|
MutUntyped {
|
||||||
value: value.assert_unique(),
|
value: value.assert_unique(),
|
||||||
ticks: Ticks::from_tick_cells(
|
ticks: Ticks::from_tick_cells(ticks, world.last_change_tick(), change_tick),
|
||||||
ticks,
|
|
||||||
world.last_change_tick(),
|
|
||||||
world.read_change_tick(),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1457,14 +1457,14 @@ impl World {
|
|||||||
self.validate_non_send_access_untyped(info.name());
|
self.validate_non_send_access_untyped(info.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let change_tick = self.change_tick();
|
||||||
|
|
||||||
let (ptr, ticks) = self.get_resource_with_ticks(component_id)?;
|
let (ptr, ticks) = self.get_resource_with_ticks(component_id)?;
|
||||||
|
|
||||||
// SAFETY: This function has exclusive access to the world so nothing aliases `ticks`.
|
// SAFETY: This function has exclusive access to the world so nothing aliases `ticks`.
|
||||||
// - index is in-bounds because the column is initialized and non-empty
|
// - index is in-bounds because the column is initialized and non-empty
|
||||||
// - no other reference to the ticks of the same row can exist at the same time
|
// - no other reference to the ticks of the same row can exist at the same time
|
||||||
let ticks = unsafe {
|
let ticks = unsafe { Ticks::from_tick_cells(ticks, self.last_change_tick(), change_tick) };
|
||||||
Ticks::from_tick_cells(ticks, self.last_change_tick(), self.read_change_tick())
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(MutUntyped {
|
Some(MutUntyped {
|
||||||
// SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
|
// SAFETY: This function has exclusive access to the world so nothing aliases `ptr`.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user