18 #include "precompiled.h"
40 return speed * (1.f - desync + 2.f*desync*(
rand(0, 256)/255.f));
61 if (state.
anims.empty())
77 const std::vector<CModel::Prop>& props = model->
GetProps();
78 for (std::vector<CModel::Prop>::const_iterator it = props.begin(); it != props.end(); ++it)
82 AddModel(propModel, it->m_ObjectEntry);
129 float actionPos = it->anims[it->animIdx]->m_ActionPos;
130 bool hasActionPos = (actionPos != -1.f);
138 float start = actionPos - actionTime*speed;
140 start = fmodf(start, duration);
159 float actionPos = it->anims[it->animIdx]->m_ActionPos;
160 float loadPos = it->anims[it->animIdx]->m_ActionPos2;
161 float soundPos = it->anims[it->animIdx]->m_SoundPos;
162 bool hasActionPos = (actionPos != -1.f);
163 bool hasLoadPos = (loadPos != -1.f);
164 bool hasSoundPos = (soundPos != -1.f);
171 speed =
m_Speed * it->anims[it->animIdx]->m_Speed;
174 float advance = time * speed;
177 if (hasLoadPos && !it->pastLoadPos && it->time + advance >= loadPos)
179 it->model->ShowAmmoProp();
180 it->pastLoadPos =
true;
184 if (hasActionPos && !it->pastActionPos && it->time + advance >= actionPos)
187 it->model->HideAmmoProp();
196 it->pastActionPos =
true;
198 if (hasSoundPos && !it->pastSoundPos && it->time + advance >= soundPos)
207 it->pastSoundPos =
true;
210 if (it->time + advance < duration)
214 it->model->UpdateTo(it->time);
221 it->time = fmod(it->time + advance, duration);
224 if (it->anims.size() > 1)
226 size_t newAnimIdx =
rand(0, it->anims.size());
227 if (newAnimIdx != it->animIdx)
229 it->animIdx = newAnimIdx;
230 it->model->SetAnimation(it->anims[it->animIdx], !
m_Looping);
234 it->pastActionPos =
false;
235 it->pastLoadPos =
false;
236 it->pastSoundPos =
false;
238 it->model->UpdateTo(it->time);
245 float nearlyEnd = duration - 1.f;
246 if (fabs(it->time - nearlyEnd) > 1.f)
248 it->time = nearlyEnd;
249 it->model->UpdateTo(it->time);
void AddModel(CModel *model, const CObjectEntry *object)
std::vector< CSkeletonAnim * > anims
void SetEntityID(entity_id_t ent)
Change the entity ID associated with this animation (currently used for playing locational sound effe...
std::vector< Prop > & GetProps()
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
bool SetAnimation(CSkeletonAnim *anim, bool once=false)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
void Update(float time)
Advance the animation state.
void ReloadUnit(CModel *model, const CObjectEntry *object)
Regenerate internal animation state from the models in the current unit.
CGame * g_Game
Globally accessible pointer to the CGame object.
void SetAnimationState(const CStr &name, bool once, float speed, float desync, const CStrW &actionSound)
Start playing an animation.
virtual CModel * ToCModel()
Dynamic cast.
A simplified syntax for accessing entity components.
CSimulation2 * GetSimulation2()
Get the pointer to the simulation2 object.
void SetAnimationSyncRepeat(float repeatTime)
Adjust the speed of the current animation, so that Update(repeatTime) will do a complete animation lo...
std::vector< CSkeletonAnim * > GetAnimations(const CStr &animationName) const
float GetDuration() const
std::vector< SModelAnimState > m_AnimStates
CUnitAnimation(entity_id_t ent, CModel *model, CObjectEntry *object)
Construct for a given unit, defaulting to the "idle" animation.
size_t rand(size_t min_inclusive, size_t max_exclusive)
return random integer in [min, max).
u32 entity_id_t
Entity ID type.
void SetAnimationSyncOffset(float actionTime)
Adjust the offset of the current animation, so that Update(actionTime) will advance it to the 'action...
static float DesyncSpeed(float speed, float desync)
const CObjectEntry * m_Object