|
Zappy Server
C++ game server: world, rules, scheduler, network
|
Owns every subsystem and runs the main game loop. More...
#include <Server.hpp>
Collaboration diagram for Server:Public Member Functions | |
| Server (const ServerConfig &config) | |
| void | run () |
| Run the game loop until the process is stopped. | |
Private Member Functions | |
| void | _scheduleRespawn () |
| (Re)schedule the periodic world resource respawn. | |
| void | _logStartup () const |
| void | _handleGameOver () |
| Freeze the world and log the winner banner. Runs once when a team wins. | |
Private Attributes | |
| ServerConfig | _config |
| Listener | _listener |
| ClientManager | _clients |
| World | _world |
| GuiNotifier | _notifier |
| Logger | _logger |
| LogObserver | _logObserver |
| Scheduler | _scheduler |
| CommandDispatcher | _dispatcher |
| bool | _gameOverHandled = false |
Static Private Attributes | |
| static constexpr int | RESPAWN_INTERVAL_MS = 20000 |
| Resources respawn every 20 time units (subject spec). | |
Owns every subsystem and runs the main game loop.
run() loops forever: poll the sockets, pass new connections / lines / disconnects to the CommandDispatcher, then let the Scheduler fire any timers that are due (respawn, starvation, incantations...). Single thread.
Definition at line 20 of file Server.hpp.
| Server::Server | ( | const ServerConfig & | config | ) |
Definition at line 23 of file Server.cpp.
References _clients, _config, _logger, _logObserver, _notifier, _world, ClientManager::addNetworkObserver(), World::addWorldObserver(), ServerConfig::clientsNb, FileSink::forRun(), Info, ServerConfig::port, Logger::setSink(), World::spawnInitialEggs(), and World::spawnResources().
Here is the call graph for this function:
|
private |
Freeze the world and log the winner banner. Runs once when a team wins.
Definition at line 63 of file Server.cpp.
References _clients, _config, _dispatcher, _gameOverHandled, _logger, _notifier, _scheduler, _world, GuiNotifier::broadcast(), Scheduler::clear(), ClientManager::disconnect(), CommandDispatcher::gameElapsed(), CommandDispatcher::gameTicks(), World::getPlayers(), Serializer::gwt(), Logger::info(), CommandDispatcher::teamJoin(), ServerConfig::teamNames, and World::winner().
Referenced by run().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 53 of file Server.cpp.
References _config, ServerConfig::height, ServerConfig::port, ServerConfig::seed, ServerConfig::teamNames, and ServerConfig::width.
Referenced by run().
Here is the caller graph for this function:
|
private |
(Re)schedule the periodic world resource respawn.
Definition at line 45 of file Server.cpp.
References _config, _scheduler, ServerConfig::freq, RESPAWN_INTERVAL_MS, and Scheduler::schedule().
Referenced by run().
Here is the call graph for this function:
Here is the caller graph for this function:| void Server::run | ( | ) |
Run the game loop until the process is stopped.
Definition at line 98 of file Server.cpp.
References _clients, _dispatcher, _gameOverHandled, _handleGameOver(), _logger, _logStartup(), _scheduler, _scheduleRespawn(), _world, ClientManager::disconnect(), PollResult::disconnectedIds, CommandDispatcher::dispatch(), CommandDispatcher::drainPendingDisconnects(), Logger::info(), World::isGameEnded(), PollResult::lines, Scheduler::msUntilNext(), PollResult::newConnections, CommandDispatcher::onDisconnect(), CommandDispatcher::onNewConnection(), ClientManager::poll(), and Scheduler::tick().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Definition at line 39 of file Server.hpp.
Referenced by _handleGameOver(), run(), and Server().
|
private |
Definition at line 37 of file Server.hpp.
Referenced by _handleGameOver(), _logStartup(), _scheduleRespawn(), and Server().
|
private |
Definition at line 45 of file Server.hpp.
Referenced by _handleGameOver(), and run().
|
private |
Definition at line 46 of file Server.hpp.
Referenced by _handleGameOver(), and run().
|
private |
Definition at line 38 of file Server.hpp.
|
private |
Definition at line 42 of file Server.hpp.
Referenced by _handleGameOver(), run(), and Server().
|
private |
Definition at line 43 of file Server.hpp.
Referenced by Server().
|
private |
Definition at line 41 of file Server.hpp.
Referenced by _handleGameOver(), and Server().
|
private |
Definition at line 44 of file Server.hpp.
Referenced by _handleGameOver(), _scheduleRespawn(), and run().
|
private |
Definition at line 40 of file Server.hpp.
Referenced by _handleGameOver(), run(), and Server().
|
staticconstexprprivate |
Resources respawn every 20 time units (subject spec).
Definition at line 35 of file Server.hpp.
Referenced by _scheduleRespawn().