R-Type  2
Doom but in better
Loading...
Searching...
No Matches
GameManager Class Reference

Manages multiple Game instances and routes messages/events. More...

#include <game_manager.hpp>

Collaboration diagram for GameManager:
Collaboration graph

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ BroadcastFunc

using GameManager::BroadcastFunc = std::function<void(uint32_t, const Message&)>

Definition at line 29 of file game_manager.hpp.

Constructor & Destructor Documentation

◆ GameManager()

GameManager::GameManager ( BroadcastFunc broadcastFunc)
explicit

Constructor that takes a broadcast function (to send packets to clients).

Parameters
broadcastFuncA function that can do "sendToClient(clientId, msg)".

Definition at line 7 of file game_manager.cpp.

Member Function Documentation

◆ assignClientToGame()

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.

◆ getGameIdForClient()

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.

◆ handleGameMessage()

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.

◆ removeClientFromGame()

void GameManager::removeClientFromGame ( uint32_t clientId)

Remove a client from whichever game they are in.

Definition at line 53 of file game_manager.cpp.

◆ syncClientToGame()

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.

◆ updateAllGames()

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.


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