Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CUnitAnimation Class Reference

Deals with synchronisation issues between raw animation data (CModel, CSkeletonAnim) and the simulation system (via CUnit), providing a simple fire-and-forget API to play animations. More...

#include <UnitAnimation.h>

Classes

struct  SModelAnimState
 

Public Member Functions

 CUnitAnimation (entity_id_t ent, CModel *model, CObjectEntry *object)
 Construct for a given unit, defaulting to the "idle" animation. More...
 
void SetEntityID (entity_id_t ent)
 Change the entity ID associated with this animation (currently used for playing locational sound effects). More...
 
void SetAnimationState (const CStr &name, bool once, float speed, float desync, const CStrW &actionSound)
 Start playing an animation. More...
 
void SetAnimationSyncRepeat (float repeatTime)
 Adjust the speed of the current animation, so that Update(repeatTime) will do a complete animation loop. More...
 
void SetAnimationSyncOffset (float actionTime)
 Adjust the offset of the current animation, so that Update(actionTime) will advance it to the 'action' point defined in the actor. More...
 
void Update (float time)
 Advance the animation state. More...
 
void ReloadUnit (CModel *model, const CObjectEntry *object)
 Regenerate internal animation state from the models in the current unit. More...
 

Private Member Functions

 NONCOPYABLE (CUnitAnimation)
 
void AddModel (CModel *model, const CObjectEntry *object)
 

Private Attributes

std::vector< SModelAnimStatem_AnimStates
 
entity_id_t m_Entity
 
CModelm_Model
 
const CObjectEntrym_Object
 
CStr m_State
 
bool m_Looping
 
float m_OriginalSpeed
 
float m_Speed
 
float m_SyncRepeatTime
 
float m_Desync
 
CStrW m_ActionSound
 

Detailed Description

Deals with synchronisation issues between raw animation data (CModel, CSkeletonAnim) and the simulation system (via CUnit), providing a simple fire-and-forget API to play animations.

(This is really just a component of CUnit and could probably be merged back into that class.)

Definition at line 35 of file UnitAnimation.h.

Constructor & Destructor Documentation

CUnitAnimation::CUnitAnimation ( entity_id_t  ent,
CModel model,
CObjectEntry object 
)

Construct for a given unit, defaulting to the "idle" animation.

Definition at line 43 of file UnitAnimation.cpp.

Member Function Documentation

void CUnitAnimation::AddModel ( CModel model,
const CObjectEntry object 
)
private

Definition at line 55 of file UnitAnimation.cpp.

CUnitAnimation::NONCOPYABLE ( CUnitAnimation  )
private
void CUnitAnimation::ReloadUnit ( CModel model,
const CObjectEntry object 
)

Regenerate internal animation state from the models in the current unit.

This should be called whenever the unit is changed externally, to keep this in sync.

Definition at line 86 of file UnitAnimation.cpp.

void CUnitAnimation::SetAnimationState ( const CStr &  name,
bool  once,
float  speed,
float  desync,
const CStrW &  actionSound 
)

Start playing an animation.

The unit's actor defines the available animations, and if more than one is available then one is picked at random (with a new random choice each loop). By default, animations start immediately and run at the given speed with no syncing. Use SetAnimationSync after this to force a specific timing, if it needs to match the simulation timing. Alternatively, set desync to a non-zero value (e.g. 0.05) to slightly randomise the offset and speed, so units don't all move in lockstep.

Parameters
nameanimation's name ("idle", "walk", etc)
onceif true then the animation freezes on its last frame; otherwise it loops
speedfraction of actor-defined speed to play back at (should typically be 1.0)
desyncmaximum fraction of length/speed to randomly adjust timings (or 0.0 for no desyncing)
actionSoundsound group name to be played at the 'action' point in the animation, or empty string

Definition at line 95 of file UnitAnimation.cpp.

void CUnitAnimation::SetAnimationSyncOffset ( float  actionTime)

Adjust the offset of the current animation, so that Update(actionTime) will advance it to the 'action' point defined in the actor.

This must be called after SetAnimationSyncRepeat sets the speed.

Parameters
actionTimetime between now and when the action should occur, in msec

Definition at line 118 of file UnitAnimation.cpp.

void CUnitAnimation::SetAnimationSyncRepeat ( float  repeatTime)

Adjust the speed of the current animation, so that Update(repeatTime) will do a complete animation loop.

Parameters
repeatTimetime for complete loop of animation, in msec

Definition at line 113 of file UnitAnimation.cpp.

void CUnitAnimation::SetEntityID ( entity_id_t  ent)

Change the entity ID associated with this animation (currently used for playing locational sound effects).

Definition at line 50 of file UnitAnimation.cpp.

void CUnitAnimation::Update ( float  time)

Advance the animation state.

Parameters
timeadvance time in msec

Definition at line 148 of file UnitAnimation.cpp.

Member Data Documentation

CStrW CUnitAnimation::m_ActionSound
private

Definition at line 119 of file UnitAnimation.h.

std::vector<SModelAnimState> CUnitAnimation::m_AnimStates
private

Definition at line 106 of file UnitAnimation.h.

float CUnitAnimation::m_Desync
private

Definition at line 118 of file UnitAnimation.h.

entity_id_t CUnitAnimation::m_Entity
private

Definition at line 110 of file UnitAnimation.h.

bool CUnitAnimation::m_Looping
private

Definition at line 114 of file UnitAnimation.h.

CModel* CUnitAnimation::m_Model
private

Definition at line 111 of file UnitAnimation.h.

const CObjectEntry* CUnitAnimation::m_Object
private

Definition at line 112 of file UnitAnimation.h.

float CUnitAnimation::m_OriginalSpeed
private

Definition at line 115 of file UnitAnimation.h.

float CUnitAnimation::m_Speed
private

Definition at line 116 of file UnitAnimation.h.

CStr CUnitAnimation::m_State
private

Definition at line 113 of file UnitAnimation.h.

float CUnitAnimation::m_SyncRepeatTime
private

Definition at line 117 of file UnitAnimation.h.


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