Coordinates entities and components, providing creation, removal, lookup, and views.
More...
#include <Registry.hpp>
|
| class | View |
| | Zero-allocation filtered view over entities containing a specific set of components. More...
|
|
| | Registry ()=default |
| | Construct a new Registry object.
|
| Entity | create () |
| | Creates a new entity.
|
| void | destroy (Entity e) |
| | Destroys an entity, removing all its components.
|
| void | clear () |
| | Destroys all entities and clears all component storages.
|
| bool | isValid (Entity e) const |
| | Checks if an entity is alive and valid.
|
| template<typename T> |
| T & | emplace (Entity e, T &&comp) |
| | Emplaces a component on an entity.
|
| template<typename T> |
| void | remove (Entity e) |
| | Removes a component of type T from an entity.
|
| template<typename T> |
| T * | get (Entity e) |
| | Retrieves a pointer to a component of type T on an entity.
|
| template<typename T> |
| T & | getRef (Entity e) |
| | Retrieves a reference to a component of type T on an entity. Throws if missing.
|
| template<typename T> |
| bool | has (Entity e) |
| | Checks if an entity possesses a component of type T.
|
| template<typename T> |
| void | subscribeToAdded (ComponentAddedCallback cb) |
| | Subscribes a callback to when a component of type T is added.
|
| template<typename T> |
| void | subscribeToRemoved (ComponentRemovedCallback cb) |
| | Subscribes a callback to when a component of type T is removed.
|
| template<typename... Components> |
| auto | view () |
| | Generates a filtered view of entities containing the requested components.
|
|
| template<typename T> |
| void | ensureStorage () |
| | Ensures a component storage exists.
|
| template<typename T> |
| ComponentStorage< T > * | getStorage () |
| | Retrieves storage class for component type.
|
| template<typename... Components> |
| void | ensureStorages () |
| | Ensures all given component type storages exist.
|
| template<typename T> |
| IStorage * | getSmallestStorage () |
| | Base case for retrieving smallest storage from parameter pack.
|
| template<typename First, typename Second, typename... Rest> |
| IStorage * | getSmallestStorage () |
| | Recursively determines smallest storage among requested components.
|
Coordinates entities and components, providing creation, removal, lookup, and views.
◆ ComponentAddedCallback
Callback function type invoked when a component is added.
◆ ComponentRemovedCallback
Callback function type invoked when a component is removed.
◆ Registry()
◆ clear()
Destroys all entities and clears all component storages.
◆ create()
Creates a new entity.
- Returns
- The created entity.
◆ destroy()
| void Registry::destroy |
( |
Entity | e | ) |
|
|
inline |
Destroys an entity, removing all its components.
- Parameters
-
◆ emplace()
template<typename T>
| T & Registry::emplace |
( |
Entity | e, |
|
|
T && | comp ) |
|
inline |
Emplaces a component on an entity.
- Template Parameters
-
| T | Component type to emplace. |
- Parameters
-
| e | Entity to emplace component on. |
| comp | Component instance to add. |
- Returns
- Reference to the emplaced component.
◆ ensureStorage()
template<typename T>
| void Registry::ensureStorage |
( |
| ) |
|
|
inlineprivate |
Ensures a component storage exists.
- Template Parameters
-
◆ ensureStorages()
template<typename... Components>
| void Registry::ensureStorages |
( |
| ) |
|
|
inlineprivate |
Ensures all given component type storages exist.
- Template Parameters
-
| Components | Pack of component types. |
◆ get()
Retrieves a pointer to a component of type T on an entity.
- Template Parameters
-
- Parameters
-
- Returns
- Pointer to the component, or nullptr if not found.
◆ getRef()
template<typename T>
| T & Registry::getRef |
( |
Entity | e | ) |
|
|
inline |
Retrieves a reference to a component of type T on an entity. Throws if missing.
- Template Parameters
-
- Parameters
-
- Returns
- Reference to the component.
◆ getSmallestStorage() [1/2]
template<typename First, typename Second, typename... Rest>
| IStorage * Registry::getSmallestStorage |
( |
| ) |
|
|
inlineprivate |
Recursively determines smallest storage among requested components.
- Template Parameters
-
| First | First type. |
| Second | Second type. |
| Rest | Remaining types. |
- Returns
- Base storage interface pointer of smallest storage.
◆ getSmallestStorage() [2/2]
template<typename T>
| IStorage * Registry::getSmallestStorage |
( |
| ) |
|
|
inlineprivate |
Base case for retrieving smallest storage from parameter pack.
- Template Parameters
-
- Returns
- Base storage interface.
◆ getStorage()
Retrieves storage class for component type.
- Template Parameters
-
- Returns
- Typed storage pointer, or nullptr if none.
◆ has()
template<typename T>
| bool Registry::has |
( |
Entity | e | ) |
|
|
inline |
Checks if an entity possesses a component of type T.
- Template Parameters
-
- Parameters
-
- Returns
- True if component exists, false otherwise.
◆ isValid()
| bool Registry::isValid |
( |
Entity | e | ) |
const |
|
inline |
Checks if an entity is alive and valid.
- Parameters
-
- Returns
- True if valid, false otherwise.
◆ remove()
template<typename T>
| void Registry::remove |
( |
Entity | e | ) |
|
|
inline |
Removes a component of type T from an entity.
- Template Parameters
-
| T | Component type to remove. |
- Parameters
-
◆ subscribeToAdded()
Subscribes a callback to when a component of type T is added.
- Template Parameters
-
- Parameters
-
◆ subscribeToRemoved()
Subscribes a callback to when a component of type T is removed.
- Template Parameters
-
- Parameters
-
◆ view()
template<typename... Components>
Generates a filtered view of entities containing the requested components.
- Template Parameters
-
| Components | Components to filter by. |
- Returns
- A View object.
◆ componentAddedCallbacks
Callbacks for component insertions.
◆ componentRemovedCallbacks
Callbacks for component removals.
◆ entities
◆ storages
| std::unordered_map<std::size_t, std::unique_ptr<IStorage> > Registry::storages |
|
private |
Map of component storage classes keyed by type ID.
The documentation for this class was generated from the following file: