Skip to content

Commit

Permalink
Speed up Entity by making it u64
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Nov 11, 2023
1 parent 38f190e commit 5e595c5
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 100 deletions.
9 changes: 4 additions & 5 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ impl<'m> EntityMapper<'m> {
}

// this new entity reference is specifically designed to never represent any living entity
let new = Entity {
generation: self.dead_start.generation + self.generations,
index: self.dead_start.index,
};
let generation = self.dead_start.generation() + self.generations;
let index = self.dead_start.index();
let new = Entity::from_raw_and_generation(index, generation);
self.generations += 1;

self.map.insert(entity, new);
Expand Down Expand Up @@ -108,7 +107,7 @@ impl<'m> EntityMapper<'m> {
// SAFETY: Entities data is kept in a valid state via `EntityMap::world_scope`
let entities = unsafe { world.entities_mut() };
assert!(entities.free(self.dead_start).is_some());
assert!(entities.reserve_generations(self.dead_start.index, self.generations));
assert!(entities.reserve_generations(self.dead_start.index(), self.generations));
}

/// Creates an [`EntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity, Entity>`], then calls the
Expand Down
Loading

0 comments on commit 5e595c5

Please sign in to comment.