Optimize Orphan animator Cleanup.
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / scene-graph-animation.cpp
index bd4656f..1ac2e43 100644 (file)
@@ -83,9 +83,7 @@ Animation::Animation( float durationSeconds, float speedFactor, const Vector2& p
 {
 }
 
-Animation::~Animation()
-{
-}
+Animation::~Animation() = default;
 
 void Animation::operator delete( void* ptr )
 {
@@ -432,60 +430,64 @@ void Animation::UpdateAnimators( BufferIndex bufferIndex, bool bake, bool animat
   const Vector2 playRange( mPlayRange * mDurationSeconds );
   float elapsedSecondsClamped = Clamp( mElapsedSeconds, playRange.x, playRange.y );
 
+  bool cleanup = false;
+
   //Loop through all animators
-  bool applied(true);
-  for ( auto&& 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);
-
-          if (animatorDuration > 0.0f && (elapsedSecondsClamped - intervalDelay) <= animatorDuration)
-          {
-            mIsActive[bufferIndex] = true;
-          }
+          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