ProtoZed  awesome branch
A simple but powerful game framework
Public Member Functions | List of all members
PZ::EntityManager Class Reference

Manager for entities, components and the relationship between them. More...

Inheritance diagram for PZ::EntityManager:
PZ::NonCopyable PZ::EventHandler

Public Member Functions

 EntityManager (Application &application)
 
 ~EntityManager ()
 
bool CreateEntity (const EntityID &id)
 Creates an entity.
 
bool CreateEntity (const EntityID &id, MetaEntity &entity)
 Creates an entity.
 
bool CreateFromArchetype (const std::string &name, const EntityID &id)
 Creates an entity from an archetype.
 
bool CreateFromArchetype (const std::string &name, const EntityID &id, MetaEntity &entity)
 Creates an entity from an archetype.
 
bool DestroyEntity (const EntityID &id)
 Flags the entity for destruction.
 
void DestroyPendingEntities ()
 Destroys flagged entities.
 
bool HasEntity (const EntityID &id) const
 Query if the entity 'id' exists.
 
MetaEntity GetEntity (const EntityID &id) const
 Gets an entity.
 
void ClearEntities ()
 Clears all entities.
 
void GetAllEntities (EntityList &list) const
 Gets a list of every entity.
 
EntityList::size_type GetEntityCount () const
 Gets the number of entities.
 
bool RegisterArchetype (Archetype *archetype)
 Registers an archetype.
 
bool UnregisterArchetype (const std::string &name)
 Unregisters the archetype described by name.
 
void UnregisterAllArchetypes ()
 Unregisters all archetypes.
 
template<class T >
bool RegisterComponent ()
 Registers a component.
 
template<class T >
bool UnregisterComponent ()
 Unregisters a component.
 
void GetAllRegisteredComponents (std::vector< HashString > &list) const
 Gets all registered components.
 
template<class T >
T * AddComponent (const EntityID &id)
 Adds a component to 'id'.
 
ComponentAddComponent (const EntityID &id, const HashString &family)
 Adds a component to 'id'.
 
template<class T >
bool RemoveComponent (const EntityID &id)
 Removes the component.
 
bool RemoveComponent (const EntityID &id, const HashString &family)
 Removes the component.
 
template<class T >
bool HasComponent (const EntityID &id) const
 Query if 'id' has a component.
 
bool HasComponent (const EntityID &id, const HashString &family) const
 Query if 'id' has a component.
 
template<class T >
T * GetComponent (const EntityID &id) const
 Gets a component.
 
ComponentGetComponent (const EntityID &id, const HashString &family) const
 Gets a component.
 
void GetAllComponents (const EntityID &id, ComponentList &list) const
 Gets all components for an entity.
 
template<class T >
const EntityComponentMapGetEntitiesWith () const
 Gets the entities with a certain component.
 
const EntityComponentMapGetEntitiesWith (const HashString &family) const
 Gets all components for an entity.
 
void UpdateAll (float deltaTime)
 Updates all components.
 
- Public Member Functions inherited from PZ::EventHandler
 EventHandler ()
 
virtual ~EventHandler ()
 
bool SubscribeTo (EventHandler &handler)
 
bool UnsubscribeTo (EventHandler &handler)
 
template<class T , class EventT >
bool RegisterEvent (T *obj, void(T::*memFn)(EventT &))
 
template<class T , class EventT >
bool UnregisterEvent (T *obj, void(T::*memFn)(EventT &))
 
void HandleEvent (const Event &e)
 
void EmitEvent (const Event &e) const
 

Additional Inherited Members

- Protected Member Functions inherited from PZ::NonCopyable
 NonCopyable ()
 

Detailed Description

Manager for entities, components and the relationship between them.

Constructor & Destructor Documentation

PZ::EntityManager::EntityManager ( Application application)
PZ::EntityManager::~EntityManager ( )

Member Function Documentation

template<class T >
T* PZ::EntityManager::AddComponent ( const EntityID id)
inline

Adds a component to 'id'.

Parameters
idThe identifier.
Returns
null if it fails, else the component.
Component* PZ::EntityManager::AddComponent ( const EntityID id,
const HashString family 
)
inline

Adds a component to 'id'.

Parameters
idThe identifier.
familyThe family of the component.
Returns
null if it fails, else the component.
void PZ::EntityManager::ClearEntities ( )

Clears all entities.

bool PZ::EntityManager::CreateEntity ( const EntityID id)

Creates an entity.

Parameters
idThe identifier.
Returns
true if it succeeds, false if it fails.
bool PZ::EntityManager::CreateEntity ( const EntityID id,
MetaEntity entity 
)

Creates an entity.

Parameters
idThe identifier.
[out]entityThe created entity (will be unchanged if it fails).
Returns
true if it succeeds, false if it fails.
bool PZ::EntityManager::CreateFromArchetype ( const std::string &  name,
const EntityID id 
)

Creates an entity from an archetype.

Parameters
nameThe name of the archetype.
idThe identifier.
Returns
true if it succeeds, false if it fails.
bool PZ::EntityManager::CreateFromArchetype ( const std::string &  name,
const EntityID id,
MetaEntity entity 
)

Creates an entity from an archetype.

Parameters
nameThe name of the archetype.
idThe identifier.
[out]entityThe created entity (will be unchanged if it fails).
Returns
true if it succeeds, false if it fails.
bool PZ::EntityManager::DestroyEntity ( const EntityID id)

Flags the entity for destruction.

Parameters
idThe identifier.
Returns
true if it succeeds, false if it fails.
void PZ::EntityManager::DestroyPendingEntities ( )

Destroys flagged entities.

void PZ::EntityManager::GetAllComponents ( const EntityID id,
ComponentList list 
) const

Gets all components for an entity.

Parameters
idThe identifier.
[in,out]listThe list.
void PZ::EntityManager::GetAllEntities ( EntityList list) const

Gets a list of every entity.

Returns
The list of entites.
void PZ::EntityManager::GetAllRegisteredComponents ( std::vector< HashString > &  list) const

Gets all registered components.

Parameters
[in,out]listThe list.
template<class T >
T* PZ::EntityManager::GetComponent ( const EntityID id) const
inline

Gets a component.

Parameters
idThe identifier.
Returns
null if it fails, else the component.
Component* PZ::EntityManager::GetComponent ( const EntityID id,
const HashString family 
) const
inline

Gets a component.

Parameters
idThe identifier.
familyThe family of the component.
Returns
null if it fails, else the component.
template<class T >
const EntityComponentMap& PZ::EntityManager::GetEntitiesWith ( ) const
inline

Gets the entities with a certain component.

Returns
The entities with the component.
const EntityComponentMap& PZ::EntityManager::GetEntitiesWith ( const HashString family) const
inline

Gets all components for an entity.

Parameters
familyThe family of the component.
Returns
The entities with the component.
MetaEntity PZ::EntityManager::GetEntity ( const EntityID id) const

Gets an entity.

Parameters
idThe identifier.
Returns
The entity.
EntityList::size_type PZ::EntityManager::GetEntityCount ( ) const

Gets the number of entities.

Returns
The entity count.
template<class T >
bool PZ::EntityManager::HasComponent ( const EntityID id) const
inline

Query if 'id' has a component.

Parameters
idThe identifier.
Returns
true if it has the component, false if not.
bool PZ::EntityManager::HasComponent ( const EntityID id,
const HashString family 
) const
inline

Query if 'id' has a component.

Parameters
idThe identifier.
familyThe family of the component.
Returns
true if it has the component, false if not.
bool PZ::EntityManager::HasEntity ( const EntityID id) const

Query if the entity 'id' exists.

Parameters
idThe identifier.
Returns
true if it has the entity, false if not.
bool PZ::EntityManager::RegisterArchetype ( Archetype archetype)

Registers an archetype.

EntityManager takes ownership of the Archetype instance.

Parameters
[in]archetypeThe archetype.
Returns
true if it succeeds, false if the archetype is already registered.
template<class T >
bool PZ::EntityManager::RegisterComponent ( )
inline

Registers a component.

Returns
true if it succeeds, false if it fails.
template<class T >
bool PZ::EntityManager::RemoveComponent ( const EntityID id)
inline

Removes the component.

Parameters
idThe identifier.
Returns
true if it succeeds, false if it fails.
bool PZ::EntityManager::RemoveComponent ( const EntityID id,
const HashString family 
)
inline

Removes the component.

Parameters
idThe identifier.
familyThe family of the component.
Returns
true if it succeeds, false if it fails.
void PZ::EntityManager::UnregisterAllArchetypes ( )

Unregisters all archetypes.

bool PZ::EntityManager::UnregisterArchetype ( const std::string &  name)

Unregisters the archetype described by name.

Parameters
nameThe name.
Returns
true if it succeeds, false if the archetype wasn't found.
template<class T >
bool PZ::EntityManager::UnregisterComponent ( )
inline

Unregisters a component.

Returns
true if it succeeds, false if it fails.
void PZ::EntityManager::UpdateAll ( float  deltaTime)

Updates all components.

Parameters
deltaTimeTime since last frame.

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