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

A Component that provides an elegant way to handle Entity animation by interacting with the Motive animation library. More...

#include <animation.h>

Inherits corgi::Component< AnimationData >.

Detailed Description

A Component that provides an elegant way to handle Entity animation by interacting with the Motive animation library.

Public Member Functions

virtual ~AnimationComponent ()
 Deconstructor of the Animation component.
 
virtual void UpdateAllEntities (corgi::WorldTime delta_time)
 Updates all Motivators in the AnimationData, as well as, any other Motivators that were initialized with AnimationComponent's MotiveEngine. More...
 
virtual void AddFromRawData (corgi::EntityRef &entity, const void *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 an AnimationComponent's data for a given Entity. More...
 
void Animate (const corgi::EntityRef &entity, const motive::RigAnim &anim)
 Begin playback of a given RigAnim on a given Entity. More...
 
bool AnimateFromTable (const corgi::EntityRef &entity, int anim_idx)
 Query the AnimTable for an animation and then play it. More...
 
bool HasAnim (const corgi::EntityRef &entity, int anim_idx) const
 Check if a certain animation exists with a given index in the AnimTable for a given Entity. More...
 
motive::MotiveTime AnimLength (const corgi::EntityRef &entity, int anim_idx) const
 Get the length of an Entity's animation, given an animation index. More...
 
int LastAnimIdx (const corgi::EntityRef &entity) const
 Get the index of the last animation that was played. More...
 
motive::MotiveEngine & engine ()
 Get a reference to the engine that can be used for external Motivators as well. For the greatest efficiency, there should only be one MotiveEngine. More...
 
const motive::MotiveEngine & engine () const
 Get a const reference to the engine that can be used for external Motivators as well. For the greatest efficiency, there should only be one MotiveEngine. More...
 
motive::AnimTable & anim_table ()
 Get a reference to the animation table that is queried when AnimateFromTable() is called. More...
 
const motive::AnimTable & anim_table () const
 Get a const reference to the animation table that is queried when AnimateFromTable() is called. More...
 
- Public Member Functions inherited from corgi::Component< AnimationData >
 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...
 
AnimationData * AddEntity (EntityRef &entity, AllocationLocation alloc_location)
 Adds an Entity to the list that this Component is tracking. More...
 
AnimationData * 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...
 
AnimationData * GetComponentData (size_t data_index)
 Gets the Component data stored at a given index. More...
 
AnimationData * GetComponentData (const EntityRef &entity)
 Gets the data for a given Entity. More...
 
const AnimationData * GetComponentData (size_t data_index) const
 Gets the Component data stored at a given index. More...
 
const AnimationData * 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 InitEntity (EntityRef &)
 Override this function with code that should be executed when an Entity is added to the Component.
 
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.
 

Additional Inherited Members

- Public Types inherited from corgi::Component< AnimationData >
typedef VectorPool
< ComponentData >::Iterator 
EntityIterator
 An iterator to iterate through all of the Entities in the Component.
 
typedef AnimationData 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< AnimationData >
static ComponentId GetComponentId ()
 Get the ID for this Component. More...
 
- Protected Member Functions inherited from corgi::Component< AnimationData >
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< AnimationData >
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

virtual void corgi::component_library::AnimationComponent::AddFromRawData ( corgi::EntityRef entity,
const void *  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]dataA void pointer to the raw FlatBuffer data.

Implements corgi::ComponentInterface.

motive::AnimTable& corgi::component_library::AnimationComponent::anim_table ( )
inline

Get a reference to the animation table that is queried when AnimateFromTable() is called.

Returns
Returns a reference to the AnimTable for this AnimationComponent.
const motive::AnimTable& corgi::component_library::AnimationComponent::anim_table ( ) const
inline

Get a const reference to the animation table that is queried when AnimateFromTable() is called.

Returns
Returns a const reference to the AnimTable for this AnimationComponent.
void corgi::component_library::AnimationComponent::Animate ( const corgi::EntityRef entity,
const motive::RigAnim &  anim 
)

Begin playback of a given RigAnim on a given Entity.

Parameters
[in]entityA const EntityRef reference to an Entity that the RigAnim anim should be applied on.
Warning
This method asserts that entity must also have a RenderMeshComponent in order for the animation to be applied.
Parameters
[in]animA const motive::RigAnim reference to the animation that should be applied on entity.
bool corgi::component_library::AnimationComponent::AnimateFromTable ( const corgi::EntityRef entity,
int  anim_idx 
)

Query the AnimTable for an animation and then play it.

Parameters
[in]entityA const EntityRef reference to the Entity whose corresponding animation should be started.
[in]anim_idxAn int index of the animation that should be started.
Returns
Returns true if a new animation was successfully started. Otherwise, it returns false if the animation could not be found in the AnimTable.
motive::MotiveTime corgi::component_library::AnimationComponent::AnimLength ( const corgi::EntityRef entity,
int  anim_idx 
) const
inline

Get the length of an Entity's animation, given an animation index.

Parameters
[in]entityA const EntityRef reference to the Entity whose corresponding animation's length should be returned.
[in]anim_idxAn int index of the animation whose length should be returned.
Returns
Returns the length of the animation, if it exists. Otherwise, it returns 0.
motive::MotiveEngine& corgi::component_library::AnimationComponent::engine ( )
inline

Get a reference to the engine that can be used for external Motivators as well. For the greatest efficiency, there should only be one MotiveEngine.

Returns
Returns a reference to the MotiveEngine for this AnimationComponent.
const motive::MotiveEngine& corgi::component_library::AnimationComponent::engine ( ) const
inline

Get a const reference to the engine that can be used for external Motivators as well. For the greatest efficiency, there should only be one MotiveEngine.

Returns
Returns a const reference to the MotiveEngine for this AnimationComponent.
virtual RawDataUniquePtr corgi::component_library::AnimationComponent::ExportRawData ( const corgi::EntityRef entity) const
virtual

Serializes an AnimationComponent's data for a given Entity.

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

Reimplemented from corgi::Component< AnimationData >.

bool corgi::component_library::AnimationComponent::HasAnim ( const corgi::EntityRef entity,
int  anim_idx 
) const
inline

Check if a certain animation exists with a given index in the AnimTable for a given Entity.

Parameters
[in]entityA const EntityRef reference to the Entity whose corresponding animation should be checked.
[in]anim_idxAn int index of the animation whose existence should be checked.
Returns
Returns true if the animation exists in the AnimTable with anim_idx. Returns false if the animation is not found in the AnimTable.
int corgi::component_library::AnimationComponent::LastAnimIdx ( const corgi::EntityRef entity) const
inline

Get the index of the last animation that was played.

Parameters
[in]entityA const EntityRef reference to the entity whose index should be returned.
Returns
Returns the index of the last animation that was played via AnimateFromTable(), or returns -1 if no animation has ever been played using that function.
virtual void corgi::component_library::AnimationComponent::UpdateAllEntities ( corgi::WorldTime  delta_time)
virtual

Updates all Motivators in the AnimationData, as well as, any other Motivators that were initialized with AnimationComponent's MotiveEngine.

Parameters
[in]delta_timeAn corgi::WorldTime representing the delta time since the last call to UpdateAllEntities.

Reimplemented from corgi::Component< AnimationData >.


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