axmol/cocos2dx/CCScheduler.cpp

789 lines
19 KiB
C++
Raw Normal View History

2012-02-01 16:45:23 +08:00
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011 Zynga Inc.
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 "CCScheduler.h"
#include "ccMacros.h"
#include "CCDirector.h"
2012-02-01 16:45:23 +08:00
#include "support/data_support/utlist.h"
#include "support/data_support/ccCArray.h"
2012-02-09 14:07:11 +08:00
#include "CCArray.h"
#include "CCScriptSupport.h"
2012-02-02 15:58:10 +08:00
2012-02-01 16:45:23 +08:00
using namespace std;
namespace cocos2d {
// data structures
// A list double-linked list used for "updates with priority"
typedef struct _listEntry
{
struct _listEntry *prev, *next;
CCObject *target; // not retained (retained by hashUpdateEntry)
int priority;
bool paused;
bool markedForDeletion; // selector will no longer be called and entry will be removed at end of the next tick
2012-02-06 10:54:51 +08:00
2012-02-01 16:45:23 +08:00
} tListEntry;
typedef struct _hashUpdateEntry
{
tListEntry **list; // Which list does it belong to ?
tListEntry *entry; // entry in the list
CCObject *target; // hash key (retained)
UT_hash_handle hh;
} tHashUpdateEntry;
// Hash Element used for "selectors with interval"
typedef struct _hashSelectorEntry
{
ccArray *timers;
CCObject *target; // hash key (retained)
unsigned int timerIndex;
CCTimer *currentTimer;
bool currentTimerSalvaged;
bool paused;
UT_hash_handle hh;
} tHashSelectorEntry;
// implementation CCTimer
CCTimer::CCTimer()
: m_pfnSelector(NULL)
, m_fInterval(0.0f)
, m_pTarget(NULL)
, m_fElapsed(0.0f)
, m_bRunForever(false)
, m_bUseDelay(false)
, m_nTimesExecuted(0)
, m_nRepeat(0)
, m_fDelay(0.0f)
2012-02-07 11:43:29 +08:00
, m_nScriptHandler(0)
2012-02-01 16:45:23 +08:00
{
}
CCTimer* CCTimer::timerWithTarget(CCObject *pTarget, SEL_SCHEDULE pfnSelector)
{
CCTimer *pTimer = new CCTimer();
pTimer->initWithTarget(pTarget, pfnSelector, 0.0f, kCCRepeatForever, 0.0f);
2012-02-01 16:45:23 +08:00
pTimer->autorelease();
return pTimer;
}
CCTimer* CCTimer::timerWithTarget(CCObject *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds)
{
CCTimer *pTimer = new CCTimer();
pTimer->initWithTarget(pTarget, pfnSelector, fSeconds, kCCRepeatForever, 0.0f);
2012-02-01 16:45:23 +08:00
pTimer->autorelease();
return pTimer;
}
2012-02-07 11:43:29 +08:00
CCTimer* CCTimer::timerWithScriptHandler(int nHandler, ccTime fSeconds)
2012-02-02 15:58:10 +08:00
{
2012-02-06 10:54:51 +08:00
CCTimer *pTimer = new CCTimer();
2012-02-02 15:58:10 +08:00
2012-02-07 11:43:29 +08:00
pTimer->initWithScriptHandler(nHandler, fSeconds);
2012-02-06 10:54:51 +08:00
pTimer->autorelease();
2012-02-02 15:58:10 +08:00
2012-02-06 10:54:51 +08:00
return pTimer;
2012-02-02 15:58:10 +08:00
}
2012-02-07 11:43:29 +08:00
bool CCTimer::initWithScriptHandler(int nHandler, ccTime fSeconds)
2012-02-02 15:58:10 +08:00
{
2012-02-07 11:43:29 +08:00
m_nScriptHandler = nHandler;
2012-02-06 10:54:51 +08:00
m_fElapsed = -1;
2012-02-02 15:58:10 +08:00
m_fInterval = fSeconds;
2012-02-06 10:54:51 +08:00
return true;
2012-02-02 15:58:10 +08:00
}
2012-02-01 16:45:23 +08:00
bool CCTimer::initWithTarget(CCObject *pTarget, SEL_SCHEDULE pfnSelector)
{
return initWithTarget(pTarget, pfnSelector, 0, kCCRepeatForever, 0.0f);
2012-02-01 16:45:23 +08:00
}
bool CCTimer::initWithTarget(CCObject *pTarget, SEL_SCHEDULE pfnSelector, ccTime fSeconds, unsigned int nRepeat, ccTime fDelay)
2012-02-01 16:45:23 +08:00
{
m_pTarget = pTarget;
m_pfnSelector = pfnSelector;
m_fElapsed = -1;
m_fInterval = fSeconds;
m_fDelay = fDelay;
m_bUseDelay = (fDelay > 0.0f) ? true : false;
m_nRepeat = nRepeat;
m_bRunForever = (nRepeat == kCCRepeatForever) ? true : false;
2012-02-01 16:45:23 +08:00
return true;
}
void CCTimer::update(ccTime dt)
{
if (m_fElapsed == -1)
{
m_fElapsed = 0;
m_nTimesExecuted = 0;
2012-02-01 16:45:23 +08:00
}
else
{
if (m_bRunForever && !m_bUseDelay)
{//standard timer usage
m_fElapsed += dt;
if (m_fElapsed >= m_fInterval)
{
if (m_pTarget != NULL && m_pfnSelector != NULL)
{
(m_pTarget->*m_pfnSelector)(m_fElapsed);
}
if (m_nScriptHandler)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nScriptHandler, m_fElapsed);
}
m_fElapsed = 0;
}
}
else
{//advanced usage
m_fElapsed += dt;
if (m_bUseDelay)
{
if( m_fElapsed >= m_fDelay )
{
if (m_pTarget != NULL && m_pfnSelector != NULL)
{
(m_pTarget->*m_pfnSelector)(m_fElapsed);
}
m_fElapsed = m_fElapsed - m_fDelay;
m_nTimesExecuted+=1;
m_bUseDelay = false;
}
}
else
{
if (m_fElapsed >= m_fInterval)
{
if (m_pTarget != NULL && m_pfnSelector != NULL)
{
(m_pTarget->*m_pfnSelector)(m_fElapsed);
}
m_fElapsed = 0;
m_nTimesExecuted += 1;
}
}
if (m_nTimesExecuted > m_nRepeat)
{ //unschedule timer
CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(m_pfnSelector, m_pTarget);
}
}
2012-02-01 16:45:23 +08:00
}
2012-02-01 16:45:23 +08:00
}
// implementation of CCScheduler
CCScheduler::CCScheduler(void)
: m_fTimeScale(1.0f)
2012-02-01 16:45:23 +08:00
, m_pUpdatesNegList(NULL)
, m_pUpdates0List(NULL)
, m_pUpdatesPosList(NULL)
, m_pHashForUpdates(NULL)
, m_pHashForSelectors(NULL)
, m_pCurrentTarget(NULL)
, m_bCurrentTargetSalvaged(false)
2012-02-07 11:43:29 +08:00
, m_pScriptHandlerEntries(NULL)
, m_bUpdateHashLocked(false)
2012-02-01 16:45:23 +08:00
{
2012-02-01 16:45:23 +08:00
}
CCScheduler::~CCScheduler(void)
{
unscheduleAllSelectors();
2012-02-09 14:07:11 +08:00
CC_SAFE_RELEASE(m_pScriptHandlerEntries);
2012-02-01 16:45:23 +08:00
}
void CCScheduler::removeHashElement(_hashSelectorEntry *pElement)
{
ccArrayFree(pElement->timers);
2012-02-06 10:54:51 +08:00
pElement->target->release();
2012-02-01 16:45:23 +08:00
pElement->target = NULL;
HASH_DEL(m_pHashForSelectors, pElement);
free(pElement);
}
void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget, float fInterval, bool bPaused)
{
this->scheduleSelector(pfnSelector, pTarget, fInterval, bPaused, kCCRepeatForever, 0.0f);
}
void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget, ccTime fInterval, bool bPaused, unsigned int repeat, ccTime delay)
2012-02-01 16:45:23 +08:00
{
CCAssert(pfnSelector, "");
CCAssert(pTarget, "");
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if (! pElement)
{
pElement = (tHashSelectorEntry *)calloc(sizeof(*pElement), 1);
pElement->target = pTarget;
if (pTarget)
{
2012-02-06 10:54:51 +08:00
pTarget->retain();
2012-02-01 16:45:23 +08:00
}
HASH_ADD_INT(m_pHashForSelectors, target, pElement);
// Is this the 1st element ? Then set the pause level to all the selectors of this target
pElement->paused = bPaused;
}
else
{
CCAssert(pElement->paused == bPaused, "");
}
if (pElement->timers == NULL)
{
pElement->timers = ccArrayNew(10);
}
2012-02-06 10:54:51 +08:00
else
2012-02-01 16:45:23 +08:00
{
for (unsigned int i = 0; i < pElement->timers->num; ++i)
{
CCTimer *timer = (CCTimer*)pElement->timers->arr[i];
if (pfnSelector == timer->m_pfnSelector)
{
CCLOG("CCSheduler#scheduleSelector. Selector already scheduled.");
timer->m_fInterval = fInterval;
return;
2012-02-06 10:54:51 +08:00
}
2012-02-01 16:45:23 +08:00
}
ccArrayEnsureExtraCapacity(pElement->timers, 1);
}
CCTimer *pTimer = new CCTimer();
pTimer->initWithTarget(pTarget, pfnSelector, fInterval, repeat, delay);
2012-02-01 16:45:23 +08:00
ccArrayAppendObject(pElement->timers, pTimer);
2012-02-06 10:54:51 +08:00
pTimer->release();
2012-02-01 16:45:23 +08:00
}
void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget)
{
// explicity handle nil arguments when removing an object
if (pTarget == 0 || pfnSelector == 0)
{
return;
}
//CCAssert(pTarget);
//CCAssert(pfnSelector);
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if (pElement)
{
for (unsigned int i = 0; i < pElement->timers->num; ++i)
{
CCTimer *pTimer = (CCTimer*)(pElement->timers->arr[i]);
if (pfnSelector == pTimer->m_pfnSelector)
{
if (pTimer == pElement->currentTimer && (! pElement->currentTimerSalvaged))
{
pElement->currentTimer->retain();
pElement->currentTimerSalvaged = true;
}
ccArrayRemoveObjectAtIndex(pElement->timers, i, true);
2012-02-01 16:45:23 +08:00
// update timerIndex in case we are in tick:, looping over the actions
if (pElement->timerIndex >= i)
{
pElement->timerIndex--;
}
if (pElement->timers->num == 0)
{
if (m_pCurrentTarget == pElement)
{
m_bCurrentTargetSalvaged = true;
}
else
{
removeHashElement(pElement);
}
}
return;
}
}
}
}
void CCScheduler::priorityIn(tListEntry **ppList, CCObject *pTarget, int nPriority, bool bPaused)
{
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
pListElement->target = pTarget;
pListElement->priority = nPriority;
pListElement->paused = bPaused;
pListElement->next = pListElement->prev = NULL;
pListElement->markedForDeletion = false;
// empey list ?
if (! *ppList)
{
DL_APPEND(*ppList, pListElement);
}
else
{
bool bAdded = false;
for (tListEntry *pElement = *ppList; pElement; pElement = pElement->next)
{
if (nPriority < pElement->priority)
{
if (pElement == *ppList)
{
DL_PREPEND(*ppList, pListElement);
}
else
{
pListElement->next = pElement;
pListElement->prev = pElement->prev;
pElement->prev->next = pListElement;
pElement->prev = pListElement;
}
bAdded = true;
break;
}
}
// Not added? priority has the higher value. Append it.
if (! bAdded)
{
DL_APPEND(*ppList, pListElement);
}
}
// update hash entry for quick access
tHashUpdateEntry *pHashElement = (tHashUpdateEntry *)calloc(sizeof(*pHashElement), 1);
pHashElement->target = pTarget;
2012-02-06 10:54:51 +08:00
pTarget->retain();
2012-02-01 16:45:23 +08:00
pHashElement->list = ppList;
pHashElement->entry = pListElement;
HASH_ADD_INT(m_pHashForUpdates, target, pHashElement);
}
void CCScheduler::appendIn(_listEntry **ppList, CCObject *pTarget, bool bPaused)
{
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
pListElement->target = pTarget;
pListElement->paused = bPaused;
pListElement->markedForDeletion = false;
DL_APPEND(*ppList, pListElement);
// update hash entry for quicker access
tHashUpdateEntry *pHashElement = (tHashUpdateEntry *)calloc(sizeof(*pHashElement), 1);
pHashElement->target = pTarget;
2012-02-06 10:54:51 +08:00
pTarget->retain();
2012-02-01 16:45:23 +08:00
pHashElement->list = ppList;
pHashElement->entry = pListElement;
HASH_ADD_INT(m_pHashForUpdates, target, pHashElement);
}
void CCScheduler::scheduleUpdateForTarget(CCObject *pTarget, int nPriority, bool bPaused)
{
tHashUpdateEntry *pHashElement = NULL;
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pHashElement);
if (pHashElement)
{
#if COCOS2D_DEBUG >= 1
CCAssert(pHashElement->entry->markedForDeletion,"");
#endif
// TODO: check if priority has changed!
pHashElement->entry->markedForDeletion = false;
return;
}
// most of the updates are going to be 0, that's way there
// is an special list for updates with priority 0
if (nPriority == 0)
{
appendIn(&m_pUpdates0List, pTarget, bPaused);
} else
if (nPriority < 0)
{
priorityIn(&m_pUpdatesNegList, pTarget, nPriority, bPaused);
}
else
{
// priority > 0
priorityIn(&m_pUpdatesPosList, pTarget, nPriority, bPaused);
}
}
void CCScheduler::removeUpdateFromHash(struct _listEntry *entry)
{
tHashUpdateEntry *element = NULL;
HASH_FIND_INT(m_pHashForUpdates, &entry->target, element);
if (element)
{
// list entry
DL_DELETE(*element->list, element->entry);
free(element->entry);
// hash entry
2012-02-06 10:54:51 +08:00
element->target->release();
2012-02-01 16:45:23 +08:00
HASH_DEL(m_pHashForUpdates, element);
free(element);
}
}
void CCScheduler::unscheduleUpdateForTarget(const CCObject *pTarget)
{
if (pTarget == NULL)
{
return;
}
tHashUpdateEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElement);
if (pElement)
{
if (m_bUpdateHashLocked)
{
pElement->entry->markedForDeletion = true;
}
else
{
this->removeUpdateFromHash(pElement->entry);
}
}
}
void CCScheduler::unscheduleAllSelectors(void)
{
// Custom Selectors
tHashSelectorEntry *pElement = NULL;
tHashSelectorEntry *pNextElement = NULL;
for (pElement = m_pHashForSelectors; pElement != NULL;)
{
// pElement may be removed in unscheduleAllSelectorsForTarget
pNextElement = (tHashSelectorEntry *)pElement->hh.next;
unscheduleAllSelectorsForTarget(pElement->target);
pElement = pNextElement;
}
// Updates selectors
tListEntry *pEntry, *pTmp;
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
{
unscheduleUpdateForTarget(pEntry->target);
}
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
{
unscheduleUpdateForTarget(pEntry->target);
}
DL_FOREACH_SAFE(m_pUpdatesPosList, pEntry, pTmp)
{
unscheduleUpdateForTarget(pEntry->target);
}
2012-02-06 10:54:51 +08:00
2012-02-09 14:07:11 +08:00
if (m_pScriptHandlerEntries)
{
m_pScriptHandlerEntries->removeAllObjects();
}
}
2012-02-01 16:45:23 +08:00
void CCScheduler::unscheduleAllSelectorsForTarget(CCObject *pTarget)
{
// explicit NULL handling
if (pTarget == NULL)
{
return;
}
// Custom Selectors
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if (pElement)
{
if (ccArrayContainsObject(pElement->timers, pElement->currentTimer)
&& (! pElement->currentTimerSalvaged))
{
pElement->currentTimer->retain();
pElement->currentTimerSalvaged = true;
}
ccArrayRemoveAllObjects(pElement->timers);
if (m_pCurrentTarget == pElement)
{
m_bCurrentTargetSalvaged = true;
}
else
{
removeHashElement(pElement);
}
}
// update selector
unscheduleUpdateForTarget(pTarget);
}
2012-02-07 11:43:29 +08:00
unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, ccTime fInterval, bool bPaused)
2012-02-02 15:58:10 +08:00
{
2012-02-07 11:43:29 +08:00
CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::entryWithHandler(nHandler, fInterval, bPaused);
2012-02-09 14:07:11 +08:00
if (!m_pScriptHandlerEntries)
{
m_pScriptHandlerEntries = CCArray::arrayWithCapacity(20);
m_pScriptHandlerEntries->retain();
}
2012-02-07 11:43:29 +08:00
m_pScriptHandlerEntries->addObject(pEntry);
2012-02-02 15:58:10 +08:00
return pEntry->getEntryID();
}
void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
{
2012-02-07 11:43:29 +08:00
for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
2012-02-02 15:58:10 +08:00
{
2012-02-07 11:43:29 +08:00
CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
2012-02-02 15:58:10 +08:00
if (pEntry->getEntryID() == uScheduleScriptEntryID)
{
pEntry->markedForDeletion();
break;
}
}
}
2012-02-01 16:45:23 +08:00
void CCScheduler::resumeTarget(CCObject *pTarget)
{
CCAssert(pTarget != NULL, "");
// custom selectors
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if (pElement)
{
pElement->paused = false;
}
// update selector
tHashUpdateEntry *pElementUpdate = NULL;
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElementUpdate);
if (pElementUpdate)
{
CCAssert(pElementUpdate->entry != NULL, "");
pElementUpdate->entry->paused = false;
}
}
void CCScheduler::pauseTarget(CCObject *pTarget)
{
CCAssert(pTarget != NULL, "");
// custom selectors
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if (pElement)
{
pElement->paused = true;
}
// update selector
tHashUpdateEntry *pElementUpdate = NULL;
HASH_FIND_INT(m_pHashForUpdates, &pTarget, pElementUpdate);
if (pElementUpdate)
{
CCAssert(pElementUpdate->entry != NULL, "");
pElementUpdate->entry->paused = true;
}
}
bool CCScheduler::isTargetPaused(CCObject *pTarget)
{
CCAssert( pTarget != NULL, "target must be non nil" );
// Custom selectors
tHashSelectorEntry *pElement = NULL;
HASH_FIND_INT(m_pHashForSelectors, &pTarget, pElement);
if( pElement )
{
return pElement->paused;
}
return false; // should never get here
}
// main loop
void CCScheduler::update(ccTime dt)
2012-02-01 16:45:23 +08:00
{
m_bUpdateHashLocked = true;
if (m_fTimeScale != 1.0f)
{
dt *= m_fTimeScale;
}
// Iterate all over the Updates selectors
tListEntry *pEntry, *pTmp;
// updates with priority < 0
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
pEntry->target->update(dt);
}
}
// updates with priority == 0
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
2012-02-06 10:54:51 +08:00
pEntry->target->update(dt);
2012-02-01 16:45:23 +08:00
}
}
// updates with priority > 0
DL_FOREACH_SAFE(m_pUpdatesPosList, pEntry, pTmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
2012-02-06 10:54:51 +08:00
pEntry->target->update(dt);
2012-02-01 16:45:23 +08:00
}
}
// Interate all over the custom selectors
for (tHashSelectorEntry *elt = m_pHashForSelectors; elt != NULL; )
{
m_pCurrentTarget = elt;
m_bCurrentTargetSalvaged = false;
if (! m_pCurrentTarget->paused)
{
// The 'timers' array may change while inside this loop
for (elt->timerIndex = 0; elt->timerIndex < elt->timers->num; ++(elt->timerIndex))
{
elt->currentTimer = (CCTimer*)(elt->timers->arr[elt->timerIndex]);
elt->currentTimerSalvaged = false;
elt->currentTimer->update(dt);
if (elt->currentTimerSalvaged)
{
// The currentTimer told the remove itself. To prevent the timer from
// accidentally deallocating itself before finishing its step, we retained
// it. Now that step is done, it's safe to release it.
elt->currentTimer->release();
}
elt->currentTimer = NULL;
}
}
// elt, at this moment, is still valid
// so it is safe to ask this here (issue #490)
elt = (tHashSelectorEntry *)elt->hh.next;
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
if (m_bCurrentTargetSalvaged && m_pCurrentTarget->timers->num == 0)
{
removeHashElement(m_pCurrentTarget);
}
}
2012-02-06 10:54:51 +08:00
2012-02-02 15:58:10 +08:00
// Interate all over the script callbacks
2012-02-09 14:07:11 +08:00
if (m_pScriptHandlerEntries)
2012-02-02 15:58:10 +08:00
{
2012-02-09 14:07:11 +08:00
for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
2012-02-02 15:58:10 +08:00
{
2012-02-09 14:07:11 +08:00
CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
if (pEntry->isMarkedForDeletion())
{
m_pScriptHandlerEntries->removeObjectAtIndex(i);
}
else if (!pEntry->isPaused())
{
pEntry->getTimer()->update(dt);
}
2012-02-02 15:58:10 +08:00
}
}
2012-02-01 16:45:23 +08:00
// delete all updates that are morked for deletion
// updates with priority < 0
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
{
if (pEntry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
}
}
// updates with priority == 0
DL_FOREACH_SAFE(m_pUpdates0List, pEntry, pTmp)
{
if (pEntry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
}
}
// updates with priority > 0
DL_FOREACH_SAFE(m_pUpdatesPosList, pEntry, pTmp)
{
if (pEntry->markedForDeletion)
{
this->removeUpdateFromHash(pEntry);
}
}
m_bUpdateHashLocked = false;
m_pCurrentTarget = NULL;
}
2012-02-06 10:54:51 +08:00
}//namespace cocos2d