18#ifndef INCLUDED_TURNMANAGER
19#define INCLUDED_TURNMANAGER
105 bool Update(
float simFrameLength,
size_t maxTurns);
119 void Interpolate(
float simFrameLength,
float realFrameLength);
149 void QuickSave(JS::HandleValue GUIMetadata);
164 void AddCommand(
int client,
int player, JS::HandleValue data,
u32 turn);
constexpr u32 DEFAULT_TURN_LENGTH
This file defines the base class of the turn managers for clients, local games and replays.
Definition: TurnManager.h:55
constexpr u32 COMMAND_DELAY_MP
In multi-player, clients can only compute turn N if all clients have finished sending commands for it...
Definition: TurnManager.h:74
constexpr u32 COMMAND_DELAY_SP
In single-player, commands are directly scheduled for the next turn.
Definition: TurnManager.h:60
Public API for simulation system.
Definition: Simulation2.h:47
Special message type for simulation commands.
Definition: NetMessage.h:114
Common turn system (used by clients and offline games).
Definition: TurnManager.h:80
uint m_ClientId
Definition: TurnManager.h:200
virtual ~CTurnManager()
Definition: TurnManager.h:88
void Interpolate(float simFrameLength, float realFrameLength)
Advance the graphics by a certain time.
Definition: TurnManager.cpp:195
std::deque< std::map< u32, std::vector< SimulationCommand > > > m_QueuedCommands
Commands queued at each turn (index 0 is for m_CurrentTurn+1)
Definition: TurnManager.h:197
u32 GetCurrentTurn() const
Definition: TurnManager.h:152
void AddCommand(int client, int player, JS::HandleValue data, u32 turn)
Store a command to be executed at a given turn.
Definition: TurnManager.cpp:209
u32 m_TurnLength
Definition: TurnManager.h:194
void QuickLoad()
Definition: TurnManager.cpp:303
bool Update(float simFrameLength, size_t maxTurns)
Advance the simulation by a certain time.
Definition: TurnManager.cpp:65
std::list< std::string > m_TimeWarpStates
Definition: TurnManager.h:215
u32 m_FinalTurn
Definition: TurnManager.h:209
JS::PersistentRootedValue m_QuickSaveMetadata
Definition: TurnManager.h:217
u32 m_ReadyTurn
The latest turn for which we have received all commands from all clients.
Definition: TurnManager.h:191
CSimulation2 & m_Simulation2
Definition: TurnManager.h:182
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.
u32 m_CommandDelay
Definition: TurnManager.h:188
void QuickSave(JS::HandleValue GUIMetadata)
Definition: TurnManager.cpp:281
NONCOPYABLE(CTurnManager)
void RewindTimeWarp()
Jumps back to the latest recorded state snapshot (if any).
Definition: TurnManager.cpp:265
static const CStr EventNameSavegameLoaded
Definition: TurnManager.h:212
bool TurnNeedsFullHash(u32 turn) const
Returns whether we should compute a complete state hash for the given turn, instead of a quick less-c...
Definition: TurnManager.cpp:243
void SetPlayerID(int playerId)
Set the current user's player ID, which will be added into command messages.
Definition: TurnManager.cpp:60
bool UpdateFastForward()
Advance the simulation by as much as possible.
Definition: TurnManager.cpp:157
size_t m_TimeWarpNumTurns
Definition: TurnManager.h:214
void ResetState(u32 newCurrentTurn, u32 newReadyTurn)
Definition: TurnManager.cpp:50
std::string m_QuickSaveState
Definition: TurnManager.h:216
u32 m_CurrentTurn
The turn that we have most recently executed.
Definition: TurnManager.h:185
CTurnManager(CSimulation2 &simulation, u32 defaultTurnLength, u32 commandDelay, int clientId, IReplayLogger &replay)
Construct for a given network session ID.
Definition: TurnManager.cpp:40
IReplayLogger & m_Replay
Definition: TurnManager.h:206
float m_DeltaSimTime
Simulation time remaining until we ought to execute the next turn (as a negative value to add elapsed...
Definition: TurnManager.h:204
int m_PlayerId
Definition: TurnManager.h:199
void EnableTimeWarpRecording(size_t numTurns)
Enables the recording of state snapshots every numTurns, which can be jumped back to via RewindTimeWa...
Definition: TurnManager.cpp:259
void FinishedAllCommands(u32 turn, u32 turnLength)
Called when all commands for a given turn have been received.
Definition: TurnManager.cpp:234
virtual void NotifyFinishedUpdate(u32 turn)=0
Called when this client has finished a simulation update.
u32 GetPendingTurns() const
Definition: TurnManager.h:158
virtual void OnSimulationMessage(CSimulationMessage *msg)=0
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.
Replay log recorder interface.
Definition: Replay.h:36
unsigned int uint
Definition: types.h:42
uint32_t u32
Definition: types.h:39