Pyrogenesis  trunk
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>

Collaboration diagram for CUnitAnimation:
Collaboration graph
[legend]

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 UpdateAnimationID ()
 Picks a new animation ID from our current state. More...
 
void AddModel (CModel *model, const CObjectEntry *object)
 

Private Attributes

std::vector< SModelAnimStatem_AnimStates
 
bool m_AnimStatesAreStatic
 True if all the current AnimStates are static, so Update() doesn't need to do any work at all. More...
 
entity_id_t m_Entity
 
CModelm_Model
 
const CObjectEntrym_Object
 
CStr m_State
 
CStr m_AnimationID = ""
 
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.)

Constructor & Destructor Documentation

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

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

Member Function Documentation

void CUnitAnimation::AddModel ( CModel model,
const CObjectEntry object 
)
private
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.

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
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
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
void CUnitAnimation::SetEntityID ( entity_id_t  ent)

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

void CUnitAnimation::Update ( float  time)

Advance the animation state.

Parameters
timeadvance time in msec
void CUnitAnimation::UpdateAnimationID ( )
private

Picks a new animation ID from our current state.

Member Data Documentation

CStrW CUnitAnimation::m_ActionSound
private
CStr CUnitAnimation::m_AnimationID = ""
private
std::vector<SModelAnimState> CUnitAnimation::m_AnimStates
private
bool CUnitAnimation::m_AnimStatesAreStatic
private

True if all the current AnimStates are static, so Update() doesn't need to do any work at all.

float CUnitAnimation::m_Desync
private
entity_id_t CUnitAnimation::m_Entity
private
bool CUnitAnimation::m_Looping
private
CModel* CUnitAnimation::m_Model
private
const CObjectEntry* CUnitAnimation::m_Object
private
float CUnitAnimation::m_OriginalSpeed
private
float CUnitAnimation::m_Speed
private
CStr CUnitAnimation::m_State
private
float CUnitAnimation::m_SyncRepeatTime
private

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