mirror of https://github.com/axmolengine/axmol.git
closed #5392: add priority check for schedulePerFrame() and add a ScheduleUpdatePriority test.
This commit is contained in:
parent
3d3fb6ad7e
commit
91db87a2f6
|
@ -465,14 +465,28 @@ void Scheduler::schedulePerFrame(const ccSchedulerFunc& callback, void *target,
|
||||||
HASH_FIND_PTR(_hashForUpdates, &target, hashElement);
|
HASH_FIND_PTR(_hashForUpdates, &target, hashElement);
|
||||||
if (hashElement)
|
if (hashElement)
|
||||||
{
|
{
|
||||||
#if COCOS2D_DEBUG >= 1
|
// check if priority has changed
|
||||||
CCASSERT(hashElement->entry->markedForDeletion,"");
|
if ((*hashElement->list)->priority != priority)
|
||||||
#endif
|
{
|
||||||
// TODO: check if priority has changed!
|
if (_updateHashLocked)
|
||||||
|
{
|
||||||
|
CCLOG("warning: you CANNOT change update priority in scheduled function");
|
||||||
hashElement->entry->markedForDeletion = false;
|
hashElement->entry->markedForDeletion = false;
|
||||||
|
hashElement->entry->paused = paused;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unscheduleUpdate(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hashElement->entry->markedForDeletion = false;
|
||||||
|
hashElement->entry->paused = paused;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// most of the updates are going to be 0, that's way there
|
// most of the updates are going to be 0, that's way there
|
||||||
// is an special list for updates with priority 0
|
// is an special list for updates with priority 0
|
||||||
|
|
|
@ -28,7 +28,8 @@ static std::function<Layer*()> createFunctions[] = {
|
||||||
CL(RescheduleSelector),
|
CL(RescheduleSelector),
|
||||||
CL(SchedulerDelayAndRepeat),
|
CL(SchedulerDelayAndRepeat),
|
||||||
CL(SchedulerIssue2268),
|
CL(SchedulerIssue2268),
|
||||||
CL(ScheduleCallbackTest)
|
CL(ScheduleCallbackTest),
|
||||||
|
CL(ScheduleUpdatePriority)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
||||||
|
@ -1148,6 +1149,47 @@ void ScheduleCallbackTest::callback(float dt)
|
||||||
log("In the callback of schedule(CC_CALLBACK_1(XXX::member_function), this), this, ...), dt = %f", dt);
|
log("In the callback of schedule(CC_CALLBACK_1(XXX::member_function), this), this, ...), dt = %f", dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ScheduleUpdatePriority
|
||||||
|
|
||||||
|
std::string ScheduleUpdatePriority::title() const
|
||||||
|
{
|
||||||
|
return "ScheduleUpdatePriorityTest";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScheduleUpdatePriority::subtitle() const
|
||||||
|
{
|
||||||
|
return "click to change update priority with random value";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScheduleUpdatePriority::onTouchBegan(Touch* touch, Event* event)
|
||||||
|
{
|
||||||
|
int priority = static_cast<int>(CCRANDOM_0_1() * 11) - 5; // -5 ~ 5
|
||||||
|
CCLOG("change update priority to %d", priority);
|
||||||
|
scheduleUpdateWithPriority(priority);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScheduleUpdatePriority::onEnter()
|
||||||
|
{
|
||||||
|
SchedulerTestLayer::onEnter();
|
||||||
|
|
||||||
|
scheduleUpdate();
|
||||||
|
|
||||||
|
auto listener = EventListenerTouchOneByOne::create();
|
||||||
|
listener->onTouchBegan = CC_CALLBACK_2(ScheduleUpdatePriority::onTouchBegan, this);
|
||||||
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScheduleUpdatePriority::onExit()
|
||||||
|
{
|
||||||
|
unscheduleUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScheduleUpdatePriority::update(float dt)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// SchedulerTestScene
|
// SchedulerTestScene
|
||||||
|
|
|
@ -302,6 +302,21 @@ public:
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ScheduleUpdatePriority : public SchedulerTestLayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(ScheduleUpdatePriority);
|
||||||
|
|
||||||
|
virtual std::string title() const override;
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
void onEnter();
|
||||||
|
void onExit();
|
||||||
|
|
||||||
|
virtual void update(float dt);
|
||||||
|
|
||||||
|
bool onTouchBegan(Touch* touch, Event* event);
|
||||||
|
};
|
||||||
|
|
||||||
class SchedulerTestScene : public TestScene
|
class SchedulerTestScene : public TestScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue