CORGI
An open source project by
FPL.
|
The EntityManager is the code that manages all Entities and Components in the game. Normally the game will instantiate EntityManager, and then use it to create and control all of its Entities. More...
#include <entity_manager.h>
The EntityManager is the code that manages all Entities and Components in the game. Normally the game will instantiate EntityManager, and then use it to create and control all of its Entities.
The main uses for this class are:
Public Types | |
typedef VectorPool< Entity > | EntityStorageContainer |
This is used to track all Entities stored by the EntityManager. | |
Public Member Functions | |
EntityManager () | |
Constructor for the EntityManager. | |
const CorgiVersion * | GetCorgiVersion () |
Returns the version of the Corgi entity library. | |
template<typename T > | |
T * | GetComponentData (const EntityRef &entity) |
Helper function for marshalling data from a Component. More... | |
template<typename T > | |
const T * | GetComponentData (const EntityRef &entity) const |
A helper function for marshalling data from a Component. More... | |
template<typename T > | |
T * | GetComponent () |
A helper function for getting a particular Component, given the Component's data type. More... | |
template<typename T > | |
const T * | GetComponent () const |
A helper function for getting a particular Component, given the Component's data type. More... | |
template<typename T > | |
void | AddEntityToComponent (EntityRef entity) |
A helper function for adding a Component to an Entity, given its data type. More... | |
ComponentInterface * | GetComponent (ComponentId id) |
A helper function for getting a particular Component, given the component ID. More... | |
const ComponentInterface * | GetComponent (ComponentId id) const |
A helper function for getting a particular Component, given a component ID. More... | |
size_t | ComponentCount () const |
Returns the number of components that have been registered with the entity manager. More... | |
template<typename T > | |
ComponentId | GetComponentId () |
A helper function to get the component ID for a given Component. More... | |
EntityRef | AllocateNewEntity () |
Allocates a new Entity (that is registered with no Components). More... | |
void | DeleteEntity (EntityRef entity) |
Deletes an Entity by removing it from the EntityManager's list and clearing any Component data associated with it. More... | |
void | DeleteEntityImmediately (EntityRef entity) |
Instantly deletes an Entity. More... | |
template<typename T > | |
ComponentId | RegisterComponent (T *new_component) |
Registers a new Component with the EntityManager. More... | |
void | RemoveAllComponents (EntityRef entity) |
Removes all Components for an Entity, destroying any data associated with it. More... | |
void | UpdateComponents (WorldTime delta_time) |
Iterates through all the registered Components and causes them to update. More... | |
void | Clear () |
Clears all data from all Components, empties the list of Components themselves, and then empties the list of Entities. This basically resets the EntityManager into its original state. | |
EntityStorageContainer::Iterator | begin () |
Returns an iterator to the beginning of the active Entities. This is suitable for iterating over every active Entity. More... | |
EntityStorageContainer::Iterator | end () |
Returns an iterator to the last of the active Entities. More... | |
void | set_entity_factory (EntityFactoryInterface *entity_factory) |
Registers an instance of the EntityFactoryInterface as the factory object to be used when Entities are created from arbitrary data. The EntityFactory is responsible for parsing arbitrary data and correctly transforming it into an Entity. More... | |
EntityRef | CreateEntityFromData (const void *data) |
Creates an Entity from arbitrary data. This is normally invoked only by classes that inherit from EntityFactoryInterface. More... | |
void | AddEntityToComponent (EntityRef entity, ComponentId component_id) |
Registers an Entity with a Component. This causes the Component to allocate data for the Entity and includes the Entity in that Component's update routines. More... | |
void | DeleteMarkedEntities () |
Deletes all the Entities that are marked for deletion. More... | |
|
inline |
void corgi::EntityManager::AddEntityToComponent | ( | EntityRef | entity, |
ComponentId | component_id | ||
) |
EntityRef corgi::EntityManager::AllocateNewEntity | ( | ) |
|
inline |
|
inline |
Returns the number of components that have been registered with the entity manager.
EntityRef corgi::EntityManager::CreateEntityFromData | ( | const void * | data | ) |
Creates an Entity from arbitrary data. This is normally invoked only by classes that inherit from EntityFactoryInterface.
Any class implementing CreateEntityFromData should establish the input format for the 'data' and a way to parse that input 'data' into an Entity.
[in] | data | A void pointer to the data to be used to create the Entity. |
void corgi::EntityManager::DeleteEntity | ( | EntityRef | entity | ) |
Deletes an Entity by removing it from the EntityManager's list and clearing any Component data associated with it.
[in] | entity | An EntityRef that points to the Entity that will be deleted at the end of the frame. |
void corgi::EntityManager::DeleteEntityImmediately | ( | EntityRef | entity | ) |
void corgi::EntityManager::DeleteMarkedEntities | ( | ) |
Deletes all the Entities that are marked for deletion.
|
inline |
Returns an iterator to the last of the active Entities.
|
inline |
|
inline |
|
inline |
A helper function for getting a particular Component, given the component ID.
[in] | id | The component ID for the desired Component. |
|
inline |
A helper function for getting a particular Component, given a component ID.
[in] | id | The component ID for the desired Component. |
|
inline |
|
inline |
|
inline |
|
inline |
Registers a new Component with the EntityManager.
T | The data type of the Component that is being registered with the EntityManager. |
[in] | new_component | A Component to be registered with to the EntityManager. |
void corgi::EntityManager::RemoveAllComponents | ( | EntityRef | entity | ) |
Removes all Components for an Entity, destroying any data associated with it.
[in] | entity | An EntityRef that points to the Entity whose Components should be removed. |
|
inline |
Registers an instance of the EntityFactoryInterface as the factory object to be used when Entities are created from arbitrary data. The EntityFactory is responsible for parsing arbitrary data and correctly transforming it into an Entity.
[in] | entity_factory | A pointer to a class that inherits from the EntityFactoryInterface, which will be registered with the EntityManager. |
void corgi::EntityManager::UpdateComponents | ( | WorldTime | delta_time | ) |
Iterates through all the registered Components and causes them to update.
[in] | delta_time | A WorldTime that represents the timestep since the last update. |