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§
source§impl Entities
impl Entities
sourcepub fn single_with<Q: QueryItem>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)
pub fn single_with<Q: QueryItem>( &self, query: Q, ) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)
Get a single entity and components in the given query if there is exactly one entity matching the query.
§Panics
This method panics if the number of matching entities is not exactly one.
sourcepub fn get_single_with<Q: QueryItem>(
&self,
query: Q,
) -> Result<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item), QuerySingleError>
pub fn get_single_with<Q: QueryItem>( &self, query: Q, ) -> Result<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item), QuerySingleError>
Get a single entity and components in the given query if there is exactly one entity matching the query.
sourcepub fn first_with_bitset(&self, bitset: &BitSetVec) -> Entity
pub fn first_with_bitset(&self, bitset: &BitSetVec) -> Entity
Get the first entity in the given bitset.
§Panics
This method panics if there are no entities in the bitset.
sourcepub fn get_first_with_bitset(&self, bitset: &BitSetVec) -> Option<Entity>
pub fn get_first_with_bitset(&self, bitset: &BitSetVec) -> Option<Entity>
Get the first entity in the given bitset.
sourcepub fn first_with<Q: QueryItem>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)
pub fn first_with<Q: QueryItem>( &self, query: Q, ) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)
Get the first entity and components in the given query.
§Panics
This method panics if there are no entities that match the query.
sourcepub fn get_first_with<Q: QueryItem>(
&self,
query: Q,
) -> Option<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item)>
pub fn get_first_with<Q: QueryItem>( &self, query: Q, ) -> Option<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item)>
Get the first entity and components in the given query.
sourcepub 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.
sourcepub fn iter_with<Q: QueryItem>(
&self,
query: Q,
) -> EntitiesIterWith<'_, <Q as QueryItem>::Iter> ⓘ
pub fn iter_with<Q: QueryItem>( &self, query: Q, ) -> EntitiesIterWith<'_, <Q as QueryItem>::Iter> ⓘ
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
}
}
}
}
sourcepub 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.
sourcepub 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.
sourcepub fn all_cloned(&self) -> Vec<Entity>
pub fn all_cloned(&self) -> Vec<Entity>
Returns a list of all Entity
s cloned into a new vec.
sourcepub fn clear_killed(&mut self)
pub fn clear_killed(&mut self)
Clears the killed entity list.
sourcepub 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.
sourcepub fn iter(&self) -> EntityIterator<'_> ⓘ
pub fn iter(&self) -> EntityIterator<'_> ⓘ
Iterates over all alive entities.
Trait Implementations§
source§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 Freeze for Entities
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &World) -> T
fn from_world(_world: &World) -> T
Self
using data from the given World
.