removes Hungarian notation

from CCACtionManager and fixes some 64-bit issues.
This commit is contained in:
Ricardo Quesada 2013-11-04 16:30:33 -08:00
parent 2f0a19c7a3
commit 24ecbc426c
2 changed files with 87 additions and 87 deletions

View File

@ -65,55 +65,55 @@ ActionManager::~ActionManager(void)
// private // private
void ActionManager::deleteHashElement(tHashElement *pElement) void ActionManager::deleteHashElement(tHashElement *element)
{ {
ccArrayFree(pElement->actions); ccArrayFree(element->actions);
HASH_DEL(_targets, pElement); HASH_DEL(_targets, element);
pElement->target->release(); element->target->release();
free(pElement); free(element);
} }
void ActionManager::actionAllocWithHashElement(tHashElement *pElement) void ActionManager::actionAllocWithHashElement(tHashElement *element)
{ {
// 4 actions per Node by default // 4 actions per Node by default
if (pElement->actions == NULL) if (element->actions == NULL)
{ {
pElement->actions = ccArrayNew(4); element->actions = ccArrayNew(4);
}else }else
if (pElement->actions->num == pElement->actions->max) if (element->actions->num == element->actions->max)
{ {
ccArrayDoubleCapacity(pElement->actions); ccArrayDoubleCapacity(element->actions);
} }
} }
void ActionManager::removeActionAtIndex(int index, tHashElement *pElement) void ActionManager::removeActionAtIndex(long index, tHashElement *element)
{ {
Action *pAction = (Action*)pElement->actions->arr[index]; Action *action = (Action*)element->actions->arr[index];
if (pAction == pElement->currentAction && (! pElement->currentActionSalvaged)) if (action == element->currentAction && (! element->currentActionSalvaged))
{ {
pElement->currentAction->retain(); element->currentAction->retain();
pElement->currentActionSalvaged = true; element->currentActionSalvaged = true;
} }
ccArrayRemoveObjectAtIndex(pElement->actions, index, true); ccArrayRemoveObjectAtIndex(element->actions, index, true);
// update actionIndex in case we are in tick. looping over the actions // update actionIndex in case we are in tick. looping over the actions
if (pElement->actionIndex >= index) if (element->actionIndex >= index)
{ {
pElement->actionIndex--; element->actionIndex--;
} }
if (pElement->actions->num == 0) if (element->actions->num == 0)
{ {
if (_currentTarget == pElement) if (_currentTarget == element)
{ {
_currentTargetSalvaged = true; _currentTargetSalvaged = true;
} }
else else
{ {
deleteHashElement(pElement); deleteHashElement(element);
} }
} }
} }
@ -122,21 +122,21 @@ void ActionManager::removeActionAtIndex(int index, tHashElement *pElement)
void ActionManager::pauseTarget(Object *target) void ActionManager::pauseTarget(Object *target)
{ {
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
pElement->paused = true; element->paused = true;
} }
} }
void ActionManager::resumeTarget(Object *target) void ActionManager::resumeTarget(Object *target)
{ {
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
pElement->paused = false; element->paused = false;
} }
} }
@ -168,40 +168,40 @@ void ActionManager::resumeTargets(cocos2d::Set *targetsToResume)
// run // run
void ActionManager::addAction(Action *pAction, Node *target, bool paused) void ActionManager::addAction(Action *action, Node *target, bool paused)
{ {
CCASSERT(pAction != NULL, ""); CCASSERT(action != NULL, "");
CCASSERT(target != NULL, ""); CCASSERT(target != NULL, "");
tHashElement *pElement = NULL; tHashElement *element = NULL;
// we should convert it to Object*, because we save it as Object* // we should convert it to Object*, because we save it as Object*
Object *tmp = target; Object *tmp = target;
HASH_FIND_INT(_targets, &tmp, pElement); HASH_FIND_INT(_targets, &tmp, element);
if (! pElement) if (! element)
{ {
pElement = (tHashElement*)calloc(sizeof(*pElement), 1); element = (tHashElement*)calloc(sizeof(*element), 1);
pElement->paused = paused; element->paused = paused;
target->retain(); target->retain();
pElement->target = target; element->target = target;
HASH_ADD_INT(_targets, target, pElement); HASH_ADD_INT(_targets, target, element);
} }
actionAllocWithHashElement(pElement); actionAllocWithHashElement(element);
CCASSERT(! ccArrayContainsObject(pElement->actions, pAction), ""); CCASSERT(! ccArrayContainsObject(element->actions, action), "");
ccArrayAppendObject(pElement->actions, pAction); ccArrayAppendObject(element->actions, action);
pAction->startWithTarget(target); action->startWithTarget(target);
} }
// remove // remove
void ActionManager::removeAllActions(void) void ActionManager::removeAllActions(void)
{ {
for (tHashElement *pElement = _targets; pElement != NULL; ) for (tHashElement *element = _targets; element != NULL; )
{ {
Object *target = pElement->target; Object *target = element->target;
pElement = (tHashElement*)pElement->hh.next; element = (tHashElement*)element->hh.next;
removeAllActionsFromTarget(target); removeAllActionsFromTarget(target);
} }
} }
@ -214,24 +214,24 @@ void ActionManager::removeAllActionsFromTarget(Object *target)
return; return;
} }
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
if (ccArrayContainsObject(pElement->actions, pElement->currentAction) && (! pElement->currentActionSalvaged)) if (ccArrayContainsObject(element->actions, element->currentAction) && (! element->currentActionSalvaged))
{ {
pElement->currentAction->retain(); element->currentAction->retain();
pElement->currentActionSalvaged = true; element->currentActionSalvaged = true;
} }
ccArrayRemoveAllObjects(pElement->actions); ccArrayRemoveAllObjects(element->actions);
if (_currentTarget == pElement) if (_currentTarget == element)
{ {
_currentTargetSalvaged = true; _currentTargetSalvaged = true;
} }
else else
{ {
deleteHashElement(pElement); deleteHashElement(element);
} }
} }
else else
@ -240,23 +240,23 @@ void ActionManager::removeAllActionsFromTarget(Object *target)
} }
} }
void ActionManager::removeAction(Action *pAction) void ActionManager::removeAction(Action *action)
{ {
// explicit null handling // explicit null handling
if (pAction == NULL) if (action == NULL)
{ {
return; return;
} }
tHashElement *pElement = NULL; tHashElement *element = NULL;
Object *target = pAction->getOriginalTarget(); Object *target = action->getOriginalTarget();
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
unsigned int i = ccArrayGetIndexOfObject(pElement->actions, pAction); long i = ccArrayGetIndexOfObject(element->actions, action);
if (UINT_MAX != i) if (i != CC_INVALID_INDEX)
{ {
removeActionAtIndex(i, pElement); removeActionAtIndex(i, element);
} }
} }
else else
@ -270,19 +270,19 @@ void ActionManager::removeActionByTag(int tag, Object *target)
CCASSERT(tag != Action::INVALID_TAG, ""); CCASSERT(tag != Action::INVALID_TAG, "");
CCASSERT(target != NULL, ""); CCASSERT(target != NULL, "");
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
unsigned int limit = pElement->actions->num; long limit = element->actions->num;
for (unsigned int i = 0; i < limit; ++i) for (long i = 0; i < limit; ++i)
{ {
Action *pAction = (Action*)pElement->actions->arr[i]; Action *action = (Action*)element->actions->arr[i];
if (pAction->getTag() == (int)tag && pAction->getOriginalTarget() == target) if (action->getTag() == (int)tag && action->getOriginalTarget() == target)
{ {
removeActionAtIndex(i, pElement); removeActionAtIndex(i, element);
break; break;
} }
} }
@ -297,21 +297,21 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
{ {
CCASSERT(tag != Action::INVALID_TAG, ""); CCASSERT(tag != Action::INVALID_TAG, "");
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
if (pElement->actions != NULL) if (element->actions != NULL)
{ {
unsigned int limit = pElement->actions->num; long limit = element->actions->num;
for (unsigned int i = 0; i < limit; ++i) for (long i = 0; i < limit; ++i)
{ {
Action *pAction = (Action*)pElement->actions->arr[i]; Action *action = (Action*)element->actions->arr[i];
if (pAction->getTag() == (int)tag) if (action->getTag() == (int)tag)
{ {
return pAction; return action;
} }
} }
} }
@ -329,11 +329,11 @@ Action* ActionManager::getActionByTag(int tag, const Object *target) const
// and, it is not possible to get the address of a reference // and, it is not possible to get the address of a reference
unsigned int ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const unsigned int ActionManager::getNumberOfRunningActionsInTarget(const Object *target) const
{ {
tHashElement *pElement = NULL; tHashElement *element = NULL;
HASH_FIND_INT(_targets, &target, pElement); HASH_FIND_INT(_targets, &target, element);
if (pElement) if (element)
{ {
return pElement->actions ? pElement->actions->num : 0; return element->actions ? element->actions->num : 0;
} }
return 0; return 0;
@ -374,10 +374,10 @@ void ActionManager::update(float dt)
{ {
_currentTarget->currentAction->stop(); _currentTarget->currentAction->stop();
Action *pAction = _currentTarget->currentAction; Action *action = _currentTarget->currentAction;
// Make currentAction nil to prevent removeAction from salvaging it. // Make currentAction nil to prevent removeAction from salvaging it.
_currentTarget->currentAction = NULL; _currentTarget->currentAction = NULL;
removeAction(pAction); removeAction(action);
} }
_currentTarget->currentAction = NULL; _currentTarget->currentAction = NULL;

View File

@ -126,7 +126,7 @@ public:
protected: protected:
// declared in ActionManager.m // declared in ActionManager.m
void removeActionAtIndex(int index, struct _hashElement *pElement); void removeActionAtIndex(long index, struct _hashElement *pElement);
void deleteHashElement(struct _hashElement *pElement); void deleteHashElement(struct _hashElement *pElement);
void actionAllocWithHashElement(struct _hashElement *pElement); void actionAllocWithHashElement(struct _hashElement *pElement);
void update(float dt); void update(float dt);