2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Valentin Milea
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "2d/CCActionManager.h"
|
|
|
|
#include "2d/CCNode.h"
|
|
|
|
#include "2d/CCAction.h"
|
|
|
|
#include "base/CCScheduler.h"
|
|
|
|
#include "base/ccMacros.h"
|
|
|
|
#include "base/ccCArray.h"
|
|
|
|
#include "base/uthash.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
//
|
|
|
|
// singleton stuff
|
|
|
|
//
|
|
|
|
typedef struct _hashElement
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
struct _ccArray* actions;
|
|
|
|
Node* target;
|
|
|
|
int actionIndex;
|
|
|
|
Action* currentAction;
|
|
|
|
bool currentActionSalvaged;
|
|
|
|
bool paused;
|
|
|
|
UT_hash_handle hh;
|
2019-11-23 20:27:39 +08:00
|
|
|
} tHashElement;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionManager::ActionManager() : _targets(nullptr), _currentTarget(nullptr), _currentTargetSalvaged(false) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
ActionManager::~ActionManager()
|
|
|
|
{
|
|
|
|
CCLOGINFO("deallocing ActionManager: %p", this);
|
|
|
|
|
|
|
|
removeAllActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::deleteHashElement(tHashElement* element)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
ccArrayFree(element->actions);
|
|
|
|
HASH_DEL(_targets, element);
|
|
|
|
element->target->release();
|
|
|
|
free(element);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::actionAllocWithHashElement(tHashElement* element)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// 4 actions per Node by default
|
|
|
|
if (element->actions == nullptr)
|
|
|
|
{
|
|
|
|
element->actions = ccArrayNew(4);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (element->actions->num == element->actions->max)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
ccArrayDoubleCapacity(element->actions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeActionAtIndex(ssize_t index, tHashElement* element)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = static_cast<Action*>(element->actions->arr[index]);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (action == element->currentAction && (!element->currentActionSalvaged))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
element->currentAction->retain();
|
|
|
|
element->currentActionSalvaged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccArrayRemoveObjectAtIndex(element->actions, index, true);
|
|
|
|
|
|
|
|
// update actionIndex in case we are in tick. looping over the actions
|
|
|
|
if (element->actionIndex >= index)
|
|
|
|
{
|
|
|
|
element->actionIndex--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element->actions->num == 0)
|
|
|
|
{
|
|
|
|
if (_currentTarget == element)
|
|
|
|
{
|
|
|
|
_currentTargetSalvaged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deleteHashElement(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pause / resume
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::pauseTarget(Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
element->paused = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::resumeTarget(Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
element->paused = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Node*> ActionManager::pauseAllRunningActions()
|
|
|
|
{
|
|
|
|
Vector<Node*> idsWithActions;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
for (tHashElement* element = _targets; element != nullptr; element = (tHashElement*)element->hh.next)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!element->paused)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
element->paused = true;
|
|
|
|
idsWithActions.pushBack(element->target);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return idsWithActions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManager::resumeTargets(const Vector<Node*>& targetsToResume)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (const auto& node : targetsToResume)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
this->resumeTarget(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// run
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::addAction(Action* action, Node* target, bool paused)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CCASSERT(action != nullptr, "action can't be nullptr!");
|
|
|
|
CCASSERT(target != nullptr, "target can't be nullptr!");
|
2021-12-25 10:04:45 +08:00
|
|
|
if (action == nullptr || target == nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
// we should convert it to Ref*, because we save it as Ref*
|
2021-12-25 10:04:45 +08:00
|
|
|
Ref* tmp = target;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &tmp, element);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!element)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
element = (tHashElement*)calloc(sizeof(*element), 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
element->paused = paused;
|
|
|
|
target->retain();
|
|
|
|
element->target = target;
|
|
|
|
HASH_ADD_PTR(_targets, target, element);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
actionAllocWithHashElement(element);
|
|
|
|
|
|
|
|
CCASSERT(!ccArrayContainsObject(element->actions, action), "action already be added!");
|
|
|
|
ccArrayAppendObject(element->actions, action);
|
|
|
|
|
|
|
|
action->startWithTarget(target);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove
|
|
|
|
|
|
|
|
void ActionManager::removeAllActions()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (tHashElement* element = _targets; element != nullptr;)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto target = element->target;
|
2021-12-25 10:04:45 +08:00
|
|
|
element = (tHashElement*)element->hh.next;
|
2019-11-23 20:27:39 +08:00
|
|
|
removeAllActionsFromTarget(target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeAllActionsFromTarget(Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// explicit null handling
|
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
if (element)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (ccArrayContainsObject(element->actions, element->currentAction) && (!element->currentActionSalvaged))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
element->currentAction->retain();
|
|
|
|
element->currentActionSalvaged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccArrayRemoveAllObjects(element->actions);
|
|
|
|
if (_currentTarget == element)
|
|
|
|
{
|
|
|
|
_currentTargetSalvaged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deleteHashElement(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeAction(Action* action)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// explicit null handling
|
|
|
|
if (action == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
|
|
|
Ref* target = action->getOriginalTarget();
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
auto i = ccArrayGetIndexOfObject(element->actions, action);
|
|
|
|
if (i != CC_INVALID_INDEX)
|
|
|
|
{
|
|
|
|
removeActionAtIndex(i, element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeActionByTag(int tag, Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
|
|
|
CCASSERT(target != nullptr, "target can't be nullptr!");
|
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
auto limit = element->actions->num;
|
|
|
|
for (int i = 0; i < limit; ++i)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = static_cast<Action*>(element->actions->arr[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (action->getTag() == (int)tag && action->getOriginalTarget() == target)
|
|
|
|
{
|
|
|
|
removeActionAtIndex(i, element);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeAllActionsByTag(int tag, Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
|
|
|
CCASSERT(target != nullptr, "target can't be nullptr!");
|
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
auto limit = element->actions->num;
|
|
|
|
for (int i = 0; i < limit;)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = static_cast<Action*>(element->actions->arr[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (action->getTag() == (int)tag && action->getOriginalTarget() == target)
|
|
|
|
{
|
|
|
|
removeActionAtIndex(i, element);
|
|
|
|
--limit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManager::removeActionsByFlags(unsigned int flags, Node* target)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (flags == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CCASSERT(target != nullptr, "target can't be nullptr!");
|
|
|
|
if (target == nullptr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
auto limit = element->actions->num;
|
|
|
|
for (int i = 0; i < limit;)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = static_cast<Action*>(element->actions->arr[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if ((action->getFlags() & flags) != 0 && action->getOriginalTarget() == target)
|
|
|
|
{
|
|
|
|
removeActionAtIndex(i, element);
|
|
|
|
--limit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get
|
|
|
|
|
|
|
|
// FIXME: Passing "const O *" instead of "const O&" because HASH_FIND_IT requires the address of a pointer
|
|
|
|
// and, it is not possible to get the address of a reference
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* ActionManager::getActionByTag(int tag, const Node* target) const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
if (element->actions != nullptr)
|
|
|
|
{
|
|
|
|
auto limit = element->actions->num;
|
|
|
|
for (int i = 0; i < limit; ++i)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = static_cast<Action*>(element->actions->arr[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (action->getTag() == (int)tag)
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Passing "const O *" instead of "const O&" because HASH_FIND_IT requires the address of a pointer
|
|
|
|
// and, it is not possible to get the address of a reference
|
2021-12-25 10:04:45 +08:00
|
|
|
ssize_t ActionManager::getNumberOfRunningActionsInTarget(const Node* target) const
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
if (element)
|
|
|
|
{
|
|
|
|
return element->actions ? element->actions->num : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Passing "const O *" instead of "const O&" because HASH_FIND_IT requires the address of a pointer
|
|
|
|
// and, it is not possible to get the address of a reference
|
2021-12-25 10:04:45 +08:00
|
|
|
size_t ActionManager::getNumberOfRunningActionsInTargetByTag(const Node* target, int tag)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
CCASSERT(tag != Action::INVALID_TAG, "Invalid tag value!");
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
tHashElement* element = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
HASH_FIND_PTR(_targets, &target, element);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!element || !element->actions)
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int count = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
auto limit = element->actions->num;
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < limit; ++i)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto action = static_cast<Action*>(element->actions->arr[i]);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (action->getTag() == tag)
|
2019-11-23 20:27:39 +08:00
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t ActionManager::getNumberOfRunningActions() const
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ssize_t count = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
struct _hashElement* element = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
struct _hashElement* tmp = nullptr;
|
|
|
|
HASH_ITER(hh, _targets, element, tmp) { count += (element->actions ? element->actions->num : 0); }
|
2019-11-23 20:27:39 +08:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
// main loop
|
|
|
|
void ActionManager::update(float dt)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
for (tHashElement* elt = _targets; elt != nullptr;)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_currentTarget = elt;
|
2019-11-23 20:27:39 +08:00
|
|
|
_currentTargetSalvaged = false;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_currentTarget->paused)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// The 'actions' MutableArray may change while inside this loop.
|
|
|
|
for (_currentTarget->actionIndex = 0; _currentTarget->actionIndex < _currentTarget->actions->num;
|
2021-12-25 10:04:45 +08:00
|
|
|
_currentTarget->actionIndex++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_currentTarget->currentAction =
|
|
|
|
static_cast<Action*>(_currentTarget->actions->arr[_currentTarget->actionIndex]);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (_currentTarget->currentAction == nullptr)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentTarget->currentActionSalvaged = false;
|
|
|
|
|
|
|
|
_currentTarget->currentAction->step(dt);
|
|
|
|
|
|
|
|
if (_currentTarget->currentActionSalvaged)
|
|
|
|
{
|
|
|
|
// The currentAction told the node to remove it. To prevent the action from
|
|
|
|
// accidentally deallocating itself before finishing its step, we retained
|
|
|
|
// it. Now that step is done, it's safe to release it.
|
|
|
|
_currentTarget->currentAction->release();
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (_currentTarget->currentAction->isDone())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
_currentTarget->currentAction->stop();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Action* action = _currentTarget->currentAction;
|
2019-11-23 20:27:39 +08:00
|
|
|
// Make currentAction nil to prevent removeAction from salvaging it.
|
|
|
|
_currentTarget->currentAction = nullptr;
|
|
|
|
removeAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentTarget->currentAction = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// elt, at this moment, is still valid
|
|
|
|
// so it is safe to ask this here (issue #490)
|
|
|
|
elt = (tHashElement*)(elt->hh.next);
|
|
|
|
|
|
|
|
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
|
|
|
|
if (_currentTargetSalvaged && _currentTarget->actions->num == 0)
|
|
|
|
{
|
|
|
|
deleteHashElement(_currentTarget);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
// if some node reference 'target', it's reference count >= 2 (issues #14050)
|
2019-11-23 20:27:39 +08:00
|
|
|
else if (_currentTarget->target->getReferenceCount() == 1)
|
|
|
|
{
|
|
|
|
deleteHashElement(_currentTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// issue #635
|
|
|
|
_currentTarget = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|