![]() |
R-Type
2
Doom but in better
|
Manages multiple Game instances and routes messages/events. More...
#include <game_manager.hpp>
Public Types | |
using | BroadcastFunc = std::function<void(uint32_t, const Message&)> |
Public Member Functions | |
GameManager (BroadcastFunc broadcastFunc) | |
Constructor that takes a broadcast function (to send packets to clients). | |
std::forward_list< std::string > | syncClientToGame (uint32_t clientId) |
Gets the current game state for syncing. | |
uint32_t | assignClientToGame (uint32_t clientId) |
Assign a client to a new or existing game. | |
void | removeClientFromGame (uint32_t clientId) |
Remove a client from whichever game they are in. | |
uint32_t | getGameIdForClient (uint32_t clientId) const |
Get the game ID for a client, or 0 if none. | |
void | updateAllGames (float dt) |
Update all games with the given deltaTime and broadcast events to clients. | |
void | handleGameMessage (uint32_t gameId, uint32_t clientId, const Message &msg) |
Handle a message from a client in a specific game. | |
Manages multiple Game instances and routes messages/events.
broadcastFunc_ is a callback for sending network messages: broadcastFunc_(clientId, Message);
Definition at line 27 of file game_manager.hpp.
using GameManager::BroadcastFunc = std::function<void(uint32_t, const Message&)> |
Definition at line 29 of file game_manager.hpp.
|
explicit |
Constructor that takes a broadcast function (to send packets to clients).
broadcastFunc | A function that can do "sendToClient(clientId, msg)". |
Definition at line 7 of file game_manager.cpp.
uint32_t GameManager::assignClientToGame | ( | uint32_t | clientId | ) |
Assign a client to a new or existing game.
Definition at line 37 of file game_manager.cpp.
uint32_t GameManager::getGameIdForClient | ( | uint32_t | clientId | ) | const |
Get the game ID for a client, or 0 if none.
Definition at line 82 of file game_manager.cpp.
void GameManager::handleGameMessage | ( | uint32_t | gameId, |
uint32_t | clientId, | ||
const Message & | msg ) |
Handle a message from a client in a specific game.
Definition at line 117 of file game_manager.cpp.
void GameManager::removeClientFromGame | ( | uint32_t | clientId | ) |
Remove a client from whichever game they are in.
Definition at line 53 of file game_manager.cpp.
std::forward_list< std::string > GameManager::syncClientToGame | ( | uint32_t | clientId | ) |
Gets the current game state for syncing.
Definition at line 11 of file game_manager.cpp.
void GameManager::updateAllGames | ( | float | dt | ) |
Update all games with the given deltaTime and broadcast events to clients.
Definition at line 90 of file game_manager.cpp.