mirror of https://github.com/axmolengine/axmol.git
issue #2790: Vector<SchedulerScriptHandlerEntry*> instead of CCArray* in CCScheduler
This commit is contained in:
parent
d7997cf0cc
commit
6b0589679b
|
@ -256,7 +256,7 @@ Scheduler::Scheduler(void)
|
||||||
, _currentTarget(nullptr)
|
, _currentTarget(nullptr)
|
||||||
, _currentTargetSalvaged(false)
|
, _currentTargetSalvaged(false)
|
||||||
, _updateHashLocked(false)
|
, _updateHashLocked(false)
|
||||||
, _scriptHandlerEntries(nullptr)
|
, _scriptHandlerEntries(20)
|
||||||
{
|
{
|
||||||
// I don't expect to have more than 30 functions to all per frame
|
// I don't expect to have more than 30 functions to all per frame
|
||||||
_functionsToPerform.reserve(30);
|
_functionsToPerform.reserve(30);
|
||||||
|
@ -265,7 +265,6 @@ Scheduler::Scheduler(void)
|
||||||
Scheduler::~Scheduler(void)
|
Scheduler::~Scheduler(void)
|
||||||
{
|
{
|
||||||
unscheduleAll();
|
unscheduleAll();
|
||||||
CC_SAFE_RELEASE(_scriptHandlerEntries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
void Scheduler::removeHashElement(_hashSelectorEntry *element)
|
||||||
|
@ -630,10 +629,7 @@ void Scheduler::unscheduleAllWithMinPriority(int minPriority)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_scriptHandlerEntries)
|
_scriptHandlerEntries.clear();
|
||||||
{
|
|
||||||
_scriptHandlerEntries->removeAllObjects();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::unscheduleAllForTarget(Object *target)
|
void Scheduler::unscheduleAllForTarget(Object *target)
|
||||||
|
@ -675,20 +671,15 @@ void Scheduler::unscheduleAllForTarget(Object *target)
|
||||||
unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval, bool paused)
|
unsigned int Scheduler::scheduleScriptFunc(unsigned int handler, float interval, bool paused)
|
||||||
{
|
{
|
||||||
SchedulerScriptHandlerEntry* entry = SchedulerScriptHandlerEntry::create(handler, interval, paused);
|
SchedulerScriptHandlerEntry* entry = SchedulerScriptHandlerEntry::create(handler, interval, paused);
|
||||||
if (!_scriptHandlerEntries)
|
_scriptHandlerEntries.pushBack(entry);
|
||||||
{
|
|
||||||
_scriptHandlerEntries = Array::createWithCapacity(20);
|
|
||||||
_scriptHandlerEntries->retain();
|
|
||||||
}
|
|
||||||
_scriptHandlerEntries->addObject(entry);
|
|
||||||
return entry->getEntryId();
|
return entry->getEntryId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
void Scheduler::unscheduleScriptEntry(unsigned int scheduleScriptEntryID)
|
||||||
{
|
{
|
||||||
for (int i = _scriptHandlerEntries->count() - 1; i >= 0; i--)
|
for (int i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
SchedulerScriptHandlerEntry* entry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
|
SchedulerScriptHandlerEntry* entry = _scriptHandlerEntries.at(i);
|
||||||
if (entry->getEntryId() == (int)scheduleScriptEntryID)
|
if (entry->getEntryId() == (int)scheduleScriptEntryID)
|
||||||
{
|
{
|
||||||
entry->markedForDeletion();
|
entry->markedForDeletion();
|
||||||
|
@ -951,14 +942,14 @@ void Scheduler::update(float dt)
|
||||||
//
|
//
|
||||||
|
|
||||||
// Iterate over all the script callbacks
|
// Iterate over all the script callbacks
|
||||||
if (_scriptHandlerEntries)
|
if (!_scriptHandlerEntries.empty())
|
||||||
{
|
{
|
||||||
for (auto i = _scriptHandlerEntries->count() - 1; i >= 0; i--)
|
for (auto i = _scriptHandlerEntries.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
SchedulerScriptHandlerEntry* eachEntry = static_cast<SchedulerScriptHandlerEntry*>(_scriptHandlerEntries->getObjectAtIndex(i));
|
SchedulerScriptHandlerEntry* eachEntry = _scriptHandlerEntries.at(i);
|
||||||
if (eachEntry->isMarkedForDeletion())
|
if (eachEntry->isMarkedForDeletion())
|
||||||
{
|
{
|
||||||
_scriptHandlerEntries->removeObjectAtIndex(i);
|
_scriptHandlerEntries.remove(i);
|
||||||
}
|
}
|
||||||
else if (!eachEntry->isPaused())
|
else if (!eachEntry->isPaused())
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,6 +107,7 @@ protected:
|
||||||
struct _listEntry;
|
struct _listEntry;
|
||||||
struct _hashSelectorEntry;
|
struct _hashSelectorEntry;
|
||||||
struct _hashUpdateEntry;
|
struct _hashUpdateEntry;
|
||||||
|
class SchedulerScriptHandlerEntry;
|
||||||
|
|
||||||
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
/** @brief Scheduler is responsible for triggering the scheduled callbacks.
|
||||||
You should not use NSTimer. Instead use this class.
|
You should not use NSTimer. Instead use this class.
|
||||||
|
@ -290,7 +291,7 @@ protected:
|
||||||
bool _currentTargetSalvaged;
|
bool _currentTargetSalvaged;
|
||||||
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
// If true unschedule will not remove anything from a hash. Elements will only be marked for deletion.
|
||||||
bool _updateHashLocked;
|
bool _updateHashLocked;
|
||||||
Array* _scriptHandlerEntries;
|
Vector<SchedulerScriptHandlerEntry*> _scriptHandlerEntries;
|
||||||
|
|
||||||
// Used for "perform Function"
|
// Used for "perform Function"
|
||||||
std::vector<std::function<void()>> _functionsToPerform;
|
std::vector<std::function<void()>> _functionsToPerform;
|
||||||
|
|
Loading…
Reference in New Issue