Struct shard_ecs::archetype::Archetype [−][src]
pub struct Archetype { /* fields omitted */ }
Implementations
Returns a reference to a specific component.
Safety:
- Component type [
C
] must be present in the archetype - panics otherwise.
Returns a mutable reference to a specific component.
Safety:
- Component type [
C
] must be present in the archetype - panics otherwise.
pub unsafe fn get_fuzzy_components_unchecked<'a, G: ComponentGroup<'a>>(
&'a self,
index: u32
) -> G::RefTuple
pub unsafe fn get_fuzzy_components_unchecked<'a, G: ComponentGroup<'a>>(
&'a self,
index: u32
) -> G::RefTuple
Returns a reference to a specific component.
Safety:
- Component group type [
G
] must be a subset of the types in the archetype - panics otherwise.
pub unsafe fn get_fuzzy_components_unchecked_mut<'a, G: ComponentGroup<'a>>(
&'a mut self,
index: u32
) -> G::MutRefTuple
pub unsafe fn get_fuzzy_components_unchecked_mut<'a, G: ComponentGroup<'a>>(
&'a mut self,
index: u32
) -> G::MutRefTuple
Returns a reference to a specific component.
Safety:
- Component group type [
G
] must be a subset of the types in the archetype - panics otherwise.
Reads a specific component from the archetype at the given index.
Safety:
- Component type [
C
] must be present in the archetype - panics otherwise.
pub unsafe fn get_slices_unchecked_exact_mut<'a, G: ComponentGroup<'a>>(
&'a mut self
) -> G::SliceMutRefTuple
pub unsafe fn get_slices_unchecked_exact_mut<'a, G: ComponentGroup<'a>>(
&'a mut self
) -> G::SliceMutRefTuple
Returns a tuple of mutable component slices to the archetype’s data.
Safety:
- Must be called exactly with the component group contained in the archetype.
- a compatible group type is also accepted.
- [
G
] must have a valid archetype descriptor.
pub unsafe fn get_slices_unchecked_exact<'a, G: ComponentGroup<'a>>(
&'a self
) -> G::SliceRefTuple
pub unsafe fn get_slices_unchecked_exact<'a, G: ComponentGroup<'a>>(
&'a self
) -> G::SliceRefTuple
Returns a tuple of component slices to the archetype’s data.
Safety:
- Must be called exactly with the component group contained in the archetype.
- a compatible group type is also accepted.
- [
G
] must have a valid archetype descriptor.
pub unsafe fn get_fuzzy_slices_unchecked<'s, G: ComponentGroup<'s>>(
&'s self
) -> G::SliceRefTuple
pub unsafe fn get_fuzzy_slices_unchecked<'s, G: ComponentGroup<'s>>(
&'s self
) -> G::SliceRefTuple
Returns the slices for the components in [G
], provided that archetype itself contains a superset of G.
This function is slower than the exact version, use that if an exact type match is known.
Safety:
- Only call this with subsets of the types stored in the archetype.
- [
G
] must have a valid archetype descriptor.
pub unsafe fn get_fuzzy_slices_unchecked_mut<'s, G: ComponentGroup<'s>>(
&'s mut self
) -> G::SliceMutRefTuple
pub unsafe fn get_fuzzy_slices_unchecked_mut<'s, G: ComponentGroup<'s>>(
&'s mut self
) -> G::SliceMutRefTuple
Returns the mutable slices for the components in [G
], provided that archetype itself contains a superset of G.
This function is slower than the exact version, use that if an exact type match is known.
Safety:
- Only call this with subsets of the types stored in the archetype.
- [
G
] must have a valid archetype descriptor.
pub unsafe fn get_entity_fuzzy_slices_unchecked<'s, G: ComponentGroup<'s>>(
&'s self
) -> (&'s [Entity], G::SliceRefTuple)
pub unsafe fn get_entity_fuzzy_slices_unchecked<'s, G: ComponentGroup<'s>>(
&'s self
) -> (&'s [Entity], G::SliceRefTuple)
Returns the entity slice and the slices for the components in [G
], provided that archetype
itself contains a superset of G.
This function is slower than the exact version, use that if an exact type match is known.
Safety:
- Only call this with subsets of the types stored in the archetype.
- [
G
] must have a valid archetype descriptor.
pub unsafe fn get_entity_fuzzy_slices_unchecked_mut<'s, G: ComponentGroup<'s>>(
&'s mut self
) -> (&'s [Entity], G::SliceMutRefTuple)
pub unsafe fn get_entity_fuzzy_slices_unchecked_mut<'s, G: ComponentGroup<'s>>(
&'s mut self
) -> (&'s [Entity], G::SliceMutRefTuple)
Returns the entity slice and the mutable slices for the components in [G
], provided that
archetype itself contains a superset of G.
This function is slower than the exact version, use that if an exact type match is known.
Safety:
- Only call this with subsets of the types stored in the archetype.
- [
G
] must have a valid archetype descriptor.
Returns a reference to the internal slice storing entity associations.
Returns a mutable reference to the internal slice storing entity associations.
pub unsafe fn push_entity_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
entity_handle: Entity,
entity: G
) -> u32
pub unsafe fn push_entity_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
entity_handle: Entity,
entity: G
) -> u32
Pushes a given entity/component-tuple into the archetype’s backing memory.
Safety:
- Must be called exactly with the component group contained in the archetype.
- a compatible group type is also accepted.
- Does not call drop on the given entity.
- Increases the size of the archetype’s memory allocations if required.
- If resizing fails, this function will panic.
Identical to push_entity_unchecked but does not actually write the entity’s component data. The memory at the the returned index MUST be written with valid component data. The metadata is not set either.
Decrements archetype size by 1, therefore assuming the last entity is moved elsewhere. As such, it does not call drop on the last entity.
pub unsafe fn write_single_component_unchecked<C: Component>(
&mut self,
index: u32,
component: C
)
pub unsafe fn write_single_component_unchecked<C: Component>(
&mut self,
index: u32,
component: C
)
Writes a single component into a specific position.
Does not call drop on the existing component at index.
Panics if called on an archetype that does not contain [C
].
pub unsafe fn write_entity_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
index: u32,
entity_handle: Entity,
entity: G
)
pub unsafe fn write_entity_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
index: u32,
entity_handle: Entity,
entity: G
)
Writes a given entity/component-tuple into the archetype’s backing memory.
Safety:
- Must be called exactly with the component group contained in the archetype.
- a compatible group type is also accepted.
- Does not call drop on the given entity.
- Does not call drop on the entity that already exists at [
index
]. - Assumes the underlying backing memory is sized accordingly to fit the data.
- Does not increase the entity counter.
- Does not check if [
index
] is out of bounds or not.
Swaps the entity at [index
] and the last entity and drops the now-last entity.
This effectively reduces the size of the archetype by 1, dropping the entity at index.
And moving the previously last entity to the position at index.
If [index
] is the last element, simply drops it instead without any swaps occurring.
Returns true if a swap occurred, or false if not.
Safety:
- [
index
] must be smaller than the amount of entities in the archetype.
Swaps the entity at [index
] and the last entity.
Makes sure the entity at [index
] is at the end of the archetype.
If [index
] is the last element, does nothing.
Returns true if a swap occurred, or false if not.
Safety:
- [
index
] must be smaller than the amount of entities in the archetype.
pub unsafe fn swap_remove_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
index: u32
) -> (G, bool)
pub unsafe fn swap_remove_unchecked<'a, G: ComponentGroup<'a>>(
&mut self,
index: u32
) -> (G, bool)
Swaps the entity at [index
] and the last entity and returns the now-last entity.
This effectively reduces the size of the archetype by 1, returning the entity at index.
And moving the previously last entity to the position at index.
If [index
] is the last element, simply returns it instead without any swaps occurring.
Returns true if a swap occurred, or false if not.
Safety:
- [
index
] must be smaller than the amount of entities in the archetype. - [
G
] must exactly match the type store in the archetype. - Ordering of component in [
G
] may be different.
Swaps the entities at the provided positions.
Safety:
- [
first
] must be smaller than the amount of entities in the archetype. - [
second
] must be smaller than the amount of entities in the archetype. - [
first
] must not be equal to [last
].
Calls drop on the entity at [index
].
Safety:
- [
index
] must be smaller than the amount of entities in the archetype.
Drops all the entities in the archetype. Does not deallocate the memory.
pub unsafe fn read_components_exact_unchecked<'a, G: ComponentGroup<'a>>(
&self,
index: u32
) -> G
pub unsafe fn read_components_exact_unchecked<'a, G: ComponentGroup<'a>>(
&self,
index: u32
) -> G
Reads the component data at [index
] and returns it.
Safety:
- [
G
] must be exactly the type stored in the archetype. - a compatible one also works. (i.e. same archetype, different ordering)
Creates an archetype with the default amount of memory allocated for it. Panics if the provided archetype descriptor is invalid.
Allocates an archetype with a given capacity for storing data into it.
Panics if the provided archetype descriptor is invalid.
Does not allocate if [capacity
] exceeds MAX_ENTITIES_PER_ARCHETYPE
.
Does not allocate if [capacity
] is 0.
Panics in case of allocation failures.