2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
#include "SchedulerTest.h"
|
|
|
|
#include "../testResource.h"
|
2017-05-04 16:24:20 +08:00
|
|
|
#include "ui/UIText.h"
|
2018-09-10 10:21:11 +08:00
|
|
|
#include "controller.h"
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
|
|
|
USING_NS_AX_EXT;
|
2022-08-29 20:51:22 +08:00
|
|
|
using namespace ax::ui;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagAnimationDance = 1,
|
2010-09-09 16:15:21 +08:00
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
SchedulerTests::SchedulerTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(SchedulerTimeScale);
|
|
|
|
ADD_TEST_CASE(TwoSchedulers);
|
|
|
|
ADD_TEST_CASE(SchedulerAutoremove);
|
|
|
|
ADD_TEST_CASE(SchedulerPauseResume);
|
|
|
|
ADD_TEST_CASE(SchedulerPauseResumeAll);
|
|
|
|
ADD_TEST_CASE(SchedulerPauseResumeAllUser);
|
|
|
|
ADD_TEST_CASE(SchedulerUnscheduleAll);
|
|
|
|
ADD_TEST_CASE(SchedulerUnscheduleAllHard);
|
|
|
|
ADD_TEST_CASE(SchedulerUnscheduleAllUserLevel);
|
|
|
|
ADD_TEST_CASE(SchedulerSchedulesAndRemove);
|
|
|
|
ADD_TEST_CASE(SchedulerUpdate);
|
|
|
|
ADD_TEST_CASE(SchedulerUpdateAndCustom);
|
|
|
|
ADD_TEST_CASE(SchedulerUpdateFromCustom);
|
|
|
|
ADD_TEST_CASE(RescheduleSelector);
|
|
|
|
ADD_TEST_CASE(SchedulerDelayAndRepeat);
|
|
|
|
ADD_TEST_CASE(SchedulerIssue2268);
|
2017-05-04 16:24:20 +08:00
|
|
|
ADD_TEST_CASE(SchedulerIssueWithReschedule);
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(ScheduleCallbackTest);
|
|
|
|
ADD_TEST_CASE(ScheduleUpdatePriority);
|
|
|
|
ADD_TEST_CASE(SchedulerIssue10232);
|
2016-12-08 11:58:58 +08:00
|
|
|
ADD_TEST_CASE(SchedulerRemoveAllFunctionsToBePerformedInCocosThread)
|
2017-01-16 17:37:59 +08:00
|
|
|
ADD_TEST_CASE(SchedulerIssue17149);
|
2017-01-18 16:32:36 +08:00
|
|
|
ADD_TEST_CASE(SchedulerRemoveEntryWhileUpdate);
|
2017-03-07 11:16:30 +08:00
|
|
|
ADD_TEST_CASE(SchedulerRemoveSelectorDuringCall);
|
2012-12-03 15:33:01 +08:00
|
|
|
};
|
2011-07-08 15:57:46 +08:00
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerAutoremove
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerAutoremove::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerAutoremove::autoremove), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerAutoremove::tick), 0.5f);
|
2010-09-09 16:15:21 +08:00
|
|
|
accum = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerAutoremove::autoremove(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
accum += dt;
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("autoremove scheduler: Time: %f", accum);
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (accum > 3)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerAutoremove::autoremove));
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("autoremove scheduler: scheduler removed");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerAutoremove::tick(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick scheduler: This scheduler should not be removed");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerAutoremove::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Self-remove an scheduler";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerAutoremove::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "1 scheduler will be autoremoved in 3 seconds. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResume
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerPauseResume::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResume::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResume::tick2), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResume::pause), 3.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResume::tick1(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResume::tick2(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResume::pause(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("paused, tick1 and tick2 should called six times");
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->pauseTarget(this);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResume::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Pause / Resume";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResume::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Scheduler should be paused after 3 seconds. See console";
|
|
|
|
}
|
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResumeAll
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerPauseResumeAll::SchedulerPauseResumeAll() {}
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerPauseResumeAll::~SchedulerPauseResumeAll() {}
|
2012-06-12 18:12:45 +08:00
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::onEnter()
|
|
|
|
{
|
2012-11-15 18:34:23 +08:00
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2012-11-15 18:34:23 +08:00
|
|
|
sprite->setPosition(VisibleRect::center());
|
|
|
|
this->addChild(sprite);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
|
2015-08-13 14:38:51 +08:00
|
|
|
sprite->setTag(123);
|
2012-11-20 16:24:27 +08:00
|
|
|
scheduleUpdate();
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::tick2), 1.0f);
|
|
|
|
scheduleOnce(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAll::pause), 3.0f);
|
2012-11-20 16:24:27 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAll::update(float /*delta*/)
|
2012-11-20 16:24:27 +08:00
|
|
|
{
|
|
|
|
// do nothing
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAll::onExit()
|
|
|
|
{
|
2013-12-07 14:28:37 +08:00
|
|
|
if (!_pausedTargets.empty())
|
2012-11-15 18:34:23 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2013-09-19 18:53:45 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAll::tick1(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick1");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAll::tick2(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick2");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAll::pause(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2015-08-12 11:37:15 +08:00
|
|
|
log("Pausing, tick1 should be called six times and tick2 three times");
|
|
|
|
auto scheduler = Director::getInstance()->getScheduler();
|
|
|
|
_pausedTargets = scheduler->pauseAllTargets();
|
2014-02-20 14:11:47 +08:00
|
|
|
|
|
|
|
// should have only 2 items: ActionManager, self
|
2022-07-16 10:43:05 +08:00
|
|
|
AXASSERT(_pausedTargets.size() == 2, "Error: pausedTargets should have only 2 items");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-08-13 14:38:51 +08:00
|
|
|
// because target 'this' has been paused above, so use another node(tag:123) as target
|
2021-12-28 16:06:23 +08:00
|
|
|
getChildByTag(123)->scheduleOnce([this](float dt) { this->resume(dt); }, 2.0f, "test resume");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAll::resume(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Resuming");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->getScheduler()->resumeTargets(_pausedTargets);
|
2013-12-07 14:28:37 +08:00
|
|
|
_pausedTargets.clear();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResumeAll::title() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2015-08-12 11:37:15 +08:00
|
|
|
return "Pause / Resume All";
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResumeAll::subtitle() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
|
|
|
return "Everything will pause after 3s, then resume at 5s. See console";
|
|
|
|
}
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerPauseResumeAllUser
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerPauseResumeAllUser::SchedulerPauseResumeAllUser() {}
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerPauseResumeAllUser::~SchedulerPauseResumeAllUser() {}
|
2012-06-12 18:12:45 +08:00
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
|
2015-08-13 14:38:51 +08:00
|
|
|
sprite->setTag(123);
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAllUser::tick1), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAllUser::tick2), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerPauseResumeAllUser::pause), 3.0f, false, 0);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerPauseResumeAllUser::onExit()
|
|
|
|
{
|
2013-12-07 14:28:37 +08:00
|
|
|
if (!_pausedTargets.empty())
|
2012-11-15 18:34:23 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->resumeTargets(_pausedTargets);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2013-09-19 18:53:45 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAllUser::tick1(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick1");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAllUser::tick2(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("tick2");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAllUser::pause(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2015-08-12 11:37:15 +08:00
|
|
|
log("Pausing, tick1 and tick2 should be called three times");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-25 21:04:32 +08:00
|
|
|
_pausedTargets = director->getScheduler()->pauseAllTargetsWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN);
|
2015-08-13 14:38:51 +08:00
|
|
|
// because target 'this' has been paused above, so use another node(tag:123) as target
|
2021-12-28 16:06:23 +08:00
|
|
|
getChildByTag(123)->scheduleOnce([this](float dt) { this->resume(dt); }, 2.0f, "test resume");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerPauseResumeAllUser::resume(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Resuming");
|
2015-08-12 11:37:15 +08:00
|
|
|
getScheduler()->resumeTargets(_pausedTargets);
|
2013-12-07 14:28:37 +08:00
|
|
|
_pausedTargets.clear();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResumeAllUser::title() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2015-08-12 11:37:15 +08:00
|
|
|
return "Pause / Resume All User scheduler";
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerPauseResumeAllUser::subtitle() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2015-08-12 11:37:15 +08:00
|
|
|
return "ticks will pause after 3s, then resume at 5s. See console";
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAll
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAll::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAll::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAll::tick2), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAll::tick3), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAll::tick4), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAll::unscheduleAll), 4);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAll::tick1(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAll::tick2(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAll::tick3(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAll::tick4(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAll::unscheduleAll(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2014-10-04 00:38:36 +08:00
|
|
|
unscheduleAllCallbacks();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAll::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Unschedule All selectors";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAll::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "All scheduled selectors will be unscheduled in 4 seconds. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAllHard
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAllHard::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManagerActive = true;
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllHard::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllHard::tick2), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllHard::tick3), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllHard::tick4), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllHard::unscheduleAll), 4);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 18:12:45 +08:00
|
|
|
void SchedulerUnscheduleAllHard::onExit()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!_actionManagerActive)
|
|
|
|
{
|
2012-11-15 18:34:23 +08:00
|
|
|
// Restore the director's action manager.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2014-03-03 11:00:30 +08:00
|
|
|
director->getScheduler()->scheduleUpdate(director->getActionManager(), Scheduler::PRIORITY_SYSTEM, false);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-19 18:53:45 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick1(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick2(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick3(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllHard::tick4(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllHard::unscheduleAll(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleAll();
|
2013-06-15 14:03:30 +08:00
|
|
|
_actionManagerActive = false;
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAllHard::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2012-06-12 18:12:45 +08:00
|
|
|
return "Unschedule All selectors (HARD)";
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAllHard::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2012-06-12 18:12:45 +08:00
|
|
|
return "Unschedules all user selectors after 4s. Action will stop. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUnscheduleAllUserLevel
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUnscheduleAllUserLevel::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-11-15 18:34:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 2, s.height / 2));
|
2012-11-15 18:34:23 +08:00
|
|
|
this->addChild(sprite);
|
2019-09-24 11:31:35 +08:00
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(3.0f, 360.0f)));
|
2012-06-12 18:12:45 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllUserLevel::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllUserLevel::tick2), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllUserLevel::tick3), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllUserLevel::tick4), 1.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUnscheduleAllUserLevel::unscheduleAll), 4);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllUserLevel::tick1(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick1");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllUserLevel::tick2(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick2");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllUserLevel::tick3(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick3");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllUserLevel::tick4(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick4");
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUnscheduleAllUserLevel::unscheduleAll(float /*dt*/)
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
2013-07-25 21:04:32 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleAllWithMinPriority(Scheduler::PRIORITY_NON_SYSTEM_MIN);
|
2012-06-12 18:12:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAllUserLevel::title() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
|
|
|
return "Unschedule All user selectors";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUnscheduleAllUserLevel::subtitle() const
|
2012-06-12 18:12:45 +08:00
|
|
|
{
|
|
|
|
return "Unschedules all user selectors after 4s. Action should not stop. See console";
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerSchedulesAndRemove
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerSchedulesAndRemove::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick1), 0.5f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick2), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::scheduleAndUnschedule), 4.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick1(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick1");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick2(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick2");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick3(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick3");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerSchedulesAndRemove::tick4(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("tick4");
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerSchedulesAndRemove::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Schedule from Schedule";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerSchedulesAndRemove::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Will unschedule and schedule selectors in 4s. See console";
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerSchedulesAndRemove::scheduleAndUnschedule(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick1));
|
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick2));
|
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::scheduleAndUnschedule));
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick3), 1.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerSchedulesAndRemove::tick4), 1.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TestNode
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2021-12-28 15:58:56 +08:00
|
|
|
void TestNode::initWithString(std::string_view str, int priority)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-12-18 16:03:07 +08:00
|
|
|
_string = str;
|
2010-09-09 16:15:21 +08:00
|
|
|
scheduleUpdateWithPriority(priority);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
TestNode::~TestNode() {}
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void TestNode::update(float /*dt*/)
|
2012-12-03 15:33:01 +08:00
|
|
|
{
|
2013-12-18 16:03:07 +08:00
|
|
|
log("%s", _string.c_str());
|
2012-12-03 15:33:01 +08:00
|
|
|
}
|
|
|
|
|
2010-09-09 16:15:21 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdate
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdate::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto d = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
d->initWithString("---", 50);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(d);
|
|
|
|
d->release();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto b = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
b->initWithString("3rd", 0);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(b);
|
|
|
|
b->release();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto a = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
a->initWithString("1st", -10);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(a);
|
|
|
|
a->release();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto c = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
c->initWithString("4th", 10);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(c);
|
|
|
|
c->release();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto e = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
e->initWithString("5th", 20);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(e);
|
|
|
|
e->release();
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
auto f = new TestNode();
|
2013-12-18 16:03:07 +08:00
|
|
|
f->initWithString("2nd", -5);
|
2010-09-09 16:15:21 +08:00
|
|
|
addChild(f);
|
|
|
|
f->release();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUpdate::removeUpdates), 4.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUpdate::removeUpdates(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2013-11-29 10:37:40 +08:00
|
|
|
auto& children = getChildren();
|
2010-09-09 16:15:21 +08:00
|
|
|
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& c : children)
|
2013-08-16 18:23:41 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto obj = static_cast<Ref*>(c);
|
2013-08-20 08:09:28 +08:00
|
|
|
auto node = static_cast<Node*>(obj);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
if (!node)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-10-04 00:38:36 +08:00
|
|
|
node->unscheduleAllCallbacks();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdate::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Schedule update with priority";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdate::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "3 scheduled updates. Priority should work. Stops in 4s. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdateAndCustom
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdateAndCustom::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
scheduleUpdate();
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateAndCustom::tick));
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateAndCustom::stopSelectors), 0.4f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateAndCustom::update(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("update called:%f", dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateAndCustom::tick(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("custom selector called:%f", dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUpdateAndCustom::stopSelectors(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
log("SchedulerUpdateAndCustom::stopSelectors");
|
2014-10-04 00:38:36 +08:00
|
|
|
unscheduleAllCallbacks();
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdateAndCustom::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Schedule Update + custom selector";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdateAndCustom::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Update + custom selector at the same time. Stops in 4s. See console";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerUpdateFromCustom
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void SchedulerUpdateFromCustom::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::schedUpdate), 2.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerUpdateFromCustom::update(float dt)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("update called:%f", dt);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUpdateFromCustom::schedUpdate(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::schedUpdate));
|
2010-09-09 16:15:21 +08:00
|
|
|
scheduleUpdate();
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::stopUpdate), 2.0f);
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerUpdateFromCustom::stopUpdate(float /*dt*/)
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(SchedulerUpdateFromCustom::stopUpdate));
|
2010-09-09 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdateFromCustom::title() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Schedule Update in 2 sec";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerUpdateFromCustom::subtitle() const
|
2010-09-09 16:15:21 +08:00
|
|
|
{
|
|
|
|
return "Update schedules in 2 secs. Stops 2 sec later. See console";
|
|
|
|
}
|
|
|
|
|
2010-09-25 14:19:15 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// RescheduleSelector
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void RescheduleSelector::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_interval = 1.0f;
|
|
|
|
_ticks = 0;
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(RescheduleSelector::schedUpdate), _interval);
|
2010-09-25 14:19:15 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RescheduleSelector::title() const
|
2010-09-25 14:19:15 +08:00
|
|
|
{
|
|
|
|
return "Reschedule Selector";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string RescheduleSelector::subtitle() const
|
2010-09-25 14:19:15 +08:00
|
|
|
{
|
|
|
|
return "Interval is 1 second, then 2, then 3...";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void RescheduleSelector::schedUpdate(float dt)
|
2010-09-25 14:19:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_ticks++;
|
2011-01-25 16:56:46 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("schedUpdate: %.4f", dt);
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_ticks > 3)
|
2011-01-25 16:56:46 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_interval += 1.0f;
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(RescheduleSelector::schedUpdate), _interval);
|
2013-06-15 14:03:30 +08:00
|
|
|
_ticks = 0;
|
2010-09-25 14:19:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 13:58:24 +08:00
|
|
|
// SchedulerDelayAndRepeat
|
|
|
|
|
|
|
|
void SchedulerDelayAndRepeat::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(SchedulerDelayAndRepeat::update), 0, 4, 3.f);
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("update is scheduled should begin after 3 seconds");
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerDelayAndRepeat::title() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Schedule with delay of 3 sec, repeat 4 times";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerDelayAndRepeat::subtitle() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "After 5 x executed, method unscheduled. See console";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void SchedulerDelayAndRepeat::update(float dt)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("update called:%f", dt);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SchedulerTimeScale
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider* SchedulerTimeScale::sliderCtl()
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
ControlSlider* slider = ControlSlider::create("extensions/sliderTrack2.png", "extensions/sliderProgress2.png",
|
|
|
|
"extensions/sliderThumb.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(SchedulerTimeScale::sliderAction),
|
|
|
|
Control::EventType::VALUE_CHANGED);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
slider->setMinimumValue(-3.0f);
|
|
|
|
slider->setMaximumValue(3.0f);
|
|
|
|
slider->setValue(1.0f);
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerTimeScale::sliderAction(Ref* sender, Control::EventType /*controlEvent*/)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
ControlSlider* pSliderCtl = static_cast<ControlSlider*>(sender);
|
2012-06-08 13:55:28 +08:00
|
|
|
float scale;
|
2012-04-18 13:58:24 +08:00
|
|
|
scale = pSliderCtl->getValue();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->setTimeScale(scale);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerTimeScale::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// rotate and jump
|
2021-12-28 16:06:23 +08:00
|
|
|
auto jump1 = JumpBy::create(4, Vec2(-s.width + 80, 0.0f), 100, 4);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto jump2 = jump1->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto rot1 = RotateBy::create(4, 360 * 2);
|
|
|
|
auto rot2 = rot1->reverse();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq3_1 = Sequence::create(jump2, jump1, nullptr);
|
|
|
|
auto seq3_2 = Sequence::create(rot1, rot2, nullptr);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto spawn = Spawn::create(seq3_1, seq3_2, nullptr);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = Repeat::create(spawn, 50);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action2 = action->clone();
|
|
|
|
auto action3 = action->clone();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto tamara = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
auto kathia = Sprite::create("Images/grossinis_sister2.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
grossini->setPosition(Vec2(40.0f, 80.0f));
|
|
|
|
tamara->setPosition(Vec2(40.0f, 80.0f));
|
|
|
|
kathia->setPosition(Vec2(40.0f, 80.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
addChild(grossini);
|
|
|
|
addChild(tamara);
|
|
|
|
addChild(kathia);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
grossini->runAction(Speed::create(action, 0.5f));
|
|
|
|
tamara->runAction(Speed::create(action2, 1.5f));
|
|
|
|
kathia->runAction(Speed::create(action3, 1.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto emitter = ParticleFireworks::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
emitter->setTexture(Director::getInstance()->getTextureCache()->addImage(s_stars1));
|
2012-04-18 13:58:24 +08:00
|
|
|
addChild(emitter);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_sliderCtl = sliderCtl();
|
2014-05-15 01:07:09 +08:00
|
|
|
_sliderCtl->setPosition(Vec2(s.width / 2.0f, s.height / 3.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_sliderCtl);
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerTimeScale::onExit()
|
|
|
|
{
|
|
|
|
// restore scale
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getScheduler()->setTimeScale(1);
|
2012-04-18 13:58:24 +08:00
|
|
|
SchedulerTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerTimeScale::title() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Scheduler timeScale Test";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerTimeScale::subtitle() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Fast-forward and rewind using scheduler.timeScale";
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// TwoSchedulers
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
ControlSlider* TwoSchedulers::sliderCtl()
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// auto frame = CGRectMake(12.0f, 12.0f, 120.0f, 7.0f);
|
|
|
|
ControlSlider* slider = ControlSlider::create("extensions/sliderTrack2.png", "extensions/sliderProgress2.png",
|
|
|
|
"extensions/sliderThumb.png");
|
|
|
|
//[[UISlider alloc] initWithFrame:frame];
|
|
|
|
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(TwoSchedulers::sliderAction),
|
|
|
|
Control::EventType::VALUE_CHANGED);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// in case the parent view draws with a custom color or gradient, use a transparent color
|
2021-12-28 16:06:23 +08:00
|
|
|
// slider.backgroundColor = [UIColor clearColor];
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
slider->setMinimumValue(0.0f);
|
|
|
|
slider->setMaximumValue(2.0f);
|
2021-12-28 16:06:23 +08:00
|
|
|
// slider.continuous = YES;
|
2012-04-18 13:58:24 +08:00
|
|
|
slider->setValue(1.0f);
|
|
|
|
|
|
|
|
return slider;
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void TwoSchedulers::sliderAction(Ref* sender, Control::EventType /*controlEvent*/)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2012-06-08 13:55:28 +08:00
|
|
|
float scale;
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
ControlSlider* slider = static_cast<ControlSlider*>(sender);
|
|
|
|
scale = slider->getValue();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (sender == sliderCtl1)
|
2012-04-18 13:58:24 +08:00
|
|
|
sched1->setTimeScale(scale);
|
|
|
|
else
|
|
|
|
sched2->setTimeScale(scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwoSchedulers::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// rotate and jump
|
|
|
|
auto jump1 = JumpBy::create(4, Vec2(0, 0), 100, 4);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto jump2 = jump1->reverse();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq = Sequence::create(jump2, jump1, nullptr);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = RepeatForever::create(seq);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
|
|
|
// Center
|
|
|
|
//
|
2013-08-16 16:05:27 +08:00
|
|
|
auto grossini = Sprite::create("Images/grossini.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
addChild(grossini);
|
2021-12-28 16:06:23 +08:00
|
|
|
grossini->setPosition(Vec2(s.width / 2, 100.0f));
|
2013-06-19 07:12:28 +08:00
|
|
|
grossini->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto defaultScheduler = Director::getInstance()->getScheduler();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Left:
|
|
|
|
//
|
|
|
|
|
|
|
|
// Create a new scheduler, and link it to the main scheduler
|
2021-12-08 00:11:53 +08:00
|
|
|
sched1 = new Scheduler();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
defaultScheduler->scheduleUpdate(sched1, 0, false);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2017-02-10 10:35:52 +08:00
|
|
|
// Create a new ActionManager, and link it to the new scheduler
|
2021-12-08 00:11:53 +08:00
|
|
|
actionManager1 = new ActionManager();
|
2014-03-03 11:00:30 +08:00
|
|
|
sched1->scheduleUpdate(actionManager1, 0, false);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (unsigned int i = 0; i < 10; i++)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// IMPORTANT: Set the actionManager running any action
|
|
|
|
sprite->setActionManager(actionManager1);
|
|
|
|
|
|
|
|
addChild(sprite);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(30 + 15 * i, 100.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-19 07:12:28 +08:00
|
|
|
sprite->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Right:
|
|
|
|
//
|
|
|
|
|
|
|
|
// Create a new scheduler, and link it to the main scheduler
|
2021-12-08 00:11:53 +08:00
|
|
|
sched2 = new Scheduler();
|
2014-03-03 11:00:30 +08:00
|
|
|
defaultScheduler->scheduleUpdate(sched2, 0, false);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2017-02-10 10:35:52 +08:00
|
|
|
// Create a new ActionManager, and link it to the new scheduler
|
2021-12-08 00:11:53 +08:00
|
|
|
actionManager2 = new ActionManager();
|
2014-03-03 11:00:30 +08:00
|
|
|
sched2->scheduleUpdate(actionManager2, 0, false);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (unsigned int i = 0; i < 10; i++)
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister2.png");
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
// IMPORTANT: Set the actionManager running any action
|
|
|
|
sprite->setActionManager(actionManager2);
|
|
|
|
|
|
|
|
addChild(sprite);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(s.width - 30 - 15 * i, 100.0f));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-19 07:12:28 +08:00
|
|
|
sprite->runAction(action->clone());
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sliderCtl1 = sliderCtl();
|
|
|
|
addChild(sliderCtl1);
|
|
|
|
sliderCtl1->retain();
|
2014-05-15 01:07:09 +08:00
|
|
|
sliderCtl1->setPosition(Vec2(s.width / 4.0f, VisibleRect::top().y - 20));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
sliderCtl2 = sliderCtl();
|
|
|
|
addChild(sliderCtl2);
|
|
|
|
sliderCtl2->retain();
|
2021-12-28 16:06:23 +08:00
|
|
|
sliderCtl2->setPosition(Vec2(s.width / 4.0f * 3.0f, VisibleRect::top().y - 20));
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TwoSchedulers::~TwoSchedulers()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto defaultScheduler = Director::getInstance()->getScheduler();
|
2012-11-15 18:34:23 +08:00
|
|
|
defaultScheduler->unscheduleAllForTarget(sched1);
|
|
|
|
defaultScheduler->unscheduleAllForTarget(sched2);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
sliderCtl1->release();
|
|
|
|
sliderCtl2->release();
|
|
|
|
|
|
|
|
sched1->release();
|
|
|
|
sched2->release();
|
|
|
|
|
|
|
|
actionManager1->release();
|
|
|
|
actionManager2->release();
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string TwoSchedulers::title() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Two custom schedulers";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string TwoSchedulers::subtitle() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Three schedulers. 2 custom + 1 default. Two different time scales";
|
|
|
|
}
|
|
|
|
|
2017-05-04 16:24:20 +08:00
|
|
|
// SchedulerIssue2268
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class TestNode2 : public Node
|
2013-03-29 21:48:35 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(TestNode2);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
~TestNode2()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::log("Delete TestNode (should not crash)");
|
2021-12-28 16:06:23 +08:00
|
|
|
this->unscheduleAllCallbacks();
|
|
|
|
}
|
2013-03-29 21:48:35 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void update(float /*dt*/) {}
|
2013-03-29 21:48:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void SchedulerIssue2268::onEnter()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerTestLayer::onEnter();
|
2013-03-29 21:48:35 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
testNode = TestNode2::create();
|
|
|
|
testNode->retain();
|
|
|
|
testNode->schedule(SEL_SCHEDULE(&TestNode::update));
|
|
|
|
this->addChild(testNode);
|
2013-03-29 21:48:35 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);
|
2013-03-29 21:48:35 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerIssue2268::update(float /*dt*/)
|
2013-03-29 21:48:35 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (testNode != nullptr)
|
|
|
|
{
|
|
|
|
// do something with testNode
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// at some point we are done, pause the nodes actions and schedulers
|
|
|
|
testNode->removeFromParentAndCleanup(false);
|
2013-03-29 21:48:35 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// at some other point we are completely done with the node and want to clear it
|
|
|
|
testNode->unscheduleAllCallbacks();
|
|
|
|
testNode->release();
|
|
|
|
testNode = nullptr;
|
|
|
|
}
|
2013-03-29 21:48:35 +08:00
|
|
|
}
|
|
|
|
SchedulerIssue2268::~SchedulerIssue2268()
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE(testNode);
|
2013-03-29 21:48:35 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerIssue2268::title() const
|
2013-03-29 21:48:35 +08:00
|
|
|
{
|
|
|
|
return "Issue #2268";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string SchedulerIssue2268::subtitle() const
|
2013-03-29 21:48:35 +08:00
|
|
|
{
|
|
|
|
return "Should not crash";
|
|
|
|
}
|
2014-03-01 13:30:20 +08:00
|
|
|
|
2017-05-04 16:24:20 +08:00
|
|
|
// SchedulerIssueWithReschedule
|
|
|
|
// https://github.com/cocos2d/cocos2d-x/pull/17706
|
|
|
|
|
|
|
|
void SchedulerIssueWithReschedule::onEnter()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2017-05-04 16:24:20 +08:00
|
|
|
Size widgetSize = getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-05-04 16:24:20 +08:00
|
|
|
auto status_text = Text::create("Checking..", "fonts/Marker Felt.ttf", 18);
|
|
|
|
status_text->setColor(Color3B(255, 255, 255));
|
|
|
|
status_text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
addChild(status_text);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-05-04 16:24:20 +08:00
|
|
|
// schedule(callback, target, interval, repeat, delay, paused, key);
|
|
|
|
auto verified = std::make_shared<bool>();
|
2021-12-28 16:06:23 +08:00
|
|
|
*verified = false;
|
|
|
|
|
|
|
|
_scheduler->schedule(
|
|
|
|
[this, verified](float dt) {
|
|
|
|
log("SchedulerIssueWithReschedule - first timer");
|
|
|
|
|
|
|
|
_scheduler->schedule(
|
|
|
|
[verified](float dt) {
|
|
|
|
log("SchedulerIssueWithReschedule - second timer. OK");
|
|
|
|
*verified = true;
|
|
|
|
},
|
|
|
|
this, 0.1f, 0, 0, false, "test_timer");
|
|
|
|
},
|
|
|
|
this, 0.1f, 0, 0, false, "test_timer");
|
|
|
|
|
|
|
|
_scheduler->schedule(
|
|
|
|
[verified, status_text](float dt) {
|
|
|
|
if (*verified)
|
|
|
|
{
|
|
|
|
log("SchedulerIssueWithReschedule - test OK");
|
|
|
|
status_text->setString("OK");
|
|
|
|
status_text->setColor(Color3B(0, 255, 0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log("SchedulerIssueWithReschedule - test failed!");
|
|
|
|
status_text->setString("Failed");
|
|
|
|
status_text->setColor(Color3B(255, 0, 0));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
this, 0.5f, 0, 0, false, "test_verify_timer");
|
2017-05-04 16:24:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssueWithReschedule::title() const
|
|
|
|
{
|
|
|
|
return "Issue with reschedule";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssueWithReschedule::subtitle() const
|
|
|
|
{
|
|
|
|
return "reschedule issue with same key";
|
|
|
|
}
|
|
|
|
|
2014-03-01 13:30:20 +08:00
|
|
|
// ScheduleCallbackTest
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
ScheduleCallbackTest::~ScheduleCallbackTest() {}
|
2014-03-01 13:30:20 +08:00
|
|
|
|
|
|
|
std::string ScheduleCallbackTest::title() const
|
|
|
|
{
|
|
|
|
return "ScheduleCallbackTest";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ScheduleCallbackTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "\n\n\n\nPlease see console.\n\
|
2014-03-03 11:00:30 +08:00
|
|
|
schedule(lambda, ...)\n\
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_CALLBACK_1(XXX::member_function), this), this, ...)\n\
|
2014-03-03 11:00:30 +08:00
|
|
|
schedule(global_function, ...)\n\
|
2014-03-01 13:30:20 +08:00
|
|
|
";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ScheduleCallbackTest_global_callback(float dt)
|
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
log("In the callback of schedule(global_function, ...), dt = %f", dt);
|
2014-03-01 13:30:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScheduleCallbackTest::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_scheduler->schedule([](float dt) { log("In the callback of schedule(lambda, ...), dt = %f", dt); }, this, 1.0f,
|
|
|
|
false, "lambda");
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
_scheduler->schedule(AX_CALLBACK_1(ScheduleCallbackTest::callback, this), this, 1.0f, false, "member_function");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-03-03 11:00:30 +08:00
|
|
|
_scheduler->schedule(ScheduleCallbackTest_global_callback, this, 1.0f, false, "global_function");
|
2014-03-01 13:30:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScheduleCallbackTest::callback(float dt)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
log("In the callback of schedule(AX_CALLBACK_1(XXX::member_function), this), this, ...), dt = %f", dt);
|
2014-03-01 13:30:20 +08:00
|
|
|
}
|
|
|
|
|
2014-05-29 13:51:43 +08:00
|
|
|
// ScheduleUpdatePriority
|
|
|
|
|
|
|
|
std::string ScheduleUpdatePriority::title() const
|
|
|
|
{
|
|
|
|
return "ScheduleUpdatePriorityTest";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ScheduleUpdatePriority::subtitle() const
|
|
|
|
{
|
|
|
|
return "click to change update priority with random value";
|
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
bool ScheduleUpdatePriority::onTouchBegan(Touch* /*touch*/, Event* /*event*/)
|
2014-05-29 13:51:43 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
int priority = static_cast<int>(AXRANDOM_0_1() * 11) - 5; // -5 ~ 5
|
|
|
|
AXLOG("change update priority to %d", priority);
|
2014-05-29 13:51:43 +08:00
|
|
|
scheduleUpdateWithPriority(priority);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScheduleUpdatePriority::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-05-29 13:51:43 +08:00
|
|
|
scheduleUpdate();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
listener->onTouchBegan = AX_CALLBACK_2(ScheduleUpdatePriority::onTouchBegan, this);
|
2014-05-29 13:51:43 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScheduleUpdatePriority::onExit()
|
|
|
|
{
|
2014-06-30 18:22:58 +08:00
|
|
|
Node::onExit();
|
2014-05-29 13:51:43 +08:00
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void ScheduleUpdatePriority::update(float /*dt*/) {}
|
2014-05-29 13:51:43 +08:00
|
|
|
|
2015-01-28 11:31:52 +08:00
|
|
|
void SchedulerIssue10232::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
|
|
|
this->scheduleOnce(SEL_SCHEDULE(&SchedulerIssue2268::update), 0.25f);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
this->scheduleOnce([](float /*dt*/) { log("SchedulerIssue10232:Schedules a lambda function"); }, 0.25f,
|
|
|
|
"SchedulerIssue10232");
|
2015-01-28 11:31:52 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void SchedulerIssue10232::update(float /*dt*/)
|
2015-01-28 11:31:52 +08:00
|
|
|
{
|
|
|
|
log("SchedulerIssue10232:Schedules a selector");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue10232::title() const
|
|
|
|
{
|
|
|
|
return "Issue #10232";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue10232::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash";
|
|
|
|
}
|
2016-12-08 11:58:58 +08:00
|
|
|
|
|
|
|
void SchedulerRemoveAllFunctionsToBePerformedInCocosThread::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-12-08 11:58:58 +08:00
|
|
|
_sprite = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
_sprite->setPosition(VisibleRect::center());
|
|
|
|
this->addChild(_sprite);
|
|
|
|
this->scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerRemoveAllFunctionsToBePerformedInCocosThread::onExit()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onExit();
|
|
|
|
this->unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void SchedulerRemoveAllFunctionsToBePerformedInCocosThread::update(float dt)
|
|
|
|
{
|
2023-03-11 22:10:18 +08:00
|
|
|
Director::getInstance()->getScheduler()->runOnAxmolThread([this]() { _sprite->setVisible(false); });
|
|
|
|
Director::getInstance()->getScheduler()->runOnAxmolThread([this]() { _sprite->setVisible(false); });
|
|
|
|
Director::getInstance()->getScheduler()->runOnAxmolThread([this]() { _sprite->setVisible(false); });
|
|
|
|
Director::getInstance()->getScheduler()->runOnAxmolThread([this]() { _sprite->setVisible(false); });
|
|
|
|
Director::getInstance()->getScheduler()->runOnAxmolThread([this]() { _sprite->setVisible(false); });
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!TestController::getInstance()->isAutoTestRunning())
|
2023-03-11 22:10:18 +08:00
|
|
|
Director::getInstance()->getScheduler()->removeAllPendingActions();
|
2016-12-08 11:58:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerRemoveAllFunctionsToBePerformedInCocosThread::title() const
|
|
|
|
{
|
|
|
|
return "Removing pending main thread tasks";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerRemoveAllFunctionsToBePerformedInCocosThread::subtitle() const
|
|
|
|
{
|
|
|
|
return "Sprite should be visible";
|
|
|
|
}
|
2017-01-16 17:37:59 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// class SchedulerIssue17149: public SchedulerTestLayer
|
2017-01-16 17:37:59 +08:00
|
|
|
//{
|
2021-12-28 16:06:23 +08:00
|
|
|
// public:
|
|
|
|
// CREATE_FUNC(SchedulerIssue17149);
|
|
|
|
//
|
|
|
|
// virtual std::string title() const override;
|
|
|
|
// void onEnter() override;
|
|
|
|
// void update(float dt) override;
|
|
|
|
//
|
|
|
|
// private:
|
|
|
|
// class ClassA
|
|
|
|
// {
|
|
|
|
// public:
|
|
|
|
// void update(float dt);
|
|
|
|
//
|
|
|
|
// int _member1;
|
|
|
|
// int _member2;
|
|
|
|
// int _member3;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// class ClassB
|
|
|
|
// {
|
|
|
|
// void update(float dt);
|
|
|
|
// int _member1;
|
|
|
|
// int _member2;
|
|
|
|
// int _member3;
|
|
|
|
// };
|
|
|
|
// };
|
2017-01-16 17:37:59 +08:00
|
|
|
|
|
|
|
// SchedulerIssue17149: https://github.com/cocos2d/cocos2d-x/issues/17149
|
|
|
|
|
|
|
|
SchedulerIssue17149::SchedulerIssue17149()
|
|
|
|
{
|
|
|
|
_memoryPool = malloc(2018);
|
|
|
|
}
|
|
|
|
|
|
|
|
SchedulerIssue17149::~SchedulerIssue17149()
|
|
|
|
{
|
|
|
|
free(_memoryPool);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue17149::title() const
|
|
|
|
{
|
|
|
|
return "Issue #17149";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerIssue17149::subtitle() const
|
|
|
|
{
|
|
|
|
return "see console, result should be 'i'm ClassB: 456'";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerIssue17149::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerIssue17149::update(float dt)
|
|
|
|
{
|
|
|
|
auto classa = new (_memoryPool) ClassA();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("Address one: %p", classa);
|
2017-01-16 17:37:59 +08:00
|
|
|
Director::getInstance()->getScheduler()->scheduleUpdate(classa, 1, false);
|
|
|
|
Director::getInstance()->getScheduler()->unscheduleUpdate(classa);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-01-16 17:37:59 +08:00
|
|
|
auto classb = new (_memoryPool) ClassB();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("Address one: %p", classb);
|
2017-01-16 17:37:59 +08:00
|
|
|
Director::getInstance()->getScheduler()->scheduleUpdate(classb, 1, false);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-01-16 17:37:59 +08:00
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerIssue17149::ClassA::ClassA() : _member1(1), _member2(2), _member3(3) {}
|
2017-01-16 17:37:59 +08:00
|
|
|
|
|
|
|
void SchedulerIssue17149::ClassA::update(float dt)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("i'm ClassA: %d%d%d", _member1, _member2, _member3);
|
2017-01-16 17:37:59 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SchedulerIssue17149::ClassB::ClassB() : _member1(4), _member2(5), _member3(6) {}
|
2017-01-16 17:37:59 +08:00
|
|
|
|
|
|
|
void SchedulerIssue17149::ClassB::update(float dt)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("i'm ClassB: %d%d%d", _member1, _member2, _member3);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-01-16 17:37:59 +08:00
|
|
|
Director::getInstance()->getScheduler()->unscheduleUpdate(this);
|
|
|
|
}
|
2017-01-18 16:32:36 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerRemoveEntryWhileUpdate
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string SchedulerRemoveEntryWhileUpdate::title() const
|
|
|
|
{
|
|
|
|
return "RemoveEntryWhileUpdate";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerRemoveEntryWhileUpdate::subtitle() const
|
|
|
|
{
|
|
|
|
return "see console, error message must not be shown.";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerRemoveEntryWhileUpdate::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
for (auto i = 0; i < 500; ++i)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
TestClass* nextObj = nullptr;
|
2017-01-18 16:32:36 +08:00
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
nextObj = _testvector[i - 1];
|
|
|
|
}
|
|
|
|
auto obj = new TestClass(i, nextObj, getScheduler());
|
2022-08-08 13:18:33 +08:00
|
|
|
_testvector.emplace_back(obj);
|
2017-01-18 16:32:36 +08:00
|
|
|
getScheduler()->scheduleUpdate(obj, 500 - i, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerRemoveEntryWhileUpdate::onExit()
|
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& obj : _testvector)
|
2017-01-18 16:32:36 +08:00
|
|
|
{
|
|
|
|
getScheduler()->unscheduleUpdate(obj);
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
_testvector.clear();
|
|
|
|
SchedulerTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
SchedulerRemoveEntryWhileUpdate::TestClass::TestClass(int index, TestClass* nextObj, ax::Scheduler* scheduler)
|
2021-12-28 16:06:23 +08:00
|
|
|
: _nextObj(nextObj), _index(index), _scheduler(scheduler)
|
|
|
|
{}
|
2017-01-18 16:32:36 +08:00
|
|
|
|
|
|
|
void SchedulerRemoveEntryWhileUpdate::TestClass::update(float dt)
|
|
|
|
{
|
|
|
|
if (_cleanedUp)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("Error: cleaned object must not be called.");
|
2017-01-18 16:32:36 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-01-18 16:32:36 +08:00
|
|
|
if (_index % 50 == 1 && _nextObj != nullptr)
|
|
|
|
{
|
|
|
|
_scheduler->unscheduleUpdate(_nextObj);
|
|
|
|
_nextObj->_cleanedUp = true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 11:16:30 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// SchedulerRemoveSelectorDuringCall
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string SchedulerRemoveSelectorDuringCall::title() const
|
|
|
|
{
|
|
|
|
return "RemoveSelectorDuringCall";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SchedulerRemoveSelectorDuringCall::subtitle() const
|
|
|
|
{
|
|
|
|
return "see console, error message must not be shown.";
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerRemoveSelectorDuringCall::onEnter()
|
|
|
|
{
|
|
|
|
SchedulerTestLayer::onEnter();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Scheduler* const scheduler(Director::getInstance()->getScheduler());
|
|
|
|
|
|
|
|
scheduler->setTimeScale(10);
|
2022-07-15 19:17:01 +08:00
|
|
|
scheduler->schedule(SEL_SCHEDULE(&SchedulerRemoveSelectorDuringCall::callback), this, 0.01f, AX_REPEAT_FOREVER,
|
2021-12-28 16:06:23 +08:00
|
|
|
0.0f, !isRunning());
|
2017-03-07 11:16:30 +08:00
|
|
|
|
|
|
|
_scheduled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SchedulerRemoveSelectorDuringCall::onExit()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Scheduler* const scheduler(Director::getInstance()->getScheduler());
|
2017-03-07 11:16:30 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
scheduler->setTimeScale(1);
|
|
|
|
scheduler->unschedule(SEL_SCHEDULE(&SchedulerRemoveSelectorDuringCall::callback), this);
|
2017-03-07 11:16:30 +08:00
|
|
|
|
|
|
|
_scheduled = false;
|
|
|
|
SchedulerTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void SchedulerRemoveSelectorDuringCall::callback(float)
|
2017-03-07 11:16:30 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!_scheduled)
|
2017-03-07 11:16:30 +08:00
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::log("Error: unscheduled callback must not be called.");
|
2017-03-07 11:16:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2017-03-07 11:16:30 +08:00
|
|
|
_scheduled = false;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Scheduler* const scheduler(Director::getInstance()->getScheduler());
|
|
|
|
scheduler->unschedule(SEL_SCHEDULE(&SchedulerRemoveSelectorDuringCall::callback), this);
|
2017-03-07 11:16:30 +08:00
|
|
|
}
|