| 207 | |
| 208 | |
| 209 | bool Tr2GrannyAnimationLayer::PlayAnimation( const Tr2GrannyAnimation* grannyAnimation, const char* animName, bool replace, int loopCount, float delay, float speed, bool clearWhenDone ) |
| 210 | { |
| 211 | if( grannyAnimation->IsUsingCMF() ) |
| 212 | { |
| 213 | if( !m_sequencer ) |
| 214 | { |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | CCP_ASSERT( grannyAnimation->IsUsingCMF() == m_useCMF ); |
| 219 | |
| 220 | const cmf::Animation* animation = grannyAnimation->FindCMFAnimationByName( animName ); |
| 221 | if( !animation ) |
| 222 | { |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | if( replace ) |
| 227 | { |
| 228 | ClearAnimations(); |
| 229 | } |
| 230 | |
| 231 | float startTime = GetLayerAnimationTime(); |
| 232 | if( !replace ) |
| 233 | { |
| 234 | float maxRemaining = 0.0f; |
| 235 | m_sequencer->EnumerateAnimations( [&]( const std::shared_ptr<cmf::AnimationPlayer>& player ) { |
| 236 | int loopCount = max( 0, player->GetLoopIndex( GetLayerAnimationTime() ) ); |
| 237 | int newLoopCount = loopCount + 1; |
| 238 | |
| 239 | player->SetLoopCount( newLoopCount ); |
| 240 | float remaining = player->GetDurationLeft( GetLayerAnimationTime() ); |
| 241 | player->SetStopTime( GetLayerAnimationTime() + remaining ); |
| 242 | if( remaining > maxRemaining ) |
| 243 | { |
| 244 | maxRemaining = remaining; |
| 245 | } |
| 246 | } ); |
| 247 | |
| 248 | delay += maxRemaining; |
| 249 | } |
| 250 | startTime += delay; |
| 251 | |
| 252 | auto player = m_sequencer->PlayAnimation( *animation ); |
| 253 | player->SetStartTime( startTime ); |
| 254 | player->SetLoopCount( loopCount ); |
| 255 | player->SetSpeed( speed ); |
| 256 | |
| 257 | if( loopCount > 0 && clearWhenDone ) |
| 258 | { |
| 259 | player->SetStopTime( GetLayerAnimationTime() + player->GetDurationLeft( GetLayerAnimationTime() ) + delay ); |
| 260 | } |
| 261 | |
| 262 | RegisterMorphTracks( player.get(), animation ); |
| 263 | |
| 264 | if( m_controlParamEnabled ) |
| 265 | { |
| 266 | auto duration = player->GetLoopDuration(); |
nothing calls this directly
no test coverage detected