Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
mce::CoroutineScheduler Class Reference

Coroutine scheduler that manages periodic tasks. More...

#include <CoroutineScheduler.hpp>

Classes

struct  Task
 Represents a single scheduled task. More...

Public Types

using Callback = eastl::function<sf::Time()>
 Callback type invoked by scheduled tasks.

Public Member Functions

 CoroutineScheduler ()=default
 Default constructor.
void addTask (Callback cb)
 Add a task to the scheduler.
void processTasks ()
 Process all scheduled tasks.

Detailed Description

Coroutine scheduler that manages periodic tasks.

The scheduler stores tasks that each have their own clock and interval. Each task's callback should return an sf::Time representing the time to wait until the next invocation. When a task's clock has elapsed at least its interval the callback is invoked and the returned sf::Time is used as the new interval.

example usage:

addTask([]() -> sf::Time {

return sf::seconds(1);

}

Member Typedef Documentation

◆ Callback

using mce::CoroutineScheduler::Callback = eastl::function<sf::Time()>

Callback type invoked by scheduled tasks.

Returns
An sf::Time that indicates how long to wait until the next invocation of this callback.

Member Function Documentation

◆ addTask()

void mce::CoroutineScheduler::addTask ( Callback cb)

Add a task to the scheduler.

Parameters
cbThe callback to schedule. The callback is invoked immediately to obtain the initial interval.

The callback should return an sf::Time specifying how long to wait until the next invocation. The task's clock is restarted when added.

◆ processTasks()

void mce::CoroutineScheduler::processTasks ( )

Process all scheduled tasks.

This should be called periodically (for example once per frame). For each task if its clock has elapsed at least its interval, the task's callback is invoked, the returned sf::Time is used as the new interval, and the task clock is restarted.


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