2#include <unordered_map>
16 std::unique_ptr<Game>
game;
71 uint32_t findOrCreateGame();
76 std::unordered_map<uint32_t, GameInstance> games_;
77 std::unordered_map<uint32_t, uint32_t> clientToGame_;
78 uint32_t nextGameId_ = 1;
80 static const size_t MAX_PLAYERS_PER_GAME = 4;
Manages multiple Game instances and routes messages/events.
uint32_t assignClientToGame(uint32_t clientId)
Assign a client to a new or existing game.
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.
std::forward_list< std::string > syncClientToGame(uint32_t clientId)
Gets the current game state for syncing.
void removeClientFromGame(uint32_t clientId)
Remove a client from whichever game they are in.
GameManager(BroadcastFunc broadcastFunc)
Constructor that takes a broadcast function (to send packets to clients).
std::function< void(uint32_t, const Message &)> BroadcastFunc
void handleGameMessage(uint32_t gameId, uint32_t clientId, const Message &msg)
Handle a message from a client in a specific game.
A single game session: a Game object plus the connected clients.
std::unique_ptr< Game > game
std::vector< uint32_t > clients
Minimal network message with a 4-byte header (type + length) and a payload.