|
Minecraft Community Edition 0.1.0
|
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. | |
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);
}
| using mce::CoroutineScheduler::Callback = eastl::function<sf::Time()> |
Callback type invoked by scheduled tasks.
| void mce::CoroutineScheduler::addTask | ( | Callback | cb | ) |
Add a task to the scheduler.
| cb | The 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.
| 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.