Pyrogenesis  trunk
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>

Collaboration diagram for CGame:
Collaboration graph
[legend]

Public Member Functions

 CGame (bool disableGraphics=false, bool replayLog=true)
 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 std::string &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)
 
void CachePlayerColors ()
 Retrieving player colors from scripts is slow, so this updates an internal cache of all players' colors. More...
 
CColor GetPlayerColor (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
 
std::string 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 ()
 
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
 
std::string m_InitialSavedState
 
bool m_IsSavedGame
 
std::string m_ReplayPath
 
bool m_IsVisualReplay
 
std::istream * m_ReplayStream
 
u32 m_FinalReplayTurn
 

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 ( bool  disableGraphics = false,
bool  replayLog = true 
)

Constructor.

CGame::~CGame ( )

Destructor.

Member Function Documentation

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.

CColor CGame::GetPlayerColor ( player_id_t  player) const
int CGame::GetPlayerID ( )
IReplayLogger& CGame::GetReplayLogger ( ) const
inline
std::string CGame::GetReplayPath ( ) const
inline
float CGame::GetSimRate ( ) const
inline
CSimulation2* CGame::GetSimulation2 ( )
inline

Get the pointer to the simulation2 object.

Returns
CSimulation2 * the value of m_Simulation2.
CTurnManager* CGame::GetTurnManager ( ) const
inline
CGameView* CGame::GetView ( )
inline

Get the pointer to the game view object.

Returns
CGameView * the value of m_GameView.
int CGame::GetViewedPlayerID ( )
CWorld* CGame::GetWorld ( )
inline

Get the pointer to the game world object.

Returns
CWorld * the value of m_World.
void CGame::Interpolate ( float  simFrameLength,
float  realFrameLength 
)
bool CGame::IsGameStarted ( ) const
inline

Get m_GameStarted.

Returns
bool the value of m_GameStarted.
bool CGame::IsVisualReplay ( ) const
inline

Get m_IsVisualReplay.

Returns
bool the value of m_IsVisualReplay.
int CGame::LoadInitialState ( )
private
int CGame::LoadVisualReplayData ( )
private
CGame::NONCOPYABLE ( CGame  )
private
PSRETURN CGame::ReallyStartGame ( )

Game initialization has been completed.

Set game started flag and start the session.

Returns
PSRETURN 0
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.

void CGame::SetPlayerID ( player_id_t  playerID)
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.
void CGame::SetTurnManager ( CTurnManager turnManager)

Replace the current turn manager.

This class will take ownership of the pointer.

void CGame::SetViewedPlayerID ( player_id_t  playerID)
void CGame::StartGame ( JS::MutableHandleValue  attribs,
const std::string &  savedState 
)
bool CGame::StartVisualReplay ( const std::string &  replayPath)
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

u32 CGame::m_FinalReplayTurn
private
bool CGame::m_GameStarted
private

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

CGameView* CGame::m_GameView
private

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

std::string CGame::m_InitialSavedState
private
bool CGame::m_IsSavedGame
private
bool CGame::m_IsVisualReplay
private
bool CGame::m_Paused

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

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

Index assigned to the current player.

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

IReplayLogger* CGame::m_ReplayLogger
private
std::string CGame::m_ReplayPath
private
std::istream* CGame::m_ReplayStream
private
float CGame::m_SimRate
private

Timescale multiplier for simulation rate.

CSimulation2* CGame::m_Simulation2
private

pointer to the CSimulation2 object operating on the game world.

CTurnManager* CGame::m_TurnManager
private
player_id_t CGame::m_ViewedPlayerID
private

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

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: