Struct shipyard::Entities [−][src]
pub struct Entities { /* fields omitted */ }
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
Returns true if entity
matches a living entity.
pub fn try_add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
) -> Result<(), AddComponent>
pub fn try_add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
) -> Result<(), AddComponent>
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Example
let world = World::new();
let entity = world.run::<EntitiesMut, _, _>(|mut entities| {
entities.add_entity((), ())
});
let (entities, mut u32s) = world.borrow::<(Entities, &mut u32)>();
entities.try_add_component(&mut u32s, 0, entity).unwrap();
pub fn add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
)
pub fn add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
)
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Unwraps errors.
Example
let world = World::new();
let entity = world.run::<EntitiesMut, _, _>(|mut entities| {
entities.add_entity((), ())
});
let (entities, mut u32s) = world.borrow::<(Entities, &mut u32)>();
entities.add_component(&mut u32s, 0, entity);
Delete 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.
pub fn add_entity<T: ViewAddEntity>(
&mut self,
storages: T,
component: T::Component
) -> EntityId
pub fn add_entity<T: ViewAddEntity>(
&mut self,
storages: T,
component: T::Component
) -> EntityId
Stores component
in a new entity, the EntityId
to this entity is returned.
Multiple components can be added at the same time using a tuple.
Example:
let world = World::new();
world.run::<(EntitiesMut, &mut usize, &mut u32), _, _>(|(mut entities, mut usizes, mut u32s)| {
let entity = entities.add_entity((&mut usizes, &mut u32s), (0, 1));
assert_eq!(usizes.get(entity), Ok(&0));
assert_eq!(u32s.get(entity), Ok(&1));
});