Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CGame Class Reference

The container that holds the rules, resources and attributes of the game. More...

#include <Game.h>

Collaboration diagram for CGame:

Public Member Functions

 CGame (bool replayLog)
 Constructor. More...
 
 ~CGame ()
 Destructor. More...
 
void StartGame (JS::MutableHandleValue attribs, const std::string &savedState)
 
PSRETURN ReallyStartGame ()
 Game initialization has been completed. More...
 
bool StartVisualReplay (const OsPath &replayPath)
 
void Update (const double deltaRealTime, bool doInterpolate=true)
 Periodic heartbeat that controls the process. More...
 
void Interpolate (float simFrameLength, float realFrameLength)
 
int GetPlayerID ()
 
void SetPlayerID (player_id_t playerID)
 
int GetViewedPlayerID ()
 
void SetViewedPlayerID (player_id_t playerID)
 
bool IsGameFinished () const
 Check if the game is finished by testing if there's a winner. More...
 
void CachePlayerColors ()
 Retrieving player colors from scripts is slow, so this updates an internal cache of all players' colors. More...
 
const CColorGetPlayerColor (player_id_t player) const
 
bool IsGameStarted () const
 Get m_GameStarted. More...
 
bool IsVisualReplay () const
 Get m_IsVisualReplay. More...
 
CWorldGetWorld ()
 Get the pointer to the game world object. More...
 
CGameViewGetView ()
 Get the pointer to the game view object. More...
 
CSimulation2GetSimulation2 ()
 Get the pointer to the simulation2 object. More...
 
void SetSimRate (float simRate)
 Set the simulation scale multiplier. More...
 
float GetSimRate () const
 
OsPath GetReplayPath () const
 
void SetTurnManager (CTurnManager *turnManager)
 Replace the current turn manager. More...
 
CTurnManagerGetTurnManager () const
 
IReplayLoggerGetReplayLogger () const
 

Public Attributes

bool m_Paused
 the game is paused and no updates will be performed if true. More...
 

Private Member Functions

 NONCOPYABLE (CGame)
 
void RegisterInit (const JS::HandleValue attribs, const std::string &savedState)
 Initializes the game with the set of attributes provided. More...
 
int LoadInitialState (const std::string &savedState)
 
int LoadVisualReplayData ()
 

Private Attributes

CWorldm_World
 pointer to the CWorld object representing the game world. More...
 
CSimulation2m_Simulation2
 pointer to the CSimulation2 object operating on the game world. More...
 
CGameViewm_GameView
 pointer to the CGameView object representing the view into the game world. More...
 
bool m_GameStarted
 the game has been initialized and ready for use if true. More...
 
float m_SimRate
 Timescale multiplier for simulation rate. More...
 
player_id_t m_PlayerID
 Index assigned to the current player. More...
 
player_id_t m_ViewedPlayerID
 Differs from m_PlayerID if a defeated player or observer views another player. More...
 
CTurnManagerm_TurnManager
 
IReplayLoggerm_ReplayLogger
 
std::vector< CColorm_PlayerColors
 
bool m_IsSavedGame
 
OsPath m_ReplayPath
 
bool m_IsVisualReplay
 
std::istream * m_ReplayStream
 
u32 m_FinalReplayTurn
 

Static Private Attributes

static const CStr EventNameSimulationUpdate = "SimulationUpdate"
 

Detailed Description

The container that holds the rules, resources and attributes of the game.

The CGame object is responsible for creating a game that is defined by a set of attributes provided. The CGame object is also responsible for maintaining the relations between CPlayer and CWorld, CSimulation and CWorld.

Constructor & Destructor Documentation

◆ CGame()

CGame::CGame ( bool  replayLog)

Constructor.

◆ ~CGame()

CGame::~CGame ( )

Destructor.

Member Function Documentation

◆ CachePlayerColors()

void CGame::CachePlayerColors ( )

Retrieving player colors from scripts is slow, so this updates an internal cache of all players' colors.

Call this just before rendering, so it will always have the latest colors.

◆ GetPlayerColor()

const CColor & CGame::GetPlayerColor ( player_id_t  player) const

◆ GetPlayerID()

int CGame::GetPlayerID ( )

◆ GetReplayLogger()

IReplayLogger & CGame::GetReplayLogger ( ) const
inline

◆ GetReplayPath()

OsPath CGame::GetReplayPath ( ) const
inline

◆ GetSimRate()

float CGame::GetSimRate ( ) const
inline

◆ GetSimulation2()

CSimulation2 * CGame::GetSimulation2 ( )
inline

Get the pointer to the simulation2 object.

Returns
CSimulation2 * the value of m_Simulation2.

◆ GetTurnManager()

CTurnManager * CGame::GetTurnManager ( ) const
inline

◆ GetView()

CGameView * CGame::GetView ( )
inline

