My Project
Public Member Functions | List of all members
Registry Class Reference

Class that handle ECS. More...

#include <Registry.hpp>

Public Member Functions

 Registry ()=default
 Construct a new Registry object.
 
 Registry (std::size_t nbEntities)
 Construct a new Registry object. More...
 
virtual ~Registry ()=default
 Destroy the Registry object.
 
template<class Component >
Sparse_array< Component > & register_component ()
 A method to register a component to the registry, it inserts it inside the various arrays contained in the object. More...
 
template<class Component >
Sparse_array< Component > & get_components ()
 Get the components object. More...
 
template<class Component >
const Sparse_array< Component > & get_components () const
 Get the components object. More...
 
Entity spawn_entity ()
 A method to spawn an entity, it adds it to the creators array. More...
 
template<class ... Components>
Entity spawn_entity_with (Components &&...components)
 A method that create an entity and add all components you want to it. More...
 
Entity entity_from_index (std::size_t idx) const
 A method to get an entity with its index. More...
 
void kill_entity (Entity const &e)
 A method to kill an entity. More...
 
template<typename Component >
Sparse_array< Component >::reference_type add_component (Entity const &e, Component &&c)
 A method to add a component to a known sparse array. More...
 
template<typename Component , typename ... Params>
Sparse_array< Component >::reference_type emplace_component (Entity const &to, Params &&...p)
 A method to add a component at a position int the sparse array, a sparse array means that some cells mey be empty. More...
 
template<typename Component >
void remove_component (Entity const &from)
 A method to remove a component from an entity. More...
 
template<class ... Component, typename Function >
void add_system (Function &&f)
 A method to add a system to the registry, adds the element to the list of systems of the registry. More...
 
template<class ... Component, typename Function >
void add_system (Function const &f)
 A method to add a system to the registry, adds the element to the list of systems of the registry. More...
 
void run_systems ()
 A method that is used to run all the systems of the registry.
 

Detailed Description

Class that handle ECS.

Constructor & Destructor Documentation

◆ Registry()

Registry::Registry ( std::size_t  nbEntities)
inlineexplicit

Construct a new Registry object.

Parameters
nbEntities

Member Function Documentation

◆ add_component()

template<typename Component >
Sparse_array<Component>::reference_type Registry::add_component ( Entity const &  e,
Component &&  c 
)
inline

A method to add a component to a known sparse array.

Template Parameters
ComponentType of component That Entity will have
Parameters
eEntity which component will be added
cComponent to add in Entity
Returns
Sparse_array<Component>::reference_type The Sparse Array of the component that had be added

◆ add_system() [1/2]

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

A method to add a system to the registry, adds the element to the list of systems of the registry.

Template Parameters
ComponentType of component
FunctionType of System function to add
Parameters
fSystem function to add

◆ add_system() [2/2]

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

A method to add a system to the registry, adds the element to the list of systems of the registry.

Template Parameters
ComponentType of component
FunctionType of System function to add
Parameters
fSystem function to add

◆ emplace_component()

template<typename Component , typename ... Params>
Sparse_array<Component>::reference_type Registry::emplace_component ( Entity const &  to,
Params &&...  p 
)
inline

A method to add a component at a position int the sparse array, a sparse array means that some cells mey be empty.

Template Parameters
ComponentType of component
ParamsParams to emplace at the Entity
Parameters
toEntity which component will be added
pParams to emplace at the Entity
Returns
Sparse_array<Component>::reference_type The Sparse Array of the component that had be added

◆ entity_from_index()

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

A method to get an entity with its index.

Parameters
idxIndex of the entity
Returns
Entity Entity at index

◆ get_components() [1/2]

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

Get the components object.

Template Parameters
ComponentType of component to get in Sparse Array list
Returns
Sparse_array<Component>& The Sparse Array of the component

◆ get_components() [2/2]

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

Get the components object.

Template Parameters
ComponentType of component to get in Sparse Array list
Returns
Sparse_array<Component> const& The Sparse Array of the component

◆ kill_entity()

void Registry::kill_entity ( Entity const &  e)
inline

A method to kill an entity.

Parameters
eEntity to kill

◆ register_component()

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

A method to register a component to the registry, it inserts it inside the various arrays contained in the object.

Template Parameters
ComponentType of component to add in Sparse Array list
Returns
Sparse_array<Component>& The new Sparse Array of the component

◆ remove_component()

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

A method to remove a component from an entity.

Template Parameters
ComponentType of component
Parameters
fromEntity where the component will be removed

◆ spawn_entity()

Entity Registry::spawn_entity ( )
inline

A method to spawn an entity, it adds it to the creators array.

Returns
Entity The new entity created

◆ spawn_entity_with()

template<class ... Components>
Entity Registry::spawn_entity_with ( Components &&...  components)
inline

A method that create an entity and add all components you want to it.

Template Parameters
ComponentsType of component That Entity will have
Parameters
componentsComponent That Entity will have
Returns
Entity The new entity created

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