18 #ifndef INCLUDED_NETTURNMANAGER
19 #define INCLUDED_NETTURNMANAGER
78 bool Update(
float simFrameLength,
size_t maxTurns);
98 void Interpolate(
float simFrameLength,
float realFrameLength);
108 virtual void OnSyncError(
u32 turn,
const std::string& expectedHash);
299 #endif // INCLUDED_NETTURNMANAGER
std::map< u32, std::map< int, std::string > > m_ClientStateHashes
CNetTurnManager(CSimulation2 &simulation, u32 defaultTurnLength, int clientId, IReplayLogger &replay)
Construct for a given network session ID.
std::vector< u32 > m_SavedTurnLengths
CNetClientTurnManager(CSimulation2 &simulation, CNetClient &client, int clientId, IReplayLogger &replay)
NONCOPYABLE(CNetServerTurnManager)
void UninitialiseClient(int client)
Inform the turn manager that a previously-initialised client has left the game and will no longer be ...
virtual ~CNetTurnManager()
CNetLocalTurnManager(CSimulation2 &simulation, IReplayLogger &replay)
virtual void NotifyFinishedOwnCommands(u32 turn)
Called when this client has finished sending all its commands scheduled for the given turn...
std::list< std::string > m_TimeWarpStates
void EnableTimeWarpRecording(size_t numTurns)
Enables the recording of state snapshots every numTurns, which can be jumped back to via RewindTimeWa...
virtual void NotifyFinishedOwnCommands(u32 turn)
Called when this client has finished sending all its commands scheduled for the given turn...
float m_DeltaSimTime
Simulation time remaining until we ought to execute the next turn (as a negative value to add elapsed...
void NotifyFinishedClientUpdate(int client, u32 turn, const std::string &hash)
u32 m_ReadyTurn
The latest turn for which we have received all commands from all clients.
Replay log recorder interface.
Implementation of CNetTurnManager for offline games.
u32 GetSavedTurnLength(u32 turn)
Returns the turn length that was used for the given turn.
std::string m_QuickSaveState
virtual void NotifyFinishedUpdate(u32 turn)
Called when this client has finished a simulation update.
Public API for simulation system.
bool WillUpdate(float simFrameLength)
Returns whether Update(simFrameLength, ...) will process at least one new turn.
virtual void NotifyFinishedUpdate(u32 turn)
Called when this client has finished a simulation update.
void SetTurnLength(u32 msecs)
size_t m_TimeWarpNumTurns
u32 m_ReadyTurn
The latest turn for which we have received all commands from all clients.
void InitialiseClient(int client, u32 turn)
Inform the turn manager of a new client who will be sending commands.
virtual void OnSyncError(u32 turn, const std::string &expectedHash)
Called when there has been an out-of-sync error.
void ResetState(u32 newCurrentTurn, u32 newReadyTurn)
Common network turn system (used by clients and offline games).
virtual void NotifyFinishedUpdate(u32 turn)=0
Called when this client has finished a simulation update.
void AddCommand(int client, int player, CScriptValRooted data, u32 turn)
Store a command to be executed at a given turn.
virtual void PostCommand(CScriptValRooted data)
Called by simulation code, to add a new command to be distributed to all clients and executed soon...
virtual void PostCommand(CScriptValRooted data)
Called by simulation code, to add a new command to be distributed to all clients and executed soon...
NONCOPYABLE(CNetTurnManager)
std::deque< std::map< u32, std::vector< SimulationCommand > > > m_QueuedCommands
Commands queued at each turn (index 0 is for m_CurrentTurn+1)
bool Update(float simFrameLength, size_t maxTurns)
Advance the simulation by a certain time.
void FinishedAllCommands(u32 turn, u32 turnLength)
Called when all commands for a given turn have been received.
void NotifyFinishedClientCommands(int client, u32 turn)
void SetPlayerID(int playerId)
Set the current user's player ID, which will be added into command messages.
void Interpolate(float simFrameLength, float realFrameLength)
Advance the graphics by a certain time.
std::map< int, u32 > m_ClientsReady
CNetServerTurnManager(CNetServerWorker &server)
CNetServerWorker & m_NetServer
std::string m_QuickSaveMetadata
bool UpdateFastForward()
Advance the simulation by as much as possible.
Implementation of CNetTurnManager for network clients.
u32 m_CurrentTurn
The turn that we have most recently executed.
virtual void OnSimulationMessage(CSimulationMessage *msg)
Called by networking code when a simulation message is received.
virtual void NotifyFinishedOwnCommands(u32 turn)=0
Called when this client has finished sending all its commands scheduled for the given turn...
std::map< int, u32 > m_ClientsSimulated
virtual void PostCommand(CScriptValRooted data)=0
Called by simulation code, to add a new command to be distributed to all clients and executed soon...
virtual void OnSimulationMessage(CSimulationMessage *msg)
Called by networking code when a simulation message is received.
virtual void OnSimulationMessage(CSimulationMessage *msg)=0
Called by networking code when a simulation message is received.
u32 GetReadyTurn()
Returns the latest turn for which all clients are ready; they will have already been told to execute ...
void RewindTimeWarp()
Jumps back to the latest recorded state snapshot (if any).
Network server worker thread.
bool TurnNeedsFullHash(u32 turn)
Returns whether we should compute a complete state hash for the given turn, instead of a quick less-c...
CSimulation2 & m_Simulation2
The server-side counterpart to CNetClientTurnManager.
Special message type for simulation commands.