CORGI
An open source project by
FPL.
|
A Component is an object that encapsulates all data and logic for Entities of a particular type. More...
#include <component.h>
Inherits corgi::ComponentInterface.
A Component is an object that encapsulates all data and logic for Entities of a particular type.
T | The structure of data that needs to be associated with each Entity. |
Classes | |
struct | ComponentData |
A structure of data that is associated with each Entity. More... | |
Public Types | |
typedef VectorPool < ComponentData >::Iterator | EntityIterator |
An iterator to iterate through all of the Entities in the Component. | |
typedef T | value_type |
The templated data type stored by this Component. | |
Public Types inherited from corgi::ComponentInterface | |
typedef std::unique_ptr < uint8_t, std::function< void(uint8_t *)> > | RawDataUniquePtr |
A pointer type for exported raw data. | |
Public Member Functions | |
Component () | |
Construct a Component without an EntityManager. | |
virtual | ~Component () |
Destructor for a Component. | |
virtual void | AddEntityGenerically (EntityRef &entity) |
Provides an alternate way to add Entities if you do not care about the returned data structure, and if you do not feel like casting the BaseComponent into something more specific. More... | |
T * | AddEntity (EntityRef &entity, AllocationLocation alloc_location) |
Adds an Entity to the list that this Component is tracking. More... | |
T * | AddEntity (EntityRef &entity) |
Adds an Entity to the list that this Component is tracking. More... | |
virtual void | RemoveEntity (EntityRef &entity) |
Removes an Entity from the list of Entities. More... | |
virtual EntityIterator | RemoveEntity (EntityIterator iter) |
Removes an Entity from the list of Entities. More... | |
virtual EntityIterator | begin () |
Gets an iterator that will iterate over every Entity associated with the Component, starting from the beginning. More... | |
virtual EntityIterator | end () |
Gets an iterator that points to the end of the list of all entites in the Component. More... | |
virtual void | UpdateAllEntities (WorldTime) |
Updates all Entities. This is normally called, once per frame, by the EntityManager. | |
virtual bool | HasDataForEntity (const EntityRef &entity) |
Checks if this component contains any data associated with the supplied entity. | |
virtual void * | GetComponentDataAsVoid (const EntityRef &entity) |
Gets the data for a given Entity as a void pointer. More... | |
virtual const void * | GetComponentDataAsVoid (const EntityRef &entity) const |
Gets the data for a given Entity as a const void pointer. More... | |
T * | GetComponentData (size_t data_index) |
Gets the Component data stored at a given index. More... | |
T * | GetComponentData (const EntityRef &entity) |
Gets the data for a given Entity. More... | |
const T * | GetComponentData (size_t data_index) const |
Gets the Component data stored at a given index. More... | |
const T * | GetComponentData (const EntityRef &entity) const |
Gets the data for a given Entity. More... | |
virtual void | ClearComponentData () |
Clears all tracked Component data. | |
template<typename ComponentDataType > | |
ComponentDataType * | Data (const EntityRef &entity) |
A utility function for retrieving the Component data for an Entity from a specific Component. More... | |
template<typename ComponentDataType > | |
bool | IsRegisteredWithComponent (const EntityRef &entity) |
A utility function for checking if an entity is registered with a particular component. More... | |
template<typename ComponentDataType > | |
ComponentDataType * | Data (const EntityRef &entity) const |
A utility function for retrieving the Component data for an Entity from a specific Component. More... | |
template<typename ComponentDataType > | |
ComponentDataType * | GetComponent () |
A utility function for retrieving a reference to a specific Component object, by type. More... | |
virtual void | Init () |
Override this function with code that should be executed when the Component is added to the EntityManager. (This typically happens once, at the beginning of the game before any Entities are added.) | |
virtual void | InitEntity (EntityRef &) |
Override this function with code that should be executed when an Entity is added to the Component. | |
virtual RawDataUniquePtr | ExportRawData (const EntityRef &) const |
Override this function to return raw data that can be read back later. More... | |
virtual void | Cleanup () |
Override this function with any code that executes when this Component is removed from the EntityManager. (i.e. Usually when the game/state is over and everything is shutting down.) | |
virtual void | CleanupEntity (EntityRef &) |
Override this function with any code that needs to be executed when an Entity is removed from this Component. | |
virtual void | SetEntityManager (EntityManager *entity_manager) |
Set the EntityManager for this Component. More... | |
virtual void | SetComponentIdOnDataType (ComponentId id) |
Sets the Component ID on the data type. More... | |
Public Member Functions inherited from corgi::ComponentInterface | |
virtual | ~ComponentInterface () |
A destructor for the Component interface. | |
virtual void | AddFromRawData (EntityRef &entity, const void *data)=0 |
Creates and populates an Entity from raw data. Components that want to be able to be constructed via the EntityFactory need to implement this. More... | |
Static Public Member Functions | |
static ComponentId | GetComponentId () |
Get the ID for this Component. More... | |
Protected Member Functions | |
size_t | GetComponentDataIndex (const EntityRef &entity) const |
Get the index of the Component data for a given Entity. More... | |
Protected Attributes | |
VectorPool< ComponentData > | component_data_ |
Storage for all of the data for the Component. | |
EntityManager * | entity_manager_ |
A pointer to the EntityManager for this Component. This is the main point of contact for Components that need to talk to other things. | |
std::unordered_map < EntityIdType, ComponentIndex > | component_index_lookup_ |
A map, for translating unique entity IDs into vectorpool indexes. | |
|
inline |
Adds an Entity to the list that this Component is tracking.
[in,out] | entity | An EntityRef reference used to add an Entity to the list of Entities that this Component keeps track of. |
[in] | alloc_location | An Enum that specifies whether to allocate from the beginning or end of the memory pool. |
|
inline |
Adds an Entity to the list that this Component is tracking.
[in,out] | entity | An EntityRef reference used to add an Entity to the list of Entities that this Component keeps track of. |
|
inlinevirtual |
Provides an alternate way to add Entities if you do not care about the returned data structure, and if you do not feel like casting the BaseComponent into something more specific.
[in,out] | entity | An EntityRef reference used to add an Entity. |
Implements corgi::ComponentInterface.
|
inlinevirtual |
|
inline |
|
inline |
|
inlinevirtual |
|
inlinevirtual |
Override this function to return raw data that can be read back later.
Implements corgi::ComponentInterface.
Reimplemented in PhysicsComponent, corgi::component_library::RenderMeshComponent, corgi::component_library::TransformComponent, corgi::component_library::GraphComponent, corgi::component_library::AnimationComponent, and corgi::component_library::MetaComponent.
|
inline |
|
inline |
Gets the Component data stored at a given index.
[in] | data_index | A size_t representing the index of the desired Component data. |
|
inline |
|
inline |
Gets the Component data stored at a given index.
[in] | data_index | A size_t representing the index of the desired Component data. |
|
inline |
|
inlinevirtual |
Gets the data for a given Entity as a void pointer.
[in] | entity | An EntityRef reference to the Entity whose data should be returned. |
Implements corgi::ComponentInterface.
|
inlinevirtual |
Gets the data for a given Entity as a const void pointer.
[in] | entity | An EntityRef reference to the Entity whose data should be returned. |
Implements corgi::ComponentInterface.
|
inlineprotected |
|
inlinestatic |
|
inline |
|
inlinevirtual |
Removes an Entity from the list of Entities.
This is done by marking the Entity as no longer using this Component, calling the destructor on the data, and returning the memory to the memory pool.
[in,out] | entity | An EntityRef reference used to remove an Entity from the list of Entities that this Component keeps track of. |
Implements corgi::ComponentInterface.
|
inlinevirtual |
Removes an Entity from the list of Entities.
This is done by marking the Entity as no longer using this Component, calling the destructor on the data, and returning the memory to the memory pool.
[in,out] | iter | An EntityIterator that references an Entity that should be removed. |
|
inlinevirtual |
Sets the Component ID on the data type.
[in] | id | The Component ID to set on the data type. |
Implements corgi::ComponentInterface.
|
inlinevirtual |
Set the EntityManager for this Component.
[in] | entity_manager | A pointer to an EntityManager to associate with this Component. |
Implements corgi::ComponentInterface.