CORGI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
corgi::component_library::TransformComponent Class Reference

A Component that handles the transformations for every Entity that registers with it. More...

#include <transform.h>

Inherits corgi::Component< TransformData >.

Detailed Description

A Component that handles the transformations for every Entity that registers with it.

Public Member Functions

virtual ~TransformComponent ()
 Destructor for TransformComponent.
 
mathfu::vec3 WorldPosition (corgi::EntityRef entity)
 Get the world position for a given Entity. More...
 
mathfu::quat WorldOrientation (corgi::EntityRef entity)
 Get the world orientation for a given Entity. More...
 
mathfu::mat4 WorldTransform (corgi::EntityRef entity)
 Get the world transform for a given Entity. More...
 
corgi::EntityRef GetRootParent (const corgi::EntityRef &entity) const
 Get the topmost parent of a given Entity. More...
 
virtual void AddFromRawData (corgi::EntityRef &entity, const void *raw_data)
 Deserialize a flat binary buffer to create and populate an Entity from raw data. More...
 
virtual RawDataUniquePtr ExportRawData (const corgi::EntityRef &entity) const
 Serializes a TransformComponent's data for a given Entity. More...
 
virtual void InitEntity (corgi::EntityRef &entity)
 Initialize a new Entity and associate it with its TransformData. More...
 
virtual void CleanupEntity (corgi::EntityRef &entity)
 Remove the Entity and cleanup any children it may have. More...
 
virtual void UpdateAllEntities (corgi::WorldTime delta_time)
 Update the world position for all Entities registered with this Component. More...
 
void AddChild (corgi::EntityRef &child, corgi::EntityRef &parent)
 Add an Entity as a child to another Entity. More...
 
void RemoveChild (corgi::EntityRef &entity)
 Remove an Entity from the intrusive list that it belongs to. More...
 
void PostLoadFixup ()
 After loading Entities, fix up any of their child links.
 
void UpdateChildLinks (corgi::EntityRef &entity)
 Take any pending child IDs and set up the child links. More...
 
corgi::EntityRef ChildWithComponent (const corgi::EntityRef &entity, corgi::ComponentId id) const
 Get the first Entity with a Component, given an ID. More...
 
corgi::EntityRef ChildWithComponents (const corgi::EntityRef &entity, const corgi::ComponentId *ids, size_t num_ids) const
 Get the first Entity with all the Components given by an array of IDs. More...
 
- Public Member Functions inherited from corgi::Component< TransformData >
 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...
 
TransformData * AddEntity (EntityRef &entity, AllocationLocation alloc_location)
 Adds an Entity to the list that this Component is tracking. More...
 
TransformData * 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 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...
 
TransformData * GetComponentData (size_t data_index)
 Gets the Component data stored at a given index. More...
 
TransformData * GetComponentData (const EntityRef &entity)
 Gets the data for a given Entity. More...
 
const TransformData * GetComponentData (size_t data_index) const
 Gets the Component data stored at a given index. More...
 
const TransformData * GetComponentData (const EntityRef &entity) const
 Gets the data for a given Entity. More...
 
virtual void ClearComponentData ()
 Clears all tracked Component data.
 
ComponentDataType * Data (const EntityRef &entity)
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
ComponentDataType * Data (const EntityRef &entity) const
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
bool IsRegisteredWithComponent (const EntityRef &entity)
 A utility function for checking if an entity is registered with a particular component. More...
 
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 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 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.
 

Additional Inherited Members

- Public Types inherited from corgi::Component< TransformData >
typedef VectorPool
< ComponentData >::Iterator 
EntityIterator
 An iterator to iterate through all of the Entities in the Component.
 
typedef TransformData 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.
 
- Static Public Member Functions inherited from corgi::Component< TransformData >
static ComponentId GetComponentId ()
 Get the ID for this Component. More...
 
- Protected Member Functions inherited from corgi::Component< TransformData >
size_t GetComponentDataIndex (const EntityRef &entity) const
 Get the index of the Component data for a given Entity. More...
 
- Protected Attributes inherited from corgi::Component< TransformData >
VectorPool< ComponentData > component_data_
 Storage for all of the data for the Component.
 
EntityManagerentity_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.
 

Member Function Documentation

void corgi::component_library::TransformComponent::AddChild ( corgi::EntityRef child,
corgi::EntityRef parent 
)

Add an Entity as a child to another Entity.

Parameters
[in]childAn EntityRef to the Entity that should be added as a child of parent.
[in]parentAn EntityRef to the Entity that should have child added as a child.
virtual void corgi::component_library::TransformComponent::AddFromRawData ( corgi::EntityRef entity,
const void *  raw_data 
)
virtual

