ecs::Registry

More...

#include <Registry.hpp>

Public Functions

Name

template <class Component > SparseArray< Component > &

template <class Component > SparseArray< Component > &

template <class Component > SparseArray< Component > const &

entityFromIndex(std::size_t idx)

void

killEntity(Entity const & e)

template <typename Component > SparseArray< Component >::referenceType

addComponent(Entity const & to, Component && c)

template <typename Component ,typename... Params> SparseArray< Component >::referenceType

emplaceComponent(Entity const & to, Params &&... p)

template <typename Component > void

removeComponent(Entity const & from)

Detailed Description

class ecs::Registry;

[This is the core of the ECS]

This class contains many feature as follows :

  • Component Manager, Registry is able to register/get components from the unordered map

  • Entity Manager, Registry is able to create/delete and add component to an Entity

(Feel free to check the Entity.hpp to learn more about the subject)

  • EntitiesBin Manager, Registry is saving killed entity in the bin that which can be recovered instead of creating another one

Public Functions Documentation

function Registry

inline Registry()

function registerComponent

template <class Component >
inline SparseArray< Component > & registerComponent()

Template Parameters:

  • Component The type of components you want to register

Return: The SparseArray of components you just registered

This function is used to register a new component in the private member _unordered_map

function getComponents

template <class Component >
inline SparseArray< Component > & getComponents()

Template Parameters:

  • Component The type of components you want to get

Return: The SparseArray of components you asked

This function is used to get all components already registered in the Registry class following the given component template

function getComponents

template <class Component >
inline SparseArray< Component > const & getComponents() const

Template Parameters:

  • Component The type of components you want to get

Return: The const SparseArray of components you asked

This function is used to get all components already registered in the Registry class following the given component template as const

function spawn_entity

inline Entity spawn_entity()

Return: The entity just created (id)

This function is used to create a new entity if it doesn't exists in the _entitiesBin, otherwise it recover it from the bin

function entityFromIndex

inline Entity entityFromIndex(
    std::size_t idx
)

Parameters:

  • idx The index of the entity whose id is desired

Return: The id of the Entity if it exists, ecs::npos otherwise

This function is used to get the id of the Entity following the give index

function killEntity

inline void killEntity(
    Entity const & e
)

Parameters:

This is used to delete the given Entity (id) For optimisation purposes, Registry class push it in the _entitiesBin

function addComponent

template <typename Component >
inline SparseArray< Component >::referenceType addComponent(
    Entity const & to,
    Component && c
)

Parameters:

  • to The Entity in which you want to add component

  • c The component you want to add

Template Parameters:

  • Component The type of component want to be added

Return: the SparseArray reference of the component

This function is used to add a component into the Entity given as parameter. In the same time, the erase function of this component is pushed into the _eraseFunctions vector, in this case we can simply delete a component without needing type of it

function emplaceComponent

template <typename Component ,
typename... Params>
inline SparseArray< Component >::referenceType emplaceComponent(
    Entity const & to,
    Params &&... p
)

Parameters:

  • to The Entity in which you want to emplace component

  • p Parameters of the component you want to emplace

Template Parameters:

  • Component The type of component you want to emplace

  • Params The parameters' type of the component you want to emplace

Return: the SparseArray reference of the component

This function is used to emplace a component with given parameters of this component

function removeComponent

template <typename Component >
inline void removeComponent(
    Entity const & from
)

Parameters:

  • from The Entity in which you want to remove component

Template Parameters:

  • Component The type of the component you want to remove

This function is used to remove a component into an Entity given as parameter


Updated on 2022-11-13 at 17:21:37 +0100

Last updated