Refactored Animator classes to reduce code binary size by 60% 45/193645/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Thu, 22 Nov 2018 18:03:55 +0000 (18:03 +0000)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Tue, 4 Dec 2018 15:44:46 +0000 (15:44 +0000)
- Moved all type independent data to base classes in both AnimatorConnector and SceneGraph::Animator
- Moved all type independent methods to base classes and made them non-virtual
- Re-implemented the type specific parts to use template method to have common base code
- Added a template specialization for float type AnimatorConnector as thats the only type that can be a property component

Change-Id: I43ba1a814b4abf21032b005751454867e446574d

dali/internal/event/animation/animator-connector-base.h
dali/internal/event/animation/animator-connector.h
dali/internal/update/animation/scene-graph-animation.cpp
dali/internal/update/animation/scene-graph-animation.h
dali/internal/update/animation/scene-graph-animator.h
dali/internal/update/manager/update-manager.cpp

index 15cee6f..ebcc4e0 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_ANIMATOR_CONNECTOR_BASE_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/internal/event/common/object-impl.h>
 #include <dali/public-api/animation/alpha-function.h>
 #include <dali/public-api/animation/time-period.h>
 #include <dali/public-api/common/dali-common.h>
+#include <dali/internal/event/common/object-impl.h>
+#include <dali/internal/update/common/property-resetter.h>
+#include <dali/internal/update/manager/update-manager.h>
+
 
 namespace Dali
 {
@@ -33,10 +36,11 @@ namespace Internal
 class Animation;
 
 /**
- * An abstract base class for animator connectors.
+ * An abstract base class to create animator connectors and property re-setters for them when needed.
  *
  * The scene-graph objects are created by a Object e.g. Actor is a proxy for SceneGraph::Node.
- * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created.
+ * AnimatorConnectorBase observes the proxy object, in order to detect when a scene-graph object is created
+ * to avoid having unnecessary animations on the scene-graph and allow apps to create animations in initialisation
  */
 class AnimatorConnectorBase: public Object::Observer
 {
@@ -48,11 +52,14 @@ public:
   AnimatorConnectorBase(
       Object& object,
       Property::Index propertyIndex,
-      int componentIndex,
+      int32_t componentIndex,
+      Internal::AnimatorFunctionBase* animatorFunction,
       AlphaFunction alpha,
       const TimePeriod& period)
-  : mParent( NULL ),
+  : mParent( nullptr ),
     mObject( &object ),
+    mAnimator( nullptr ),
+    mAnimatorFunction( animatorFunction ),
     mAlphaFunction(alpha),
     mTimePeriod(period),
     mPropertyIndex( propertyIndex ),
@@ -66,14 +73,84 @@ public:
    */
   virtual ~AnimatorConnectorBase()
   {
+    if( mObject )
+    {
+      mObject->RemoveObserver( *this );
+    }
+
+    // If there is not a SceneGraph::Animator, the AnimatorConnector is responsible for deleting the mAnimatorFunction
+    // otherwise, the animator function ownership is transferred to the SceneGraph::Animator
+    if( !mAnimator )
+    {
+      delete mAnimatorFunction;
+    }
+  }
+
+  /**
+   * Helper function to create a Scenegraph::Animator and PropertyResetter and add it to its correspondent
+   * SceneGraph::Animation.
+   *
+   * @note This function will only be called the first time the object is added to the scene or at creation time if
+   * the object was already in the scene
+   */
+  void CreateAnimator()
+  {
+    DALI_ASSERT_DEBUG( mAnimator == NULL );
+    DALI_ASSERT_DEBUG( mAnimatorFunction != NULL );
+    DALI_ASSERT_DEBUG( mParent != NULL );
+
+    //Get the PropertyOwner the animator is going to animate
+    const SceneGraph::PropertyOwner& propertyOwner = mObject->GetSceneObject();
+
+    // Get SceneGraph::BaseProperty
+    const SceneGraph::PropertyBase* baseProperty = mObject->GetSceneObjectAnimatableProperty( mPropertyIndex );
+    DALI_ASSERT_ALWAYS( baseProperty && "Property is not animatable" );
+
+    // Check if property is a component of another property
+    const int32_t componentIndex = mObject->GetPropertyComponentIndex( mPropertyIndex );
+    if( componentIndex != Property::INVALID_COMPONENT_INDEX )
+    {
+      mComponentIndex = componentIndex;
+    }
+
+    // call the type specific method to create the concrete animator
+    bool resetterRequired = DoCreateAnimator( propertyOwner, *baseProperty );
+
+    DALI_ASSERT_DEBUG( mAnimator != NULL );
+
+    // Add the new SceneGraph::Animator to its correspondent SceneGraph::Animation via message
+    const SceneGraph::Animation* animation = mParent->GetSceneObject();
+    DALI_ASSERT_DEBUG( NULL != animation );
+    AddAnimatorMessage( mParent->GetEventThreadServices(), *animation, *mAnimator );
+
+    // Add the new SceneGraph::PropertyResetter to the update manager via message
+    if( resetterRequired )
+    {
+      OwnerPointer<SceneGraph::PropertyResetterBase> resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
+      AddResetterMessage( mParent->GetEventThreadServices().GetUpdateManager(), resetter );
+    }
   }
 
   /**
+   * Type specific extension of animator creation
+   */
+  virtual bool DoCreateAnimator( const SceneGraph::PropertyOwner& propertyOwner, const SceneGraph::PropertyBase& baseProperty ) = 0;
+
+  /**
    * Set the parent of the AnimatorConnector.
    * @pre The connector does not already have a parent.
    * @param [in] parent The parent object.
    */
-  virtual void SetParent(Animation& parent) = 0;
+  void SetParent( Animation& parent )
+  {
+    DALI_ASSERT_ALWAYS( mParent == NULL && "AnimationConnector already has a parent" );
+    mParent = &parent;
+
+    if( mObject )
+    {
+      CreateAnimator();
+    }
+  }
 
   /**
    * Retrieve the parent of the AnimatorConnector.
@@ -94,7 +171,7 @@ public:
     return mPropertyIndex;
   }
 
-  int GetComponentIndex() const
+  int32_t GetComponentIndex() const
   {
     return mComponentIndex;
   }
@@ -104,14 +181,19 @@ private:
   /**
    * From Object::Observer
    */
-  virtual void SceneObjectAdded( Object& object )
+  virtual void SceneObjectAdded( Object& object ) override final
   {
+    // If the animator has not been created yet, create it now.
+    if( !mAnimator && mObject )
+    {
+      CreateAnimator();
+    }
   }
 
   /**
    * From Object::Observer
    */
-  virtual void SceneObjectRemoved( Object& object )
+  virtual void SceneObjectRemoved( Object& object ) override final
   {
   }
 
@@ -120,19 +202,21 @@ private:
    */
   virtual void ObjectDestroyed( Object& object )
   {
-    mObject = NULL;
+    mObject = nullptr;
   }
 
 protected:
 
   Animation* mParent; ///< The parent owns the connector.
   Object* mObject; ///< Not owned by the animator connector. Valid until ObjectDestroyed() is called.
+  SceneGraph::AnimatorBase* mAnimator;
+  Internal::AnimatorFunctionBase* mAnimatorFunction;  ///< Owned by the animator connector until an Scenegraph::Animator is created
 
   AlphaFunction mAlphaFunction;
   TimePeriod mTimePeriod;
 
   Property::Index mPropertyIndex;
-  int mComponentIndex;
+  int32_t mComponentIndex;
 
 };
 
index b3ae1e5..df34741 100644 (file)
@@ -24,8 +24,6 @@
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/update/animation/property-accessor.h>
 #include <dali/internal/update/animation/property-component-accessor.h>
-#include <dali/internal/update/common/property-resetter.h>
-#include <dali/internal/update/manager/update-manager.h>
 
 namespace Dali
 {
@@ -34,19 +32,19 @@ namespace Internal
 {
 
 /**
- * AnimatorConnector is used to connect SceneGraph::Animators and
- * PropertyResetters for newly created scene-graph objects.
+ * AnimatorConnector is used to connect SceneGraph::Animators.
  *
  * SceneGraph::Animators weakly reference scene objects, and are automatically deleted when orphaned.
  * Therefore the AnimatorConnector is NOT responsible for disconnecting animators.
+ * This is the common template for non float properties, there's a specialization for float properties as they can be component properties
  */
 template < typename PropertyType >
 class AnimatorConnector : public AnimatorConnectorBase
 {
 public:
 
-  typedef SceneGraph::Animator< PropertyType, PropertyAccessor<PropertyType> > AnimatorType;
-  typedef SceneGraph::AnimatableProperty< PropertyType > PropertyInterfaceType;
+  using AnimatorType = SceneGraph::Animator< PropertyType, PropertyAccessor<PropertyType> >;
+  using PropertyInterfaceType = SceneGraph::AnimatableProperty< PropertyType >;
 
   /**
    * Construct a new animator connector.
@@ -60,17 +58,17 @@ public:
    */
   static AnimatorConnectorBase* New( Object& object,
                                      Property::Index propertyIndex,
-                                     int componentIndex,
+                                     int32_t componentIndex,
                                      AnimatorFunctionBase* animatorFunction,
                                      AlphaFunction alpha,
                                      const TimePeriod& period )
   {
-    return new AnimatorConnector< PropertyType >( object,
-                                                  propertyIndex,
-                                                  componentIndex,
-                                                  animatorFunction,
-                                                  alpha,
-                                                  period );
+    return new AnimatorConnector( object,
+                                  propertyIndex,
+                                  componentIndex,
+                                  animatorFunction,
+                                  alpha,
+                                  period );
   }
 
   /**
@@ -78,33 +76,6 @@ public:
    */
   virtual ~AnimatorConnector()
   {
-    if( mObject )
-    {
-      mObject->RemoveObserver( *this );
-    }
-
-    // If there is not a SceneGraph::Animator, the AnimatorConnector is responsible for deleting the mAnimatorFunction
-    // otherwise, the animator function ownership is transferred to the SceneGraph::Animator
-    if( !mAnimator )
-    {
-      delete mAnimatorFunction;
-      mAnimatorFunction = 0;
-    }
-  }
-
-  /**
-   * From AnimatorConnectorBase.
-   * This is only expected to be called once, when added to an Animation.
-   */
-  void SetParent( Animation& parent )
-  {
-    DALI_ASSERT_ALWAYS( mParent == NULL && "AnimationConnector already has a parent" );
-    mParent = &parent;
-
-    if( mObject )
-    {
-      CreateAnimator();
-    }
   }
 
 private:
@@ -114,102 +85,162 @@ private:
    */
   AnimatorConnector( Object& object,
                      Property::Index propertyIndex,
-                     int componentIndex,
+                     int32_t componentIndex,
                      Internal::AnimatorFunctionBase* animatorFunction,
                      AlphaFunction alpha,
                      const TimePeriod& period )
-  : AnimatorConnectorBase( object, propertyIndex, componentIndex, alpha, period ),
-    mAnimator(0),
-    mAnimatorFunction( animatorFunction )
+  : AnimatorConnectorBase( object, propertyIndex, componentIndex, animatorFunction, alpha, period )
   {
   }
 
   // Undefined
-  AnimatorConnector( const AnimatorConnector& );
-
-  // Undefined
-  AnimatorConnector& operator=( const AnimatorConnector& rhs );
+  AnimatorConnector() = delete;
+  AnimatorConnector( const AnimatorConnector& ) = delete;
+  AnimatorConnector& operator=( const AnimatorConnector& rhs ) = delete;
 
   /**
-   * From Object::Observer
+   * @copydoc AnimatorConnectorBase::DoCreateAnimator()
    */
-  virtual void SceneObjectAdded( Object& object )
+  bool DoCreateAnimator( const SceneGraph::PropertyOwner& propertyOwner, const SceneGraph::PropertyBase& baseProperty ) override final
   {
-    //If the animator has not been created yet, create it now.
-    if( !mAnimator && mObject )
+    bool resetterRequired = false;
+    // components only supported for float property type
+    DALI_ASSERT_DEBUG( mComponentIndex == Property::INVALID_COMPONENT_INDEX );
+    // Animating the whole property
+
+    // Cast to AnimatableProperty
+    const PropertyInterfaceType* animatableProperty = dynamic_cast< const PropertyInterfaceType* >( &baseProperty );
+
+    if( animatableProperty == nullptr )
     {
-      CreateAnimator();
+      if( baseProperty.IsTransformManagerProperty() )
+      {
+        mAnimator = SceneGraph::AnimatorTransformProperty< PropertyType,TransformManagerPropertyAccessor<PropertyType> >::New( propertyOwner, baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
+        // Don't reset transform manager properties - TransformManager will do it more efficiently
+      }
+      else
+      {
+        DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
+      }
     }
+    else
+    {
+      // Create the animator and resetter
+      mAnimator = AnimatorType::New( propertyOwner, *animatableProperty, mAnimatorFunction,
+                                     mAlphaFunction, mTimePeriod );
+      resetterRequired = true;
+    }
+    return resetterRequired;
   }
+};
 
-   /**
-   * Helper function to create a Scenegraph::Animator and PropertyResetter and add it to its correspondent
-   * SceneGraph::Animation.
-   *
-   * @note This function will only be called the first time the object is added to the scene or at creation time if
-   * the object was already in the scene
+/**
+ * Specialization for float as that type supports component properties
+ */
+template <>
+class AnimatorConnector< float > : public AnimatorConnectorBase
+{
+public:
+
+  using AnimatorType = SceneGraph::Animator< float, PropertyAccessor<float> >;
+  using PropertyInterfaceType = SceneGraph::AnimatableProperty< float >;
+
+  /**
+   * Construct a new animator connector.
+   * @param[in] object The object for a scene-graph object to animate.
+   * @param[in] propertyIndex The index of a property provided by the object.
+   * @param[in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4 (INVALID_PROPERTY_COMPONENTINDEX to use the whole property)
+   * @param[in] animatorFunction A function used to animate the property.
+   * @param[in] alpha The alpha function to apply.
+   * @param[in] period The time period of the animator.
+   * @return A pointer to a newly allocated animator connector.
    */
-  void CreateAnimator()
+  static AnimatorConnectorBase* New( Object& object,
+                                     Property::Index propertyIndex,
+                                     int32_t componentIndex,
+                                     AnimatorFunctionBase* animatorFunction,
+                                     AlphaFunction alpha,
+                                     const TimePeriod& period )
   {
-    DALI_ASSERT_DEBUG( mAnimator == NULL );
-    DALI_ASSERT_DEBUG( mAnimatorFunction != NULL );
-    DALI_ASSERT_DEBUG( mParent != NULL );
+    return new AnimatorConnector( object,
+                                  propertyIndex,
+                                  componentIndex,
+                                  animatorFunction,
+                                  alpha,
+                                  period );
+  }
 
-    //Get the PropertyOwner the animator is going to animate
-    const SceneGraph::PropertyOwner& propertyOwner = mObject->GetSceneObject();
+  /**
+   * Virtual destructor.
+   */
+  virtual ~AnimatorConnector()
+  {
+  }
 
-    // Get SceneGraph::BaseProperty
-    const SceneGraph::PropertyBase* baseProperty = mObject->GetSceneObjectAnimatableProperty( mPropertyIndex );
-    DALI_ASSERT_ALWAYS( baseProperty && "Property is not animatable" );
+private:
 
-    OwnerPointer<SceneGraph::PropertyResetterBase> resetter;
+  /**
+   * Private constructor; see also AnimatorConnector::New().
+   */
+  AnimatorConnector( Object& object,
+                     Property::Index propertyIndex,
+                     int32_t componentIndex,
+                     Internal::AnimatorFunctionBase* animatorFunction,
+                     AlphaFunction alpha,
+                     const TimePeriod& period )
+  : AnimatorConnectorBase( object, propertyIndex, componentIndex, animatorFunction, alpha, period )
+  {
+  }
 
-    // Check if property is a component of another property
-    const int32_t componentIndex = mObject->GetPropertyComponentIndex( mPropertyIndex );
-    if( componentIndex != Property::INVALID_COMPONENT_INDEX )
-    {
-      mComponentIndex = componentIndex;
-    }
+  // Undefined
+  AnimatorConnector() = delete;
+  AnimatorConnector( const AnimatorConnector& ) = delete;
+  AnimatorConnector& operator=( const AnimatorConnector& rhs ) = delete;
 
+  /**
+   * @copydoc AnimatorConnectorBase::DoCreateAnimator()
+   */
+  bool DoCreateAnimator( const SceneGraph::PropertyOwner& propertyOwner, const SceneGraph::PropertyBase& baseProperty ) override final
+  {
+    bool resetterRequired = false;
     if( mComponentIndex == Property::INVALID_COMPONENT_INDEX )
     {
       // Animating the whole property
 
       // Cast to AnimatableProperty
-      const PropertyInterfaceType* animatableProperty = dynamic_cast< const PropertyInterfaceType* >( baseProperty );
+      const PropertyInterfaceType* animatableProperty = dynamic_cast< const PropertyInterfaceType* >( &baseProperty );
 
-      if( animatableProperty == NULL )
+      if( animatableProperty == nullptr )
       {
-        if( baseProperty->IsTransformManagerProperty() )
+        if( baseProperty.IsTransformManagerProperty() )
         {
-          mAnimator = SceneGraph::AnimatorTransformProperty< PropertyType,TransformManagerPropertyAccessor<PropertyType> >::New( propertyOwner, *baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
+          mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyAccessor<float> >::New( propertyOwner, baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
           // Don't reset transform manager properties - TransformManager will do it more efficiently
         }
         else
         {
-          DALI_ASSERT_DEBUG( animatableProperty != NULL && "Animating non-animatable property" );
+          DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
         }
-
       }
       else
       {
         // Create the animator and resetter
         mAnimator = AnimatorType::New( propertyOwner, *animatableProperty, mAnimatorFunction,
                                        mAlphaFunction, mTimePeriod );
-        resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
+        resetterRequired = true;
       }
     }
     else
     {
       {
         // Animating a component of the property
-        if ( PropertyTypes::Get< Vector2 >() == baseProperty->GetType() )
+        if ( PropertyTypes::Get< Vector2 >() == baseProperty.GetType() )
         {
           // Animate float component of Vector2 property
 
           // Cast to AnimatableProperty of type Vector2
-          const SceneGraph::AnimatableProperty<Vector2>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector2>* >( baseProperty );
-          DALI_ASSERT_DEBUG( animatableProperty != NULL && "Animating non-animatable property" );
+          const SceneGraph::AnimatableProperty<Vector2>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector2>* >( &baseProperty );
+          DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
 
           switch( mComponentIndex )
           {
@@ -237,45 +268,42 @@ private:
             }
           }
 
-          if( mAnimator != nullptr )
-          {
-            resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
-          }
+          resetterRequired = ( mAnimator != nullptr );
         }
 
-        else if ( PropertyTypes::Get< Vector3 >() == baseProperty->GetType() )
+        else if ( PropertyTypes::Get< Vector3 >() == baseProperty.GetType() )
         {
           // Animate float component of Vector3 property
           // Cast to AnimatableProperty of type Vector3
-          const SceneGraph::AnimatableProperty<Vector3>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector3>* >( baseProperty );
+          const SceneGraph::AnimatableProperty<Vector3>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector3>* >( &baseProperty );
 
-          if( animatableProperty == NULL )
+          if( animatableProperty == nullptr )
           {
-            if( baseProperty->IsTransformManagerProperty() )
+            if( baseProperty.IsTransformManagerProperty() )
             {
               if( mComponentIndex == 0 )
               {
-                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,0> >::New( propertyOwner, *baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
+                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,0> >::New( propertyOwner, baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
               }
               else if( mComponentIndex == 1 )
               {
-                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,1> >::New( propertyOwner, *baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
+                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,1> >::New( propertyOwner, baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
               }
               else if( mComponentIndex == 2 )
               {
-                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,2> >::New( propertyOwner, *baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
+                mAnimator = SceneGraph::AnimatorTransformProperty< float,TransformManagerPropertyComponentAccessor<Vector3,2> >::New( propertyOwner, baseProperty, mAnimatorFunction, mAlphaFunction, mTimePeriod );
               }
             }
             else
             {
-              DALI_ASSERT_DEBUG( animatableProperty != NULL && "Animating non-animatable property" );
+              DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
             }
             // Don't manually reset transform property - TransformManager will do it more efficiently
           }
           else
           {
             // Dynamic cast will fail if BaseProperty is not a Vector3 AnimatableProperty
-            DALI_ASSERT_DEBUG( animatableProperty != NULL && "Animating non-animatable property" );
+            DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
 
             switch( mComponentIndex )
             {
@@ -312,21 +340,18 @@ private:
               }
             }
 
-            if( mAnimator != nullptr )
-            {
-              resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
-            }
+            resetterRequired = ( mAnimator != nullptr );
           }
         }
-        else if ( PropertyTypes::Get< Vector4 >() == baseProperty->GetType() )
+        else if ( PropertyTypes::Get< Vector4 >() == baseProperty.GetType() )
         {
           // Animate float component of Vector4 property
 
           // Cast to AnimatableProperty of type Vector4
-          const SceneGraph::AnimatableProperty<Vector4>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector4>* >( baseProperty );
+          const SceneGraph::AnimatableProperty<Vector4>* animatableProperty = dynamic_cast< const SceneGraph::AnimatableProperty<Vector4>* >( &baseProperty );
 
           //Dynamic cast will fail if BaseProperty is not a Vector4 AnimatableProperty
-          DALI_ASSERT_DEBUG( animatableProperty != NULL && "Animating non-animatable property" );
+          DALI_ASSERT_DEBUG( animatableProperty && "Animating non-animatable property" );
 
           switch( mComponentIndex )
           {
@@ -372,36 +397,14 @@ private:
               break;
             }
           }
-          if( mAnimator != nullptr )
-          {
-            resetter = SceneGraph::AnimatorResetter::New( propertyOwner, *baseProperty, *mAnimator );
-          }
+          resetterRequired = ( mAnimator != nullptr );
         }
       }
     }
-
-    DALI_ASSERT_DEBUG( mAnimator != NULL );
-
-    // Add the new SceneGraph::Animator to its correspondent SceneGraph::Animation via message
-    const SceneGraph::Animation* animation = mParent->GetSceneObject();
-    DALI_ASSERT_DEBUG( NULL != animation );
-    AddAnimatorMessage( mParent->GetEventThreadServices(), *animation, *mAnimator );
-
-    // Add the new SceneGraph::PropertyResetter to the update manager via message
-    if( resetter != nullptr )
-    {
-      AddResetterMessage( mParent->GetEventThreadServices().GetUpdateManager(), resetter );
-    }
+    return resetterRequired;
   }
-
-protected:
-
-  SceneGraph::AnimatorBase* mAnimator;
-
-  Internal::AnimatorFunctionBase* mAnimatorFunction;  ///< Owned by the animator connector until an Scenegraph::Animator is created
 };
 
-
 } // namespace Internal
 
 } // namespace Dali
index e9dd7b3..ad3abd4 100644 (file)
@@ -122,9 +122,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 );
     }
   }
 }
@@ -224,9 +224,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 );
   }
 }
 
