Berserk
Classes | Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
Scheduler Class Referencefinal

Scheduler is responsible for triggering the scheduled callbacks. More...

#include <Scheduler.hpp>

Public Types

using ScheduledFunc = std::function< void(float)>
 
using PerformFunc = std::function< void()>
 
using Handle = size_t
 

Public Member Functions

BRK_API Handle Schedule (ScheduledFunc func, float interval, uint32 repeat=0, float delay=0.0f, bool paused=false)
 Schedule function for execution on game thread. More...
 
BRK_API Handle ScheduleOnce (ScheduledFunc func, float delay, bool paused=false)
 Schedule function for execution on game thread. More...
 
BRK_API Handle ScheduleUpdate (ScheduledFunc func, uint32 repeat=0, float delay=0.0f, bool paused=false)
 Schedule function for execution on game thread. More...
 
BRK_API void ScheduleOnGameThread (PerformFunc func)
 Schedule function to perform exactly on the game thread. More...
 
BRK_API void Cancel (Handle handle)
 Unschedule function associated with specified handle. More...
 
BRK_API void Pause (Handle handle)
 Pause scheduling of function associated with specified handle. More...
 
BRK_API void Resume (Handle handle)
 Resume scheduling of function associated with specified handle. More...
 

Static Public Attributes

static const uint32 REPEAT_FOREVER = 0x7fffffff
 

Friends

class Engine
 

Detailed Description

Scheduler is responsible for triggering the scheduled callbacks.

Use this class to:

Scheduler provides handlers for scheduler functions, so parameters and execution can be tweaked after scheduling.

Member Typedef Documentation

◆ Handle

Handle to identify scheduled function entry

◆ PerformFunc

using Scheduler::PerformFunc = std::function<void()>

Function type to perform once on game thread

◆ ScheduledFunc

using Scheduler::ScheduledFunc = std::function<void(float)>

Function type to schedule

Member Function Documentation

◆ Cancel()

void Scheduler::Cancel ( Scheduler::Handle  handle)

Unschedule function associated with specified handle.

Note
Must be called from game thread
Parameters
handleHandle of scheduled function

◆ Pause()

void Scheduler::Pause ( Scheduler::Handle  handle)

Pause scheduling of function associated with specified handle.

Note
Must be called from game thread
Parameters
handleHandle of scheduled function

◆ Resume()

void Scheduler::Resume ( Scheduler::Handle  handle)

Resume scheduling of function associated with specified handle.

Note
Must be called from game thread
Parameters
handleHandle of scheduled function

◆ Schedule()

BRK_NS_BEGIN Scheduler::Handle Scheduler::Schedule ( Scheduler::ScheduledFunc  func,
float  interval,
uint32  repeat = 0,
float  delay = 0.0f,
bool  paused = false 
)

Schedule function for execution on game thread.

The scheduled function will be called every interval seconds. If paused is true, then it won't be called until it is resumed. Param repeat lets the action be executed repeat + 1 times in total. Param delay is how much to wait before scheduling first time.

Note
Must be called from game thread
Use REPEAT_FOREVER to schedule function to repeat forever.
Parameters
funcFunction to schedule
intervalInterval in seconds to schedule; must be greater that 0
repeatRepeats count to schedule; pass 0 to schedule exactly once
delayDelay in seconds before first schedule
pausedPass true if paused; not scheduled until paused is set to false
Returns
Handle of scheduled function

◆ ScheduleOnce()

Scheduler::Handle Scheduler::ScheduleOnce ( Scheduler::ScheduledFunc  func,
float  delay,
bool  paused = false 
)

Schedule function for execution on game thread.

The scheduled function will be called once. If paused is true, then it won't be called until it is resumed. Param delay is how much to wait before scheduling first time.

Note
Must be called from game thread
Parameters
funcFunction to schedule
delayDelay in seconds before first schedule
pausedPass true if paused; not scheduled until paused is set to false
Returns
Handle of scheduled function

◆ ScheduleOnGameThread()

void Scheduler::ScheduleOnGameThread ( Scheduler::PerformFunc  func)

Schedule function to perform exactly on the game thread.

Use this function to safely notify user by callback after async operation completions.

Note
Thread-safe
Parameters
funcFunction to schedule

◆ ScheduleUpdate()

Scheduler::Handle Scheduler::ScheduleUpdate ( Scheduler::ScheduledFunc  func,
uint32  repeat = 0,
float  delay = 0.0f,
bool  paused = false 
)

Schedule function for execution on game thread.

The scheduled function will be called every frame. If paused is true, then it won't be called until it is resumed. Param repeat lets the action be executed repeat + 1 times in total. Param delay is how much to wait before scheduling first time.

Note
Must be called from game thread
Use REPEAT_FOREVER to schedule function to repeat forever.
Parameters
funcFunction to schedule
repeatRepeats count to schedule; pass 0 to schedule exactly once
delayDelay in seconds before first schedule
pausedPass true if paused; not scheduled until paused is set to false
Returns
Handle of scheduled function

Friends And Related Function Documentation

◆ Engine

friend class Engine
friend

Member Data Documentation

◆ REPEAT_FOREVER

const uint32 Scheduler::REPEAT_FOREVER = 0x7fffffff
static

Auxiliary constant to say, that function must be scheduled forever


The documentation for this class was generated from the following files: