all destructs increment the generation
This commit is contained in:
parent
0c194b734a
commit
180b349721
@ -299,9 +299,12 @@ impl<'m> SceneEntityMapper<'m> {
|
|||||||
/// safely allocate any more references, this method takes ownership of `self` in order to render it unusable.
|
/// safely allocate any more references, this method takes ownership of `self` in order to render it unusable.
|
||||||
pub fn finish(self, world: &mut World) {
|
pub fn finish(self, world: &mut World) {
|
||||||
// SAFETY: We never constructed the entity and never released it for something else to construct.
|
// SAFETY: We never constructed the entity and never released it for something else to construct.
|
||||||
unsafe {
|
let reuse_row = unsafe {
|
||||||
world.release_generations_unchecked(self.dead_start.row(), self.generations);
|
world
|
||||||
}
|
.entities
|
||||||
|
.mark_free(self.dead_start.row(), self.generations)
|
||||||
|
};
|
||||||
|
world.allocator.free(reuse_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an [`SceneEntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity>`], then calls the
|
/// Creates an [`SceneEntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity>`], then calls the
|
||||||
|
|||||||
@ -2373,6 +2373,7 @@ impl<'w> EntityWorldMut<'w> {
|
|||||||
|
|
||||||
/// Destructs the entity, without releasing it.
|
/// Destructs the entity, without releasing it.
|
||||||
/// This may be later [`constructed`](Self::construct).
|
/// This may be later [`constructed`](Self::construct).
|
||||||
|
/// Note that this still increases the generation to differentiate different constructions of the same row.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn destruct(&mut self) -> &mut Self {
|
pub fn destruct(&mut self) -> &mut Self {
|
||||||
self.destruct_with_caller(MaybeLocation::caller())
|
self.destruct_with_caller(MaybeLocation::caller())
|
||||||
@ -2517,7 +2518,10 @@ impl<'w> EntityWorldMut<'w> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
|
// SAFETY: We just destructed it.
|
||||||
|
self.entity = unsafe { self.world.entities.mark_free(self.entity.row(), 1) };
|
||||||
self.world.flush();
|
self.world.flush();
|
||||||
|
self.update_location(); // In case some command re-constructs this entity.
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2536,11 +2540,7 @@ impl<'w> EntityWorldMut<'w> {
|
|||||||
|
|
||||||
pub(crate) fn despawn_with_caller(mut self, caller: MaybeLocation) {
|
pub(crate) fn despawn_with_caller(mut self, caller: MaybeLocation) {
|
||||||
self.destruct_with_caller(caller);
|
self.destruct_with_caller(caller);
|
||||||
// SAFETY: We just destructed.
|
self.world.allocator.free(self.entity);
|
||||||
unsafe {
|
|
||||||
self.world
|
|
||||||
.release_generations_unchecked(self.entity.row(), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures any commands triggered by the actions of Self are applied, equivalent to [`World::flush`]
|
/// Ensures any commands triggered by the actions of Self are applied, equivalent to [`World::flush`]
|
||||||
|
|||||||
@ -1553,20 +1553,6 @@ impl World {
|
|||||||
Ok(entity)
|
Ok(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Releases `entity` to be reused.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// It must have been destructed.
|
|
||||||
pub(crate) unsafe fn release_generations_unchecked(
|
|
||||||
&mut self,
|
|
||||||
entity: EntityRow,
|
|
||||||
generations: u32,
|
|
||||||
) {
|
|
||||||
self.allocator
|
|
||||||
.free(self.entities.mark_free(entity, generations));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clears the internal component tracker state.
|
/// Clears the internal component tracker state.
|
||||||
///
|
///
|
||||||
/// The world maintains some internal state about changed and removed components. This state
|
/// The world maintains some internal state about changed and removed components. This state
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user