![]() |
PRooFPS-dd Dev Doc 1.0
PRooFPS-dd Developer Documentation
|
GameMode class represent the Frag Table and the winning condition checks. More...
GameMode class represent the Frag Table and the winning condition checks.
It identifies players by their name thus it is essential that all players have unique name.
TODO: not sure exactly about my original idea, but definitely the current design should be changed a bit. GameMode should NOT contain anything related to "frags", it should be more abstract. It should be called scores, frag limit shall be score limit, which is the round win limit in TRG but frag limit otherwise. Frags, frag table, etc. should be introduced in derived class such as DeathMatchMode. However this definitely won't be "fixed" in 2024.
TODO: regarding fetchConfig(): probably GameMode should autonomuously handle relevant config, including validation. However, for this to happen, it should implement an IConfigHandler so Config class can invoke its validateConfig() function when Config::validate() is invoked. On the long run this mechanism should be extended to other classes as well where the CVAR definitions are also present.
Definition at line 92 of file GameMode.h.
#include <GameMode.h>
Inheritance diagram for proofps_dd::GameMode:Public Member Functions | |
| CConsole & | getConsole () const |
| virtual | ~GameMode () |
| virtual void | fetchConfig (PGEcfgProfiles &cfgProfiles, pge_network::PgeINetwork &network) |
| Fetches configuration from the given PGEcfgProfiles instance. | |
| GameModeType | getGameModeType () const |
| const char * | getGameModeTypeName () const |
| const std::chrono::time_point< std::chrono::steady_clock > & | getResetTime () const |
| unsigned int | getTimeLimitSecs () const |
| void | setTimeLimitSecs (unsigned int secs) |
| Set the time limit for the game. | |
| unsigned int | getTimeRemainingMillisecs () const |
| void | clientUpdateTimeRemainingMillisecs (const unsigned int &nRemMillisecs, pge_network::PgeINetwork &network) |
| Updates the remaining time on client side, based on the remaining time received from server. | |
| virtual void | restart (pge_network::PgeINetwork &network) |
| Similar to restartWithoutRemovingPlayers() but it also removes all players from this GameMode instance. | |
| virtual void | restartWithoutRemovingPlayers (pge_network::PgeINetwork &network, const proofps_dd::GameRestartType_KeepPlayers &eRestartType) |
| Resets winning time and winning condition, also zeros out relevant members of PlayersTableRow for all players. | |
| virtual bool | serverCheckAndUpdateWinningConditions (pge_network::PgeINetwork &network) |
| Evaluates conditions to see if game is won or not. | |
| void | clientReceiveAndUpdateWinningConditions (pge_network::PgeINetwork &network, bool bGameSessionWon) |
| Handles server's update about current game session goal, e.g. | |
| virtual void | serverTickUpdateWinningConditions (pge_network::PgeINetwork &network) |
| Shall be invoked regularly (per tick or per frame) at the end of server tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly. | |
| virtual void | clientTickUpdateWinningConditions (pge_network::PgeINetwork &network) |
| Shall be invoked regularly (per tick or per frame) at the end of client tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly. | |
| bool | isGameWon () const |
| Returns the current game session win state i.e. | |
| bool | wasGameWonAlreadyInPreviousTick () const |
| Returns if the current game session was already won in the previous tick. | |
| bool | hasJustBeenWonThisTick () const |
| Returns if the current game session has been just detected as won in this tick i.e. | |
| const std::chrono::time_point< std::chrono::steady_clock > & | getWinTime () const |
| const std::list< PlayersTableRow > & | getPlayersTable () const |
| const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & | getExternalPlayersContainer () const |
| virtual bool | addPlayer (const Player &player, pge_network::PgeINetwork &network)=0 |
| Adds the specified player. | |
| virtual bool | updatePlayer (const Player &player, pge_network::PgeINetwork &network)=0 |
| Updates data for the specified player. | |
| virtual bool | removePlayer (const Player &player, pge_network::PgeINetwork &network)=0 |
| Removes data for the specified player. | |
| bool | renamePlayer (const std::string &sOldName, const std::string &sNewName) |
| Renames the player. | |
| virtual bool | isTeamBasedGame () const =0 |
| Derived class shall return false if it is non-team-based game, otherwise true. | |
| virtual bool | isRoundBased () const =0 |
| virtual bool | isRespawnAllowedAfterDie () const =0 |
| virtual bool | isPlayerAllowedForGameplay (const Player &player) const |
| Checks if given player is allowed for gameplay. | |
| virtual bool | isPlayerMovementAllowed () const |
| unsigned int | getSpectatorModePlayersCount () const |
| void | text (PR00FsUltimateRenderingEngine &pure, const std::string &s, int x, int y) const |
Static Public Member Functions | |
| static const char * | getLoggerModuleName () |
| static GameMode * | createGameMode (GameModeType gm, const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers) |
| Similar to singleton design pattern, there is always maximum one instance. | |
| static GameMode * | getGameMode () |
| static bool | isTeamBasedGame (GameModeType gm) |
| static bool | isRoundBased (GameModeType gm) |
| static const char * | getGameModeTypeName (GameModeType gm) |
| static GameModeType | getGameModeTypeFromConfig (PGEcfgProfiles &cfgProfiles) |
| static const char * | getRank (const PlayersTableRow &row) |
Static Public Attributes | |
| static constexpr char * | szCvarSvGamemode = "sv_gamemode" |
| static constexpr char * | szCvarSvGmTimeLimit = "sv_gm_timelimit_secs" |
| static constexpr char * | szCvarSvDmFragLimit = "sv_dm_fraglimit" |
| static constexpr char * | szCvarSvRgmRoundWinLimit = "sv_rgm_roundwinlimit" |
| static constexpr int | nSvGmTimeLimitSecsDef = 0 |
| static constexpr int | nSvGmTimeLimitSecsMin = 0 |
| static constexpr int | nSvGmTimeLimitSecsMax = 60 * 60 * 24 |
| static constexpr int | nSvDmFragLimitDef = 10 |
| static constexpr int | nSvDmFragLimitMin = 0 |
| static constexpr int | nSvDmFragLimitMax = 999 |
| static constexpr int | nSvRgmRoundWinLimitDef = 5 |
| static constexpr int | nSvRgmRoundWinLimitMin = 1 |
| static constexpr int | nSvRgmRoundWinLimitMax = 999 |
Protected Member Functions | |
| GameMode (GameModeType gm, const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers) | |
| GameMode (const GameMode &)=delete | |
| GameMode & | operator= (const GameMode &)=delete |
| GameMode (GameMode &&)=delete | |
| GameMode && | operator= (GameMode &&)=delete |
| virtual bool | serverSendGameSessionStateToClient (pge_network::PgeINetwork &network, const pge_network::PgeNetworkConnectionHandle &connHandle) |
| virtual bool | serverSendGameSessionStateToClients (pge_network::PgeINetwork &network, const proofps_dd::GameRestartType_KeepPlayers &eRestartType) |
| void | handleEventGameWon (pge_network::PgeINetwork &network) |
Protected Attributes | |
| std::chrono::time_point< std::chrono::steady_clock > | m_timeWin |
| std::list< PlayersTableRow > | m_players |
| const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & | m_mapPlayersExternal |
| bool | m_bWon { false } |
| bool | m_bWonPrevious { false } |
| GameModeType | m_gameModeType |
Private Attributes | |
| std::chrono::time_point< std::chrono::steady_clock > | m_timeReset |
| unsigned int | m_nTimeLimitSecs {} |
Static Private Attributes | |
| static std::unique_ptr< GameMode > | m_gamemode {} |
|
virtual |
Definition at line 192 of file GameMode.cpp.
|
protected |
Definition at line 450 of file GameMode.cpp.
|
protecteddelete |
|
protecteddelete |
|
pure virtual |
Adds the specified player.
In case of server instance, if the added player is a client, it SHALL immediately send game win condition to this client using serverSendGameSessionStateToClient(). In case of server instance, it SHALL automatically evaluate winning condition using serverCheckAndUpdateWinningConditions() after adding the player. Note that once a game is won, it stays won even if players are updated to fail the winning conditions, until explicit call to restart().
Note that GameMode does not ensure that a spectating player cannot win a game. The game shall ensure that the player does not gain any frags while in spectator mode! Therefore, if the added player already has enough frags to flip game won state, the game will go into won state, regardless of the player's spectating state!
Fails if a player with same name is already added.
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamDeathMatchMode, proofps_dd::TeamRoundGameMode, and SpecialGameMode.
| void proofps_dd::GameMode::clientReceiveAndUpdateWinningConditions | ( | pge_network::PgeINetwork & | network, |
| bool | bGameSessionWon ) |
Handles server's update about current game session goal, e.g.
game is won. Server sends out such notification occasionally only, when something relevant has changed about the current game session.
This function is for client instance only.
| bGameSessionWon | True if the current game session goal has been just reached, false otherwise. |
Definition at line 322 of file GameMode.cpp.
|
virtual |
Shall be invoked regularly (per tick or per frame) at the end of client tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly.
This function is for client instance only.
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 350 of file GameMode.cpp.
| void proofps_dd::GameMode::clientUpdateTimeRemainingMillisecs | ( | const unsigned int & | nRemMillisecs, |
| pge_network::PgeINetwork & | network ) |
Updates the remaining time on client side, based on the remaining time received from server.
Basically it corrects the game restart time on client side so client will have the roughly same game restart time as the server.
| nRemMillisecs | Remaining time in milliseconds, from server. |
| network | PGE network instance to be used to know if we are server or client. |
Definition at line 247 of file GameMode.cpp.
|
static |
Similar to singleton design pattern, there is always maximum one instance.
However, if there is an already existing instance, it automatically gets destroyed before the new one is created. This makes sure we always get a fresh object built up from scratch, and we can forget about the previous one. This is exactly the mechanism we need for GameMode, from the application's perspective.
| gm | Type of game to create. |
| mapPlayers | Players container, sometimes might be needed to fetch some attributes of players (e.g. HP). |
Definition at line 56 of file GameMode.cpp.
|
virtual |
Fetches configuration from the given PGEcfgProfiles instance.
Derived class shall extend this function by overriding and calling this parent implementation from the specialized implementation.
For now it does not do validation, as all validations are currently implemented in the Config class. TODO: on the long run, validation should be also done, by proper planning and implementing an IConfigHandler interface, as described in the comment above.
| cfgProfiles | The current user config profile from where we can fetch value of GameMode-specific CVARs. |
| network | PGE network instance to be used to know if we are server or client. |
Reimplemented in proofps_dd::DeathMatchMode, and proofps_dd::TeamRoundGameMode.
Definition at line 196 of file GameMode.cpp.
| CConsole & proofps_dd::GameMode::getConsole | ( | ) | const |
Definition at line 187 of file GameMode.cpp.
| const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & proofps_dd::GameMode::getExternalPlayersContainer | ( | ) | const |
Definition at line 381 of file GameMode.cpp.
|
static |
Definition at line 82 of file GameMode.cpp.
| proofps_dd::GameModeType proofps_dd::GameMode::getGameModeType | ( | ) | const |
Definition at line 203 of file GameMode.cpp.
|
static |
Definition at line 126 of file GameMode.cpp.
| const char * proofps_dd::GameMode::getGameModeTypeName | ( | ) | const |
Definition at line 208 of file GameMode.cpp.
|
static |
Definition at line 111 of file GameMode.cpp.
|
static |
Definition at line 51 of file GameMode.cpp.
| const std::list< proofps_dd::PlayersTableRow > & proofps_dd::GameMode::getPlayersTable | ( | ) | const |
Definition at line 376 of file GameMode.cpp.
|
static |
Definition at line 142 of file GameMode.cpp.
| const std::chrono::time_point< std::chrono::steady_clock > & proofps_dd::GameMode::getResetTime | ( | ) | const |
Definition at line 213 of file GameMode.cpp.
| unsigned int proofps_dd::GameMode::getSpectatorModePlayersCount | ( | ) | const |
Definition at line 428 of file GameMode.cpp.
| unsigned int proofps_dd::GameMode::getTimeLimitSecs | ( | ) | const |
Definition at line 218 of file GameMode.cpp.
| unsigned int proofps_dd::GameMode::getTimeRemainingMillisecs | ( | ) | const |
Definition at line 228 of file GameMode.cpp.
| const std::chrono::time_point< std::chrono::steady_clock > & proofps_dd::GameMode::getWinTime | ( | ) | const |
Definition at line 371 of file GameMode.cpp.
|
protected |
Definition at line 494 of file GameMode.cpp.
| bool proofps_dd::GameMode::hasJustBeenWonThisTick | ( | ) | const |
Returns if the current game session has been just detected as won in this tick i.e.
it was not yet won in the previous tick (wasGameWonAlreadyInPreviousTick() returns false) but now is won in the current tick (isGameWon() returns true).
This function is the recommended way for both server and client instances to check for and handle the change of winning state.
It is true only for a short period of time slice which can be 1 tick or 1 frame, depending on how often your game instance invokes either serverCheckAndUpdateWinningConditions() or clientTickUpdateWinningConditions().
Definition at line 366 of file GameMode.cpp.
| bool proofps_dd::GameMode::isGameWon | ( | ) | const |
Returns the current game session win state i.e.
game goal is reached or not.
Note that once a game is won, it stays won even if all players are removed, until explicit call to restart() or restartWithoutRemovingPlayers().
Definition at line 356 of file GameMode.cpp.
|
virtual |
Checks if given player is allowed for gameplay.
For example, in a team-based game mode, server can freeze player actions when no team is assigned to the player. But it also checks for spectator mode.
Can be used by both server and client instances. Must also work properly on client-side, since in player-follow spectating view, this function is used to determine which players can be spectated.
Reimplemented in proofps_dd::DeathMatchMode, proofps_dd::TeamDeathMatchMode, and SpecialGameMode.
Definition at line 418 of file GameMode.cpp.
|
virtual |
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 423 of file GameMode.cpp.
|
pure virtual |
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamRoundGameMode, and SpecialGameMode.
|
pure virtual |
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamRoundGameMode, and SpecialGameMode.
|
static |
Definition at line 100 of file GameMode.cpp.
|
pure virtual |
Derived class shall return false if it is non-team-based game, otherwise true.
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamDeathMatchMode, and SpecialGameMode.
|
static |
Definition at line 87 of file GameMode.cpp.
|
pure virtual |
Removes data for the specified player.
Fails if player with same cannot be found.
Does not evaluate winning conditions, since once a game is won, it stays won even if all players are removed, until explicit call to restart().
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamRoundGameMode, and SpecialGameMode.
| bool proofps_dd::GameMode::renamePlayer | ( | const std::string & | sOldName, |
| const std::string & | sNewName ) |
Renames the player.
All players must have unique name. The function fails if there is already a player having the same name as sNewName, or if there was no such player with name as sOldName.
| sOldName | The previous name of the player that we want to change. |
| sNewName | The new name of the player we want to change to. |
Definition at line 386 of file GameMode.cpp.
|
virtual |
Similar to restartWithoutRemovingPlayers() but it also removes all players from this GameMode instance.
Used by both server and clients. A typical situation for clients to invoke this is when they get disconnected from server.
| network | PGE network instance to be used to send out MsgGameSessionStateFromServer to clients. |
Definition at line 263 of file GameMode.cpp.
|
virtual |
Resets winning time and winning condition, also zeros out relevant members of PlayersTableRow for all players.
It is recommended to first invoke updatePlayer() for all players with zeroed values and then call this.
Used by both server and clients: clients invoke it upon receiving MsgGameSessionStateFromServer.
| network | PGE network instance to be used to send out MsgGameSessionStateFromServer to clients. |
| eRestartType | Players stats are defaulted depending on restart type. Cannot be GameRestartType_KeepPlayers::None. |
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 270 of file GameMode.cpp.
|
virtual |
Evaluates conditions to see if game is won or not.
Shall be invoked regularly (per tick or per frame) at the beginning of server tick or frame loop so hasJustBeenWonThisTick() can work properly.
This class checks elapsed game session time against time limit, if any set. Derived class shall extend this function by overriding and calling this parent implementation from the specialized implementation.
A game shall not be won without any players, so at least 1 player needs to be present to win any game. Note that once a game is won, it stays won even if all players are removed, until explicit call to restart() or restartWithoutRemovingPlayers().
This function is for server instance only. It also sends out MsgGameSessionStateFromServer to all clients in case game session state is changed as a result of the call.
| network | PGE network instance to be used to send out MsgGameSessionStateFromServer if needed. |
Reimplemented in proofps_dd::DeathMatchMode, proofps_dd::TeamDeathMatchMode, and proofps_dd::TeamRoundGameMode.
Definition at line 299 of file GameMode.cpp.
|
protectedvirtual |
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 458 of file GameMode.cpp.
|
protectedvirtual |
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 476 of file GameMode.cpp.
|
virtual |
Shall be invoked regularly (per tick or per frame) at the end of server tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly.
This function is for server instance only.
Reimplemented in proofps_dd::TeamRoundGameMode.
Definition at line 344 of file GameMode.cpp.
| void proofps_dd::GameMode::setTimeLimitSecs | ( | unsigned int | secs | ) |
Set the time limit for the game.
If time limit expires, the winner is the player with most frags, even if frag limit is not set or not reached. Note: behavior is unspecified if this value is changed on-the-fly during a game. For now, please also call restart() explicitly.
| secs | The time limit in seconds. If 0, there is no time limit. |
Definition at line 223 of file GameMode.cpp.
| void proofps_dd::GameMode::text | ( | PR00FsUltimateRenderingEngine & | pure, |
| const std::string & | s, | ||
| int | x, | ||
| int | y ) const |
Definition at line 441 of file GameMode.cpp.
|
pure virtual |
Updates data for the specified player.
In case of server instance, it SHALL automatically evaluate winning condition using serverCheckAndUpdateWinningConditions() after updating the player. Note that once a game is won, it stays won even if players are updated to fail the winning conditions, until explicit call to restart().
Note that GameMode does not ensure that a spectating player cannot win a game. The game shall ensure that the player does not gain any frags while in spectator mode! Therefore, if the added player already has enough frags to flip game won state, the game will go into won state, regardless of the player's spectating state!
Fails if player with same cannot be found.
Implemented in proofps_dd::DeathMatchMode, proofps_dd::TeamDeathMatchMode, and SpecialGameMode.
| bool proofps_dd::GameMode::wasGameWonAlreadyInPreviousTick | ( | ) | const |
Returns if the current game session was already won in the previous tick.
The idea is the following:
Definition at line 361 of file GameMode.cpp.
|
protected |
Definition at line 438 of file GameMode.h.
|
protected |
Definition at line 439 of file GameMode.h.
|
staticprivate |
Definition at line 506 of file GameMode.h.
|
protected |
Definition at line 440 of file GameMode.h.
|
protected |
Definition at line 437 of file GameMode.h.
|
private |
Definition at line 462 of file GameMode.h.
|
protected |
Definition at line 436 of file GameMode.h.
|
private |
Definition at line 461 of file GameMode.h.
|
protected |
Definition at line 435 of file GameMode.h.
|
staticconstexpr |
Definition at line 110 of file GameMode.h.
|
staticconstexpr |
Definition at line 112 of file GameMode.h.
|
staticconstexpr |
Definition at line 111 of file GameMode.h.
|
staticconstexpr |
Definition at line 103 of file GameMode.h.
|
staticconstexpr |
Definition at line 105 of file GameMode.h.
|
staticconstexpr |
Definition at line 104 of file GameMode.h.
|
staticconstexpr |
Definition at line 117 of file GameMode.h.
|
staticconstexpr |
Definition at line 119 of file GameMode.h.
|
staticconstexpr |
Definition at line 118 of file GameMode.h.
|
staticconstexpr |
Definition at line 100 of file GameMode.h.
|
staticconstexpr |
Definition at line 96 of file GameMode.h.
|
staticconstexpr |
Definition at line 98 of file GameMode.h.
|
staticconstexpr |
Definition at line 101 of file GameMode.h.