R-Type  2
Doom but in better
Loading...
Searching...
No Matches
Registry Class Reference

Manages entities and their associated components, enabling the creation, deletion, and interaction of entities within a system. More...

#include <Registry.hpp>

Collaboration diagram for Registry:
Collaboration graph

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< GameMessagesync_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

EventDispatcherdispatcher
 
Queuequeue
 

Detailed Description

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.

Member Typedef Documentation

◆ eraseFunc

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.

◆ reference

template<typename Component >
using Registry::reference = typename ComponentContainer<Component>::reference

A type alias for a reference to a component in a ComponentContainer.

Template Parameters
ComponentThe component type.

Definition at line 32 of file Registry.hpp.

Constructor & Destructor Documentation

◆ Registry()

Registry::Registry ( EventDispatcher * _dispatcher,
Queue * _queue )

Default constructor.

Definition at line 3 of file Registry.cpp.

Member Function Documentation

◆ add_component()

template<typename Component >
reference< Component > Registry::add_component ( const Entity & entity,
Component && component )
inline

Adds a component to an entity.

Template Parameters
ComponentThe component type.
Parameters
entityThe entity to add the component to.
componentThe component to add.
Returns
A reference to the added component.

Definition at line 134 of file Registry.hpp.

◆ add_system()

template<typename... Components, typename Function >
void Registry::add_system ( Function && f)
inline

Adds a system to the registry.

A system is a function that operates on entities and their components.

Template Parameters
ComponentsThe types of components required by the system.
FunctionThe type of the system function.
Parameters
fThe system function to add.

Definition at line 55 of file Registry.hpp.

◆ emplace_component()

template<typename Component , typename... Params>
reference< Component > Registry::emplace_component ( const Entity & entity,
Params &&... params )
inline

Emplaces a component for an entity with constructor parameters.

Template Parameters
ComponentThe component type.
ParamsThe parameter types for the component's constructor.
Parameters
entityThe entity to add the component to.
paramsThe parameters for constructing the component.
Returns
A reference to the added component.

Definition at line 150 of file Registry.hpp.

◆ entity_from_index()

Entity Registry::entity_from_index ( std::size_t idx) const

Retrieves an entity by its index.

Parameters
idxThe index of the entity.
Returns
The entity corresponding to the given index.

Definition at line 30 of file Registry.cpp.

◆ get_component_array()

template<typename... Components>
std::tuple< ComponentContainer< Components > &... > Registry::get_component_array ( )
inline

Retrieves component containers for multiple component types.

Template Parameters
ComponentsThe component types.
Returns
A tuple containing references to the component containers.

Definition at line 110 of file Registry.hpp.

◆ get_components()

template<class Component >
ComponentContainer< Component > & Registry::get_components ( )
inline

Retrieves the component container for a specific type.

Template Parameters
ComponentThe component type.
Returns
A reference to the component container.

Definition at line 121 of file Registry.hpp.

◆ kill_entity()

void Registry::kill_entity ( const Entity & entity)

Deletes an entity and removes all its components.

Parameters
entityThe entity to delete.

Definition at line 35 of file Registry.cpp.

◆ register_component()

template<class Component >
ComponentContainer< Component > & Registry::register_component ( )
inline

Registers a new component type.

Template Parameters
ComponentThe component type to register.
Returns
A reference to the component container for the given type.

Definition at line 85 of file Registry.hpp.

◆ remove_component()

template<typename Component >
void Registry::remove_component ( const Entity & entity)
inline

Removes a component from an entity.

Template Parameters
ComponentThe component type.
Parameters
entityThe entity to remove the component from.

Definition at line 163 of file Registry.hpp.

◆ run_systems()

void Registry::run_systems ( )

Executes all registered systems.

Definition at line 11 of file Registry.cpp.

◆ spawn_entity()

Entity Registry::spawn_entity ( )

Creates a new entity.

Returns
The newly created entity.

Definition at line 23 of file Registry.cpp.

◆ sync_game()

std::vector< GameMessage > Registry::sync_game ( )

Creates a list of GameMessages that syncs the player to the game.

Returns
A vector with GameMessages of the current game state.

Definition at line 18 of file Registry.cpp.

Field Documentation

◆ dispatcher

EventDispatcher* Registry::dispatcher

Definition at line 191 of file Registry.hpp.

◆ queue

Queue* Registry::queue

Definition at line 192 of file Registry.hpp.


The documentation for this class was generated from the following files: