温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cocos2d-x CCScheduler

发布时间:2020-05-30 05:21:11 来源:网络 阅读:1332 作者:cgw0827 栏目:游戏开发


CCNode::CCNode(void){

   m_pScheduler = director->getScheduler();

   m_pScheduler->retain();

}


void CCNode::schedule(SEL_SCHEDULE selector)

{

this->schedule(selector, 0.0f, kCCRepeatForever, 0.0f);

}


void CCNode::schedule(SEL_SCHEDULE selector, float interval, unsignedint repeat, float delay)

{

CCAssert( selector, "Argument must be non-nil");

CCAssert( interval >=0, "Argument must be positive");


m_pScheduler->scheduleSelector(selector, this, interval , repeat, delay, !m_bRunning);

}


void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, CCObject *pTarget, float fInterval, unsignedint repeat, float delay, bool bPaused)

{

CCAssert(pfnSelector, "Argument selector must be non-NULL");

CCAssert(pTarget, "Argument target must be non-NULL");


tHashTimerEntry *pElement = NULL;

HASH_FIND_INT(m_pHashForTimers, &pTarget, pElement);


if (! pElement)

   {

       pElement = (tHashTimerEntry *)calloc(sizeof(*pElement), 1);

       pElement->target = pTarget;

if (pTarget)

       {

           pTarget->retain();

       }

HASH_ADD_INT(m_pHashForTimers, 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);

   }

else

   {

for (unsignedint i = 0; i < pElement->timers->num; ++i)

       {

CCTimer *timer = (CCTimer*)pElement->timers->arr[i];


if (pfnSelector == timer->getSelector())

           {

CCLOG("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer->getInterval(), fInterval);

               timer->setInterval(fInterval);

return;

           }        

       }

ccArrayEnsureExtraCapacity(pElement->timers, 1);

   }


CCTimer *pTimer = newCCTimer();

   pTimer->initWithTarget(pTarget, pfnSelector, fInterval, repeat, delay);

ccArrayAppendObject(pElement->timers, pTimer);

   pTimer->release();    

}






bool CCDirector::init(void)

{

   

// scheduler

m_pScheduler = newCCScheduler();

// action manager

m_pActionManager = newCCActionManager();

m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCPrioritySystem, false);

}


// Draw the Scene

voidCCDirector::drawScene(void)

{


//tick before glClear: issue #533

if (! m_bPaused)

   {

m_pScheduler->update(m_fDeltaTime);

   }

}


void CCDisplayLinkDirector::mainLoop(void)

{

if (m_bPurgeDirecotorInNextLoop)

   {

m_bPurgeDirecotorInNextLoop = false;

purgeDirector();

   }

elseif (! m_bInvalid)

    {

drawScene();


// release the objects

CCPoolManager::sharedPoolManager()->pop();        

    }

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI