* @brief Updates the currently playing animations */
| 174 | * @brief Updates the currently playing animations |
| 175 | */ |
| 176 | void AnimHandler::updateAnimations(double deltaTime) |
| 177 | { |
| 178 | Animations::Animation* anim = getActiveAnimationPtr(); |
| 179 | if (!anim || !anim->m_Data.isValid()) |
| 180 | return; |
| 181 | |
| 182 | // Increase current timeline-position |
| 183 | bool reversed = anim->m_Dir != EModelScriptAniDir::MSB_FORWARD; |
| 184 | float framesPerSecond = anim->m_FpsRate * m_SpeedMultiplier; |
| 185 | float numFrames = static_cast<float>(anim->m_FrameCount); |
| 186 | size_t lastFrame = static_cast<size_t>(m_AnimationFrame); |
| 187 | m_LastProcessedFrame = static_cast<size_t>(m_AnimationFrame); |
| 188 | m_AnimationFrame += deltaTime * framesPerSecond; |
| 189 | |
| 190 | // If we have advanced one frame, we need to check for events to trigger |
| 191 | if (m_LastProcessedFrame != m_AnimationFrame) |
| 192 | { |
| 193 | triggerEvents(m_LastProcessedFrame, static_cast<int>(m_AnimationFrame)); |
| 194 | } |
| 195 | |
| 196 | if (m_AnimationFrame >= numFrames) |
| 197 | { |
| 198 | // If there is a next animation, play this now |
| 199 | Handle::AnimationHandle next = anim->m_Next; |
| 200 | |
| 201 | if (next.isValid()) |
| 202 | { |
| 203 | //if(anim->m_NextName != "S_RUN" && anim->m_NextName != "S_RUNL") |
| 204 | // LogInfo() << "Setting next Ani: " << anim->m_NextName; |
| 205 | |
| 206 | playAnimation(next); |
| 207 | return; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | // Try to play it by name. But check if it even exists first, because otherwise, we would be stuck |
| 212 | // inside the current animation with nowhere to go. |
| 213 | // |
| 214 | // This happens in G2, where T_WALKL_2_WALK defines "S_WALK" as next animation, but "S_WALK" doesn't exist. |
| 215 | if (!hasAnimation(anim->m_NextName)) |
| 216 | { |
| 217 | if (!addAnimation(anim->m_NextName)) |
| 218 | { |
| 219 | stopAnimation(); |
| 220 | return; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | playAnimation(anim->m_NextName); |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | if (m_LoopActiveAnimation) |
| 229 | m_AnimationFrame = 0.0f; |
| 230 | else |
| 231 | { |
| 232 | stopAnimation(); // Animation done and not looping |
| 233 | return; |
no test coverage detected