Get the pointer to the game view object.

Returns
CGameView * the value of m_GameView.

◆ GetViewedPlayerID()

int CGame::GetViewedPlayerID ( )

◆ GetWorld()

CWorld * CGame::GetWorld ( )
inline

Get the pointer to the game world object.

Returns
CWorld * the value of m_World.

◆ Interpolate()

void CGame::Interpolate ( float  simFrameLength,
float  realFrameLength 
)

◆ IsGameFinished()

bool CGame::IsGameFinished ( ) const

Check if the game is finished by testing if there's a winner.

It is used to end a non visual autostarted game.

Returns
true if there's a winner, false otherwise.

◆ IsGameStarted()

bool CGame::IsGameStarted ( ) const
inline

Get m_GameStarted.

Returns
bool the value of m_GameStarted.

◆ IsVisualReplay()

bool CGame::IsVisualReplay ( ) const
inline

Get m_IsVisualReplay.

Returns
bool the value of m_IsVisualReplay.

◆ LoadInitialState()

int CGame::LoadInitialState ( const std::string &  savedState)
private

◆ LoadVisualReplayData()

int CGame::LoadVisualReplayData ( )
private

◆ NONCOPYABLE()

CGame::NONCOPYABLE ( CGame  )
private

◆ ReallyStartGame()

PSRETURN CGame::ReallyStartGame ( )

Game initialization has been completed.

Set game started flag and start the session.

Returns
PSRETURN 0

◆ RegisterInit()

void CGame::RegisterInit ( const JS::HandleValue  attribs,
const std::string &  savedState 
)
private

Initializes the game with the set of attributes provided.

Makes calls to initialize the game view, world, and simulation objects. Calls are made to facilitate progress reporting of the initialization.

◆ SetPlayerID()

void CGame::SetPlayerID ( player_id_t  playerID)

◆ SetSimRate()

void CGame::SetSimRate ( float  simRate)
inline

Set the simulation scale multiplier.

Parameters
simRateFloat value to set m_SimRate to. Because m_SimRate is also used to scale TimeSinceLastFrame it must be clamped to 0.0f.

◆ SetTurnManager()

void CGame::SetTurnManager ( CTurnManager turnManager)

Replace the current turn manager.

This class will take ownership of the pointer.

◆ SetViewedPlayerID()

void CGame::SetViewedPlayerID ( player_id_t  playerID)

◆ StartGame()

void CGame::StartGame ( JS::MutableHandleValue  attribs,
const std::string &  savedState 
)

◆ StartVisualReplay()

bool CGame::StartVisualReplay ( const OsPath replayPath)

◆ Update()

void CGame::Update ( const double  deltaRealTime,
bool  doInterpolate = true 
)

Periodic heartbeat that controls the process.

performs all per-frame updates. Simulation update is called and game status update is called.

Parameters
deltaRealTimeElapsed real time since last beat/frame, in seconds.
doInterpolatePerform graphics interpolation if true.
Returns
bool false if it can't keep up with the desired simulation rate indicating that you might want to render less frequently.

Member Data Documentation

◆ EventNameSimulationUpdate

const CStr CGame::EventNameSimulationUpdate = "SimulationUpdate"
staticprivate

◆ m_FinalReplayTurn

u32 CGame::m_FinalReplayTurn
private

◆ m_GameStarted

bool CGame::m_GameStarted
private

the game has been initialized and ready for use if true.

◆ m_GameView

CGameView* CGame::m_GameView
private

pointer to the CGameView object representing the view into the game world.

◆ m_IsSavedGame

bool CGame::m_IsSavedGame
private

◆ m_IsVisualReplay

bool CGame::m_IsVisualReplay
private

◆ m_Paused

bool CGame::m_Paused

the game is paused and no updates will be performed if true.

◆ m_PlayerColors

std::vector<CColor> CGame::m_PlayerColors
private

◆ m_PlayerID

player_id_t CGame::m_PlayerID
private

Index assigned to the current player.

1-8 to control players, 0 for gaia, -1 for observer.

◆ m_ReplayLogger

IReplayLogger* CGame::m_ReplayLogger
private

◆ m_ReplayPath

OsPath CGame::m_ReplayPath
private

◆ m_ReplayStream

std::istream* CGame::m_ReplayStream
private

◆ m_SimRate

float CGame::m_SimRate
private

Timescale multiplier for simulation rate.

◆ m_Simulation2

CSimulation2* CGame::m_Simulation2
private

pointer to the CSimulation2 object operating on the game world.

◆ m_TurnManager

CTurnManager* CGame::m_TurnManager
private

◆ m_ViewedPlayerID

player_id_t CGame::m_ViewedPlayerID
private

Differs from m_PlayerID if a defeated player or observer views another player.

◆ m_World

CWorld* CGame::m_World
private

pointer to the CWorld object representing the game world.


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