|
Zappy Server
C++ game server: world, rules, scheduler, network
|
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 |
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.
Definition at line 23 of file Scheduler.hpp.
| 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:| 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:| 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:| void Scheduler::schedule | ( | std::chrono::milliseconds | delay, |
| std::function< void()> | cb | ||
| ) |
Definition at line 3 of file Scheduler.cpp.
References _queue.
Referenced by CommandDispatcher::_handleBroadcast(), CommandDispatcher::_handleEject(), CommandDispatcher::_handleFork(), CommandDispatcher::_handleForward(), CommandDispatcher::_handleIncantation(), CommandDispatcher::_handleInventory(), CommandDispatcher::_handleLeft(), CommandDispatcher::_handleLook(), CommandDispatcher::_handleRight(), CommandDispatcher::_handleSet(), CommandDispatcher::_handleTake(), Server::_scheduleRespawn(), and CommandDispatcher::_startStarvationTimer().
Here is the caller graph for this function:| 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:
|
private |
Definition at line 46 of file Scheduler.hpp.
Referenced by clear(), msUntilNext(), rescale(), schedule(), and tick().