pub struct Entities { /* private fields */ }
Expand description
Entities holds the EntityIds to all entities: living, removed and dead.
A living entity is an entity currently present, with or without component.
Removed and dead entities don’t have any component.
The big difference is that removed ones can become alive again.
The life cycle of an entity looks like this:
Generation -> Deletion -> Dead
⬑–––––↵
Implementations
sourceimpl Entities
impl Entities
sourcepub fn is_alive(&self, entity: EntityId) -> bool
pub fn is_alive(&self, entity: EntityId) -> bool
Returns true
if entity
matches a living entity.
sourcepub fn add_component<S>(
&self,
entity: EntityId,
storages: S,
component: <S as AddComponent>::Component
) where
S: AddComponent,
pub fn add_component<S>(
&self,
entity: EntityId,
storages: S,
component: <S as AddComponent>::Component
) where
S: AddComponent,
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Panics
entity
is not alive.
Example
use shipyard::{EntitiesView, ViewMut, World};
let mut world = World::new();
let entity = world.add_entity(());
let (entities, mut u32s) = world.borrow::<(EntitiesView, ViewMut<u32>)>().unwrap();
entities.add_component(entity, &mut u32s, 0);
sourcepub fn delete_unchecked(&mut self, entity_id: EntityId) -> bool
pub fn delete_unchecked(&mut self, entity_id: EntityId) -> bool
Deletes an entity, returns true if the entity was alive.
If the entity has components, they will not be deleted and still be accessible using this id.
sourcepub fn add_entity<T>(
&mut self,
storages: T,
component: <T as AddEntity>::Component
) -> EntityId where
T: AddEntity,
pub fn add_entity<T>(
&mut self,
storages: T,
component: <T as AddEntity>::Component
) -> EntityId where
T: AddEntity,
Stores component
in a new entity and returns its EntityId
.
Multiple components can be added at the same time using a tuple.
Example:
use shipyard::{EntitiesViewMut, ViewMut, World};
let world = World::new();
let (mut entities, mut usizes, mut u32s) = world
.borrow::<(EntitiesViewMut, ViewMut<usize>, ViewMut<u32>)>()
.unwrap();
let entity = entities.add_entity((&mut usizes, &mut u32s), (0, 1));
assert_eq!(usizes[entity], 0);
assert_eq!(u32s[entity], 1);
sourcepub fn bulk_add_entity<T, I>(
&mut self,
storages: T,
component: I
) -> BulkEntityIter<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
where
T: AddEntity + BulkReserve,
I: IntoIterator<Item = <T as AddEntity>::Component>,
pub fn bulk_add_entity<T, I>(
&mut self,
storages: T,
component: I
) -> BulkEntityIter<'_>ⓘNotable traits for BulkEntityIter<'a>impl<'a> Iterator for BulkEntityIter<'a> type Item = EntityId;
where
T: AddEntity + BulkReserve,
I: IntoIterator<Item = <T as AddEntity>::Component>,
Creates multiple new entities and returns an iterator yielding the new EntityId
s.
Multiple components can be added at the same time using a tuple.
Example
use shipyard::{EntitiesViewMut, ViewMut, World};
let world = World::new();
let (mut entities, mut usizes, mut u32s) = world
.borrow::<(EntitiesViewMut, ViewMut<usize>, ViewMut<u32>)>()
.unwrap();
let entity0 = entities.bulk_add_entity((), (0..1).map(|_| {})).next();
let entity1 = entities.bulk_add_entity(&mut u32s, 1..2).next();
let new_entities =
entities.bulk_add_entity((&mut u32s, &mut usizes), (10..20).map(|i| (i as u32, i)));
Trait Implementations
sourceimpl<'a> IntoIterator for &'a Entities
impl<'a> IntoIterator for &'a Entities
sourceimpl Storage for Entities
impl Storage for Entities
sourcefn memory_usage(&self) -> Option<StorageMemoryUsage>
fn memory_usage(&self) -> Option<StorageMemoryUsage>
Returns how much memory this storage uses.
sourcefn sparse_array(&self) -> Option<&SparseArray<[EntityId; 32]>>
fn sparse_array(&self) -> Option<&SparseArray<[EntityId; 32]>>
Returns a SparseSet
’s internal SparseArray
. Read more
Auto Trait Implementations
impl RefUnwindSafe for Entities
impl Send for Entities
impl Sync for Entities
impl Unpin for Entities
impl UnwindSafe for Entities
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.