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 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;
}
}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 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_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§
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
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self using data from the given World.