r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
ecs::Registry Class Reference

Class for managing entities and their components. More...

#include <Registry.hpp>

+ Collaboration diagram for ecs::Registry:

Classes

class  EntityBuilder
 
class  IPool
 
class  Pool
 

Public Member Functions

 Registry ()=default
 
 ~Registry ()=default
 
 Registry (const Registry &)=delete
 
Registryoperator= (const Registry &)=delete
 
 Registry (Registry &&)=delete
 
Registryoperator= (Registry &&)=delete
 
EntityBuilder createEntity ()
 
template<typename T , typename... Args>
T & addComponent (Entity e, Args &&...args)
 
template<typename T >
T * getComponent (Entity e)
 
template<typename T >
std::unordered_map< Entity, T > & getAll ()
 
template<typename T >
bool hasComponent (Entity e)
 
template<typename T >
void removeComponent (Entity e)
 
void onComponentAdded (std::function< void(Entity, const std::type_info &)> cb)
 

Private Member Functions

template<typename T >
Pool< T > & getPool ()
 

Private Attributes

Entity m_lastEntity = INVALID_ENTITY
 
std::vector< Entitym_entities
 
std::unordered_map< std::type_index, std::unique_ptr< IPool > > m_components
 
std::vector< std::function< void(Entity, const std::type_info &)> > m_onComponentAddedCallbacks
 

Detailed Description

Class for managing entities and their components.

Definition at line 24 of file Registry.hpp.

Constructor & Destructor Documentation

◆ Registry() [1/3]

ecs::Registry::Registry ( )
default

◆ ~Registry()

ecs::Registry::~Registry ( )
default

◆ Registry() [2/3]

ecs::Registry::Registry ( const Registry & )
delete

◆ Registry() [3/3]

ecs::Registry::Registry ( Registry && )
delete

Member Function Documentation

◆ addComponent()

template<typename T , typename... Args>
T & ecs::Registry::addComponent ( Entity e,
Args &&... args )
inline

Definition at line 60 of file Registry.hpp.

References getPool(), and m_onComponentAddedCallbacks.

Referenced by ecs::Registry::EntityBuilder::with().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createEntity()

◆ getAll()

◆ getComponent()

◆ getPool()

template<typename T >
Pool< T > & ecs::Registry::getPool ( )
inlineprivate

Definition at line 129 of file Registry.hpp.

References m_components.

Referenced by addComponent(), getAll(), getComponent(), hasComponent(), and removeComponent().

+ Here is the caller graph for this function:

◆ hasComponent()

template<typename T >
bool ecs::Registry::hasComponent ( Entity e)
inline

◆ onComponentAdded()

void ecs::Registry::onComponentAdded ( std::function< void(Entity, const std::type_info &)> cb)
inline

Definition at line 91 of file Registry.hpp.

References m_onComponentAddedCallbacks.

◆ operator=() [1/2]

Registry & ecs::Registry::operator= ( const Registry & )
delete

◆ operator=() [2/2]

Registry & ecs::Registry::operator= ( Registry && )
delete

◆ removeComponent()

template<typename T >
void ecs::Registry::removeComponent ( Entity e)
inline

Member Data Documentation

◆ m_components

std::unordered_map<std::type_index, std::unique_ptr<IPool> > ecs::Registry::m_components
private

Definition at line 140 of file Registry.hpp.

Referenced by getPool().

◆ m_entities

std::vector<Entity> ecs::Registry::m_entities
private

Definition at line 139 of file Registry.hpp.

Referenced by createEntity().

◆ m_lastEntity

Entity ecs::Registry::m_lastEntity = INVALID_ENTITY
private

Definition at line 138 of file Registry.hpp.

Referenced by createEntity().

◆ m_onComponentAddedCallbacks

std::vector<std::function<void(Entity, const std::type_info &)> > ecs::Registry::m_onComponentAddedCallbacks
private

Definition at line 141 of file Registry.hpp.

Referenced by addComponent(), and onComponentAdded().


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