VOX
A little voxel engine
Loading...
Searching...
No Matches
ecs::Manager< entityType > Class Template Reference

This class is the main class of the ECS system you can use it to create entitites, add component to entities, fetch components from entities and remove them. More...

#include <Manager.hpp>

Collaboration diagram for ecs::Manager< entityType >:
Collaboration graph

Classes

class  ComponentAlreadyExists
 
class  ComponentDoesNotExist
 
class  EntityAlreadyExists
 
class  EntityDoesNotExist
 

Public Types

typedef SparseSet< entityType > entitySet
 
template<typename ComponentType >
using componentSet = ComponentStorage< entityType, ComponentType >
 

Public Member Functions

 Manager ()
 
 ~Manager ()
 
 Manager (Manager &other)=delete
 
 Manager (Manager &&other)=delete
 
Manageroperator= (Manager &other)=delete
 
Manageroperator= (Manager &&other)=delete
 
std::pair< bool, entityType > createEntity ()
 Create a new entity. More...
 
void removeEntity (entityType entity)
 Remove an entity from the manager. More...
 
bool isAlive (entityType entity) const
 
template<typename ComponentType >
void add (entityType entity, ComponentType component)
 add a component to an entity More...
 
template<typename... ComponentTypes>
void add (entityType entity, ComponentTypes... components)
 add multiple components to an entity More...
 
template<typename... ComponentTypes>
void remove (entityType entity)
 remove any components from an entity More...
 
template<typename ComponentType >
ComponentType & getComponent (entityType entity)
 get a component attached to an entity More...
 
template<typename... ComponentTypes>
std::tuple< ComponentTypes &... > getComponents (entityType entity)
 Get multiple components attached to an entity as a tuple. More...
 
template<typename ComponentType >
ComponentType * tryGetComponent (entityType entity)
 Try to get a component attached to an entity. More...
 
template<typename... ComponentTypes>
std::tuple< ComponentTypes *... > tryGetComponents (entityType entity)
 try to get multiple components attached to an entity as a tuple More...
 
template<typename... ComponentTypes>
View< entityType, ComponentTypes... > view ()
 get an iterable view of entities that have all the components listed in the tparams More...
 

Static Public Member Functions

static constexpr uint32_t getEntityVersion (const entityType &entity)
 Get the version of the entity, see the entity doc for more info. More...
 
static constexpr uint32_t getEntityIndex (const entityType &entity)
 Get the index of the entity in the entity array, see the entity doc for more info. More...
 

Friends

template<ValidEntity entity, typename... ComponentTypes>
class View
 

Detailed Description

template<ValidEntity entityType = ecs::entity>
class ecs::Manager< entityType >

This class is the main class of the ECS system you can use it to create entitites, add component to entities, fetch components from entities and remove them.

Go see the Entity page for more info on how the entities are stored

Template Parameters
entityTypethe internal type used for entities id, must be integral and unsigned, default uint32_t

Member Typedef Documentation

◆ componentSet

template<ValidEntity entityType = ecs::entity>
template<typename ComponentType >
using ecs::Manager< entityType >::componentSet = ComponentStorage<entityType, ComponentType>

◆ entitySet

template<ValidEntity entityType = ecs::entity>
typedef SparseSet<entityType> ecs::Manager< entityType >::entitySet

Constructor & Destructor Documentation

◆ Manager() [1/3]

template<ValidEntity entityType = ecs::entity>
ecs::Manager< entityType >::Manager ( )
inline

◆ ~Manager()

template<ValidEntity entityType = ecs::entity>
ecs::Manager< entityType >::~Manager ( )
inline

◆ Manager() [2/3]

template<ValidEntity entityType = ecs::entity>
ecs::Manager< entityType >::Manager ( Manager< entityType > &  other)
delete

◆ Manager() [3/3]

template<ValidEntity entityType = ecs::entity>
ecs::Manager< entityType >::Manager ( Manager< entityType > &&  other)
delete

Member Function Documentation

◆ add() [1/2]

template<ValidEntity entityType = ecs::entity>
template<typename ComponentType >
void ecs::Manager< entityType >::add ( entityType  entity,
ComponentType  component 
)
inline

add a component to an entity

Template Parameters
ComponentType
Parameters
entity
component

◆ add() [2/2]

template<ValidEntity entityType = ecs::entity>
template<typename... ComponentTypes>
void ecs::Manager< entityType >::add ( entityType  entity,
ComponentTypes...  components 
)
inline

