pub struct Registry { /* private fields */ }
Expand description
The primary construct in the Shard Entity Component System (ECS).
Implementations
sourceimpl Registry
impl Registry
sourcepub fn create_entity<'c, G: ComponentGroup>(
&mut self,
components: G
) -> Result<Entity, G>
pub fn create_entity<'c, G: ComponentGroup>(
&mut self,
components: G
) -> Result<Entity, G>
Creates a new entity using the provided components. Returns Ok with a Entity if successful, or Err(components) if not. Returns Err if the provided component group is invalid or an internal limit is exceeded. Panics in case of allocation failure.
sourcepub fn destroy_entity(&mut self, entity: Entity) -> bool
pub fn destroy_entity(&mut self, entity: Entity) -> bool
Removes the entity from the registry. This function return false if the entity given is invalid.
sourcepub fn remove_entity<'a, G: ComponentGroup>(
&'a mut self,
entity: Entity
) -> Option<G>
pub fn remove_entity<'a, G: ComponentGroup>(
&'a mut self,
entity: Entity
) -> Option<G>
Removes the entity from the registry if it matches the given component group exactly. Otherwise, it simply leaves the entity as is. This function return None if either entity given is invalid, or does not match the given component group.
sourcepub fn has_component<C: Component>(&self, entity: Entity) -> bool
pub fn has_component<C: Component>(&self, entity: Entity) -> bool
Returns true if a given entity has the specified component. Returns false if entity is invalid or does not have the specified component.
sourcepub fn has_components<'registry, G: ComponentGroup>(
&'registry self,
entity: Entity
) -> bool
pub fn has_components<'registry, G: ComponentGroup>(
&'registry self,
entity: Entity
) -> bool
Returns true if a given entity has all of the specified components.
Returns false if entity is invalid or does not have all of the specified components.
If you need to check for only a single components, prefer to use Registry::has_component
instead.
sourcepub fn get_component<C: Component>(&self, entity: Entity) -> Option<&C>
pub fn get_component<C: Component>(&self, entity: Entity) -> Option<&C>
Returns a reference to the specified component if the entity has it. Returns false if entity is invalid or does not have the specified component.
sourcepub fn get_components<'registry, G: ComponentGroup>(
&'registry self,
entity: Entity
) -> Option<G::RefTuple<'registry>>
pub fn get_components<'registry, G: ComponentGroup>(
&'registry self,
entity: Entity
) -> Option<G::RefTuple<'registry>>
Returns a tuple of references to the specified components if the entity has all of them.
Returns false if entity is invalid or does not have the specified components.
If you need to get only a single component, use Registry::get_component
instead.
sourcepub fn get_component_mut<C: Component>(
&mut self,
entity: Entity
) -> Option<&mut C>
pub fn get_component_mut<C: Component>(
&mut self,
entity: Entity
) -> Option<&mut C>
Returns a mutable reference to the specified component if the entity has it.
Returns false if entity is invalid or does not have the specified component.
If you need to get only a single component, use Registry::get_component_mut
instead.
sourcepub fn get_components_mut<'registry, G: ComponentGroup>(
&'registry mut self,
entity: Entity
) -> Option<G::MutRefTuple<'registry>>
pub fn get_components_mut<'registry, G: ComponentGroup>(
&'registry mut self,
entity: Entity
) -> Option<G::MutRefTuple<'registry>>
Returns a tuple of mutable references to the specified components if the entity has all of them. Returns false if entity is invalid or does not have the specified components.
sourcepub fn add_component<C: Component>(
&mut self,
entity: Entity,
component: C
) -> Result<(), C>
pub fn add_component<C: Component>(
&mut self,
entity: Entity,
component: C
) -> Result<(), C>
Adds a given component to the entity if it’s not yet present. Returns the original component in case of failure for any reason. Reasons for failure:
- Invalid entity provided.
- Destination archetype could not be created.
sourceimpl Registry
impl Registry
sourcepub fn iter_entities(&self) -> impl Iterator<Item = Entity> + '_
pub fn iter_entities(&self) -> impl Iterator<Item = Entity> + '_
Returns an iterator which iterates over all entities in the registry.
sourcepub fn iter_components_matching<'registry, G: ComponentGroup>(
&'registry self
) -> impl Iterator<Item = <G as ComponentGroup>::SliceRefTuple<'registry>> + 'registry
pub fn iter_components_matching<'registry, G: ComponentGroup>(
&'registry self
) -> impl Iterator<Item = <G as ComponentGroup>::SliceRefTuple<'registry>> + 'registry
Returns an iterator which iterates over all components in archetypes matching the specified predicate.
sourcepub fn iter_components_matching_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> impl Iterator<Item = <G as ComponentGroup>::SliceMutRefTuple<'registry>> + 'registry
pub fn iter_components_matching_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> impl Iterator<Item = <G as ComponentGroup>::SliceMutRefTuple<'registry>> + 'registry
Returns an iterator which mutably iterates over all components in archetypes matching the specified predicate.
sourcepub fn iter_entity_components_matching<'registry, G: ComponentGroup>(
&'registry self
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)> + 'registry
pub fn iter_entity_components_matching<'registry, G: ComponentGroup>(
&'registry self
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)> + 'registry
Returns an iterator which iterates over all entities and components in archetypes matching the specified predicate.
sourcepub fn iter_entity_components_matching_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)> + 'registry
pub fn iter_entity_components_matching_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)> + 'registry
Returns an iterator which mutably iterates over all entities and components in archetypes matching the specified predicate.
sourcepub fn iter_filtered_components_matching<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry self,
filter_closure: F
) -> impl Iterator<Item = <G as ComponentGroup>::SliceRefTuple<'registry>> + 'registry
pub fn iter_filtered_components_matching<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry self,
filter_closure: F
) -> impl Iterator<Item = <G as ComponentGroup>::SliceRefTuple<'registry>> + 'registry
Returns an iterator which iterates over all components in archetypes matching the specified predicate. Archetypes not matching the filter closure are excluded.
sourcepub fn iter_filtered_components_matching_mut<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry mut self,
filter_closure: F
) -> impl Iterator<Item = <G as ComponentGroup>::SliceMutRefTuple<'registry>> + 'registry
pub fn iter_filtered_components_matching_mut<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry mut self,
filter_closure: F
) -> impl Iterator<Item = <G as ComponentGroup>::SliceMutRefTuple<'registry>> + 'registry
Returns an iterator which mutably iterates over all components in archetypes matching the specified predicate. Archetypes not matching the filter closure are excluded.
sourcepub fn iter_filtered_entity_components_matching<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry self,
filter_closure: F
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)> + 'registry
pub fn iter_filtered_entity_components_matching<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry self,
filter_closure: F
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)> + 'registry
Returns an iterator which iterates over all entities and components in archetypes matching the specified predicate. Archetypes not matching the filter closure are excluded.
sourcepub fn iter_filtered_entity_components_matching_mut<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry mut self,
filter_closure: F
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)> + 'registry
pub fn iter_filtered_entity_components_matching_mut<'registry, G: ComponentGroup, F: Fn(&ArchetypeDescriptor) -> bool + 'registry>(
&'registry mut self,
filter_closure: F
) -> impl Iterator<Item = (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)> + 'registry
Returns an iterator which mutably iterates over all entities and components in archetypes matching the specified predicate. Archetypes not matching the filter closure are excluded.
sourcepub fn iter_components_exact<'registry, G: ComponentGroup>(
&'registry self
) -> <G as ComponentGroup>::SliceRefTuple<'registry>
pub fn iter_components_exact<'registry, G: ComponentGroup>(
&'registry self
) -> <G as ComponentGroup>::SliceRefTuple<'registry>
Returns a tuple of component slices if the exact archetype matching the predicate exists.
sourcepub fn iter_components_exact_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> <G as ComponentGroup>::SliceMutRefTuple<'registry>
pub fn iter_components_exact_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> <G as ComponentGroup>::SliceMutRefTuple<'registry>
Returns a tuple of mutable component slices if the exact archetype matching the predicate exists.
sourcepub fn iter_entity_components_exact<'registry, G: ComponentGroup>(
&'registry self
) -> (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)
pub fn iter_entity_components_exact<'registry, G: ComponentGroup>(
&'registry self
) -> (&'registry [Entity], <G as ComponentGroup>::SliceRefTuple<'registry>)
Returns a tuple of an entity slice and component slices if the exact archetype matching the predicate exists.
sourcepub fn iter_entity_components_exact_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)
pub fn iter_entity_components_exact_mut<'registry, G: ComponentGroup>(
&'registry mut self
) -> (&'registry [Entity], <G as ComponentGroup>::SliceMutRefTuple<'registry>)
Returns a tuple of an entity slice and mutable component slices if the exact archetype matching the predicate exists.