Struct Archetype

Source
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

Source

pub fn new<'a>( components: impl Iterator<Item = &'a ComponentInfo> + Clone, ) -> Self

Creates new archetype with the given set of components.

Source

pub fn has_component(&self, ty: TypeId) -> bool

Returns true if archetype contains component with specified id.

Source

pub fn contains_borrow(&self, ty: TypeId) -> bool

Returns true if archetype contains component with specified id.

Source

pub fn contains_borrow_mut(&self, ty: TypeId) -> bool

Returns true if archetype contains component with specified id.

Source

pub fn matches(&self, type_ids: impl Iterator<Item = TypeId>) -> bool

Returns true if archetype matches components set specified.

Source

pub fn ids(&self) -> impl ExactSizeIterator<Item = TypeId> + Clone + '_

Returns iterator over component type ids.

Source

pub fn infos( &self, ) -> impl ExactSizeIterator<Item = &ComponentInfo> + Clone + '_

Returns iterator over component type infos.

Source

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.

Source

pub fn spawn_one<T>(&mut self, id: EntityId, value: T, epoch: EpochId) -> u32
where T: 'static,

Spawns new entity in the archetype.

Returns index of the newly created entity in the archetype.

Source

pub fn spawn<B>(&mut self, id: EntityId, bundle: B, epoch: EpochId) -> u32
where B: DynamicBundle,

Spawns new entity in the archetype.

Returns index of the newly created entity in the archetype.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn set<T>( &mut self, id: EntityId, idx: u32, value: T, epoch: EpochId, encoder: LocalActionEncoder<'_>, )
where T: 'static,

Set component to the entity

§Safety

Archetype must contain that component type.

Source

pub unsafe fn get<T>(&mut self, entity_idx: u32) -> &T
where T: 'static,

Get component of the entity

§Safety

Archetype must contain that component type.

Source

pub unsafe fn get_mut<T>(&mut self, entity_idx: u32, epoch: EpochId) -> &mut T
where T: 'static,

Borrows component mutably. Updates component epoch.

§Safety

Archetype must contain that component type. epoch must be advanced before this call.

Source

pub unsafe fn get_mut_nobump<T>(&mut self, entity_idx: u32) -> &mut T
where T: 'static,

Borrows component mutably. Does not update component epoch.

§Safety

Archetype must contain that component type.

Source

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.

Source

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.

Source

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§

Source§

impl Drop for Archetype

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'de, F, T> Deserialize<'de, As<F>> for T
where F: BareFormula + ?Sized, T: Deserialize<'de, F>,

Source§

fn deserialize(deserializer: Deserializer<'de>) -> Result<T, DeserializeError>

Deserializes value provided deserializer. Returns deserialized value and the number of bytes consumed from the and of input. Read more
Source§

fn deserialize_in_place( &mut self, deserializer: Deserializer<'de>, ) -> Result<(), DeserializeError>

Deserializes value in-place provided deserializer. Overwrites self with data from the input. Read more
Source§

impl<'de, F, T> Deserialize<'de, Ref<F>> for T
where F: BareFormula + ?Sized, T: Deserialize<'de, F> + ?Sized,

Source§

fn deserialize(de: Deserializer<'de>) -> Result<T, DeserializeError>

Deserializes value provided deserializer. Returns deserialized value and the number of bytes consumed from the and of input. Read more
Source§

fn deserialize_in_place( &mut self, de: Deserializer<'de>, ) -> Result<(), DeserializeError>

Deserializes value in-place provided deserializer. Overwrites self with data from the input. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<F, T> Serialize<As<F>> for T
where F: BareFormula + ?Sized, T: Serialize<F>,

Source§

fn serialize<B>( self, sizes: &mut Sizes, buffer: B, ) -> Result<(), <B as Buffer>::Error>
where B: Buffer,

Serializes self into the given buffer. heap specifies the size of the buffer’s heap occupied prior to this call. Read more
Source§

fn size_hint(&self) -> Option<Sizes>

Returns heap and stack sizes required to serialize self. If some sizes are returned they must be exact. Read more
Source§

impl<F, T> Serialize<Ref<F>> for T
where F: BareFormula + ?Sized, T: Serialize<F>,

Source§

fn serialize<B>( self, sizes: &mut Sizes, buffer: B, ) -> Result<(), <B as Buffer>::Error>
where B: Buffer,

Serializes self into the given buffer. heap specifies the size of the buffer’s heap occupied prior to this call. Read more
Source§

fn size_hint(&self) -> Option<Sizes>

Returns heap and stack sizes required to serialize self. If some sizes are returned they must be exact. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.