5 _queue.push({std::chrono::steady_clock::now() + delay, std::move(cb)});
10 auto now = std::chrono::steady_clock::now();
12 auto cb = std::move(
_queue.top().callback);
20 if (
_queue.empty())
return -1;
22 auto now = std::chrono::steady_clock::now();
23 auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(
_queue.top().fireAt - now);
24 return diff.count() < 0 ? 0 :
static_cast<int>(diff.count());
34 auto now = std::chrono::steady_clock::now();
35 std::vector<TimedEvent> events;
37 events.push_back(
_queue.top());
40 for (
auto& e : events) {
41 auto remaining = e.fireAt - now;
42 auto scaled = std::chrono::duration_cast<std::chrono::nanoseconds>(remaining * ratio);
43 e.fireAt = now + scaled;
void schedule(std::chrono::milliseconds delay, std::function< void()> cb)
void clear()
Drop all pending events (e.g. on game end, to freeze the world instantly).
std::priority_queue< TimedEvent, std::vector< TimedEvent >, std::greater< TimedEvent > > _queue
int msUntilNext() const
Milliseconds until the next event. Pass directly to poll() as timeout. Returns -1 if the queue is emp...
void rescale(float ratio)
Rescale all pending fire times by ratio.