Skip to content

Commit

Permalink
Unified identifer for entities & relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger committed Jan 9, 2024
1 parent 06bf928 commit 29ddce2
Show file tree
Hide file tree
Showing 7 changed files with 614 additions and 152 deletions.
14 changes: 6 additions & 8 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::{entity::Entity, world::World};
use crate::{entity::Entity, identifier::masks::IdentifierMask, world::World};
use bevy_utils::EntityHashMap;

use super::inc_generation_by;

/// Operation to map all contained [`Entity`] fields in a type to new values.
///
/// As entity IDs are valid only for the [`World`] they're sourced from, using [`Entity`]
Expand Down Expand Up @@ -70,10 +68,10 @@ impl<'m> EntityMapper<'m> {
}

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

self.map.insert(entity, new);
Expand Down Expand Up @@ -109,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 29ddce2

Please sign in to comment.