SDEngine
Game Engine
Loading...
Searching...
No Matches
sd::EntityManager Class Reference

#include <EntityManager.hpp>

+ Inheritance diagram for sd::EntityManager:
+ Collaboration diagram for sd::EntityManager:

Classes

struct  UnpackGroup
 
struct  UnpackGroup< ComponentGroup< Ts... > >
 
struct  UnpackGroup< std::tuple< Ts... > >
 

Public Member Functions

Entity create ()
 
template<typename T , typename... Args>
T * add_component (Entity e, Args &&... args)
 
template<typename T >
T * try_get_component (Entity e)
 
template<typename T >
T & get_component (Entity e)
 See TryGetComponent for safe pointer version.
 
template<typename T >
const T & get_component (Entity e) const
 
void serialize (Serializer &s) const override
 
void deserialize (Serializer &s) override
 
template<typename T >
bool try_remove_component (Entity e)
 
void destroy (Entity e)
 
std::vector< ComponentDebugInfoget_all_component_info (Entity e) const
 
bool is_alive (Entity e) const
 
int get_entity_count () const
 
int get_alive_entity_count () const
 
template<typename... Args>
auto view ()
 
template<typename T >
bool has_component (Entity e) const
 
template<typename... Components>
std::tuple< Components &... > get_component_group (Entity e)
 
template<typename... Components>
std::tuple< const Components &... > get_component_group (Entity e) const
 
template<typename T >
SparseEntitySet< T > * get_component_pool ()
 
template<typename T >
bool has_component_pool ()
 
template<typename T , typename... Args>
T * add_component (Entity e, Args &&... args)
 
template<typename T >
T * try_get_component (Entity e)
 
template<typename T >
T & get_component (Entity e)
 
template<typename T >
const T & get_component (Entity e) const
 
template<typename T >
bool try_remove_component (Entity e)
 
template<typename... Args>
auto view ()
 
template<typename T >
bool has_component (Entity e) const
 
template<typename... Components>
std::tuple< Components &... > get_component_group (Entity e)
 
template<typename... Components>
std::tuple< const Components &... > get_component_group (Entity e) const
 
template<typename T >
SparseEntitySet< T > * get_component_pool ()
 
template<typename T >
bool has_component_pool ()
 
- Public Member Functions inherited from sd::Serializable
virtual ~Serializable ()=default
 

Private Types

using ComponentMask = std::bitset< 256 >
 

Private Member Functions

u32 pop_free_list ()
 
void ValidateInvariants () const
 

Private Attributes

std::vector< u32m_generations
 
std::vector< u32m_free_list
 
std::vector< std::unique_ptr< SparseEntitySetBase > > m_component_pools
 
SparseEntitySet< ComponentMaskm_entity_masks
 

Friends

class RuntimeStateManager
 

Detailed Description

EntityManager is the central ECS manager, that manages entities, components and allows for queries into the system using views. If you intend to use the entitymanager with a custom component, it will require you to register the component using the REGISTER_COMPONENT macro.

Querying the ECS

Many systems and subsystems query the ECS for entities and their components, the views can be created per component, for multiple components, or of a ComponentGroup of components.

Member Typedef Documentation

◆ ComponentMask

using sd::EntityManager::ComponentMask = std::bitset<256>
private

Member Function Documentation

◆ add_component() [1/2]

template<typename T , typename... Args>
T * sd::EntityManager::add_component ( Entity  e,
Args &&...  args 
)

◆ add_component() [2/2]

template<typename T , typename... Args>
T * sd::EntityManager::add_component ( Entity  e,
Args &&...  args 
)

◆ create()

Entity EntityManager::create ( )
inline

◆ deserialize()

void EntityManager::deserialize ( Serializer s)
inlineoverridevirtual

Implements sd::Serializable.

◆ destroy()

void EntityManager::destroy ( Entity  e)
inline

◆ get_alive_entity_count()

int sd::EntityManager::get_alive_entity_count ( ) const
inline

◆ get_all_component_info()

std::vector< ComponentDebugInfo > EntityManager::get_all_component_info ( Entity  e) const
inline

◆ get_component() [1/4]

template<typename T >
T & sd::EntityManager::get_component ( Entity  e)

See TryGetComponent for safe pointer version.

Template Parameters
T
Parameters
e
Returns

◆ get_component() [2/4]

template<typename T >
T & sd::EntityManager::get_component ( Entity  e)

◆ get_component() [3/4]

template<typename T >
const T & sd::EntityManager::get_component ( Entity  e) const

◆ get_component() [4/4]

template<typename T >
const T & sd::EntityManager::get_component ( Entity  e) const

◆ get_component_group() [1/4]

template<typename... Components>
std::tuple< Components &... > sd::EntityManager::get_component_group ( Entity  e)

◆ get_component_group() [2/4]

template<typename... Components>
std::tuple< Components &... > sd::EntityManager::get_component_group ( Entity  e)

◆ get_component_group() [3/4]

template<typename... Components>
std::tuple< const Components &... > sd::EntityManager::get_component_group ( Entity  e) const

◆ get_component_group() [4/4]

template<typename... Components>
std::tuple< const Components &... > sd::EntityManager::get_component_group ( Entity  e) const

◆ get_component_pool() [1/2]

template<typename T >
SparseEntitySet< T > * sd::EntityManager::get_component_pool ( )

◆ get_component_pool() [2/2]

template<typename T >
SparseEntitySet< T > * sd::EntityManager::get_component_pool ( )

◆ get_entity_count()

int sd::EntityManager::get_entity_count ( ) const
inline

◆ has_component() [1/2]

template<typename T >
bool sd::EntityManager::has_component ( Entity  e) const

◆ has_component() [2/2]

template<typename T >
bool sd::EntityManager::has_component ( Entity  e) const

◆ has_component_pool() [1/2]

template<typename T >
bool sd::EntityManager::has_component_pool ( )

◆ has_component_pool() [2/2]

template<typename T >
bool sd::EntityManager::has_component_pool ( )

◆ is_alive()

bool EntityManager::is_alive ( Entity  e) const
inline

◆ pop_free_list()

uint32_t EntityManager::pop_free_list ( )
inlineprivate

◆ serialize()

void EntityManager::serialize ( Serializer s) const
inlineoverridevirtual

Implements sd::Serializable.

◆ try_get_component() [1/2]

template<typename T >
T * sd::EntityManager::try_get_component ( Entity  e)

◆ try_get_component() [2/2]

template<typename T >
T * sd::EntityManager::try_get_component ( Entity  e)

◆ try_remove_component() [1/2]

template<typename T >
bool sd::EntityManager::try_remove_component ( Entity  e)

◆ try_remove_component() [2/2]

template<typename T >
bool sd::EntityManager::try_remove_component ( Entity  e)

◆ ValidateInvariants()

void sd::EntityManager::ValidateInvariants ( ) const
inlineprivate

◆ view() [1/2]

template<typename... Args>
auto sd::EntityManager::view ( )

◆ view() [2/2]

template<typename... Args>
auto sd::EntityManager::view ( )

Friends And Related Symbol Documentation

◆ RuntimeStateManager

Member Data Documentation

◆ m_component_pools

std::vector<std::unique_ptr<SparseEntitySetBase> > sd::EntityManager::m_component_pools
private

◆ m_entity_masks

SparseEntitySet<ComponentMask> sd::EntityManager::m_entity_masks
private

◆ m_free_list

std::vector<u32> sd::EntityManager::m_free_list
private

◆ m_generations

std::vector<u32> sd::EntityManager::m_generations
private

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