Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
CGame Class Reference

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

#include <Game.h>

Public Member Functions

 CGame (bool disableGraphics=false)
 Constructor. More...
 
 ~CGame ()
 Destructor. More...
 
void StartGame (const CScriptValRooted &attribs, const std::string &savedState)
 
PSRETURN ReallyStartGame ()
 Game initialization has been completed. More...
 
bool Update (const double deltaRealTime, bool doInterpolate=true)
 Periodic heartbeat that controls the process. More...
 
void Interpolate (float simFrameLength, float realFrameLength)
 
int GetPlayerID ()
 
void SetPlayerID (int playerID)
 
void CachePlayerColours ()
 Retrieving player colours from scripts is slow, so this updates an internal cache of all players' colours. More...
 
CColor GetPlayerColour (int player) const
 
bool IsGameStarted () const
 Get m_GameStarted. 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 ()
 
void SetTurnManager (CNetTurnManager *turnManager)
 Replace the current turn manager. More...
 
CNetTurnManagerGetTurnManager () 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 CScriptValRooted &attribs, const std::string &savedState)
 Initializes the game with the set of attributes provided. More...
 
int LoadInitialState ()
 

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...
 
int m_PlayerID
 
CNetTurnManagerm_TurnManager
 
IReplayLoggerm_ReplayLogger
 
std::vector< CColorm_PlayerColours
 
std::string m_InitialSavedState
 
bool m_IsSavedGame
 

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.

Definition at line 39 of file Game.h.

Constructor & Destructor Documentation

CGame::CGame ( bool  disableGraphics = false)

Constructor.

Definition at line 62 of file Game.cpp.

CGame::~CGame ( )

Destructor.

Definition at line 89 of file Game.cpp.

Member Function Documentation

void CGame::CachePlayerColours ( )

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

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

Definition at line 332 of file Game.cpp.

CColor CGame::GetPlayerColour ( int  player) const

Definition at line 354 of file Game.cpp.

int CGame::GetPlayerID ( )

Definition at line 249 of file Game.cpp.

IReplayLogger& CGame::GetReplayLogger ( ) const
inline

Definition at line 162 of file Game.h.

float CGame::GetSimRate ( )
inline

Definition at line 150 of file Game.h.

CSimulation2* CGame::GetSimulation2 ( )
inline

Get the pointer to the simulation2 object.

Returns
CSimulation2 * the value of m_Simulation2.

Definition at line 136 of file Game.h.

CNetTurnManager* CGame::GetTurnManager ( ) const
inline

Definition at line 159 of file Game.h.

CGameView* CGame::GetView ( )
inline

Get the pointer to the game view object.

Returns
CGameView * the value of m_GameView.

Definition at line 128 of file Game.h.

CWorld* CGame::GetWorld ( )
inline

Get the pointer to the game world object.

Returns
CWorld * the value of m_World.

Definition at line 120 of file Game.h.

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

Definition at line 321 of file Game.cpp.

bool CGame::IsGameStarted ( ) const
inline

Get m_GameStarted.

Returns
bool the value of m_GameStarted.

Definition at line 110 of file Game.h.

int CGame::LoadInitialState ( )
private

Definition at line 173 of file Game.cpp.

CGame::NONCOPYABLE ( CGame  )
private
PSRETURN CGame::ReallyStartGame ( )

Game initialization has been completed.

Set game started flag and start the session.

Returns
PSRETURN 0

Definition at line 198 of file Game.cpp.

void CGame::RegisterInit ( const CScriptValRooted 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.

Definition at line 119 of file Game.cpp.

void CGame::SetPlayerID ( int  playerID)

Definition at line 254 of file Game.cpp.

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.

Definition at line 147 of file Game.h.

void CGame::SetTurnManager ( CNetTurnManager turnManager)

Replace the current turn manager.

This class will take ownership of the pointer.

Definition at line 102 of file Game.cpp.

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

Definition at line 261 of file Game.cpp.

bool 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.

Definition at line 272 of file Game.cpp.

Member Data Documentation

bool CGame::m_GameStarted
private

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

Definition at line 57 of file Game.h.

CGameView* CGame::m_GameView
private

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

Definition at line 53 of file Game.h.

std::string CGame::m_InitialSavedState
private

Definition at line 172 of file Game.h.

bool CGame::m_IsSavedGame
private

Definition at line 173 of file Game.h.

bool CGame::m_Paused

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

Definition at line 74 of file Game.h.

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

Definition at line 169 of file Game.h.

int CGame::m_PlayerID
private

Definition at line 63 of file Game.h.

IReplayLogger* CGame::m_ReplayLogger
private

Definition at line 167 of file Game.h.

float CGame::m_SimRate
private

Timescale multiplier for simulation rate.

Definition at line 61 of file Game.h.

CSimulation2* CGame::m_Simulation2
private

pointer to the CSimulation2 object operating on the game world.

Definition at line 49 of file Game.h.

CNetTurnManager* CGame::m_TurnManager
private

Definition at line 65 of file Game.h.

CWorld* CGame::m_World
private

pointer to the CWorld object representing the game world.

Definition at line 45 of file Game.h.


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