Revert "[Tizen] (Animation) Reorder animation variables according to size & remove...
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-impl.cpp
index 2b0bf2e..c27f31b 100644 (file)
@@ -112,18 +112,17 @@ AnimationPtr Animation::New(float durationSeconds)
 }
 
 Animation::Animation( EventThreadServices& eventThreadServices, AnimationPlaylist& playlist, float durationSeconds, EndAction endAction, EndAction disconnectAction, AlphaFunction defaultAlpha )
-: mAnimation( NULL ),
-  mEventThreadServices( eventThreadServices ),
+: mEventThreadServices( eventThreadServices ),
   mPlaylist( playlist ),
-  mFinishedSignal(),
-  mConnectors(),
-  mConnectorTargetValues(),
-  mPlayRange( Vector2(0.0f,1.0f)),
+  mAnimation( NULL ),
+  mNotificationCount( 0 ),
+  mFinishedCallback( NULL ),
+  mFinishedCallbackObject( NULL ),
   mDurationSeconds( durationSeconds ),
   mSpeedFactor(1.0f),
-  mNotificationCount( 0 ),
   mLoopCount(1),
   mCurrentLoop(0),
+  mPlayRange( Vector2(0.0f,1.0f)),
   mEndAction( endAction ),
   mDisconnectAction( disconnectAction ),
   mDefaultAlpha( defaultAlpha ),
@@ -268,20 +267,33 @@ void Animation::Play()
 
   if( mEndAction != EndAction::Discard ) // If the animation is discarded, then we do not want to change the target values
   {
-    // Sort according to end time with earlier end times coming first, if the end time is the same, then the connectors are not moved
-    std::stable_sort( mConnectorTargetValues.begin(), mConnectorTargetValues.end(), CompareConnectorEndTimes );
-
-    // Loop through all connector target values sorted by increasing end time
-    ConnectorTargetValuesContainer::const_iterator iter = mConnectorTargetValues.begin();
-    const ConnectorTargetValuesContainer::const_iterator endIter = mConnectorTargetValues.end();
-    for( ; iter != endIter; ++iter )
+    unsigned int connectorTargetValuesIndex( 0 );
+    unsigned int numberOfConnectorTargetValues = mConnectorTargetValues.size();
+
+    /*
+     * Loop through all Animator connectors, if connector index matches the current index stored in mConnectorTargetValues container then
+     * should apply target values for this index to the object.
+     */
+    for ( unsigned int connectorIndex = 0; connectorIndex < mConnectors.Count(); connectorIndex ++)
     {
-      AnimatorConnectorBase* connector = mConnectors[ iter->connectorIndex ];
-
-      Object* object = connector->GetObject();
-      if( object )
+      // Use index to check if the current connector is next in the mConnectorTargetValues container, meaning targetValues have been pushed in AnimateXXFunction
+      if ( connectorTargetValuesIndex < numberOfConnectorTargetValues )
       {
-        object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), iter->targetValue, iter->propertyChangeType );
+        ConnectorTargetValues& connectorPair = mConnectorTargetValues[ connectorTargetValuesIndex ];
+
+        if ( connectorPair.connectorIndex == connectorIndex )
+        {
+          // Current connector index matches next in the stored connectors with target values so apply target value.
+          connectorTargetValuesIndex++; // Found a match for connector so increment index to next one
+
+          AnimatorConnectorBase* connector = mConnectors[ connectorIndex ];
+
+          Object* object = connector->GetObject();
+          if( object )
+          {
+            object->NotifyPropertyAnimation( *this, connector->GetPropertyIndex(), connectorPair.targetValue );
+          }
+        }
       }
     }
   }
@@ -370,14 +382,6 @@ void Animation::AnimateBy(Property& target, Property::Value& relativeValue, Alph
 
   ExtendDuration( period );
 
-  // Store data to later notify the object that its property is being animated
-  ConnectorTargetValues connectorPair;
-  connectorPair.targetValue = relativeValue;
-  connectorPair.connectorIndex = mConnectors.Count();
-  connectorPair.timePeriod = period;
-  connectorPair.propertyChangeType = Object::PropertyChange::ADJUST_VALUE_BY;
-  mConnectorTargetValues.push_back( connectorPair );
-
   switch ( targetType )
   {
     case Property::BOOLEAN:
@@ -509,8 +513,6 @@ void Animation::AnimateTo(Object& targetObject, Property::Index targetPropertyIn
   ConnectorTargetValues connectorPair;
   connectorPair.targetValue = destinationValue;
   connectorPair.connectorIndex = mConnectors.Count();
-  connectorPair.timePeriod = period;
-  connectorPair.propertyChangeType = Object::PropertyChange::SET;
   mConnectorTargetValues.push_back( connectorPair );
 
   switch ( destinationType )
@@ -780,6 +782,12 @@ void Animation::EmitSignalFinish()
     Dali::Animation handle( this );
     mFinishedSignal.Emit( handle );
   }
+
+  // This callback is used internally, to avoid the overhead of using a signal.
+  if ( mFinishedCallback )
+  {
+    mFinishedCallback( mFinishedCallbackObject );
+  }
 }
 
 bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
@@ -800,6 +808,12 @@ bool Animation::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface*
   return connected;
 }
 
+void Animation::SetFinishedCallback( FinishedCallback callback, Object* object )
+{
+  mFinishedCallback = callback;
+  mFinishedCallbackObject = object;
+}
+
 void Animation::AddAnimatorConnector( AnimatorConnectorBase* connector )
 {
   DALI_ASSERT_DEBUG( NULL != connector );
@@ -975,10 +989,6 @@ Vector2 Animation::GetPlayRange() const
   return mPlayRange;
 }
 
-bool Animation::CompareConnectorEndTimes( const Animation::ConnectorTargetValues& lhs, const Animation::ConnectorTargetValues& rhs )
-{
-  return ( ( lhs.timePeriod.delaySeconds + lhs.timePeriod.durationSeconds ) < ( rhs.timePeriod.delaySeconds + rhs.timePeriod.durationSeconds ) );
-}
 
 } // namespace Internal