Manages entities and their components in the ECS.
More...
#include <registry.hpp>
|
| Entity | createEntity () |
| | Create a new entity.
|
| template<typename Component> |
| void | addComponent (Entity e, Component c) |
| | Add a component to an entity.
|
| template<typename Component> |
| Component & | getComponent (Entity e) |
| | Get a component from an entity.
|
| template<typename Component> |
| bool | hasComponent (Entity e) |
| | Check if an entity has a specific component.
|
| template<typename... Components> |
| std::vector< Entity > | view () |
| | Get all entities that have all specified components.
|
| const auto & | getEntities () const |
|
| template<typename Component> |
| std::unordered_map< Entity, Component > & | getComponentStorage () |
| | Get or create the storage for a component type.
|
Manages entities and their components in the ECS.
◆ addComponent()
template<typename Component>
| void solarsim::Registry::addComponent |
( |
Entity | e, |
|
|
Component | c ) |
|
inline |
Add a component to an entity.
- Template Parameters
-
| Component | Type of component to add |
- Parameters
-
| e | Entity to add the component to |
| c | Component instance to add |
- Note
- Overwrites existing component of same type
- Warning
- Entity must exist (created via createEntity())
◆ createEntity()
| Entity solarsim::Registry::createEntity |
( |
| ) |
|
|
inlinenodiscard |
Create a new entity.
- Returns
- Entity The newly created entity ID
◆ getComponent()
template<typename Component>
| Component & solarsim::Registry::getComponent |
( |
Entity | e | ) |
|
|
inline |
Get a component from an entity.
- Template Parameters
-
| Component | Type of component to retrieve |
- Parameters
-
| e | Entity to get the component from |
- Returns
- Component& Reference to the component
- Exceptions
-
| std::out_of_range | if entity doesn't have the component |
◆ getComponentStorage()
template<typename Component>
| std::unordered_map< Entity, Component > & solarsim::Registry::getComponentStorage |
( |
| ) |
|
|
inlineprivate |
Get or create the storage for a component type.
- Template Parameters
-
| Component | Component type to get storage for |
- Returns
- std::unordered_map<Entity, Component>& Reference to the component storage
- Note
- Creates storage on first access for a component type
◆ getEntities()
| const auto & solarsim::Registry::getEntities |
( |
| ) |
const |
|
inline |
Get all entities currently in scene
- Returns
- std::unordered_seet<Entity> A set of all entities
◆ hasComponent()
template<typename Component>
| bool solarsim::Registry::hasComponent |
( |
Entity | e | ) |
|
|
inline |
Check if an entity has a specific component.
- Template Parameters
-
| Component | Type of component to check for |
- Parameters
-
- Returns
- bool True if entity has the component
◆ view()
template<typename... Components>
| std::vector< Entity > solarsim::Registry::view |
( |
| ) |
|
|
inlinenodiscard |
Get all entities that have all specified components.
- Template Parameters
-
| Components | Component types to filter by |
- Returns
- std::vector<Entity> Entities matching the component filter
◆ componentStorages
| std::unordered_map<std::type_index, std::unique_ptr<IComponentStorage> > solarsim::Registry::componentStorages |
|
private |
Type-indexed component storage
◆ entities
| std::unordered_set<Entity> solarsim::Registry::entities |
|
private |
Set of all active entities
◆ nextEntity
| uint32_t solarsim::Registry::nextEntity = 0 |
|
private |
The documentation for this class was generated from the following file: