PRooFPS-dd Dev Doc 1.0
PRooFPS-dd Developer Documentation
Loading...
Searching...
No Matches
proofps_dd::GameMode Class Referenceabstract

GameMode class represent the Frag Table and the winning condition checks. More...

Detailed Description

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. 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 56 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)=0
 Fetches configuration from the given PGEcfgProfiles instance.
 
GameModeType getGameModeType () const
 
const std::chrono::time_point< std::chrono::steady_clock > & getResetTime () const
 
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)
 Resets winning time and winning condition, also zeros out relevant members of FragTableRow for all players.
 
virtual bool serverCheckAndUpdateWinningConditions (pge_network::PgeINetwork &network)=0
 Evaluates conditions to see if game is won or not.
 
virtual void clientReceiveAndUpdateWinningConditions (pge_network::PgeINetwork &network, bool bGameSessionWon)=0
 Handles server's update about current game session goal, e.g.
 
bool isGameWon () const
 Returns the current game session win state i.e.
 
const std::chrono::time_point< std::chrono::steady_clock > & getWinTime () const
 
const std::list< FragTableRow > & getFragTable () 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)=0
 Removes data for the specified player.
 
bool renamePlayer (const std::string &sOldName, const std::string &sNewName)
 Renames the player.
 
void text (PR00FsUltimateRenderingEngine &pure, const std::string &s, int x, int y) const
 

Static Public Member Functions

static const char * getLoggerModuleName ()
 
static GameModecreateGameMode (GameModeType gm)
 

Static Public Attributes

static constexpr char * szCvarSvDmFragLimit = "sv_dm_fraglimit"
 
static constexpr char * szCvarSvDmTimeLimit = "sv_dm_timelimit_secs"
 
static constexpr int nSvDmFragLimitDef = 10
 
static constexpr int nSvDmFragLimitMin = 0
 
static constexpr int nSvDmFragLimitMax = 999
 
static constexpr int nSvDmTimeLimitSecsDef = 0
 
static constexpr int nSvDmTimeLimitSecsMin = 0
 
static constexpr int nSvDmTimeLimitSecsMax = 60 * 60 * 24
 

Protected Member Functions

 GameMode (GameModeType gm)
 
 GameMode (const GameMode &)=delete
 
GameModeoperator= (const GameMode &)=delete
 
 GameMode (GameMode &&)=delete
 
GameMode && operator= (GameMode &&)=delete
 
bool serverSendGameSessionStateToClient (pge_network::PgeINetwork &network, const pge_network::PgeNetworkConnectionHandle &connHandle)
 
bool serverSendGameSessionStateToClients (pge_network::PgeINetwork &network)
 

Protected Attributes

std::chrono::time_point< std::chrono::steady_clock > m_timeWin
 
std::list< FragTableRowm_players
 
bool m_bWon { false }
 
std::chrono::time_point< std::chrono::steady_clock > m_timeReset
 

Private Attributes

GameModeType m_gameModeType
 

Constructor & Destructor Documentation

◆ ~GameMode()

proofps_dd::GameMode::~GameMode ( )
virtual

Definition at line 46 of file GameMode.cpp.

◆ GameMode() [1/3]

proofps_dd::GameMode::GameMode ( proofps_dd::GameModeType gm)
protected

Definition at line 141 of file GameMode.cpp.

◆ GameMode() [2/3]

proofps_dd::GameMode::GameMode ( const GameMode & )
protecteddelete

◆ GameMode() [3/3]

proofps_dd::GameMode::GameMode ( GameMode && )
protecteddelete

Member Function Documentation

◆ addPlayer()

virtual bool proofps_dd::GameMode::addPlayer ( const Player & player,
pge_network::PgeINetwork & network )
pure virtual

Adds the specified player.

In case of server instance, it automatically evaluates winning condition, and in case of winning it also updates winning time and sends out MsgGameSessionStateFromServer to all clients. 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().

Fails if a player with same name is already added.

Returns
True if added the new player, false otherwise.

Implemented in proofps_dd::DeathMatchMode.

◆ clientReceiveAndUpdateWinningConditions()

virtual void proofps_dd::GameMode::clientReceiveAndUpdateWinningConditions ( pge_network::PgeINetwork & network,
bool bGameSessionWon )
pure virtual

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.

Parameters
bGameSessionWonTrue if the current game session goal has been just reached, false otherwise.

Implemented in proofps_dd::DeathMatchMode.

◆ createGameMode()

proofps_dd::GameMode * proofps_dd::GameMode::createGameMode ( proofps_dd::GameModeType gm)
static

Definition at line 30 of file GameMode.cpp.

◆ fetchConfig()

virtual void proofps_dd::GameMode::fetchConfig ( PGEcfgProfiles & cfgProfiles,
pge_network::PgeINetwork & network )
pure virtual

Fetches configuration from the given PGEcfgProfiles instance.

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.

Parameters
cfgProfilesThe current user config profile from where we can fetch value of GameMode-specific CVARs.
networkPGE network instance to be used to know if we are server or client.

Implemented in proofps_dd::DeathMatchMode.

◆ getConsole()

CConsole & proofps_dd::GameMode::getConsole ( ) const

Definition at line 41 of file GameMode.cpp.

◆ getFragTable()

const std::list< proofps_dd::FragTableRow > & proofps_dd::GameMode::getFragTable ( ) const
Returns
List of frag table entries, which is basically a list of added players with some statistics.

Definition at line 95 of file GameMode.cpp.

◆ getGameModeType()

proofps_dd::GameModeType proofps_dd::GameMode::getGameModeType ( ) const

Definition at line 50 of file GameMode.cpp.

◆ getLoggerModuleName()

const char * proofps_dd::GameMode::getLoggerModuleName ( )
static

Definition at line 25 of file GameMode.cpp.

◆ getResetTime()

const std::chrono::time_point< std::chrono::steady_clock > & proofps_dd::GameMode::getResetTime ( ) const

Definition at line 55 of file GameMode.cpp.

◆ getWinTime()

const std::chrono::time_point< std::chrono::steady_clock > & proofps_dd::GameMode::getWinTime ( ) const
Returns
Timestamp of moment when current game was won by a player. It is Epoch time 0 if the game is not yet won.

Definition at line 90 of file GameMode.cpp.

◆ isGameWon()

bool proofps_dd::GameMode::isGameWon ( ) const

Returns the current game session win state i.e.

game goal is reached or not.

Returns
True if current game session is won (goal reached), false otherwise.

Definition at line 85 of file GameMode.cpp.

◆ operator=() [1/2]

GameMode & proofps_dd::GameMode::operator= ( const GameMode & )
protecteddelete

◆ operator=() [2/2]

GameMode && proofps_dd::GameMode::operator= ( GameMode && )
protecteddelete

◆ removePlayer()

virtual bool proofps_dd::GameMode::removePlayer ( const Player & player)
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().

Returns
True if removed the existing player, false otherwise.

Implemented in proofps_dd::DeathMatchMode.

◆ renamePlayer()

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.

Parameters
sOldNameThe previous name of the player that we want to change.
sNewNameThe new name of the player we want to change to.
Returns
True if rename was successful, false otherwise.

Definition at line 100 of file GameMode.cpp.

◆ restart()

void proofps_dd::GameMode::restart ( pge_network::PgeINetwork & network)
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.

Parameters
networkPGE network instance to be used to send out MsgGameSessionStateFromServer to clients.

Definition at line 60 of file GameMode.cpp.

◆ restartWithoutRemovingPlayers()

void proofps_dd::GameMode::restartWithoutRemovingPlayers ( pge_network::PgeINetwork & network)
virtual

Resets winning time and winning condition, also zeros out relevant members of FragTableRow 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.

Parameters
networkPGE network instance to be used to send out MsgGameSessionStateFromServer to clients.

Definition at line 67 of file GameMode.cpp.

◆ serverCheckAndUpdateWinningConditions()

virtual bool proofps_dd::GameMode::serverCheckAndUpdateWinningConditions ( pge_network::PgeINetwork & network)
pure virtual

