|
R-Type
2
Doom but in better
|
Manages entities and their associated components, enabling the creation, deletion, and interaction of entities within a system. More...
#include <Registry.hpp>

Public Types | |
| template<typename Component > | |
| using | reference = typename ComponentContainer<Component>::reference |
| A type alias for a reference to a component in a ComponentContainer. | |
| using | eraseFunc = std::function<void(Entity const&)> |
| A function type for erasing components associated with an entity. | |
Public Member Functions | |
| Registry (EventDispatcher *_dispatcher, Queue *_queue) | |
| Default constructor. | |
| template<typename... Components, typename Function > | |
| void | add_system (Function &&f) |
| Adds a system to the registry. | |
| void | run_systems () |
| Executes all registered systems. | |
| std::vector< GameMessage > | sync_game () |
| Creates a list of GameMessages that syncs the player to the game. | |
| template<class Component > | |
| ComponentContainer< Component > & | register_component () |
| Registers a new component type. | |
| template<typename... Components> | |
| std::tuple< ComponentContainer< Components > &... > | get_component_array () |
| Retrieves component containers for multiple component types. | |
| template<class Component > | |
| ComponentContainer< Component > & | get_components () |
| Retrieves the component container for a specific type. | |
| template<typename Component > | |
| reference< Component > | add_component (const Entity &entity, Component &&component) |
| Adds a component to an entity. | |
| template<typename Component , typename... Params> | |
| reference< Component > | emplace_component (const Entity &entity, Params &&... params) |
| Emplaces a component for an entity with constructor parameters. | |
| template<typename Component > | |
| void | remove_component (const Entity &entity) |
| Removes a component from an entity. | |
| Entity | spawn_entity () |
| Creates a new entity. | |
| Entity | entity_from_index (std::size_t idx) const |
| Retrieves an entity by its index. | |
| void | kill_entity (const Entity &entity) |
| Deletes an entity and removes all its components. | |
Data Fields | |
| EventDispatcher * | dispatcher |
| Queue * | queue |
Manages entities and their associated components, enabling the creation, deletion, and interaction of entities within a system.
The Registry class acts as the core of an ECS (Entity-Component-System) architecture, handling the registration of components, the spawning and killing of entities, and the execution of systems.
Definition at line 23 of file Registry.hpp.
| using Registry::eraseFunc = std::function<void(Entity const&)> |
A function type for erasing components associated with an entity.
Definition at line 38 of file Registry.hpp.
| using Registry::reference = typename ComponentContainer<Component>::reference |
A type alias for a reference to a component in a ComponentContainer.
| Component | The component type. |
Definition at line 32 of file Registry.hpp.
| Registry::Registry | ( | EventDispatcher * | _dispatcher, |
| Queue * | _queue ) |
Default constructor.
Definition at line 3 of file Registry.cpp.
|
inline |
Adds a component to an entity.
| Component | The component type. |
| entity | The entity to add the component to. |
| component | The component to add. |
Definition at line 134 of file Registry.hpp.
|
inline |
Adds a system to the registry.
A system is a function that operates on entities and their components.
| Components | The types of components required by the system. |
| Function | The type of the system function. |
| f | The system function to add. |
Definition at line 55 of file Registry.hpp.
|
inline |
Emplaces a component for an entity with constructor parameters.
| Component | The component type. |
| Params | The parameter types for the component's constructor. |
| entity | The entity to add the component to. |
| params | The parameters for constructing the component. |
Definition at line 150 of file Registry.hpp.
| Entity Registry::entity_from_index | ( | std::size_t | idx | ) | const |
Retrieves an entity by its index.
| idx | The index of the entity. |
Definition at line 30 of file Registry.cpp.
|
inline |
Retrieves component containers for multiple component types.
| Components | The component types. |
Definition at line 110 of file Registry.hpp.
|
inline |
Retrieves the component container for a specific type.
| Component | The component type. |
Definition at line 121 of file Registry.hpp.
| void Registry::kill_entity | ( | const Entity & | entity | ) |
Deletes an entity and removes all its components.
| entity | The entity to delete. |
Definition at line 35 of file Registry.cpp.
|
inline |
Registers a new component type.
| Component | The component type to register. |
Definition at line 85 of file Registry.hpp.
|
inline |
Removes a component from an entity.
| Component | The component type. |
| entity | The entity to remove the component from. |
Definition at line 163 of file Registry.hpp.
| void Registry::run_systems | ( | ) |
Executes all registered systems.
Definition at line 11 of file Registry.cpp.
| Entity Registry::spawn_entity | ( | ) |
| std::vector< GameMessage > Registry::sync_game | ( | ) |
Creates a list of GameMessages that syncs the player to the game.
Definition at line 18 of file Registry.cpp.
| EventDispatcher* Registry::dispatcher |
Definition at line 191 of file Registry.hpp.
| Queue* Registry::queue |
Definition at line 192 of file Registry.hpp.