Pyrogenesis  trunk
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CTurnManager Class Referenceabstract

Common turn system (used by clients and offline games). More...

#include <TurnManager.h>

Inheritance diagram for CTurnManager:
Inheritance graph
[legend]
Collaboration diagram for CTurnManager:
Collaboration graph
[legend]

Public Member Functions

 CTurnManager (CSimulation2 &simulation, u32 defaultTurnLength, u32 commandDelay, int clientId, IReplayLogger &replay)
 Construct for a given network session ID. More...
 
virtual ~CTurnManager ()
 
void ResetState (u32 newCurrentTurn, u32 newReadyTurn)
 
void SetPlayerID (int playerId)
 Set the current user's player ID, which will be added into command messages. More...
 
bool Update (float simFrameLength, size_t maxTurns)
 Advance the simulation by a certain time. More...
 
bool UpdateFastForward ()
 Advance the simulation by as much as possible. More...
 
void Interpolate (float simFrameLength, float realFrameLength)
 Advance the graphics by a certain time. More...
 
virtual void OnSimulationMessage (CSimulationMessage *msg)=0
 Called by networking code when a simulation message is received. More...
 
virtual void PostCommand (JS::HandleValue data)=0
 Called by simulation code, to add a new command to be distributed to all clients and executed soon. More...
 
void FinishedAllCommands (u32 turn, u32 turnLength)
 Called when all commands for a given turn have been received. More...
 
void EnableTimeWarpRecording (size_t numTurns)
 Enables the recording of state snapshots every numTurns, which can be jumped back to via RewindTimeWarp(). More...
 
void RewindTimeWarp ()
 Jumps back to the latest recorded state snapshot (if any). More...
 
void QuickSave (JS::HandleValue GUIMetadata)
 
void QuickLoad ()
 
u32 GetCurrentTurn () const
 
u32 GetPendingTurns () const
 

Protected Member Functions

void AddCommand (int client, int player, JS::HandleValue data, u32 turn)
 Store a command to be executed at a given turn. More...
 
virtual void NotifyFinishedOwnCommands (u32 turn)=0
 Called when this client has finished sending all its commands scheduled for the given turn. More...
 
virtual void NotifyFinishedUpdate (u32 turn)=0
 Called when this client has finished a simulation update. More...
 
bool TurnNeedsFullHash (u32 turn) const
 Returns whether we should compute a complete state hash for the given turn, instead of a quick less-complete hash. More...
 

Protected Attributes

CSimulation2m_Simulation2
 
u32 m_CurrentTurn
 The turn that we have most recently executed. More...
 
u32 m_CommandDelay
 
u32 m_ReadyTurn
 The latest turn for which we have received all commands from all clients. More...
 
u32 m_TurnLength
 
std::deque< std::map< u32, std::vector< SimulationCommand > > > m_QueuedCommands
 Commands queued at each turn (index 0 is for m_CurrentTurn+1) More...
 
int m_PlayerId
 
uint m_ClientId
 
float m_DeltaSimTime
 Simulation time remaining until we ought to execute the next turn (as a negative value to add elapsed time increments to until we reach 0). More...
 
IReplayLoggerm_Replay
 
u32 m_FinalTurn
 

Private Member Functions

 NONCOPYABLE (CTurnManager)
 

Private Attributes

size_t m_TimeWarpNumTurns
 
std::list< std::string > m_TimeWarpStates
 
std::string m_QuickSaveState
 
JS::PersistentRootedValue m_QuickSaveMetadata
 

Static Private Attributes

static const CStr EventNameSavegameLoaded = "SavegameLoaded"
 

Detailed Description

Common turn system (used by clients and offline games).

Constructor & Destructor Documentation

◆ CTurnManager()

CTurnManager::CTurnManager ( CSimulation2 simulation,
u32  defaultTurnLength,
u32  commandDelay,
int  clientId,
IReplayLogger replay 
)

Construct for a given network session ID.

◆ ~CTurnManager()

virtual CTurnManager::~CTurnManager ( )
inlinevirtual

Member Function Documentation

◆ AddCommand()

void CTurnManager::AddCommand ( int  client,
int  player,
JS::HandleValue  data,
u32  turn 
)
protected

Store a command to be executed at a given turn.

◆ EnableTimeWarpRecording()

void CTurnManager::EnableTimeWarpRecording ( size_t  numTurns)

Enables the recording of state snapshots every numTurns, which can be jumped back to via RewindTimeWarp().

If numTurns is 0 then recording is disabled.

◆ FinishedAllCommands()

void CTurnManager::FinishedAllCommands ( u32  turn,
u32  turnLength 
)

Called when all commands for a given turn have been received.

This allows Update to progress to that turn.

◆ GetCurrentTurn()

u32 CTurnManager::GetCurrentTurn ( ) const
inline

◆ GetPendingTurns()

