@@ -32,11 +32,6 @@ typedef struct
3232 * Target's current running actions.
3333 */
3434 ArrayList (TweenAction * ) current [1 ];
35-
36- /**
37- * A queue action currently is running in current list.
38- */
39- TweenAction * queueAction ;
4035}
4136Tween ;
4237
@@ -66,8 +61,6 @@ static inline Tween* GetTween()
6661 AArrayList -> Clear (tween -> current );
6762 }
6863
69- tween -> queueAction = NULL ;
70-
7164 return tween ;
7265}
7366
@@ -139,6 +132,20 @@ static inline void SetActionValue(TweenAction* action)
139132}
140133
141134
135+ static void PopQueueActionToRun (Tween * tween )
136+ {
137+ // get a queue action to run
138+ TweenAction * action = AArrayQueue_Pop (tween -> queue , TweenAction * );
139+
140+ if (action != NULL )
141+ {
142+ // add the running queue action into current list
143+ AArrayList_Add (tween -> current , action );
144+ SetActionValue (action );
145+ }
146+ }
147+
148+
142149static void * RunActions (Array (TweenAction * )* actions , void * tweenID )
143150{
144151 Tween * tween ;
@@ -183,17 +190,14 @@ static void* RunActions(Array(TweenAction*)* actions, void* tweenID)
183190 }
184191 }
185192
193+ PopQueueActionToRun (tween );
194+
186195 return tweenID ;
187196}
188197
189198
190- static void RemoveActionByIndex (Tween * tween , TweenAction * action , int index )
199+ static void RemoveCurrentActionByIndex (Tween * tween , TweenAction * action , int index )
191200{
192- if (action == tween -> queueAction )
193- {
194- tween -> queueAction = NULL ;
195- }
196-
197201 AArrayList -> RemoveByLast (tween -> current , index );
198202 AArrayList_Add (actionCacheList , action );
199203}
@@ -211,7 +215,7 @@ static bool TryRemoveAction(void* tweenID, TweenAction* action)
211215
212216 if (action == tweenAction )
213217 {
214- RemoveActionByIndex (tween , action , i );
218+ RemoveCurrentActionByIndex (tween , action , i );
215219 return true;
216220 }
217221 }
@@ -254,10 +258,6 @@ static bool TryRemoveAllActions(void* tweenID)
254258 AArrayList_Add (actionCacheList , action );
255259 }
256260
257- // if queueAction not NULL it must be in tweenData->current
258- // so just set NULL
259- tween -> queueAction = NULL ;
260-
261261 return true;
262262 }
263263
@@ -308,10 +308,6 @@ static bool TryCompleteAllActions(void* tweenID, bool isFireOnComplete)
308308 AArrayList_Add (actionCacheList , action );
309309 }
310310
311- // if queueAction not NULL it must be in tweenData->current
312- // so just set NULL
313- tween -> queueAction = NULL ;
314-
315311 return true;
316312 }
317313
@@ -344,20 +340,7 @@ static void Update(float deltaSeconds)
344340 for (int i = tweenRunningMap -> elementList -> size - 1 ; i > -1 ; -- i )
345341 {
346342 Tween * tween = AArrayIntMap_GetAt (tweenRunningMap , i , Tween * );
347-
348- // get a queue action to run
349- if (tween -> queueAction == NULL )
350- {
351- tween -> queueAction = AArrayQueue_Pop (tween -> queue , TweenAction * );
352-
353- if (tween -> queueAction != NULL )
354- {
355- // add the running queue action into current list
356- AArrayList_Add (tween -> current , tween -> queueAction );
357- SetActionValue (tween -> queueAction );
358- }
359- }
360-
343+
361344 if (tween -> current -> size == 0 )
362345 {
363346 // all actions complete so remove tweenData and push to cache
@@ -399,8 +382,13 @@ static void Update(float deltaSeconds)
399382 {
400383 action -> OnComplete (action );
401384 }
385+
386+ RemoveCurrentActionByIndex (tween , action , j );
402387
403- RemoveActionByIndex (tween , action , j );
388+ if (action -> isQueue )
389+ {
390+ PopQueueActionToRun (tween );
391+ }
404392 }
405393 }
406394 }
0 commit comments