Axmol Engine 2.4.0-258ceca
|
Scheduler is responsible for triggering the scheduled callbacks. More...
#include <Scheduler.h>
Inherits Object.
Public Member Functions | |
Scheduler () | |
Constructor. | |
virtual | ~Scheduler () |
Destructor. | |
float | getTimeScale () |
Gets the time scale of schedule callbacks. | |
void | setTimeScale (float timeScale) |
Modifies the time of all scheduled callbacks. | |
void | update (float dt) |
'update' the scheduler. | |
void | schedule (const ccSchedulerFunc &callback, void *target, float interval, unsigned int repeat, float delay, bool paused, std::string_view key) |
The scheduled method will be called every 'interval' seconds. | |
void | schedule (const ccSchedulerFunc &callback, void *target, float interval, bool paused, std::string_view key) |
The scheduled method will be called every 'interval' seconds for ever. | |
void | schedule (SEL_SCHEDULE selector, Object *target, float interval, unsigned int repeat, float delay, bool paused) |
The scheduled method will be called every interval seconds. | |
void | schedule (SEL_SCHEDULE selector, Object *target, float interval, bool paused) |
The scheduled method will be called every interval seconds for ever. | |
template<class T> | |
void | scheduleUpdate (T *target, int priority, bool paused) |
Schedules the 'update' selector for a given target with a given priority. | |
unsigned int | scheduleScriptFunc (unsigned int handler, float interval, bool paused) |
The scheduled script callback will be called every 'interval' seconds. | |
void | unschedule (std::string_view key, void *target) |
Unschedules a callback for a key and a given target. | |
void | unschedule (SEL_SCHEDULE selector, Object *target) |
Unschedules a selector for a given target. | |
void | unscheduleUpdate (void *target) |
Unschedules the update selector for a given target. | |
void | unscheduleAllForTarget (void *target) |
Unschedules all selectors for a given target. | |
void | unscheduleAll () |
Unschedules all selectors from all targets. | |
void | unscheduleAllWithMinPriority (int minPriority) |
Unschedules all selectors from all targets with a minimum priority. | |
void | unscheduleScriptEntry (unsigned int scheduleScriptEntryID) |
Unschedule a script entry. | |
bool | isScheduled (std::string_view key, const void *target) const |
Checks whether a callback associated with 'key' and 'target' is scheduled. | |
bool | isScheduled (SEL_SCHEDULE selector, const Object *target) const |
Checks whether a selector for a given target is scheduled. | |
void | pauseTarget (void *target) |
Pauses the target. | |
void | resumeTarget (void *target) |
Resumes the target. | |
bool | isTargetPaused (void *target) |
Returns whether or not the target is paused. | |
std::set< void * > | pauseAllTargets () |
Pause all selectors from all targets. | |
std::set< void * > | pauseAllTargetsWithMinPriority (int minPriority) |
Pause all selectors from all targets with a minimum priority. | |
void | resumeTargets (const std::set< void * > &targetsToResume) |
Resume selectors on a set of targets. | |
void | runOnAxmolThread (std::function< void()> action) |
Calls a function on the cocos2d thread. | |
void | removeAllPendingActions () |
Remove all pending functions queued to be performed with Scheduler::runOnAxmolThread Functions unscheduled in this manner will not be executed This function is thread safe. | |
![]() | |
void | retain () |
Retains the ownership. | |
void | release () |
Releases the ownership immediately. | |
Object * | autorelease () |
Releases the ownership sometime soon automatically. | |
unsigned int | getReferenceCount () const |
Returns the Object's current reference count. | |
virtual | ~Object () |
Destructor. | |
Static Public Attributes | |
static const int | PRIORITY_SYSTEM |
Priority level reserved for system services. | |
static const int | PRIORITY_NON_SYSTEM_MIN |
Minimum priority level for user scheduling. | |
Additional Inherited Members | |
![]() | |
unsigned int | _ID |
object id, ScriptSupport need public _ID | |
int | _luaID |
Lua reference id. | |
Scheduler is responsible for triggering the scheduled callbacks.
You should not use system timer for your game logic. Instead, use this class.
There are 2 different types of callbacks (selectors):
The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'.
Scheduler | ( | ) |
Constructor.
@js ctor
|
virtual |
Destructor.
@js NA @lua NA
|
inline |
Gets the time scale of schedule callbacks.
|
inline |
Modifies the time of all scheduled callbacks.
You can use this property to create a 'slow motion' or 'fast forward' effect. Default is 1.0. To create a 'slow motion' effect, use values below 1.0. To create a 'fast forward' effect, use values higher than 1.0.
void update | ( | float | dt | ) |
'update' the scheduler.
You should NEVER call this method, unless you know what you are doing. @lua NA
void schedule | ( | const ccSchedulerFunc & | callback, |
void * | target, | ||
float | interval, | ||
unsigned int | repeat, | ||
float | delay, | ||
bool | paused, | ||
std::string_view | key ) |
The scheduled method will be called every 'interval' seconds.
If paused is true, then it won't be called until it is resumed. If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdate' instead. If the 'callback' is already scheduled, then only the interval parameter will be updated without re-scheduling it again. repeat let the action be repeated repeat + 1 times, use AX_REPEAT_FOREVER to let the action run continuously delay is the amount of time the action will wait before it'll start.
callback | The callback function. |
target | The target of the callback function. |
interval | The interval to schedule the callback. If the value is 0, then the callback will be scheduled every frame. |
repeat | repeat+1 times to schedule the callback. |
delay | Schedule call back after delay seconds. If the value is not 0, the first schedule will happen after delay seconds. But it will only affect first schedule. After first schedule, the delay time is determined by interval . |
paused | Whether or not to pause the schedule. |
key | The key to identify the callback function, because there is not way to identify a std::function<>. |
void schedule | ( | const ccSchedulerFunc & | callback, |
void * | target, | ||
float | interval, | ||
bool | paused, | ||
std::string_view | key ) |
The scheduled method will be called every 'interval' seconds for ever.
callback | The callback function. |
target | The target of the callback function. |
interval | The interval to schedule the callback. If the value is 0, then the callback will be scheduled every frame. |
paused | Whether or not to pause the schedule. |
key | The key to identify the callback function, because there is not way to identify a std::function<>. |
void schedule | ( | SEL_SCHEDULE | selector, |
Object * | target, | ||
float | interval, | ||
unsigned int | repeat, | ||
float | delay, | ||
bool | paused ) |
The scheduled method will be called every interval
seconds.
If paused is true, then it won't be called until it is resumed. If 'interval' is 0, it will be called every frame, but if so, it's recommended to use 'scheduleUpdate' instead. If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again. repeat let the action be repeated repeat + 1 times, use AX_REPEAT_FOREVER to let the action run continuously delay is the amount of time the action will wait before it'll start
selector | The callback function. |
target | The target of the callback function. |
interval | The interval to schedule the callback. If the value is 0, then the callback will be scheduled every frame. |
repeat | repeat+1 times to schedule the callback. |
delay | Schedule call back after delay seconds. If the value is not 0, the first schedule will happen after delay seconds. But it will only affect first schedule. After first schedule, the delay time is determined by interval . |
paused | Whether or not to pause the schedule. |
void schedule | ( | SEL_SCHEDULE | selector, |
Object * | target, | ||
float | interval, | ||
bool | paused ) |
The scheduled method will be called every interval
seconds for ever.
selector | The callback function. |
target | The target of the callback function. |
interval | The interval to schedule the callback. If the value is 0, then the callback will be scheduled every frame. |
paused | Whether or not to pause the schedule. |
|
inline |
Schedules the 'update' selector for a given target with a given priority.
The 'update' selector will be called every frame. The lower the priority, the earlier it is called.
unsigned int scheduleScriptFunc | ( | unsigned int | handler, |
float | interval, | ||
bool | paused ) |
The scheduled script callback will be called every 'interval' seconds.
If paused is true, then it won't be called until it is resumed. If 'interval' is 0, it will be called every frame. return schedule script entry ID, used for unscheduleScriptFunc().
@warn Don't invoke this function unless you know what you are doing. @js NA @lua NA
void unschedule | ( | std::string_view | key, |
void * | target ) |
Unschedules a callback for a key and a given target.
If you want to unschedule the 'callbackPerFrame', use unscheduleUpdate.
key | The key to identify the callback function, because there is not way to identify a std::function<>. |
target | The target to be unscheduled. |
void unschedule | ( | SEL_SCHEDULE | selector, |
Object * | target ) |
Unschedules a selector for a given target.
If you want to unschedule the "update", use unscheduleUpdate()
.
selector | The selector that is unscheduled. |
target | The target of the unscheduled selector. |
void unscheduleUpdate | ( | void * | target | ) |
Unschedules the update selector for a given target.
target | The target to be unscheduled. |
void unscheduleAllForTarget | ( | void * | target | ) |
Unschedules all selectors for a given target.
This also includes the "update" selector.
target | The target to be unscheduled. |
void unscheduleAll | ( | ) |
Unschedules all selectors from all targets.
You should NEVER call this method, unless you know what you are doing.
void unscheduleAllWithMinPriority | ( | int | minPriority | ) |
Unschedules all selectors from all targets with a minimum priority.
You should only call this with PRIORITY_NON_SYSTEM_MIN
or higher.
minPriority | The minimum priority of selector to be unscheduled. Which means, all selectors which priority is higher than minPriority will be unscheduled. |
void unscheduleScriptEntry | ( | unsigned int | scheduleScriptEntryID | ) |
Unschedule a script entry.
bool isScheduled | ( | std::string_view | key, |
const void * | target ) const |
Checks whether a callback associated with 'key' and 'target' is scheduled.
key | The key to identify the callback function, because there is not way to identify a std::function<>. |
target | The target of the callback. |
bool isScheduled | ( | SEL_SCHEDULE | selector, |
const Object * | target ) const |
Checks whether a selector for a given target is scheduled.
selector | The selector to be checked. |
target | The target of the callback. |
void pauseTarget | ( | void * | target | ) |
Pauses the target.
All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed. If the target is not present, nothing happens.
target | The target to be paused. |
void resumeTarget | ( | void * | target | ) |
Resumes the target.
The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again. If the target is not present, nothing happens.
target | The target to be resumed. |
bool isTargetPaused | ( | void * | target | ) |
Returns whether or not the target is paused.
target | The target to be checked. |
std::set< void * > pauseAllTargets | ( | ) |
Pause all selectors from all targets.
You should NEVER call this method, unless you know what you are doing.
std::set< void * > pauseAllTargetsWithMinPriority | ( | int | minPriority | ) |
Pause all selectors from all targets with a minimum priority.
You should only call this with PRIORITY_NON_SYSTEM_MIN or higher.
minPriority | The minimum priority of selector to be paused. Which means, all selectors which priority is higher than minPriority will be paused. |
void resumeTargets | ( | const std::set< void * > & | targetsToResume | ) |
Resume selectors on a set of targets.
This can be useful for undoing a call to pauseAllSelectors.
targetsToResume | The set of targets to be resumed. |
void runOnAxmolThread | ( | std::function< void()> | action | ) |
Calls a function on the cocos2d thread.
Useful when you need to call a cocos2d function from another thread. This function is thread safe.
function | The function to be run in cocos2d thread. |
void removeAllPendingActions | ( | ) |
Remove all pending functions queued to be performed with Scheduler::runOnAxmolThread Functions unscheduled in this manner will not be executed This function is thread safe.
|
static |
Priority level reserved for system services.
@lua NA @js NA
|
static |
Minimum priority level for user scheduling.
Priority level of user scheduling should bigger then this value.
@lua NA @js NA