X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fanimation%2Fscene-graph-animation.cpp;h=1ac2e43e86779aaad6800bd8ad3355dff2054a68;hb=870c5461a0f8b1a4b23d83aaa02d7275c090a502;hp=73317ae0c8f19c8502a97f4b5f451695ae784512;hpb=c79aac9678d349a5afb9992a847ec1481ba09758;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/animation/scene-graph-animation.cpp b/dali/internal/update/animation/scene-graph-animation.cpp index 73317ae..1ac2e43 100644 --- a/dali/internal/update/animation/scene-graph-animation.cpp +++ b/dali/internal/update/animation/scene-graph-animation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,12 @@ namespace Internal namespace SceneGraph { -Animation* Animation::New( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, EndAction endAction, EndAction disconnectAction ) +Animation* Animation::New( float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, EndAction endAction, EndAction disconnectAction ) { return new ( gAnimationMemoryPool.AllocateRawThreadSafe() ) Animation( durationSeconds, speedFactor, playRange, loopCount, endAction, disconnectAction ); } -Animation::Animation( float durationSeconds, float speedFactor, const Vector2& playRange, int loopCount, Dali::Animation::EndAction endAction, Dali::Animation::EndAction disconnectAction ) +Animation::Animation( float durationSeconds, float speedFactor, const Vector2& playRange, int32_t loopCount, Dali::Animation::EndAction endAction, Dali::Animation::EndAction disconnectAction ) : mPlayRange( playRange ), mDurationSeconds( durationSeconds ), mDelaySeconds( 0.0f ), @@ -78,13 +78,12 @@ Animation::Animation( float durationSeconds, float speedFactor, const Vector2& p mDisconnectAction(disconnectAction), mState(Stopped), mProgressReachedSignalRequired( false ), - mAutoReverseEnabled( false ) + mAutoReverseEnabled( false ), + mIsActive{ false } { } -Animation::~Animation() -{ -} +Animation::~Animation() = default; void Animation::operator delete( void* ptr ) { @@ -105,7 +104,7 @@ void Animation::SetProgressNotification( float progress ) } } -void Animation::SetLoopCount(int loopCount) +void Animation::SetLoopCount(int32_t loopCount) { mLoopCount = loopCount; mCurrentLoop = 0; @@ -122,9 +121,9 @@ void Animation::SetDisconnectAction(Dali::Animation::EndAction action) { mDisconnectAction = action; - for ( AnimatorIter iter = mAnimators.Begin(), endIter = mAnimators.End(); iter != endIter; ++iter ) + for ( auto&& item : mAnimators ) { - (*iter)->SetDisconnectAction( action ); + item->SetDisconnectAction( action ); } } } @@ -176,6 +175,8 @@ void Animation::PlayFrom( float progress ) mState = Playing; SetAnimatorsActive( true ); + + mCurrentLoop = 0; } } @@ -207,7 +208,7 @@ void Animation::Pause() void Animation::Bake(BufferIndex bufferIndex, EndAction action) { - if( action == Dali::Animation::BakeFinal ) + if( action == Dali::Animation::BAKE_FINAL ) { if( mSpeedFactor > 0.0f ) { @@ -224,9 +225,9 @@ void Animation::Bake(BufferIndex bufferIndex, EndAction action) void Animation::SetAnimatorsActive( bool active ) { - for ( AnimatorIter iter = mAnimators.Begin(), endIter = mAnimators.End(); iter != endIter; ++iter ) + for ( auto&& item : mAnimators ) { - (*iter)->SetActive( active ); + item->SetActive( active ); } } @@ -238,7 +239,7 @@ bool Animation::Stop(BufferIndex bufferIndex) { animationFinished = true; // The actor-thread should be notified of this - if( mEndAction != Dali::Animation::Discard ) + if( mEndAction != Dali::Animation::DISCARD ) { Bake( bufferIndex, mEndAction ); @@ -264,7 +265,7 @@ void Animation::OnDestroy(BufferIndex bufferIndex) { if (mState == Playing || mState == Paused) { - if (mEndAction != Dali::Animation::Discard) + if (mEndAction != Dali::Animation::DISCARD) { Bake( bufferIndex, mEndAction ); @@ -283,13 +284,12 @@ void Animation::SetLoopingMode( bool loopingMode ) { mAutoReverseEnabled = loopingMode; - for ( AnimatorIter iter = mAnimators.Begin(), endIter = mAnimators.End(); iter != endIter; ++iter ) + for ( auto&& item : mAnimators ) { // Send some variables together to figure out the Animation status - (*iter)->SetSpeedFactor( mSpeedFactor ); - (*iter)->SetLoopCount( mLoopCount ); - - (*iter)->SetLoopingMode( loopingMode ); + item->SetSpeedFactor( mSpeedFactor ); + item->SetLoopCount( mLoopCount ); + item->SetLoopingMode( loopingMode ); } } @@ -301,7 +301,7 @@ void Animation::AddAnimator( OwnerPointer& animator ) mAnimators.PushBack( animator.Release() ); } -void Animation::Update(BufferIndex bufferIndex, float elapsedSeconds, bool& looped, bool& finished, bool& progressReached ) +void Animation::Update( BufferIndex bufferIndex, float elapsedSeconds, bool& looped, bool& finished, bool& progressReached ) { looped = false; finished = false; @@ -316,7 +316,7 @@ void Animation::Update(BufferIndex bufferIndex, float elapsedSeconds, bool& loop if (mState == Playing) { // Sign value of speed factor. It can optimize many arithmetic comparision - int signSpeedFactor = ( mSpeedFactor < 0.0f ) ? -1 : 1; + float signSpeedFactor = ( mSpeedFactor < 0.0f ) ? -1.f : 1.f; // If there is delay time before Animation starts, wait the Animation until mDelaySeconds. if( mDelaySeconds > 0.0f ) @@ -377,7 +377,7 @@ void Animation::Update(BufferIndex bufferIndex, float elapsedSeconds, bool& loop // Make elapsed second as edge of range forcely. mElapsedSeconds = edgeRangeSeconds + signSpeedFactor * Math::MACHINE_EPSILON_10; - UpdateAnimators(bufferIndex, finished && (mEndAction != Dali::Animation::Discard), finished ); + UpdateAnimators(bufferIndex, finished && (mEndAction != Dali::Animation::DISCARD), finished ); // After update animation, mElapsedSeconds must be begin of value mElapsedSeconds = playRangeStartSeconds + playRangeEndSeconds - edgeRangeSeconds; @@ -425,58 +425,69 @@ void Animation::Update(BufferIndex bufferIndex, float elapsedSeconds, bool& loop void Animation::UpdateAnimators( BufferIndex bufferIndex, bool bake, bool animationFinished ) { + mIsActive[bufferIndex] = false; + const Vector2 playRange( mPlayRange * mDurationSeconds ); float elapsedSecondsClamped = Clamp( mElapsedSeconds, playRange.x, playRange.y ); + bool cleanup = false; + //Loop through all animators - bool applied(true); - for ( AnimatorIter iter = mAnimators.Begin(); iter != mAnimators.End(); ) + for(auto& animator : mAnimators) { - AnimatorBase *animator = *iter; - - if( animator->Orphan() ) + if(animator->Orphan()) { - //Remove animators whose PropertyOwner has been destroyed - iter = mAnimators.Erase(iter); + cleanup = true; + continue; } - else + + bool applied(true); + if(animator->IsEnabled()) { - if( animator->IsEnabled() ) - { - const float intervalDelay( animator->GetIntervalDelay() ); + const float intervalDelay(animator->GetIntervalDelay()); - if( elapsedSecondsClamped >= intervalDelay ) + if(elapsedSecondsClamped >= intervalDelay) + { + // Calculate a progress specific to each individual animator + float progress(1.0f); + const float animatorDuration = animator->GetDuration(); + if(animatorDuration > 0.0f) // animators can be "immediate" { - // Calculate a progress specific to each individual animator - float progress(1.0f); - const float animatorDuration = animator->GetDuration(); - if (animatorDuration > 0.0f) // animators can be "immediate" - { - progress = Clamp((elapsedSecondsClamped - intervalDelay) / animatorDuration, 0.0f , 1.0f ); - } - animator->Update(bufferIndex, progress, bake); + progress = Clamp((elapsedSecondsClamped - intervalDelay) / animatorDuration, 0.0f, 1.0f); } - applied = true; - } - else - { - applied = false; - } + animator->Update(bufferIndex, progress, bake); - if ( animationFinished ) - { - animator->SetActive( false ); + if (animatorDuration > 0.0f && (elapsedSecondsClamped - intervalDelay) <= animatorDuration) + { + mIsActive[bufferIndex] = true; + } } + applied = true; + } + else + { + applied = false; + } - if (applied) - { - INCREASE_COUNTER(PerformanceMonitor::ANIMATORS_APPLIED); - } + if(animationFinished) + { + animator->SetActive(false); + } - ++iter; + if(applied) + { + INCREASE_COUNTER(PerformanceMonitor::ANIMATORS_APPLIED); } } + if(cleanup) + { + //Remove animators whose PropertyOwner has been destroyed + mAnimators.Erase(std::remove_if(mAnimators.begin(), + mAnimators.end(), + [](auto& animator) { return animator->Orphan(); }), + mAnimators.end()); + } } } // namespace SceneGraph