Evaluates conditions to see if game is won or not.

Since conditions depend on game mode, the actual implementation must be in the specific derived game mode class. Note that once a game is won, it stays won even if all players are removed, until explicit call to restart().

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.

Parameters
networkPGE network instance to be used to send out MsgGameSessionStateFromServer if needed.
Returns
True if game is won, false otherwise.

Implemented in proofps_dd::DeathMatchMode.

◆ serverSendGameSessionStateToClient()

bool proofps_dd::GameMode::serverSendGameSessionStateToClient ( pge_network::PgeINetwork & network,
const pge_network::PgeNetworkConnectionHandle & connHandle )
protected

Definition at line 146 of file GameMode.cpp.

◆ serverSendGameSessionStateToClients()

bool proofps_dd::GameMode::serverSendGameSessionStateToClients ( pge_network::PgeINetwork & network)
protected

Definition at line 163 of file GameMode.cpp.

◆ text()

void proofps_dd::GameMode::text ( PR00FsUltimateRenderingEngine & pure,
const std::string & s,
int x,
int y ) const

Definition at line 132 of file GameMode.cpp.

◆ updatePlayer()

virtual bool proofps_dd::GameMode::updatePlayer ( const Player & player,
pge_network::PgeINetwork & network )
pure virtual

Updates data for the specified player.

In case of server instance, it automatically evaluates winning condition, and in case of winning it also updates winning time and sends out MsgGameSessionStateFromServer to all clients. 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().

Fails if player with same cannot be found.

Returns
True if updated the existing player, false otherwise.

Implemented in proofps_dd::DeathMatchMode.

Member Data Documentation

◆ m_bWon

bool proofps_dd::GameMode::m_bWon { false }
protected

Definition at line 216 of file GameMode.h.

◆ m_gameModeType

GameModeType proofps_dd::GameMode::m_gameModeType
private

Definition at line 231 of file GameMode.h.

◆ m_players

std::list<FragTableRow> proofps_dd::GameMode::m_players
protected

Definition at line 215 of file GameMode.h.

◆ m_timeReset

std::chrono::time_point<std::chrono::steady_clock> proofps_dd::GameMode::m_timeReset
protected

Definition at line 217 of file GameMode.h.

◆ m_timeWin

std::chrono::time_point<std::chrono::steady_clock> proofps_dd::GameMode::m_timeWin
protected

Definition at line 214 of file GameMode.h.

◆ nSvDmFragLimitDef

int proofps_dd::GameMode::nSvDmFragLimitDef = 10
staticconstexpr

Definition at line 63 of file GameMode.h.

◆ nSvDmFragLimitMax

int proofps_dd::GameMode::nSvDmFragLimitMax = 999
staticconstexpr

Definition at line 65 of file GameMode.h.

◆ nSvDmFragLimitMin

int proofps_dd::GameMode::nSvDmFragLimitMin = 0
staticconstexpr

Definition at line 64 of file GameMode.h.

◆ nSvDmTimeLimitSecsDef

int proofps_dd::GameMode::nSvDmTimeLimitSecsDef = 0
staticconstexpr

Definition at line 70 of file GameMode.h.

◆ nSvDmTimeLimitSecsMax

int proofps_dd::GameMode::nSvDmTimeLimitSecsMax = 60 * 60 * 24
staticconstexpr

Definition at line 72 of file GameMode.h.

◆ nSvDmTimeLimitSecsMin

int proofps_dd::GameMode::nSvDmTimeLimitSecsMin = 0
staticconstexpr

Definition at line 71 of file GameMode.h.

◆ szCvarSvDmFragLimit

char* proofps_dd::GameMode::szCvarSvDmFragLimit = "sv_dm_fraglimit"
staticconstexpr

Definition at line 60 of file GameMode.h.

◆ szCvarSvDmTimeLimit

char* proofps_dd::GameMode::szCvarSvDmTimeLimit = "sv_dm_timelimit_secs"
staticconstexpr

Definition at line 61 of file GameMode.h.


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