|
1 |
| -use crate::{entity::Entity, world::World}; |
| 1 | +use crate::{ |
| 2 | + entity::Entity, |
| 3 | + identifier::masks::{IdentifierMask, HIGH_MASK}, |
| 4 | + world::World, |
| 5 | +}; |
2 | 6 | use bevy_utils::EntityHashMap;
|
3 | 7 |
|
4 |
| -use super::inc_generation_by; |
5 |
| - |
6 | 8 | /// Operation to map all contained [`Entity`] fields in a type to new values.
|
7 | 9 | ///
|
8 | 10 | /// As entity IDs are valid only for the [`World`] they're sourced from, using [`Entity`]
|
@@ -70,11 +72,13 @@ impl<'m> EntityMapper<'m> {
|
70 | 72 | }
|
71 | 73 |
|
72 | 74 | // this new entity reference is specifically designed to never represent any living entity
|
73 |
| - let new = Entity { |
74 |
| - generation: inc_generation_by(self.dead_start.generation, self.generations), |
75 |
| - index: self.dead_start.index, |
76 |
| - }; |
77 |
| - self.generations += 1; |
| 75 | + let new = Entity::from_raw_and_generation( |
| 76 | + self.dead_start.index(), |
| 77 | + IdentifierMask::inc_masked_high_by(self.dead_start.generation, self.generations), |
| 78 | + ); |
| 79 | + |
| 80 | + // Prevent generations counter from being a greater value than HIGH_MASK. |
| 81 | + self.generations = (self.generations + 1) & HIGH_MASK; |
78 | 82 |
|
79 | 83 | self.map.insert(entity, new);
|
80 | 84 |
|
@@ -109,7 +113,7 @@ impl<'m> EntityMapper<'m> {
|
109 | 113 | // SAFETY: Entities data is kept in a valid state via `EntityMap::world_scope`
|
110 | 114 | let entities = unsafe { world.entities_mut() };
|
111 | 115 | assert!(entities.free(self.dead_start).is_some());
|
112 |
| - assert!(entities.reserve_generations(self.dead_start.index, self.generations)); |
| 116 | + assert!(entities.reserve_generations(self.dead_start.index(), self.generations)); |
113 | 117 | }
|
114 | 118 |
|
115 | 119 | /// Creates an [`EntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity, Entity>`], then calls the
|
|
0 commit comments