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>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)where
Q: QueryItem,
pub fn single_with<Q>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)where
Q: QueryItem,
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>(
&self,
query: Q,
) -> Result<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item), QuerySingleError>where
Q: QueryItem,
pub fn get_single_with<Q>(
&self,
query: Q,
) -> Result<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item), QuerySingleError>where
Q: QueryItem,
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>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)where
Q: QueryItem,
pub fn first_with<Q>(
&self,
query: Q,
) -> (Entity, <<Q as QueryItem>::Iter as Iterator>::Item)where
Q: QueryItem,
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>(
&self,
query: Q,
) -> Option<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item)>where
Q: QueryItem,
pub fn get_first_with<Q>(
&self,
query: Q,
) -> Option<(Entity, <<Q as QueryItem>::Iter as Iterator>::Item)>where
Q: QueryItem,
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>(
&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
}
}
}
}
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
source§fn register_schema()
fn register_schema()
source§fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
fn cast<T>(this: &Self) -> &Twhere
T: HasSchema,
source§fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
fn try_cast<T>(this: &Self) -> Result<&T, SchemaMismatchError>where
T: HasSchema,
source§fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
fn cast_mut<T>(this: &mut Self) -> &mut Twhere
T: HasSchema,
source§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,
source§fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
fn as_schema_ref(&self) -> SchemaRef<'_>where
Self: Sized,
T
to a SchemaRef
source§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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
)§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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
.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoArcAny for T
impl<T> IntoArcAny for T
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> RawDefault for Twhere
T: Default,
impl<T> RawDefault for Twhere
T: Default,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.