pub struct Archetypes {
archetypes: Vec<Archetype>,
by_types: HashMap<Box<[TypeId]>, u32>,
}Expand description
Every archetype of a world.
Fields§
§archetypes: Vec<Archetype>§by_types: HashMap<Box<[TypeId]>, u32>Implementations§
Source§impl Archetypes
impl Archetypes
Sourcepub(crate) fn find_with<T>(
&self,
types: T,
is_match: impl FnMut(&[TypeId]) -> bool,
) -> Option<u32>where
T: ExactSizeIterator<Item = TypeId>,
pub(crate) fn find_with<T>(
&self,
types: T,
is_match: impl FnMut(&[TypeId]) -> bool,
) -> Option<u32>where
T: ExactSizeIterator<Item = TypeId>,
The id of the archetype whose types are types as is_match reads
them, or None when no such archetype is registered.
This is the allocation-free lookup: the type sequence is hashed as it is iterated and compared in place, so a caller that holds the types apart rather than in one slice builds no key for a hit. The hash comes from the map’s own hasher, so it always agrees with how the stored keys were hashed.
Relies on hashbrown’s raw-entry feature: without it this does not
compile rather than silently missing every lookup.
Sourcepub(crate) fn register(&mut self, archetype: Archetype) -> u32
pub(crate) fn register(&mut self, archetype: Archetype) -> u32
Register a freshly built archetype and return its id.
Sourcepub fn get(&self, id: u32) -> Result<&Archetype, ArchetypeAccessError>
pub fn get(&self, id: u32) -> Result<&Archetype, ArchetypeAccessError>
The archetype with this id.
An id is only minted when an archetype is registered, so an id that names
nothing came from another world or from arithmetic on a u32; either
way it answers ArchetypeAccessError::NoSuchArchetype rather than
quietly naming no archetype.
Sourcepub(crate) fn get_mut(
&mut self,
id: u32,
) -> Result<&mut Archetype, ArchetypeAccessError>
pub(crate) fn get_mut( &mut self, id: u32, ) -> Result<&mut Archetype, ArchetypeAccessError>
The archetype with this id, mutably. See Archetypes::get.
Sourcepub fn as_slice(&self) -> &[Archetype]
pub fn as_slice(&self) -> &[Archetype]
Every archetype, as a slice.
An archetype’s id is its position in this slice, which is what
crate::Location::archetype and Archetype::names are read
against.