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>
|
| 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...
|
|
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.)
◆ CUnitAnimation()
Construct for a given unit, defaulting to the "idle" animation.
◆ AddModel()
◆ NONCOPYABLE()
◆ 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()
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
-
name | animation's name ("idle", "walk", etc) |
once | if true then the animation freezes on its last frame; otherwise it loops |
speed | fraction of actor-defined speed to play back at (should typically be 1.0) |
desync | maximum fraction of length/speed to randomly adjust timings (or 0.0 for no desyncing) |
actionSound | sound 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
-
actionTime | time 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
-
repeatTime | time for complete loop of animation, in msec |
◆ Update()
void CUnitAnimation::Update |
( |
float |
time | ) |
|
Advance the animation state.
- Parameters
-
◆ m_ActionSound
CStrW CUnitAnimation::m_ActionSound |
|
private |
◆ m_AnimationID
CStr CUnitAnimation::m_AnimationID = "" |
|
private |
◆ m_AnimStates
◆ 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
◆ m_Looping
bool CUnitAnimation::m_Looping |
|
private |
◆ m_Model
CModel* CUnitAnimation::m_Model |
|
private |
◆ m_Object
◆ 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: