Remove some dead code related to scene graph animator classes
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / scene-graph-animator.h
index 19d4ecc..ce7b1c0 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_SCENE_GRAPH_ANIMATOR_H__
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
  */
 
 // INTERNAL INCLUDES
-#include <dali/devel-api/common/owner-container.h>
-#include <dali/internal/event/animation/key-frames-impl.h>
-#include <dali/internal/event/animation/path-impl.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/common/property-base.h>
 #include <dali/public-api/animation/alpha-function.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/animation/time-period.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/public-api/math/quaternion.h>
 #include <dali/public-api/math/radian.h>
+#include <dali/devel-api/common/owner-container.h>
+#include <dali/internal/event/animation/key-frames-impl.h>
+#include <dali/internal/event/animation/path-impl.h>
+#include <dali/internal/update/nodes/node.h>
+#include <dali/internal/update/common/property-base.h>
 #include <dali/internal/update/animation/property-accessor.h>
 #include <dali/integration-api/debug.h>
 
@@ -65,10 +65,30 @@ public:
   typedef float (*AlphaFunc)(float progress); ///< Definition of an alpha function
 
   /**
+   * Observer to determine when the animator is no longer present
+   */
+  class LifecycleObserver
+  {
+  public:
+    /**
+     * Called shortly before the animator is destroyed.
+     */
+    virtual void ObjectDestroyed() = 0;
+
+  protected:
+    /**
+     * Virtual destructor, no deletion through this interface
+     */
+    virtual ~LifecycleObserver() = default;
+  };
+
+
+  /**
    * Constructor.
    */
   AnimatorBase()
-  : mDurationSeconds(1.0f),
+  : mLifecycleObserver(nullptr),
+    mDurationSeconds(1.0f),
     mIntervalDelaySeconds(0.0f),
     mSpeedFactor(1.0f),
     mLoopCount(1),
@@ -86,6 +106,20 @@ public:
    */
   virtual ~AnimatorBase()
   {
+    if( mLifecycleObserver != nullptr )
+    {
+      mLifecycleObserver->ObjectDestroyed();
+    }
+  }
+
+  void AddLifecycleObserver( LifecycleObserver& observer )
+  {
+    mLifecycleObserver = &observer;
+  }
+
+  void RemoveLifecycleObserver( LifecycleObserver& observer )
+  {
+    mLifecycleObserver = nullptr;
   }
 
   /**
@@ -119,7 +153,7 @@ public:
     mSpeedFactor = factor;
   }
 
-  void SetLoopCount(int loopCount)
+  void SetLoopCount(int32_t loopCount)
   {
     mLoopCount = loopCount;
   }
@@ -140,6 +174,10 @@ public:
         value = 2.0f * std::abs( progress - 0.5f );
       }
     }
+    else
+    {
+      value = progress;
+    }
 
     return value;
   }
@@ -291,7 +329,7 @@ public:
         float upperBound(1.0f);
         float currentT(0.5f);
         float currentX = EvaluateCubicBezier( controlPoints.x, controlPoints.z, currentT);
-        while( fabs( progress - currentX ) > tolerance )
+        while( fabsf( progress - currentX ) > tolerance )
         {
           if( progress > currentX )
           {
@@ -399,11 +437,12 @@ protected:
     return 3.0f*(1.0f-t)*(1.0f-t)*t*p0 + 3.0f*(1.0f-t)*tSquare*p1 + tSquare*t;
   }
 
+  LifecycleObserver* mLifecycleObserver;
   float mDurationSeconds;
   float mIntervalDelaySeconds;
   float mSpeedFactor;
 
-  int mLoopCount;
+  int32_t mLoopCount;
 
   AlphaFunction mAlphaFunction;
 
@@ -509,7 +548,7 @@ public:
    */
   virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
   {
-    if( mLoopCount != 1 ) // Looping mode
+    if( mLoopCount >= 0 )
     {
       // Update the progress value
       progress = SetProgress( progress );
@@ -519,7 +558,8 @@ public:
 
     const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
 
-    const PropertyType result = (*mAnimatorFunction)( alpha, current );
+    // need to cast the return value in case property is integer
+    const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
     if ( bake )
     {
       mPropertyAccessor.Bake( bufferIndex, result );
@@ -668,7 +708,7 @@ public:
    */
   virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
   {
-    if( mLoopCount != 1 ) // Looping mode
+    if( mLoopCount >= 0 )
     {
       // Update the progress value
       progress = SetProgress( progress );
@@ -678,8 +718,8 @@ public:
 
     const T& current = mPropertyAccessor.Get( bufferIndex );
 
-    const T result = (*mAnimatorFunction)( alpha, current );
-
+    // need to cast the return value in case property is integer
+    T result = static_cast<T>( (*mAnimatorFunction)( alpha, current ) );
 
     if ( bake )
     {
@@ -757,14 +797,9 @@ struct AnimatorFunctionBase
     return property;
   }
 
-  virtual float operator()(float progress, const int& property)
-  {
-    return property;
-  }
-
-  virtual float operator()(float progress, const unsigned int& property)
+  virtual float operator()(float progress, const int32_t& property)
   {
-    return property;
+    return static_cast<float>( property );
   }
 
   virtual float operator()(float progress, const float& property)
@@ -803,12 +838,12 @@ struct AnimateByInteger : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float alpha, const int& property)
+  float operator()(float alpha, const int32_t& property)
   {
-    return int(property + mRelative * alpha + 0.5f );
+    return truncf(static_cast<float>( property ) + static_cast<float>( mRelative ) * alpha + 0.5f );
   }
 
-  int mRelative;
+  int32_t mRelative;
 };
 
 struct AnimateToInteger : public AnimatorFunctionBase
@@ -819,12 +854,12 @@ struct AnimateToInteger : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float alpha, const int& property)
+  float operator()(float alpha, const int32_t& property)
   {
-    return int(property + ((mTarget - property) * alpha) + 0.5f);
+    return truncf(static_cast<float>( property ) + (static_cast<float>(mTarget - property) * alpha) + 0.5f);
   }
 
-  int mTarget;
+  int32_t mTarget;
 };
 
 struct AnimateByFloat : public AnimatorFunctionBase
@@ -1095,13 +1130,13 @@ struct KeyFrameIntegerFunctor : public AnimatorFunctionBase
   }
 
   using AnimatorFunctionBase::operator();
-  float operator()(float progress, const int& property)
+  float operator()(float progress, const int32_t& property)
   {
     if(mKeyFrames->IsActive(progress))
     {
-      return mKeyFrames->GetValue(progress, mInterpolation);
+      return static_cast<float>( mKeyFrames->GetValue(progress, mInterpolation) );
     }
-    return property;
+    return static_cast<float>( property );
   }
 
   KeyFrameIntegerPtr mKeyFrames;