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

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

#include <NetTurnManager.h>

Inheritance diagram for CNetTurnManager:
CNetClientTurnManager CNetLocalTurnManager

Public Member Functions

 CNetTurnManager (CSimulation2 &simulation, u32 defaultTurnLength, int clientId, IReplayLogger &replay)
 Construct for a given network session ID. More...
 
virtual ~CNetTurnManager ()
 
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...
 
bool WillUpdate (float simFrameLength)
 Returns whether Update(simFrameLength, ...) will process at least one new turn. 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 OnSyncError (u32 turn, const std::string &expectedHash)
 Called when there has been an out-of-sync error. More...
 
virtual void PostCommand (CScriptValRooted 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 ()
 
void QuickLoad ()
 
u32 GetCurrentTurn ()
 

Protected Member Functions

void AddCommand (int client, int player, CScriptValRooted 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)
 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_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...
 
bool m_HasSyncError
 
IReplayLoggerm_Replay
 

Private Member Functions

 NONCOPYABLE (CNetTurnManager)
 

Private Attributes

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

Detailed Description

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

Definition at line 52 of file NetTurnManager.h.

Constructor & Destructor Documentation

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

Construct for a given network session ID.

Definition at line 60 of file NetTurnManager.cpp.

virtual CNetTurnManager::~CNetTurnManager ( )
inlinevirtual

Definition at line 61 of file NetTurnManager.h.

Member Function Documentation

void CNetTurnManager::AddCommand ( int  client,
int  player,
CScriptValRooted  data,
u32  turn 
)
protected

Store a command to be executed at a given turn.

Definition at line 259 of file NetTurnManager.cpp.

void CNetTurnManager::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.

Definition at line 300 of file NetTurnManager.cpp.

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

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

This allows Update to progress to that turn.

Definition at line 275 of file NetTurnManager.cpp.

u32 CNetTurnManager::GetCurrentTurn ( )
inline

Definition at line 136 of file NetTurnManager.h.

void CNetTurnManager::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

Definition at line 250 of file NetTurnManager.cpp.

CNetTurnManager::NONCOPYABLE ( CNetTurnManager  )
private
virtual void CNetTurnManager::NotifyFinishedOwnCommands ( u32  turn)
protectedpure virtual

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

Implemented in CNetLocalTurnManager, and CNetClientTurnManager.

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

Called when this client has finished a simulation update.

Implemented in CNetLocalTurnManager, and CNetClientTurnManager.

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

Called by networking code when a simulation message is received.

Implemented in CNetLocalTurnManager, and CNetClientTurnManager.

void CNetTurnManager::OnSyncError ( u32  turn,
const std::string &  expectedHash 
)
virtual

Called when there has been an out-of-sync error.

Definition at line 221 of file NetTurnManager.cpp.

virtual void CNetTurnManager::PostCommand ( CScriptValRooted  data)
pure virtual

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

Implemented in CNetLocalTurnManager, and CNetClientTurnManager.

void CNetTurnManager::QuickLoad ( )

Definition at line 344 of file NetTurnManager.cpp.

void CNetTurnManager::QuickSave ( )

Definition at line 322 of file NetTurnManager.cpp.

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

Definition at line 74 of file NetTurnManager.cpp.

void CNetTurnManager::RewindTimeWarp ( )

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

Definition at line 306 of file NetTurnManager.cpp.

void CNetTurnManager::SetPlayerID ( int  playerId)

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

Definition at line 84 of file NetTurnManager.cpp.

bool CNetTurnManager::TurnNeedsFullHash ( u32  turn)
protected

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

Definition at line 284 of file NetTurnManager.cpp.

bool CNetTurnManager::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

Definition at line 102 of file NetTurnManager.cpp.

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

Definition at line 182 of file NetTurnManager.cpp.

bool CNetTurnManager::WillUpdate ( float  simFrameLength)

Returns whether Update(simFrameLength, ...) will process at least one new turn.

Parameters
simFrameLengthLength of the previous frame, in simulation seconds

Definition at line 89 of file NetTurnManager.cpp.

Member Data Documentation

uint CNetTurnManager::m_ClientId
protected

Definition at line 175 of file NetTurnManager.h.

u32 CNetTurnManager::m_CurrentTurn
protected

The turn that we have most recently executed.

Definition at line 163 of file NetTurnManager.h.

float CNetTurnManager::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).

Definition at line 179 of file NetTurnManager.h.

bool CNetTurnManager::m_HasSyncError
protected

Definition at line 181 of file NetTurnManager.h.

int CNetTurnManager::m_PlayerId
protected

Definition at line 174 of file NetTurnManager.h.

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

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

Definition at line 172 of file NetTurnManager.h.

std::string CNetTurnManager::m_QuickSaveMetadata
private

Definition at line 189 of file NetTurnManager.h.

std::string CNetTurnManager::m_QuickSaveState
private

Definition at line 188 of file NetTurnManager.h.

u32 CNetTurnManager::m_ReadyTurn
protected

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

Definition at line 166 of file NetTurnManager.h.

IReplayLogger& CNetTurnManager::m_Replay
protected

Definition at line 183 of file NetTurnManager.h.

CSimulation2& CNetTurnManager::m_Simulation2
protected

Definition at line 160 of file NetTurnManager.h.

size_t CNetTurnManager::m_TimeWarpNumTurns
private

Definition at line 186 of file NetTurnManager.h.

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

Definition at line 187 of file NetTurnManager.h.

u32 CNetTurnManager::m_TurnLength
protected

Definition at line 169 of file NetTurnManager.h.


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