Uranus
1.0.1.0
Uranus is a GameEngine written in C++
|
Registry class, used to store and manage entities and their components. More...
#include <Registry.hpp>
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. | |
Registry class, used to store and manage entities and their components.
SparseArray< Component >::ReferenceType uranus::ecs::Registry::addComponent | ( | const Entity & | to, |
Component && | c | ||
) |
Add a component to an entity.
Component | Type of the component |
to | Entity to add the component to |
c | Component to add |
SparseArray< Component >::ReferenceType uranus::ecs::Registry::emplaceComponent | ( | const Entity & | to, |
Params &&... | p | ||
) |
Emplace a component to an entity.
Component | Type of the component |
Params | Variadic parameters to pass to the constructor |
to | Entity to add the component to |
p | Parameters to pass to the constructor |
|
inline |
Get the number of entities alive.
|
inline |
Create an entity from an index.
idx | Index of the entity |
SparseArray< Component >::ReferenceType uranus::ecs::Registry::getComponent | ( | const Entity & | e | ) |
Get a component from an entity.
Component | Type of the component |
e | Entity to get the component from |
SparseArray< Component >::ConstReferenceType uranus::ecs::Registry::getComponent | ( | const Entity & | e | ) | const |
Get a const component from an entity.
Component | Type of the component |
e | Entity to get the component from |
SparseArray< Component >::ReferenceType uranus::ecs::Registry::getComponent | ( | const size_t & | e | ) |
Get a component from an index.
Component | Type of the component |
e | Index of the entity to get the component from |
SparseArray< Component >::ConstReferenceType uranus::ecs::Registry::getComponent | ( | const size_t & | e | ) | const |
Get a const component from an index.
Component | Type of the component |
e | Index of the entity to get the component from |
SparseArray< Component > & uranus::ecs::Registry::getComponents |
Get the SparseArray of a component type.
Component | Type of the component |
SparseArray< Component > const & uranus::ecs::Registry::getComponents | ( | ) | const |
Get the const SparseArray of a component type.
Component | Type of the component |
|
inline |
Get the counter used to generate new entity ids.
|
inline |
Destroy an entity.
e | Entity to destroy |
|
inline |
Destroy an entity.
e | Index of the entity to destroy |
SparseArray< Component > & uranus::ecs::Registry::registerComponent | ( | std::function< void(const size_t &)> && | deleteFunction | ) |
Register a component type and it's delete function.
Component | Type of the component |
deleteFunction | Function to call when the component is deleted |
SparseArray< Component > & uranus::ecs::Registry::registerComponent | ( | std::function< void(const size_t &)> & | deleteFunction | ) |
Register a component type and it's delete function.
Component | Type of the component |
deleteFunction | Function to call when the component is deleted |
void uranus::ecs::Registry::removeComponent | ( | const Entity & | from | ) |
Remove a component from an entity.
Component | Type of the component |
from | Entity to remove the component from |
void uranus::ecs::Registry::removeComponent | ( | const size_t & | from | ) |
Remove a component from an entity.
Component | Type of the component |
from | Index of the entity to remove the component from |
|
inline |
Spawn a new entity.
|
private |
Get the maximum index of an entity.