Uranus  1.0.1.0
Uranus is a GameEngine written in C++
Loading...
Searching...
No Matches
uranus::ecs::Registry Class Reference

Registry class, used to store and manage entities and their components. More...

#include <Registry.hpp>

Collaboration diagram for uranus::ecs::Registry:
[legend]

Public Member Functions

template<typename Component >
SparseArray< Component >::ReferenceType addComponent (const Entity &to, Component &&c)
 Add a component to an entity. More...
 
template<typename Component , typename... Params>
SparseArray< Component >::ReferenceType emplaceComponent (const Entity &to, Params &&...p)
 Emplace a component to an entity. More...
 
int entitiesAliveCount () const
 Get the number of entities alive. More...
 
Entity entityFromIndex (std::size_t idx) const
 Create an entity from an index. More...
 
template<class Component >
SparseArray< Component >::ReferenceType getComponent (const Entity &e)
 Get a component from an entity. More...
 
template<class Component >
SparseArray< Component >::ConstReferenceType getComponent (const Entity &e) const
 Get a const component from an entity. More...
 
template<class Component >
SparseArray< Component >::ReferenceType getComponent (const size_t &e)
 Get a component from an index. More...
 
template<class Component >
SparseArray< Component >::ConstReferenceType getComponent (const size_t &e) const
 Get a const component from an index. More...
 
template<class Component >
SparseArray< Component > & getComponents ()
 Get the SparseArray of a component type. More...
 
template<class Component >
SparseArray< Component > const & getComponents () const
 Get the const SparseArray of a component type. More...
 
template<class Component >
SparseArray< Component > const & getComponents () const
 
size_t getEntityCounter () const
 Get the counter used to generate new entity ids. More...
 
void killAllEntities ()
 Destroy all entities.
 
void killEntity (const Entity &e)
 Destroy an entity. More...
 
void killEntity (const size_t &e)
 Destroy an entity. More...
 
template<class Component >
SparseArray< Component > & registerComponent (std::function< void(const size_t &)> &&)
 Register a component type and it's delete function. More...
 
template<class Component >
SparseArray< Component > & registerComponent (std::function< void(const size_t &)> &)
 Register a component type and it's delete function. More...
 
template<typename Component >
void removeComponent (const Entity &from)
 Remove a component from an entity. More...
 
template<typename Component >
void removeComponent (const size_t &from)
 Remove a component from an entity. More...
 
Entity spawnEntity ()
 Spawn a new entity. More...
 

Private Attributes

std::unordered_map< std::type_index, std::any > _componentsArrays
 Get the maximum index of an entity. More...
 
std::unordered_map< std::type_index, std::function< void(size_t const &)> > _destroyArrays
 Map containing all the components delete functions.
 
size_t _entityCounter = 0
 Counter used to generate new entity ids.
 
std::list< size_t > _freeIds
 Queue containing the ids of the destroyed entities.
 

Detailed Description

Registry class, used to store and manage entities and their components.

Member Function Documentation

◆ addComponent()

template<typename Component >
SparseArray< Component >::ReferenceType uranus::ecs::Registry::addComponent ( const Entity to,
Component &&  c 
)

Add a component to an entity.

Template Parameters
ComponentType of the component
Parameters
toEntity to add the component to
cComponent to add
Returns
Reference to the component

◆ emplaceComponent()

template<typename Component , typename... Params>
SparseArray< Component >::ReferenceType uranus::ecs::Registry::emplaceComponent ( const Entity to,
Params &&...  p 
)

Emplace a component to an entity.

Template Parameters
ComponentType of the component
ParamsVariadic parameters to pass to the constructor
Parameters
toEntity to add the component to
pParameters to pass to the constructor
Returns
Reference to the component

◆ entitiesAliveCount()

int uranus::ecs::Registry::entitiesAliveCount ( ) const
inline

Get the number of entities alive.

Returns
Number of entities alive

◆ entityFromIndex()

Entity uranus::ecs::Registry::entityFromIndex ( std::size_t  idx) const
inline

