|
Eile Mit Weile
|
Manages all active GameInstances. More...
#include <GameInstanceManager.hpp>
Static Public Member Functions | |
| static bool | TryGetGameInstance (const std::string &game_id, GameInstance *&game_instance_ptr) |
| static bool | TryGetPlayerAndGameInstance (const std::string &player_id, Player *&player, GameInstance *&game_instance_ptr, std::string &err) |
| static bool | TryAddPlayerToAnyGame (Player *player, GameInstance *&game_instance_ptr, std::string &err) |
| static bool | TryAddPlayer (Player *player, GameInstance *&game_instance_ptr, std::string &err) |
| static bool | TryRemovePlayer (Player *player, const std::string &game_id, std::string &err) |
| static bool | TryRemovePlayer (Player *player, GameInstance *&game_instance_ptr, std::string &err) |
Static Private Member Functions | |
| static GameInstance * | CreateNewGame () |
| static GameInstance * | FindJoinableGameInstance () |
Static Private Attributes | |
| static std::shared_mutex | games_lut_lock |
| static std::unordered_map< std::string, GameInstance * > | games_lut = {} |
Manages all active GameInstances.
The GameInstanceManager only exists on the server side. It stores all currently active games and offers functionality to retrieve game instances by id and adding players to games. If a new player requests to join a game but no valid GameInstance is available, then this class will generate a new GameInstance and add it to the unordered_map of (active) game instances.
Note: This class design is taken from https://gitlab.ethz.ch/hraymond/cse-lama-example-project. They made the choice to have all members be static, which is why this class is a singleton and should not be instantiated. It also references the PlayerManager and ServerNetworkManager classes without having to instantiate them as member vars. We consider this bad practice but changing would require a lot of refactoring so we decided to keep it as is.
|
staticprivate |
Creates a new GameInstance and adds it to the unordered_map of game instances.
|
staticprivate |
Finds a non-full, non-started game instance or creates a new one if none is found.
|
static |
Try to add Player to the provided game_instance_ptr. Returns true if success and false otherwise. Error message will be written into err.
|
static |
Try to add Player to any GameInstance. Returns true if Player is successfully added to a GameInstance. The joined GameInstance will be written into game_instance_ptr. Error message will be written into err.
|
static |
returns true if the desired game_instance 'game_id' was found or false otherwise. The found game instance is written into game_instance_ptr.
|
static |
returns true if the desired player player_id was found and is connected to a game_instance. The found player and GameInstance will be written into player and game_instance_ptr Error message will be written into err.
|
static |
Try to remove Player from the provided game_id (see GameInstance::GetId). Returns true if success and false otherwise. Error message will be written into err.
|
static |
Try to remove Player from the provided game_instance_ptr. Returns true if success and false otherwise. Error message will be written into err.
|
staticprivate |
Unordered_map of all active game instances.
|
inlinestaticprivate |
Mutex to lock the unordered_map of game instances for reading and writing.