pub struct Archetype { /* private fields */ }Expand description
Collection of all entities with same set of components.
Archetypes are typically managed by the World instance.
This type is exposed for Query implementations.
Implementations§
Source§impl Archetype
impl Archetype
Sourcepub fn new<'a>(
components: impl Iterator<Item = &'a ComponentInfo> + Clone,
) -> Self
pub fn new<'a>( components: impl Iterator<Item = &'a ComponentInfo> + Clone, ) -> Self
Creates new archetype with the given set of components.
Sourcepub fn has_component(&self, ty: TypeId) -> bool
pub fn has_component(&self, ty: TypeId) -> bool
Returns true if archetype contains component with specified id.
Sourcepub fn contains_borrow(&self, ty: TypeId) -> bool
pub fn contains_borrow(&self, ty: TypeId) -> bool
Returns true if archetype contains component with specified id.
Sourcepub fn contains_borrow_mut(&self, ty: TypeId) -> bool
pub fn contains_borrow_mut(&self, ty: TypeId) -> bool
Returns true if archetype contains component with specified id.
Sourcepub fn matches(&self, type_ids: impl Iterator<Item = TypeId>) -> bool
pub fn matches(&self, type_ids: impl Iterator<Item = TypeId>) -> bool
Returns true if archetype matches components set specified.
Sourcepub fn ids(&self) -> impl ExactSizeIterator<Item = TypeId> + Clone + '_
pub fn ids(&self) -> impl ExactSizeIterator<Item = TypeId> + Clone + '_
Returns iterator over component type ids.
Sourcepub fn infos(
&self,
) -> impl ExactSizeIterator<Item = &ComponentInfo> + Clone + '_
pub fn infos( &self, ) -> impl ExactSizeIterator<Item = &ComponentInfo> + Clone + '_
Returns iterator over component type infos.
Sourcepub fn spawn_empty(&mut self, id: EntityId) -> u32
pub fn spawn_empty(&mut self, id: EntityId) -> u32
Spawns new entity in the archetype.
Returns index of the newly created entity in the archetype.
Sourcepub fn spawn_one<T>(&mut self, id: EntityId, value: T, epoch: EpochId) -> u32where
T: 'static,
pub fn spawn_one<T>(&mut self, id: EntityId, value: T, epoch: EpochId) -> u32where
T: 'static,
Spawns new entity in the archetype.
Returns index of the newly created entity in the archetype.
Sourcepub fn spawn<B>(&mut self, id: EntityId, bundle: B, epoch: EpochId) -> u32where
B: DynamicBundle,
pub fn spawn<B>(&mut self, id: EntityId, bundle: B, epoch: EpochId) -> u32where
B: DynamicBundle,
Spawns new entity in the archetype.
Returns index of the newly created entity in the archetype.
Sourcepub fn despawn(
&mut self,
id: EntityId,
idx: u32,
encoder: LocalActionEncoder<'_>,
) -> Option<EntityId>
pub fn despawn( &mut self, id: EntityId, idx: u32, encoder: LocalActionEncoder<'_>, ) -> Option<EntityId>
Despawns specified entity in the archetype.
Returns id of the entity that took the place of despawned.
Sourcepub unsafe fn despawn_unchecked(
&mut self,
id: EntityId,
idx: u32,
encoder: LocalActionEncoder<'_>,
) -> Option<EntityId>
pub unsafe fn despawn_unchecked( &mut self, id: EntityId, idx: u32, encoder: LocalActionEncoder<'_>, ) -> Option<EntityId>
Despawns specified entity in the archetype.
Returns id of the entity that took the place of despawned.
§Safety
idx must be in bounds of the archetype entities array.
Sourcepub unsafe fn set_bundle<B>(
&mut self,
id: EntityId,
idx: u32,
bundle: B,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
)where
B: DynamicBundle,
pub unsafe fn set_bundle<B>(
&mut self,
id: EntityId,
idx: u32,
bundle: B,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
)where
B: DynamicBundle,
Set components from bundle to the entity.
§Safety
Bundle must not contain components that are absent in this archetype.
Sourcepub unsafe fn set<T>(
&mut self,
id: EntityId,
idx: u32,
value: T,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
)where
T: 'static,
pub unsafe fn set<T>(
&mut self,
id: EntityId,
idx: u32,
value: T,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
)where
T: 'static,
Sourcepub unsafe fn get_mut<T>(&mut self, entity_idx: u32, epoch: EpochId) -> &mut Twhere
T: 'static,
pub unsafe fn get_mut<T>(&mut self, entity_idx: u32, epoch: EpochId) -> &mut Twhere
T: 'static,
Borrows component mutably. Updates component epoch.
§Safety
Archetype must contain that component type.
epoch must be advanced before this call.
Sourcepub unsafe fn get_mut_nobump<T>(&mut self, entity_idx: u32) -> &mut Twhere
T: 'static,
pub unsafe fn get_mut_nobump<T>(&mut self, entity_idx: u32) -> &mut Twhere
T: 'static,
Borrows component mutably. Does not update component epoch.
§Safety
Archetype must contain that component type.
Sourcepub unsafe fn insert_bundle<B>(
&mut self,
id: EntityId,
dst: &mut Archetype,
src_idx: u32,
bundle: B,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
replace: bool,
) -> (u32, Option<EntityId>)where
B: DynamicBundle,
pub unsafe fn insert_bundle<B>(
&mut self,
id: EntityId,
dst: &mut Archetype,
src_idx: u32,
bundle: B,
epoch: EpochId,
encoder: LocalActionEncoder<'_>,
replace: bool,
) -> (u32, Option<EntityId>)where
B: DynamicBundle,
Add components from bundle to the entity, moving entity to new archetype.
§Safety
src_idx must be in bounds of this archetype.
This archetype must not contain at least one component type from the bundle.
dst archetype must contain all component types from this archetype and the bundle.
Sourcepub unsafe fn remove<T>(
&mut self,
id: EntityId,
dst: &mut Archetype,
src_idx: u32,
) -> (u32, Option<EntityId>, T)where
T: 'static,
pub unsafe fn remove<T>(
&mut self,
id: EntityId,
dst: &mut Archetype,
src_idx: u32,
) -> (u32, Option<EntityId>, T)where
T: 'static,
Removes one component from the entity moving it to new archetype.
§Safety
src_idx must be in bounds of this archetype.
This archetype must contain specified type.
dst archetype must contain all component types from this archetype except specified type.
Sourcepub unsafe fn drop_bundle(
&mut self,
id: EntityId,
dst: &mut Archetype,
src_idx: u32,
encoder: LocalActionEncoder<'_>,
) -> (u32, Option<EntityId>)
pub unsafe fn drop_bundle( &mut self, id: EntityId, dst: &mut Archetype, src_idx: u32, encoder: LocalActionEncoder<'_>, ) -> (u32, Option<EntityId>)
Moves entity from one archetype to another. Dropping components types that are not present in dst archetype. All components present in dst archetype must be present in src archetype.
§Safety
src_idx must be in bounds of this archetype.
dst archetype must contain all component types from this archetype except types from bundle.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Archetype
impl !RefUnwindSafe for Archetype
impl Send for Archetype
impl Sync for Archetype
impl Unpin for Archetype
impl !UnwindSafe for Archetype
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<'de, F, T> Deserialize<'de, As<F>> for T
impl<'de, F, T> Deserialize<'de, As<F>> for T
Source§fn deserialize(deserializer: Deserializer<'de>) -> Result<T, DeserializeError>
fn deserialize(deserializer: Deserializer<'de>) -> Result<T, DeserializeError>
Source§fn deserialize_in_place(
&mut self,
deserializer: Deserializer<'de>,
) -> Result<(), DeserializeError>
fn deserialize_in_place( &mut self, deserializer: Deserializer<'de>, ) -> Result<(), DeserializeError>
self with data from the input. Read moreSource§impl<'de, F, T> Deserialize<'de, Ref<F>> for T
impl<'de, F, T> Deserialize<'de, Ref<F>> for T
Source§fn deserialize(de: Deserializer<'de>) -> Result<T, DeserializeError>
fn deserialize(de: Deserializer<'de>) -> Result<T, DeserializeError>
Source§fn deserialize_in_place(
&mut self,
de: Deserializer<'de>,
) -> Result<(), DeserializeError>
fn deserialize_in_place( &mut self, de: Deserializer<'de>, ) -> Result<(), DeserializeError>
self with data from the input. Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more