pub struct Entities { /* private fields */ }Expand description
Hands out entity slots and recycles them.
Implementations§
Source§impl Entities
impl Entities
Sourcepub fn spawn(&mut self) -> Entity
pub fn spawn(&mut self) -> Entity
Allocate an entity, reusing a free slot when one exists.
Reuse is newest-first, which keeps the index range compact: an ordered query walks slots rather than entities, so a store whose indices are spread thin pays for the gaps.
§Panics
Never in practice: the slot count is bounded by u32::MAX, and a
tree with four billion live entities has other problems. Written
as a saturating count rather than an unwrap so there is no panic
to reason about.
Sourcepub fn is_alive(&self, entity: Entity) -> bool
pub fn is_alive(&self, entity: Entity) -> bool
Whether this exact handle still names a live entity.
Both halves are checked. A handle whose slot is alive but whose generation is stale names an entity that no longer exists, and is the whole reason the generation is there.
Sourcepub fn despawn(&mut self, entity: Entity) -> bool
pub fn despawn(&mut self, entity: Entity) -> bool
Free an entity’s slot. Returns whether it was alive to begin with.
Despawning an already-dead handle is a no-op rather than an error: it is the natural outcome of two systems both deciding something should go, and turning it into a failure would make every caller check first.