u32 CTurnManager::GetPendingTurns ( ) const
inline
Returns
how many turns are ready to be computed. (used to detect players/observers that fall behind the live game.

◆ Interpolate()

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

Advance the graphics by a certain time.

Parameters
simFrameLengthLength of the previous frame, in simulation seconds
realFrameLengthLength of the previous frame, in real time seconds

◆ NONCOPYABLE()

CTurnManager::NONCOPYABLE ( CTurnManager  )
private

◆ NotifyFinishedOwnCommands()

virtual void CTurnManager::NotifyFinishedOwnCommands ( u32  turn)
protectedpure virtual

Called when this client has finished sending all its commands scheduled for the given turn.

Implemented in CNetClientTurnManager, and CLocalTurnManager.

◆ NotifyFinishedUpdate()

virtual void CTurnManager::NotifyFinishedUpdate ( u32  turn)
protectedpure virtual

Called when this client has finished a simulation update.

Implemented in CNetClientTurnManager, CReplayTurnManager, and CLocalTurnManager.

◆ OnSimulationMessage()

virtual void CTurnManager::OnSimulationMessage ( CSimulationMessage msg)
pure virtual

Called by networking code when a simulation message is received.

Implemented in CNetClientTurnManager, and CLocalTurnManager.

◆ PostCommand()

virtual void CTurnManager::PostCommand ( JS::HandleValue  data)
pure virtual

Called by simulation code, to add a new command to be distributed to all clients and executed soon.

Implemented in CNetClientTurnManager, and CLocalTurnManager.

◆ QuickLoad()

void CTurnManager::QuickLoad ( )

◆ QuickSave()

void CTurnManager::QuickSave ( JS::HandleValue  GUIMetadata)

◆ ResetState()

void CTurnManager::ResetState ( u32  newCurrentTurn,
u32  newReadyTurn 
)

◆ RewindTimeWarp()

void CTurnManager::RewindTimeWarp ( )

Jumps back to the latest recorded state snapshot (if any).

◆ SetPlayerID()

void CTurnManager::SetPlayerID ( int  playerId)

Set the current user's player ID, which will be added into command messages.

◆ TurnNeedsFullHash()

bool CTurnManager::TurnNeedsFullHash ( u32  turn) const
protected

Returns whether we should compute a complete state hash for the given turn, instead of a quick less-complete hash.

◆ Update()

bool CTurnManager::Update ( float  simFrameLength,
size_t  maxTurns 
)

Advance the simulation by a certain time.

If this brings us past the current turn length, the next turns are processed and the function returns true. Otherwise, nothing happens and it returns false.

Parameters
simFrameLengthLength of the previous frame, in simulation seconds
maxTurnsMaximum number of turns to simulate at once

◆ UpdateFastForward()

bool CTurnManager::UpdateFastForward ( )

Advance the simulation by as much as possible.

Intended for catching up over a small number of turns when rejoining a multiplayer match. Returns true if it advanced by at least one turn.

Member Data Documentation

◆ EventNameSavegameLoaded

const CStr CTurnManager::EventNameSavegameLoaded = "SavegameLoaded"
staticprivate

◆ m_ClientId

uint CTurnManager::m_ClientId
protected

◆ m_CommandDelay

u32 CTurnManager::m_CommandDelay
protected

◆ m_CurrentTurn

u32 CTurnManager::m_CurrentTurn
protected

The turn that we have most recently executed.

◆ m_DeltaSimTime

float CTurnManager::m_DeltaSimTime
protected

Simulation time remaining until we ought to execute the next turn (as a negative value to add elapsed time increments to until we reach 0).

◆ m_FinalTurn

u32 CTurnManager::m_FinalTurn
protected

◆ m_PlayerId

int CTurnManager::m_PlayerId
protected

◆ m_QueuedCommands

std::deque<std::map<u32, std::vector<SimulationCommand> > > CTurnManager::m_QueuedCommands
protected

Commands queued at each turn (index 0 is for m_CurrentTurn+1)

◆ m_QuickSaveMetadata

JS::PersistentRootedValue CTurnManager::m_QuickSaveMetadata
private

◆ m_QuickSaveState

std::string CTurnManager::m_QuickSaveState
private

◆ m_ReadyTurn

u32 CTurnManager::m_ReadyTurn
protected

The latest turn for which we have received all commands from all clients.

◆ m_Replay

IReplayLogger& CTurnManager::m_Replay
protected

◆ m_Simulation2

CSimulation2& CTurnManager::m_Simulation2
protected

◆ m_TimeWarpNumTurns

size_t CTurnManager::m_TimeWarpNumTurns
private

◆ m_TimeWarpStates

std::list<std::string> CTurnManager::m_TimeWarpStates
private

◆ m_TurnLength

u32 CTurnManager::m_TurnLength
protected

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