pub struct Entities { /* private fields */ }
Expand description
Holds a list of alive entities.
It also holds a list of entities that were recently killed, which allows to remove components of deleted entities at the end of a game frame.
Implementations§
§impl Entities
impl Entities
pub fn iter_with<Q>(
&self,
query: Q
) -> EntitiesIterWith<'_, <Q as QueryItem>::Iter> ⓘwhere
Q: QueryItem,
pub fn iter_with<Q>( &self, query: Q ) -> EntitiesIterWith<'_, <Q as QueryItem>::Iter> ⓘwhere Q: QueryItem,
Iterate over the entities and components in the given query.
The QueryItem
trait is automatically implemented for references to Comp
and
CompMut
and for tuples of up to 26 items, so you can join over your mutable or immutable
component borrows in your systems.
You can also pass a single component, to iterate only over the components that have alive entities.
Example
fn my_system(entities: Res<Entities>, mut pos: CompMut<Pos>, vel: Comp<Vel>) {
for (entity, (pos, vel)) in entities.iter_with((&mut pos, &vel)) {
pos.x += vel.x;
pos.y += vel.y;
}
}
You may optionally iterate over components with &Optional(&comp)
or mutably with
&mut OptionalMut(&mut comp_mut)
. Entities are not filtered by component in OptionalQueryItem
.
None is returned for these. If done with single Optional query item, all entities are iterated over.
Syntax is &Optional(&comp)
, or &mut OptionalMut(&mut comp)
. Reference to comp and reference to Optional
is required for now.
Optional
Example
fn my_system(entities: Res<Entities>, mut pos: CompMut<Pos>, vel: Comp<Vel>, pos_max: Comp<PosMax>) {
for (entity, (pos, vel, pos_max)) in entities.iter_with((&mut pos, &vel, &Optional(&pos_max))) {
// Update pos from vel on all entities that have pos and vel components
pos.x += vel.x;
pos.y += vel.y;
// limit pos.x by pos_max.x if entity has PosMax component
if let Some(pos_max) = pos_max {
if pos.x > pos_max.x {
pos.x = pos_max.x
}
}
}
}
pub fn create(&mut self) -> Entity
pub fn create(&mut self) -> Entity
Creates a new Entity
and returns it.
This function will not reuse the index of an entity that is still in the killed entities.
pub fn is_alive(&self, entity: Entity) -> bool
pub fn is_alive(&self, entity: Entity) -> bool
Checks if the Entity
is still alive.
Returns true if it is alive. Returns false if it has been killed.
pub fn clear_killed(&mut self)
pub fn clear_killed(&mut self)
Clears the killed entity list.
pub fn bitset(&self) -> &BitSetVec
pub fn bitset(&self) -> &BitSetVec
Returns a bitset where each index where the bit is set to 1 indicates the index of an alive entity.
Useful for joining over Entity
and ComponentStore<T>
at the same time.
pub fn iter_with_bitset<'a>(
&'a self,
bitset: &'a BitSetVec
) -> EntityIterator<'a> ⓘ
pub fn iter_with_bitset<'a>( &'a self, bitset: &'a BitSetVec ) -> EntityIterator<'a> ⓘ
Iterates over entities using the provided bitset.
Trait Implementations§
§impl HasSchema for Entities
impl HasSchema for Entities
§fn register_schema()
fn register_schema()
§fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
fn cast<T>(this: &Self) -> &Twhere T: HasSchema,
§fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where T: HasSchema,
§fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
fn cast_mut<T>(this: &mut Self) -> &mut Twhere T: HasSchema,
§fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where
T: HasSchema,
fn try_cast_mut<T>(this: &mut Self) -> Result<&mut T, SchemaMismatchError>where T: HasSchema,
§fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where Self: Sized,
T
to a SchemaRef
§fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where
Self: Sized,
fn as_schema_mut(&mut self) -> SchemaRefMut<'_>where Self: Sized,
T
to a SchemaRefMut
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere T: Default,
§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Self
using data from the given World
.