add multiple components to an entity

Template Parameters
ComponentTypes
Parameters
entity
components

◆ createEntity()

template<ValidEntity entityType = ecs::entity>
std::pair< bool, entityType > ecs::Manager< entityType >::createEntity ( )
inline

Create a new entity.

Return values
std::pair<TRUE,entityType>if the entity was created successfully
std::pair<FALSE,undefined>if the entity could not be created

◆ getComponent()

template<ValidEntity entityType = ecs::entity>
template<typename ComponentType >
ComponentType & ecs::Manager< entityType >::getComponent ( entityType  entity)
inline

get a component attached to an entity

Warning
may throw if the entity does not have the component prefer using tryGetComponent
Template Parameters
ComponentType
Parameters
entity
Returns
ComponentType&

◆ getComponents()

template<ValidEntity entityType = ecs::entity>
template<typename... ComponentTypes>
std::tuple< ComponentTypes &... > ecs::Manager< entityType >::getComponents ( entityType  entity)
inline

Get multiple components attached to an entity as a tuple.

Warning
may throw if the entity does not have one of the components, prefer using tryGetComponents

you can use

auto [comp1, comp2] = getComponents<Comp1, Comp2>(entity);
uint32_t entity
Definition: ecs_CONSTANTS.hpp:10


Template Parameters
ComponentTypes
Parameters
entity
Returns
std::tuple<ComponentTypes &...>

◆ getEntityIndex()

template<ValidEntity entityType = ecs::entity>
static constexpr uint32_t ecs::Manager< entityType >::getEntityIndex ( const entityType &  entity)
inlinestaticconstexpr

Get the index of the entity in the entity array, see the entity doc for more info.

Parameters
entity
Returns
uint32_t

◆ getEntityVersion()

template<ValidEntity entityType = ecs::entity>
static constexpr uint32_t ecs::Manager< entityType >::getEntityVersion ( const entityType &  entity)
inlinestaticconstexpr

Get the version of the entity, see the entity doc for more info.

Parameters
entity
Returns
uint32_t

◆ isAlive()

template<ValidEntity entityType = ecs::entity>
bool ecs::Manager< entityType >::isAlive ( entityType  entity) const
inline

◆ operator=() [1/2]

template<ValidEntity entityType = ecs::entity>
Manager & ecs::Manager< entityType >::operator= ( Manager< entityType > &&  other)
delete

◆ operator=() [2/2]

template<ValidEntity entityType = ecs::entity>
Manager & ecs::Manager< entityType >::operator= ( Manager< entityType > &  other)
delete

◆ remove()

template<ValidEntity entityType = ecs::entity>
template<typename... ComponentTypes>
void ecs::Manager< entityType >::remove ( entityType  entity)
inline

remove any components from an entity

Template Parameters
ComponentTypes
Parameters
entity

◆ removeEntity()

template<ValidEntity entityType = ecs::entity>
void ecs::Manager< entityType >::removeEntity ( entityType  entity)
inline

Remove an entity from the manager.

Warning
Undefined behavior if the entity does not exist
Parameters
entity

◆ tryGetComponent()

template<ValidEntity entityType = ecs::entity>
template<typename ComponentType >
ComponentType * ecs::Manager< entityType >::tryGetComponent ( entityType  entity)
inline

Try to get a component attached to an entity.

Template Parameters
ComponentType
Parameters
entity
Returns
ComponentType *

◆ tryGetComponents()

template<ValidEntity entityType = ecs::entity>
template<typename... ComponentTypes>
std::tuple< ComponentTypes *... > ecs::Manager< entityType >::tryGetComponents ( entityType  entity)
inline

try to get multiple components attached to an entity as a tuple

Template Parameters
ComponentTypes
Parameters
entity
Returns
std::tuple<ComponentTypes *...>

◆ view()

template<ValidEntity entityType = ecs::entity>
template<typename... ComponentTypes>
View< entityType, ComponentTypes... > ecs::Manager< entityType >::view ( )
inline

get an iterable view of entities that have all the components listed in the tparams

Template Parameters
ComponentTypes
Returns
View<entityType, ComponentTypes...>

Friends And Related Function Documentation

◆ View

template<ValidEntity entityType = ecs::entity>
template<ValidEntity entity, typename... ComponentTypes>
friend class View
friend

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