Deserialize a flat binary buffer to create and populate an Entity from raw data.

Parameters
[in,out]entityAn EntityRef reference that points to an Entity that is being added from the raw data.
[in]raw_dataA void pointer to the raw FlatBuffer data.

Implements corgi::ComponentInterface.

corgi::EntityRef corgi::component_library::TransformComponent::ChildWithComponent ( const corgi::EntityRef entity,
corgi::ComponentId  id 
) const
inline

Get the first Entity with a Component, given an ID.

Note
Searches in breadth-first order.
Parameters
[in]entityThe EntityRef to the parent Entity whose children should be searched.
[in]idThe ComponentId to identify the Component that should be checked during the search.
Returns
Returns an EntityRef to the first Entity that has the Component with ID id. Otherwise, it returns an invalid EntityRef, if no such child exists.
corgi::EntityRef corgi::component_library::TransformComponent::ChildWithComponents ( const corgi::EntityRef entity,
const corgi::ComponentId ids,
size_t  num_ids 
) const

Get the first Entity with all the Components given by an array of IDs.

Note
Searches in breadth-first order.
Parameters
[in]entityThe EntityRef to the parent Entity whose children should be searched.
[in]idsAn array of ComponentId to identify all the Components that should be checked during the search.
[in]num_idsThe length of the ids array.
Returns
Returns an EntityRef to the first Entity that has all the Components in the ids array. Otherwise, it returns an invalid EntityRef, if no such child exists.
virtual void corgi::component_library::TransformComponent::CleanupEntity ( corgi::EntityRef entity)
virtual

Remove the Entity and cleanup any children it may have.

Parameters
[in]entityAn EntityRef reference to the Entity that should have itself and any children removed.

Reimplemented from corgi::Component< TransformData >.

virtual RawDataUniquePtr corgi::component_library::TransformComponent::ExportRawData ( const corgi::EntityRef entity) const
virtual

Serializes a TransformComponent's data for a given Entity.

Parameters
[in]entityAn EntityRef reference to an Entity whose corresponding TransformData will be serialized.
Returns
Returns a RawDataUniquePtr to the start of the raw data in a flat binary buffer.

Reimplemented from corgi::Component< TransformData >.

corgi::EntityRef corgi::component_library::TransformComponent::GetRootParent ( const corgi::EntityRef entity) const

Get the topmost parent of a given Entity.

Parameters
[in]entityAn EntityRef to the Entity whose topmost parent should be returned.
Returns
Returns an EntityRef to the topmost parent of this Entity. If not parents exist, then it returns the entity itself.
virtual void corgi::component_library::TransformComponent::InitEntity ( corgi::EntityRef entity)
virtual

Initialize a new Entity and associate it with its TransformData.

Parameters
[in]entityAn EntityRef to the Entity that should be associated with its corresponding TransformData.

Reimplemented from corgi::Component< TransformData >.

void corgi::component_library::TransformComponent::RemoveChild ( corgi::EntityRef entity)

Remove an Entity from the intrusive list that it belongs to.

Parameters
[in]entityAn EntityRef to the Entity that should be removed, as a child, in the intrusive list.
virtual void corgi::component_library::TransformComponent::UpdateAllEntities ( corgi::WorldTime  delta_time)
virtual

Update the world position for all Entities registered with this Component.

Parameters
[in]delta_timeThe delta time since the last call to this method.

Reimplemented from corgi::Component< TransformData >.

void corgi::component_library::TransformComponent::UpdateChildLinks ( corgi::EntityRef entity)

Take any pending child IDs and set up the child links.

Parameters
[in]entityAn EntityRef to the parent Entity whose child links should be updated.
mathfu::quat corgi::component_library::TransformComponent::WorldOrientation ( corgi::EntityRef  entity)

Get the world orientation for a given Entity.

Parameters
[in]entityAn EntityRef to the Entity whose world orientation should be returned.
Returns
Returns the world orientation for this Entity as a mathfu::quat.
mathfu::vec3 corgi::component_library::TransformComponent::WorldPosition ( corgi::EntityRef  entity)

Get the world position for a given Entity.

Parameters
[in]entityAn EntityRef to the Entity whose world position should be returned.
Returns
Returns the world position of the Entity as a mathfu::vec3.
mathfu::mat4 corgi::component_library::TransformComponent::WorldTransform ( corgi::EntityRef  entity)

Get the world transform for a given Entity.

Parameters
[in]entityAn EntityRef to the Entity whose world transform should be returned.
Returns
Returns the world transform as a mathfu::mat4.

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