Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
Scheduler Class Reference

Priority queue of timed callbacks. Drives all game timing. More...

#include <Scheduler.hpp>

+ Collaboration diagram for Scheduler:

Public Member Functions

void schedule (std::chrono::milliseconds delay, std::function< void()> cb)
 
void tick ()
 
void clear ()
 Drop all pending events (e.g. on game end, to freeze the world instantly).
 
int msUntilNext () const
 Milliseconds until the next event. Pass directly to poll() as timeout. Returns -1 if the queue is empty (poll blocks until I/O arrives).
 
void rescale (float ratio)
 Rescale all pending fire times by ratio.
 

Private Attributes

std::priority_queue< TimedEvent, std::vector< TimedEvent >, std::greater< TimedEvent > > _queue
 

Detailed Description

Priority queue of timed callbacks. Drives all game timing.

Every action duration (movement, incantation, starvation...) is a scheduled callback. The server feeds msUntilNext() directly to poll() so the process sleeps exactly as long as needed: no busy-waiting.

See also
server/doc.md - "core/Scheduler" and "Main Loop" sections.

Definition at line 23 of file Scheduler.hpp.

Member Function Documentation

◆ clear()

void Scheduler::clear ( )

Drop all pending events (e.g. on game end, to freeze the world instantly).

Definition at line 27 of file Scheduler.cpp.

References _queue.

Referenced by Server::_handleGameOver().

+ Here is the caller graph for this function:

◆ msUntilNext()

int Scheduler::msUntilNext ( ) const

Milliseconds until the next event. Pass directly to poll() as timeout. Returns -1 if the queue is empty (poll blocks until I/O arrives).

Definition at line 18 of file Scheduler.cpp.

References _queue.

Referenced by Server::run().

+ Here is the caller graph for this function:

◆ rescale()

void Scheduler::rescale ( float  ratio)

Rescale all pending fire times by ratio.

Called when the GUI sends sst T to change frequency. Pass oldFreq / newFreq. O(n log n) heap rebuild – acceptable since sst is infrequent.

Definition at line 32 of file Scheduler.cpp.

References _queue.

Referenced by CommandDispatcher::_handleSst().

+ Here is the caller graph for this function:

◆ schedule()

void Scheduler::schedule ( std::chrono::milliseconds  delay,
std::function< void()>  cb 
)

◆ tick()

void Scheduler::tick ( )

Definition at line 8 of file Scheduler.cpp.

References _queue.

Referenced by Server::run().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _queue

std::priority_queue<TimedEvent, std::vector<TimedEvent>, std::greater<TimedEvent> > Scheduler::_queue
private

Definition at line 46 of file Scheduler.hpp.

Referenced by clear(), msUntilNext(), rescale(), schedule(), and tick().


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