diff --git a/Engine/Toolkit/Math/TweenEase.c b/Engine/Toolkit/Math/TweenEase.c index 40a22cd..acd46f8 100644 --- a/Engine/Toolkit/Math/TweenEase.c +++ b/Engine/Toolkit/Math/TweenEase.c @@ -34,7 +34,6 @@ static float Linear(float time) static float Smooth(float time) { - ALog_E("Smooth"); return time * time * (3.0f - 2.0f * time); } diff --git a/Engine/Toolkit/Utils/Tween.c b/Engine/Toolkit/Utils/Tween.c index 12e1a6d..28b6f85 100644 --- a/Engine/Toolkit/Utils/Tween.c +++ b/Engine/Toolkit/Utils/Tween.c @@ -32,11 +32,6 @@ typedef struct * Target's current running actions. */ ArrayList(TweenAction*) current[1]; - - /** - * A queue action currently is running in current list. - */ - TweenAction* queueAction; } Tween; @@ -66,8 +61,6 @@ static inline Tween* GetTween() AArrayList ->Clear(tween->current); } - tween->queueAction = NULL; - return tween; } @@ -139,6 +132,20 @@ static inline void SetActionValue(TweenAction* action) } +static void PopQueueActionToRun(Tween* tween) +{ + // get a queue action to run + TweenAction* action = AArrayQueue_Pop(tween->queue, TweenAction*); + + if (action != NULL) + { + // add the running queue action into current list + AArrayList_Add(tween->current, action); + SetActionValue(action); + } +} + + static void* RunActions(Array(TweenAction*)* actions, void* tweenID) { Tween* tween; @@ -183,17 +190,14 @@ static void* RunActions(Array(TweenAction*)* actions, void* tweenID) } } + PopQueueActionToRun(tween); + return tweenID; } -static void RemoveActionByIndex(Tween* tween, TweenAction* action, int index) +static void RemoveCurrentActionByIndex(Tween* tween, TweenAction* action, int index) { - if (action == tween->queueAction) - { - tween->queueAction = NULL; - } - AArrayList->RemoveByLast(tween->current, index); AArrayList_Add(actionCacheList, action); } @@ -211,7 +215,7 @@ static bool TryRemoveAction(void* tweenID, TweenAction* action) if (action == tweenAction) { - RemoveActionByIndex(tween, action, i); + RemoveCurrentActionByIndex(tween, action, i); return true; } } @@ -254,10 +258,6 @@ static bool TryRemoveAllActions(void* tweenID) AArrayList_Add(actionCacheList, action); } - // if queueAction not NULL it must be in tweenData->current - // so just set NULL - tween->queueAction = NULL; - return true; } @@ -308,10 +308,6 @@ static bool TryCompleteAllActions(void* tweenID, bool isFireOnComplete) AArrayList_Add(actionCacheList, action); } - // if queueAction not NULL it must be in tweenData->current - // so just set NULL - tween->queueAction = NULL; - return true; } @@ -344,20 +340,7 @@ static void Update(float deltaSeconds) for (int i = tweenRunningMap->elementList->size - 1; i > -1; --i) { Tween* tween = AArrayIntMap_GetAt(tweenRunningMap, i, Tween*); - - // get a queue action to run - if (tween->queueAction == NULL) - { - tween->queueAction = AArrayQueue_Pop(tween->queue, TweenAction*); - - if (tween->queueAction != NULL) - { - // add the running queue action into current list - AArrayList_Add(tween->current, tween->queueAction); - SetActionValue(tween->queueAction); - } - } - + if (tween->current->size == 0) { // all actions complete so remove tweenData and push to cache @@ -399,8 +382,13 @@ static void Update(float deltaSeconds) { action->OnComplete(action); } + + RemoveCurrentActionByIndex(tween, action, j); - RemoveActionByIndex(tween, action, j); + if (action->isQueue) + { + PopQueueActionToRun(tween); + } } } }