@@ -283,13 +283,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 +300,7 @@ void Animation::AddAnimator( OwnerPointer<AnimatorBase>& 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;
@@ -430,7 +429,7 @@ void Animation::UpdateAnimators( BufferIndex bufferIndex, bool bake, bool animat
 
   //Loop through all animators
   bool applied(true);
-  for ( AnimatorIter iter = mAnimators.Begin(); iter != mAnimators.End(); )
+  for ( auto&& iter = mAnimators.Begin(); iter != mAnimators.End(); )
   {
     AnimatorBase *animator = *iter;
 
index c2b0278..426d694 100644 (file)
@@ -35,13 +35,6 @@ namespace Internal
 namespace SceneGraph
 {
 
-class Animation;
-
-typedef OwnerContainer< Animation* > AnimationContainer;
-
-typedef AnimationContainer::Iterator AnimationIter;
-typedef AnimationContainer::ConstIterator AnimationConstIter;
-
 /**
  * Animations are used to change the properties of scene graph objects, as part of a scene
  * managers "update" phase. An animation is a container of Animator objects; the actual setting
@@ -51,7 +44,7 @@ class Animation
 {
 public:
 
-  typedef Dali::Animation::EndAction EndAction;
+  using EndAction = Dali::Animation::EndAction;
 
   enum State
   {
@@ -283,15 +276,6 @@ public:
   void AddAnimator( OwnerPointer<AnimatorBase>& animator );
 
   /**
-   * Retrieve the animators from an animation.
-   * @return The container of animators.
-   */
-  AnimatorContainer& GetAnimators()
-  {
-    return mAnimators;
-  }
-
-  /**
    * This causes the animators to change the properties of objects in the scene graph.
    * @pre The animation is playing or paused.
    * @param[in] bufferIndex The buffer to update.
@@ -343,7 +327,7 @@ private:
 
 protected:
 
-  AnimatorContainer mAnimators;
+  OwnerContainer< AnimatorBase* > mAnimators;
 
   Vector2 mPlayRange;
 
@@ -379,7 +363,7 @@ namespace SceneGraph
 
 inline void SetDurationMessage( EventThreadServices& eventThreadServices, const Animation& animation, float durationSeconds )
 {
-  typedef MessageValue1< Animation, float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -390,7 +374,7 @@ inline void SetDurationMessage( EventThreadServices& eventThreadServices, const
 
 inline void SetProgressNotificationMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress )
 {
-  typedef MessageValue1< Animation, float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -402,7 +386,7 @@ inline void SetProgressNotificationMessage( EventThreadServices& eventThreadServ
 
 inline void SetLoopingMessage( EventThreadServices& eventThreadServices, const Animation& animation, int32_t loopCount )
 {
-  typedef MessageValue1< Animation, int32_t > LocalType;
+  using LocalType = MessageValue1< Animation, int32_t >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -413,7 +397,7 @@ inline void SetLoopingMessage( EventThreadServices& eventThreadServices, const A
 
 inline void SetEndActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action )
 {
-  typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType;
+  using LocalType = MessageValue1< Animation, Dali::Animation::EndAction >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -424,7 +408,7 @@ inline void SetEndActionMessage( EventThreadServices& eventThreadServices, const
 
 inline void SetDisconnectActionMessage( EventThreadServices& eventThreadServices, const Animation& animation, Dali::Animation::EndAction action )
 {
-  typedef MessageValue1< Animation, Dali::Animation::EndAction > LocalType;
+  using LocalType = MessageValue1< Animation, Dali::Animation::EndAction >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -435,7 +419,7 @@ inline void SetDisconnectActionMessage( EventThreadServices& eventThreadServices
 
 inline void SetCurrentProgressMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress )
 {
-  typedef MessageValue1< Animation, float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -446,7 +430,7 @@ inline void SetCurrentProgressMessage( EventThreadServices& eventThreadServices,
 
 inline void SetSpeedFactorMessage( EventThreadServices& eventThreadServices, const Animation& animation, float factor )
 {
-  typedef MessageValue1< Animation, float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -457,7 +441,7 @@ inline void SetSpeedFactorMessage( EventThreadServices& eventThreadServices, con
 
 inline void SetPlayRangeMessage( EventThreadServices& eventThreadServices, const Animation& animation, const Vector2& range )
 {
-  typedef MessageValue1< Animation, Vector2 > LocalType;
+  using LocalType = MessageValue1< Animation, Vector2 >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -468,7 +452,7 @@ inline void SetPlayRangeMessage( EventThreadServices& eventThreadServices, const
 
 inline void PlayAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation )
 {
-  typedef Message< Animation > LocalType;
+  using LocalType = Message< Animation >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -479,7 +463,7 @@ inline void PlayAnimationMessage( EventThreadServices& eventThreadServices, cons
 
 inline void PlayAnimationFromMessage( EventThreadServices& eventThreadServices, const Animation& animation, float progress )
 {
-  typedef MessageValue1< Animation,float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -490,7 +474,7 @@ inline void PlayAnimationFromMessage( EventThreadServices& eventThreadServices,
 
 inline void PauseAnimationMessage( EventThreadServices& eventThreadServices, const Animation& animation )
 {
-  typedef Message< Animation > LocalType;
+  using LocalType = Message< Animation >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -501,7 +485,7 @@ inline void PauseAnimationMessage( EventThreadServices& eventThreadServices, con
 
 inline void AddAnimatorMessage( EventThreadServices& eventThreadServices, const Animation& animation, AnimatorBase& animator )
 {
-  typedef MessageValue1< Animation, OwnerPointer<AnimatorBase> > LocalType;
+  using LocalType = MessageValue1< Animation, OwnerPointer<AnimatorBase> >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -513,7 +497,7 @@ inline void AddAnimatorMessage( EventThreadServices& eventThreadServices, const
 
 inline void PlayAfterMessage( EventThreadServices& eventThreadServices, const Animation& animation, float delaySeconds )
 {
-  typedef MessageValue1< Animation, float > LocalType;
+  using LocalType = MessageValue1< Animation, float >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -524,7 +508,7 @@ inline void PlayAfterMessage( EventThreadServices& eventThreadServices, const An
 
 inline void SetLoopingModeMessage( EventThreadServices& eventThreadServices, const Animation& animation, bool loopingMode )
 {
-  typedef MessageValue1< Animation, bool > LocalType;
+  using LocalType = MessageValue1< Animation, bool >;
 
   // Reserve some memory inside the message queue
   uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
index ae18f06..13c4d07 100644 (file)
@@ -40,29 +40,74 @@ namespace Dali
 namespace Internal
 {
 
-typedef Dali::Animation::Interpolation Interpolation;
+using Interpolation = Dali::Animation::Interpolation;
 
-struct AnimatorFunctionBase;
-
-namespace SceneGraph
+/**
+ * AnimatorFunction base class.
+ * Needs to be declared first so AnimatorBase knows about it's destructor
+ * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
+ */
+struct AnimatorFunctionBase
 {
+  /**
+   * Constructor
+   */
+  AnimatorFunctionBase() {}
+
+  /*
+   * Virtual destructor (Intended as base class)
+   */
+  virtual ~AnimatorFunctionBase() {}
+
+  ///Stub "()" operators.
+  virtual bool operator()(float progress, const bool& property)
+  {
+    return property;
+  }
 
-class AnimatorBase;
+  virtual float operator()(float progress, const int32_t& property)
+  {
+    return static_cast<float>( property );
+  }
 
-typedef OwnerContainer< AnimatorBase* > AnimatorContainer;
+  virtual float operator()(float progress, const float& property)
+  {
+    return property;
+  }
 
-typedef AnimatorContainer::Iterator AnimatorIter;
-typedef AnimatorContainer::ConstIterator AnimatorConstIter;
+  virtual Vector2 operator()(float progress, const Vector2& property)
+  {
+    return property;
+  }
+
+  virtual Vector3 operator()(float progress, const Vector3& property)
+  {
+    return property;
+  }
+
+  virtual Vector4 operator()(float progress, const Vector4& property)
+  {
+    return property;
+  }
+
+  virtual Quaternion operator()(float progress, const Quaternion& property)
+  {
+    return property;
+  }
+};
+
+namespace SceneGraph
+{
 
 /**
  * An abstract base class for Animators, which can be added to scene graph animations.
  * Each animator changes a single property of an object in the scene graph.
  */
-class AnimatorBase
+class AnimatorBase : public PropertyOwner::Observer
 {
 public:
 
-  typedef float (*AlphaFunc)(float progress); ///< Definition of an alpha function
+  using AlphaFunc = float (*)(float progress); ///< Definition of an alpha function
 
   /**
    * Observer to determine when the animator is no longer present
@@ -86,17 +131,23 @@ public:
   /**
    * Constructor.
    */
-  AnimatorBase()
-  : mLifecycleObserver(nullptr),
-    mDurationSeconds(1.0f),
-    mIntervalDelaySeconds(0.0f),
-    mSpeedFactor(1.0f),
-    mLoopCount(1),
-    mAlphaFunction(AlphaFunction::DEFAULT),
-    mDisconnectAction(Dali::Animation::BakeFinal),
-    mAnimationPlaying(false),
-    mEnabled(true),
-    mConnectedToSceneGraph(false),
+  AnimatorBase( PropertyOwner* propertyOwner,
+                AnimatorFunctionBase* animatorFunction,
+                AlphaFunction alphaFunction,
+                const TimePeriod& timePeriod )
+  : mLifecycleObserver( nullptr ),
+    mPropertyOwner( propertyOwner ),
+    mAnimatorFunction( animatorFunction ),
+    mDurationSeconds( timePeriod.durationSeconds ),
+    mIntervalDelaySeconds( timePeriod.delaySeconds ),
+    mSpeedFactor( 1.0f ),
+    mCurrentProgress( 0.f ),
+    mLoopCount( 1 ),
+    mAlphaFunction( alphaFunction ),
+    mDisconnectAction( Dali::Animation::BakeFinal ),
+    mAnimationPlaying( false ),
+    mEnabled( true ),
+    mConnectedToSceneGraph( false ),
     mAutoReverseEnabled( false )
   {
   }
@@ -106,6 +157,11 @@ public:
    */
   virtual ~AnimatorBase()
   {
+    delete mAnimatorFunction;
+    if (mPropertyOwner && mConnectedToSceneGraph)
+    {
+      mPropertyOwner->RemoveObserver(*this);
+    }
     if( mLifecycleObserver != nullptr )
     {
       mLifecycleObserver->ObjectDestroyed();
@@ -122,10 +178,48 @@ public:
     mLifecycleObserver = nullptr;
   }
 
+private: // From PropertyOwner::Observer
+
+  /**
+   * @copydoc PropertyOwner::Observer::PropertyOwnerConnected( PropertyOwner& owner )
+   */
+  void PropertyOwnerConnected( PropertyOwner& owner ) override final
+  {
+    mEnabled = true;
+  }
+
+  /**
+   * @copydoc PropertyOwner::Observer::PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
+   */
+  void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner ) override final
+  {
+    // If we are active, then bake the value if required
+    if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
+    {
+      // Bake to target-value if BakeFinal, otherwise bake current value
+      Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
+    }
+
+    mEnabled = false;
+  }
+
+  /**
+   * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed( PropertyOwner& owner )
+   */
+  void PropertyOwnerDestroyed( PropertyOwner& owner ) override final
+  {
+    mPropertyOwner = nullptr;
+  }
+
+public:
   /**
    * Called when Animator is added to the scene-graph in update-thread.
    */
-  virtual void ConnectToSceneGraph() = 0;
+  void ConnectToSceneGraph()
+  {
+    mConnectedToSceneGraph = true;
+    mPropertyOwner->AddObserver(*this);
+  }
 
   /**
    * Set the duration of the animator.
@@ -380,7 +474,7 @@ public:
   }
 
   /**
-   * Retrive wheter the animator's target object is valid and on the stage.
+   * Whether the animator's target object is valid and on the stage.
    * @return The enabled state.
    */
   bool IsEnabled() const
@@ -403,7 +497,10 @@ public:
    * @return True if animator is orphan, false otherwise   *
    * @note The SceneGraph::Animation will delete any orphan animator in its Update method.
    */
-  virtual bool Orphan() = 0;
+  bool Orphan()
+  {
+    return (mPropertyOwner == nullptr);
+  }
 
   /**
    * Update the scene object attached to the animator.
@@ -411,7 +508,29 @@ public:
    * @param[in] progress A value from 0 to 1, where 0 is the start of the animation, and 1 is the end point.
    * @param[in] bake Bake.
    */
-  virtual void Update(BufferIndex bufferIndex, float progress, bool bake) = 0;
+  void Update( BufferIndex bufferIndex, float progress, bool bake )
+  {
+    if( mLoopCount >= 0 )
+    {
+      // Update the progress value
+      progress = SetProgress( progress );
+    }
+
+    float alpha = ApplyAlphaFunction( progress );
+
+    // PropertyType specific part
+    DoUpdate( bufferIndex, bake, alpha );
+
+    mCurrentProgress = progress;
+  }
+
+  /**
+   * Type specific part of the animator
+   * @param bufferIndex index to use
+   * @param bake whether to bake or not
+   * @param alpha value from alpha based on progress
+   */
+  virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) = 0;
 
 protected:
 
@@ -429,9 +548,12 @@ protected:
   }
 
   LifecycleObserver* mLifecycleObserver;
+  PropertyOwner* mPropertyOwner;
+  AnimatorFunctionBase* mAnimatorFunction;
   float mDurationSeconds;
   float mIntervalDelaySeconds;
   float mSpeedFactor;
+  float mCurrentProgress;
 
   int32_t mLoopCount;
 
@@ -448,7 +570,7 @@ protected:
  * An animator for a specific property type PropertyType.
  */
 template < typename PropertyType, typename PropertyAccessorType >
-class Animator : public AnimatorBase, public PropertyOwner::Observer
+class Animator : public AnimatorBase
 {
 public:
 
@@ -466,18 +588,12 @@ public:
                             AlphaFunction alphaFunction,
                             const TimePeriod& timePeriod )
   {
-    typedef Animator< PropertyType, PropertyAccessorType > AnimatorType;
-
     // The property was const in the actor-thread, but animators are used in the scene-graph thread.
-    AnimatorType* animator = new AnimatorType( const_cast<PropertyOwner*>( &propertyOwner ),
-                                               const_cast<PropertyBase*>( &property ),
-                                               animatorFunction );
-
-    animator->SetAlphaFunction( alphaFunction );
-    animator->SetIntervalDelay( timePeriod.delaySeconds );
-    animator->SetDuration( timePeriod.durationSeconds );
-
-    return animator;
+    return new Animator( const_cast<PropertyOwner*>( &propertyOwner ),
+                                  const_cast<PropertyBase*>( &property ),
+                                  animatorFunction,
+                                  alphaFunction,
+                                  timePeriod );
   }
 
   /**
@@ -485,71 +601,18 @@ public:
    */
   virtual ~Animator()
   {
-    if (mPropertyOwner && mConnectedToSceneGraph)
-    {
-      mPropertyOwner->RemoveObserver(*this);
-    }
-
-    delete mAnimatorFunction;
-  }
-
-  /**
-   * Called when Animator is added to the scene-graph in update-thread.
-   */
-  virtual void ConnectToSceneGraph()
-  {
-    mConnectedToSceneGraph = true;
-    mPropertyOwner->AddObserver(*this);
-  }
-
-  /**
-   * Called when mPropertyOwner is connected to the scene graph.
-   */
-  virtual void PropertyOwnerConnected( PropertyOwner& owner )
-  {
-    mEnabled = true;
-  }
-
-  /**
-   * Called when mPropertyOwner is disconnected from the scene graph.
-   */
-  virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
-  {
-    // If we are active, then bake the value if required
-    if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
-    {
-      // Bake to target-value if BakeFinal, otherwise bake current value
-      Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
-    }
-
-    mEnabled = false;
-  }
-
-  /**
-   * Called shortly before mPropertyOwner is destroyed
-   */
-  virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
-  {
-    mPropertyOwner = NULL;
   }
 
   /**
-   * From AnimatorBase.
+   * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
    */
-  virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
+  virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
   {
-    if( mLoopCount >= 0 )
-    {
-      // Update the progress value
-      progress = SetProgress( progress );
-    }
-
-    float alpha = ApplyAlphaFunction( progress );
-
     const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
 
     // 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 );
@@ -558,16 +621,6 @@ public:
     {
       mPropertyAccessor.Set( bufferIndex, result );
     }
-
-    mCurrentProgress = progress;
-  }
-
-  /**
-   * From AnimatorBase.
-   */
-  virtual bool Orphan()
-  {
-    return (mPropertyOwner == NULL);
   }
 
 private:
@@ -577,11 +630,11 @@ private:
    */
   Animator( PropertyOwner* propertyOwner,
             PropertyBase* property,
-            AnimatorFunctionBase* animatorFunction )
-  : mPropertyOwner( propertyOwner ),
-    mPropertyAccessor( property ),
-    mAnimatorFunction( animatorFunction ),
-    mCurrentProgress( 0.0f )
+            AnimatorFunctionBase* animatorFunction,
+            AlphaFunction alphaFunction,
+            const TimePeriod& timePeriod )
+  : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
+    mPropertyAccessor( property )
   {
     // WARNING - this object is created in the event-thread
     // The scene-graph mPropertyOwner object cannot be observed here
@@ -595,11 +648,8 @@ private:
 
 protected:
 
-  PropertyOwner* mPropertyOwner;
   PropertyAccessorType mPropertyAccessor;
 
-  AnimatorFunctionBase* mAnimatorFunction;
-  float mCurrentProgress;
 };
 
 
@@ -607,8 +657,8 @@ protected:
 /**
  * An animator for a specific property type PropertyType.
  */
-template <typename T, typename PropertyAccessorType>
-class AnimatorTransformProperty : public AnimatorBase, public PropertyOwner::Observer
+template <typename PropertyType, typename PropertyAccessorType>
+class AnimatorTransformProperty : public AnimatorBase
 {
 public:
 
@@ -628,15 +678,11 @@ public:
   {
 
     // The property was const in the actor-thread, but animators are used in the scene-graph thread.
-    AnimatorTransformProperty* animator = new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
-                                               const_cast<PropertyBase*>( &property ),
-                                               animatorFunction );
-
-    animator->SetAlphaFunction( alphaFunction );
-    animator->SetIntervalDelay( timePeriod.delaySeconds );
-    animator->SetDuration( timePeriod.durationSeconds );
-
-    return animator;
+    return new AnimatorTransformProperty( const_cast<PropertyOwner*>( &propertyOwner ),
+                                                                         const_cast<PropertyBase*>( &property ),
+                                                                         animatorFunction,
+                                                                         alphaFunction,
+                                                                         timePeriod );
   }
 
   /**
@@ -644,71 +690,17 @@ public:
    */
   virtual ~AnimatorTransformProperty()
   {
-    if (mPropertyOwner && mConnectedToSceneGraph)
-    {
-      mPropertyOwner->RemoveObserver(*this);
-    }
-
-    delete mAnimatorFunction;
   }
 
   /**
-   * Called when Animator is added to the scene-graph in update-thread.
+   * @copydoc AnimatorBase::DoUpdate( BufferIndex bufferIndex, bool bake, float alpha )
    */
-  virtual void ConnectToSceneGraph()
+  virtual void DoUpdate( BufferIndex bufferIndex, bool bake, float alpha ) override final
   {
-    mConnectedToSceneGraph = true;
-    mPropertyOwner->AddObserver(*this);
-  }
-
-  /**
-   * Called when mPropertyOwner is connected to the scene graph.
-   */
-  virtual void PropertyOwnerConnected( PropertyOwner& owner )
-  {
-    mEnabled = true;
-  }
-
-  /**
-   * Called when mPropertyOwner is disconnected from the scene graph.
-   */
-  virtual void PropertyOwnerDisconnected( BufferIndex bufferIndex, PropertyOwner& owner )
-  {
-    // If we are active, then bake the value if required
-    if ( mAnimationPlaying && mDisconnectAction != Dali::Animation::Discard )
-    {
-      // Bake to target-value if BakeFinal, otherwise bake current value
-      Update( bufferIndex, ( mDisconnectAction == Dali::Animation::Bake ? mCurrentProgress : 1.0f ), true );
-    }
-
-    mEnabled = false;
-  }
-
-  /**
-   * Called shortly before mPropertyOwner is destroyed
-   */
-  virtual void PropertyOwnerDestroyed( PropertyOwner& owner )
-  {
-    mPropertyOwner = NULL;
-  }
-
-  /**
-   * From AnimatorBase.
-   */
-  virtual void Update( BufferIndex bufferIndex, float progress, bool bake )
-  {
-    if( mLoopCount >= 0 )
-    {
-      // Update the progress value
-      progress = SetProgress( progress );
-    }
-
-    float alpha = ApplyAlphaFunction( progress );
-
-    const T& current = mPropertyAccessor.Get( bufferIndex );
+    const PropertyType& current = mPropertyAccessor.Get( bufferIndex );
 
     // need to cast the return value in case property is integer
-    T result = static_cast<T>( (*mAnimatorFunction)( alpha, current ) );
+    const PropertyType result = static_cast<PropertyType>( (*mAnimatorFunction)( alpha, current ) );
 
     if ( bake )
     {
@@ -718,16 +710,6 @@ public:
     {
       mPropertyAccessor.Set( bufferIndex, result );
     }
-
-    mCurrentProgress = progress;
-  }
-
-  /**
-   * From AnimatorBase.
-   */
-  virtual bool Orphan()
-  {
-    return (mPropertyOwner == NULL);
   }
 
 private:
@@ -737,86 +719,29 @@ private:
    */
   AnimatorTransformProperty( PropertyOwner* propertyOwner,
             PropertyBase* property,
-            AnimatorFunctionBase* animatorFunction )
-  : mPropertyOwner( propertyOwner ),
-    mPropertyAccessor( property ),
-    mAnimatorFunction( animatorFunction ),
-    mCurrentProgress( 0.0f )
+            AnimatorFunctionBase* animatorFunction,
+            AlphaFunction alphaFunction,
+            const TimePeriod& timePeriod )
+  : AnimatorBase( propertyOwner, animatorFunction, alphaFunction, timePeriod ),
+    mPropertyAccessor( property )
   {
     // WARNING - this object is created in the event-thread
     // The scene-graph mPropertyOwner object cannot be observed here
   }
 
   // Undefined
-  AnimatorTransformProperty( const AnimatorTransformProperty& );
-
-  // Undefined
-  AnimatorTransformProperty& operator=( const AnimatorTransformProperty& );
+  AnimatorTransformProperty() = delete;
+  AnimatorTransformProperty( const AnimatorTransformProperty& ) = delete;
+  AnimatorTransformProperty& operator=( const AnimatorTransformProperty& ) = delete;
 
 protected:
 
-  PropertyOwner* mPropertyOwner;
   PropertyAccessorType mPropertyAccessor;
 
-  AnimatorFunctionBase* mAnimatorFunction;
-  float mCurrentProgress;
 };
 
 } // namespace SceneGraph
 
-/*
- * AnimatorFunction base class.
- * All update functions must inherit from AnimatorFunctionBase and overload the appropiate "()" operator
- */
-struct AnimatorFunctionBase
-{
-  /**
-   * Constructor
-   */
-  AnimatorFunctionBase(){}
-
-  /*
-   * Virtual destructor (Intended as base class)
-   */
-  virtual ~AnimatorFunctionBase(){}
-
-  ///Stub "()" operators.
-  virtual bool operator()(float progress, const bool& property)
-  {
-    return property;
-  }
-
-  virtual float operator()(float progress, const int32_t& property)
-  {
-    return static_cast<float>( property );
-  }
-
-  virtual float operator()(float progress, const float& property)
-  {
-    return property;
-  }
-
-  virtual Vector2 operator()(float progress, const Vector2& property)
-  {
-    return property;
-  }
-
-  virtual Vector3 operator()(float progress, const Vector3& property)
-  {
-    return property;
-  }
-
-  virtual Vector4 operator()(float progress, const Vector4& property)
-  {
-    return property;
-  }
-
-  virtual Quaternion operator()(float progress, const Quaternion& property)
-  {
-    return property;
-  }
-};
-
 // Update functions
 
 struct AnimateByInteger : public AnimatorFunctionBase
index 1cb1179..dbc7125 100644 (file)
@@ -269,7 +269,7 @@ struct UpdateManager::Impl
   OwnerContainer< PropertyOwner* >     customObjects;                 ///< A container of owned objects (with custom properties)
 
   OwnerContainer< PropertyResetterBase* > propertyResetters;          ///< A container of property resetters
-  AnimationContainer                   animations;                    ///< A container of owned animations
+  OwnerContainer< Animation* >         animations;                    ///< A container of owned animations
   PropertyNotificationContainer        propertyNotifications;         ///< A container of owner property notifications.
   OwnerContainer< Renderer* >          renderers;                     ///< A container of owned renderers
   OwnerContainer< TextureSet* >        textureSets;                   ///< A container of owned texture sets
@@ -644,11 +644,10 @@ bool UpdateManager::ProcessGestures( BufferIndex bufferIndex, uint32_t lastVSync
 
 void UpdateManager::Animate( BufferIndex bufferIndex, float elapsedSeconds )
 {
-  AnimationContainer &animations = mImpl->animations;
-  AnimationIter iter = animations.Begin();
+  auto&& iter = mImpl->animations.Begin();
   bool animationLooped = false;
 
-  while ( iter != animations.End() )
+  while ( iter != mImpl->animations.End() )
   {
     Animation* animation = *iter;
     bool finished = false;
@@ -667,7 +666,7 @@ void UpdateManager::Animate( BufferIndex bufferIndex, float elapsedSeconds )
     // Remove animations that had been destroyed but were still waiting for an update
     if (animation->GetState() == Animation::Destroyed)
     {
-      iter = animations.Erase(iter);
+      iter = mImpl->animations.Erase(iter);
     }
     else
     {