Create an entity from an index.

Parameters
idxIndex of the entity
Returns
The newly created entity

◆ getComponent() [1/4]

template<class Component >
SparseArray< Component >::ReferenceType uranus::ecs::Registry::getComponent ( const Entity e)

Get a component from an entity.

Template Parameters
ComponentType of the component
Parameters
eEntity to get the component from
Returns
Reference to the component

◆ getComponent() [2/4]

template<class Component >
SparseArray< Component >::ConstReferenceType uranus::ecs::Registry::getComponent ( const Entity e) const

Get a const component from an entity.

Template Parameters
ComponentType of the component
Parameters
eEntity to get the component from
Returns
Const reference to the component

◆ getComponent() [3/4]

template<class Component >
SparseArray< Component >::ReferenceType uranus::ecs::Registry::getComponent ( const size_t &  e)

Get a component from an index.

Template Parameters
ComponentType of the component
Parameters
eIndex of the entity to get the component from
Returns
Reference to the component

◆ getComponent() [4/4]

template<class Component >
SparseArray< Component >::ConstReferenceType uranus::ecs::Registry::getComponent ( const size_t &  e) const

Get a const component from an index.

Template Parameters
ComponentType of the component
Parameters
eIndex of the entity to get the component from
Returns
Const reference to the component

◆ getComponents() [1/2]

template<class Component >
SparseArray< Component > & uranus::ecs::Registry::getComponents

Get the SparseArray of a component type.

Template Parameters
ComponentType of the component
Returns
Reference to the SparseArray of the component type

◆ getComponents() [2/2]

template<class Component >
SparseArray< Component > const & uranus::ecs::Registry::getComponents ( ) const

Get the const SparseArray of a component type.

Template Parameters
ComponentType of the component
Returns
Const reference to the SparseArray of the component type

◆ getEntityCounter()

size_t uranus::ecs::Registry::getEntityCounter ( ) const
inline

Get the counter used to generate new entity ids.

Returns
Counter used to generate new entity ids

◆ killEntity() [1/2]

void uranus::ecs::Registry::killEntity ( const Entity e)
inline

Destroy an entity.

Parameters
eEntity to destroy

◆ killEntity() [2/2]

void uranus::ecs::Registry::killEntity ( const size_t &  e)
inline

Destroy an entity.

Parameters
eIndex of the entity to destroy

◆ registerComponent() [1/2]

template<class Component >
SparseArray< Component > & uranus::ecs::Registry::registerComponent ( std::function< void(const size_t &)> &&  deleteFunction)

Register a component type and it's delete function.

Template Parameters
ComponentType of the component
Parameters
deleteFunctionFunction to call when the component is deleted
Returns
Reference to the SparseArray of the component

◆ registerComponent() [2/2]

template<class Component >
SparseArray< Component > & uranus::ecs::Registry::registerComponent ( std::function< void(const size_t &)> &  deleteFunction)

Register a component type and it's delete function.

Template Parameters
ComponentType of the component
Parameters
deleteFunctionFunction to call when the component is deleted
Returns
Reference to the SparseArray of the component

◆ removeComponent() [1/2]

template<typename Component >
void uranus::ecs::Registry::removeComponent ( const Entity from)

Remove a component from an entity.

Template Parameters
ComponentType of the component
Parameters
fromEntity to remove the component from

◆ removeComponent() [2/2]

template<typename Component >
void uranus::ecs::Registry::removeComponent ( const size_t &  from)

Remove a component from an entity.

Template Parameters
ComponentType of the component
Parameters
fromIndex of the entity to remove the component from

◆ spawnEntity()

Entity uranus::ecs::Registry::spawnEntity ( )
inline

Spawn a new entity.

Returns
The new entity

Field Documentation

◆ _componentsArrays

std::unordered_map<std::type_index, std::any> uranus::ecs::Registry::_componentsArrays
private

Get the maximum index of an entity.

Returns
Maximum index of an entity Map containing all the components SparseArrays

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