R-Type
Public Member Functions | Friends | List of all members
GameEngine::Registry Class Reference

Entity component system, handling entities, components and systems. More...

#include <Registry.hpp>

Public Member Functions

 Registry (const std::size_t maxEntities)
 Constructor. More...
 
template<class Component >
SparseArray< Component > & registerComponent ()
 Register a new component to the registry. More...
 
template<class Component >
SparseArray< Component > & getComponent ()
 Getter to a speecific component's SparseArray. More...
 
template<class Component >
const SparseArray< Component > & getComponent () const
 Getter to a speecific component's SparseArray. More...
 
Entity spawnEntity ()
 Spawns a new entity. Entities can't be spawned otherwise. More...
 
Entity spawnEntity (const std::size_t &id)
 Spawns a new entity. Entities can't be spawned otherwise. More...
 
Entity getEntityById (const std::size_t &id) const
 Getter for an entity at a given index. Will throw an error if the entity hasn't been spawned. More...
 
void killEntity (const Entity &entity)
 Kills the entity given, it destroys all the components to this entity. More...
 
template<typename Component >
SparseArray< Component >::referenceType addComponent (const Entity &entity, Component &&component)
 Add a component to the entity given. More...
 
template<typename Component >
SparseArray< Component >::referenceType addComponent (const Entity &entity, const Component &component)
 Add a component to the entity given. More...
 
template<typename Component , typename... Params>
SparseArray< Component >::referenceType emplaceComponent (const Entity &entity, Params &&...params)
 Emplace the component type to the entities given. More...
 
template<typename Component >
void removeComponent (const Entity &entity)
 Removes a component to the specified entity. More...
 
template<typename Component >
bool isComponentRegistered ()
 tells if a component is registered More...
 
template<typename Function , class... Components>
void addSystem (const Function &function)
 Adds a system to the registry. The system function can take reference to some component's SparseArrays, they will be automatically get. More...
 
template<typename SystemClass , class... Components>
void addSystem (std::shared_ptr< SystemClass > systemClass)
 Adds a system to the registry. This method is to use when the class system needs to stay at the same place in the memory (for example DrawSystem) More...
 
void runSystems ()
 Runs all the registered system functions. Need to be called in the main loop. More...
 

Friends

class Debug::DebugMenu
 

Detailed Description

Entity component system, handling entities, components and systems.

Constructor & Destructor Documentation

◆ Registry()

GameEngine::Registry::Registry ( const std::size_t  maxEntities)
inline

Constructor.

Parameters
maxEntitiesMaximum amount of entities at once. Will set the maximum size for the components array.

Member Function Documentation

◆ addComponent() [1/2]

template<typename Component >
SparseArray<Component>::referenceType GameEngine::Registry::addComponent ( const Entity entity,
Component &&  component 
)
inline

Add a component to the entity given.

Template Parameters
Componenttype of the component to add to the entity.
Parameters
entityEntity on which the component will be added.
componentComponent to add to the entity. The component will be moved.
Returns
A reference to the component.

◆ addComponent() [2/2]

template<typename Component >
SparseArray<Component>::referenceType GameEngine::Registry::addComponent ( const Entity entity,
const Component &  component 
)
inline

Add a component to the entity given.

Template Parameters
Componenttype of the component to add to the entity.
Parameters
entityEntity on which the component will be added.
componentComponent to add to the entity. The component will be copied.
Returns
A reference to the component.

◆ addSystem() [1/2]

template<typename Function , class... Components>
void GameEngine::Registry::addSystem ( const Function &  function)
inline

Adds a system to the registry. The system function can take reference to some component's SparseArrays, they will be automatically get.

Template Parameters
Functiontype of the system function to registeru
...ComponentsVariadic template for the components which are in parameter of the system function.
Parameters
functionSystem function to register.

◆ addSystem() [2/2]

template<typename SystemClass , class... Components>
void GameEngine::Registry::addSystem ( std::shared_ptr< SystemClass >  systemClass)
inline

Adds a system to the registry. This method is to use when the class system needs to stay at the same place in the memory (for example DrawSystem)

Template Parameters
SystemClassClass of the system to register, must have an overload for the ()
...ComponentsVariadic template for the components which are in parameter of the system function.
Parameters
systemClassSystem class to register.

◆ emplaceComponent()

template<typename Component , typename... Params>
SparseArray<Component>::referenceType GameEngine::Registry::emplaceComponent ( const Entity entity,
Params &&...  params 
)
inline

Emplace the component type to the entities given.

Template Parameters
Componenttype of the component to emplace to the entities.
...ParamsVariadic parameters of Entities to emplace the component to.
Parameters
entityFirst entity to emplace.
...paramsVariadic parameter of entities.
Returns
A reference to the component of the first entity.

◆ getComponent() [1/2]

template<class Component >
SparseArray<Component>& GameEngine::Registry::getComponent ( )
inline

Getter to a speecific component's SparseArray.

Template Parameters
Componenttype of the component to get
Returns
A reference to the component's SparseArray

◆ getComponent() [2/2]

template<class Component >
const SparseArray<Component>& GameEngine::Registry::getComponent ( ) const
inline

Getter to a speecific component's SparseArray.

Template Parameters
Componenttype of the component to get
Returns
A constant reference to the component's SparseArray

◆ getEntityById()

Entity GameEngine::Registry::getEntityById ( const std::size_t &  id) const
inline

Getter for an entity at a given index. Will throw an error if the entity hasn't been spawned.

Parameters
idIndex of the entity.
Returns
The entity at the given index.

◆ isComponentRegistered()

template<typename Component >
bool GameEngine::Registry::isComponentRegistered ( )
inline

tells if a component is registered

Template Parameters
Componentcomponent to find
Returns
boolean indicating whether the component is registered

◆ killEntity()

void GameEngine::Registry::killEntity ( const Entity entity)
inline

Kills the entity given, it destroys all the components to this entity.

Parameters
entityEntity to kill.

◆ registerComponent()

template<class Component >
SparseArray<Component>& GameEngine::Registry::registerComponent ( )
inline

Register a new component to the registry.

Template Parameters
Componenttype of the component to register
Returns
A reference to the register component's SparseArray

◆ removeComponent()

template<typename Component >
void GameEngine::Registry::removeComponent ( const Entity entity)
inline

Removes a component to the specified entity.

Template Parameters
Componenttype of the component to remove.
Parameters
entityEntity to remove the component from.

◆ runSystems()

void GameEngine::Registry::runSystems ( )
inline

Runs all the registered system functions. Need to be called in the main loop.

◆ spawnEntity() [1/2]

Entity GameEngine::Registry::spawnEntity ( )
inline

Spawns a new entity. Entities can't be spawned otherwise.

Returns
The spawned entity.

◆ spawnEntity() [2/2]

Entity GameEngine::Registry::spawnEntity ( const std::size_t &  id)
inline

Spawns a new entity. Entities can't be spawned otherwise.

Parameters
idId of the entity to spawn.
Returns
The spawned entity.

Friends And Related Function Documentation

◆ Debug::DebugMenu

friend class Debug::DebugMenu
friend

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