Skip to content

Commit 12aba64

Browse files
Make entity generation a new type and remove identifier (#19121)
# Objective This is a followup to #18704 . There's lots more followup work, but this is the minimum to unblock #18670, etc. This direction has been given the green light by Alice [here](#18704 (comment)). ## Solution I could have split this over multiple PRs, but I figured skipping straight here would be easiest for everyone and would unblock things the quickest. This removes the now no longer needed `identifier` module and makes `Entity::generation` go from `NonZeroU32` to `struct EntityGeneration(u32)`. ## Testing CI --------- Co-authored-by: Mark Nokalt <marknokalt@live.com>
1 parent 0b48587 commit 12aba64

File tree

12 files changed

+193
-664
lines changed

12 files changed

+193
-664
lines changed

benches/benches/bevy_ecs/world/entity_hash.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_ecs::entity::{Entity, EntityHashSet};
1+
use bevy_ecs::entity::{Entity, EntityGeneration, EntityHashSet};
22
use criterion::{BenchmarkId, Criterion, Throughput};
33
use rand::{Rng, SeedableRng};
44
use rand_chacha::ChaCha8Rng;
@@ -21,7 +21,10 @@ fn make_entity(rng: &mut impl Rng, size: usize) -> Entity {
2121
let bits = ((generation as u64) << 32) | id;
2222
let e = Entity::from_bits(bits);
2323
assert_eq!(e.index(), !(id as u32));
24-
assert_eq!(e.generation(), generation as u32);
24+
assert_eq!(
25+
e.generation(),
26+
EntityGeneration::FIRST.after_versions(generation as u32)
27+
);
2528
e
2629
}
2730

crates/bevy_ecs/src/entity/map_entities.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use indexmap::IndexSet;
33

44
use crate::{
55
entity::{hash_map::EntityHashMap, Entity},
6-
identifier::masks::{IdentifierMask, HIGH_MASK},
76
world::World,
87
};
98

@@ -229,11 +228,9 @@ impl EntityMapper for SceneEntityMapper<'_> {
229228
// this new entity reference is specifically designed to never represent any living entity
230229
let new = Entity::from_raw_and_generation(
231230
self.dead_start.row(),
232-
IdentifierMask::inc_masked_high_by(self.dead_start.generation, self.generations),
231+
self.dead_start.generation.after_versions(self.generations),
233232
);
234-
235-
// Prevent generations counter from being a greater value than HIGH_MASK.
236-
self.generations = (self.generations + 1) & HIGH_MASK;
233+
self.generations = self.generations.wrapping_add(1);
237234

238235
self.map.insert(source, new);
239236

0 commit comments

Comments
 (0)