Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
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:

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 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...
 
void ReloadAnimation ()
 Reload animation so any changes take immediate effect. More...
 

Private Member Functions

 NONCOPYABLE (CUnitAnimation)
 
void PickAnimationID ()
 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::CUnitAnimation ( entity_id_t  ent,
CModel model,
CObjectEntry object 
)

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

Member Function Documentation

◆ AddModel()

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

◆ NONCOPYABLE()

CUnitAnimation::NONCOPYABLE ( CUnitAnimation  )
private

◆ PickAnimationID()

void CUnitAnimation::PickAnimationID ( )
private

Picks a new animation ID from our current state.

◆ ReloadAnimation()

void CUnitAnimation::ReloadAnimation ( )

Reload animation so any changes take immediate effect.

◆ ReloadUnit()

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.

◆ SetAnimationState()

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

◆ SetAnimationSyncOffset()

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

◆ SetAnimationSyncRepeat()

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

◆ Update()

void CUnitAnimation::Update ( float  time)

Advance the animation state.

Parameters
timeadvance time in msec

Member Data Documentation

◆ m_ActionSound

CStrW CUnitAnimation::m_ActionSound
private

◆ m_AnimationID

CStr CUnitAnimation::m_AnimationID = ""
private

◆ m_AnimStates

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

◆ m_AnimStatesAreStatic

bool CUnitAnimation::m_AnimStatesAreStatic
private

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

◆ m_Desync

float CUnitAnimation::m_Desync
private

◆ m_Entity

entity_id_t CUnitAnimation::m_Entity
private

◆ m_Looping

bool CUnitAnimation::m_Looping
private

◆ m_Model

CModel* CUnitAnimation::m_Model
private

◆ m_Object

const CObjectEntry* CUnitAnimation::m_Object
private

◆ m_OriginalSpeed

float CUnitAnimation::m_OriginalSpeed
private

◆ m_Speed

float CUnitAnimation::m_Speed
private

◆ m_State

CStr CUnitAnimation::m_State
private

◆ m_SyncRepeatTime

float CUnitAnimation::m_SyncRepeatTime
private

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