![]() |
Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Common turn system (used by clients and offline games). More...
#include <TurnManager.h>


Public Types | |
| using | UpdateCallback = std::function< void(const std::string &, const std::optional< JS::HandleValueArray >)> |
Public Member Functions | |
| CTurnManager (CSimulation2 &simulation, std::uint32_t defaultTurnLength, std::uint32_t commandDelay, int clientId, IReplayLogger &replay) | |
| Construct for a given network session ID. More... | |
| virtual | ~CTurnManager () |
| void | ResetState (turn_id_t newCurrentTurn, turn_id_t 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, const UpdateCallback &sendEventToAll) |
| 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 (turn_id_t turn, std::uint32_t 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) |
| std::optional< JS::Value > | TryQuickLoad () |
| turn_id_t | GetCurrentTurn () const |
| turn_id_t | GetPendingTurns () const |
Static Public Attributes | |
| static const CStr | EventNameSavegameLoaded = "SavegameLoaded" |
Protected Member Functions | |
| void | AddCommand (int client, int player, JS::HandleValue data, turn_id_t turn) |
| Store a command to be executed at a given turn. More... | |
| virtual void | NotifyFinishedOwnCommands (turn_id_t turn)=0 |
| Called when this client has finished sending all its commands scheduled for the given turn. More... | |
| virtual void | NotifyFinishedUpdate (turn_id_t turn, const UpdateCallback &sendEventToAll)=0 |
| Called when this client has finished a simulation update. More... | |
| bool | TurnNeedsFullHash (turn_id_t 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 | |
| CSimulation2 & | m_Simulation2 |
| turn_id_t | m_CurrentTurn |
| The turn that we have most recently executed. More... | |
| std::uint32_t | m_CommandDelay |
| turn_id_t | m_ReadyTurn |
| The latest turn for which we have received all commands from all clients. More... | |
| std::uint32_t | m_TurnLength |
| std::deque< std::map< turn_id_t, std::vector< SimulationCommand > > > | m_QueuedCommands |
| Commands queued at each turn (index 0 is for m_CurrentTurn+1) More... | |
| int | m_PlayerId |
| unsigned int | 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... | |
| IReplayLogger & | m_Replay |
| turn_id_t | 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 |
Common turn system (used by clients and offline games).
| using CTurnManager::UpdateCallback = std::function<void(const std::string&, const std::optional<JS::HandleValueArray>)> |
| CTurnManager::CTurnManager | ( | CSimulation2 & | simulation, |
| std::uint32_t | defaultTurnLength, | ||
| std::uint32_t | commandDelay, | ||
| int | clientId, | ||
| IReplayLogger & | replay | ||
| ) |
Construct for a given network session ID.
|
inlinevirtual |
|
protected |
Store a command to be executed at a given turn.
| 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.
| void CTurnManager::FinishedAllCommands | ( | turn_id_t | turn, |
| std::uint32_t | turnLength | ||
| ) |
Called when all commands for a given turn have been received.
This allows Update to progress to that turn.
|
inline |
|
inline |
| void CTurnManager::Interpolate | ( | float | simFrameLength, |
| float | realFrameLength | ||
| ) |
Advance the graphics by a certain time.
| simFrameLength | Length of the previous frame, in simulation seconds |
| realFrameLength | Length of the previous frame, in real time seconds |
|
private |
|
protectedpure virtual |
Called when this client has finished sending all its commands scheduled for the given turn.
Implemented in CNetClientTurnManager, and CLocalTurnManager.
|
protectedpure virtual |
Called when this client has finished a simulation update.
Implemented in CNetClientTurnManager, CLocalTurnManager, and CReplayTurnManager.
|
pure virtual |
Called by networking code when a simulation message is received.
Implemented in CNetClientTurnManager, and CLocalTurnManager.
|
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.
| void CTurnManager::QuickSave | ( | JS::HandleValue | GUIMetadata | ) |
| void CTurnManager::RewindTimeWarp | ( | ) |
Jumps back to the latest recorded state snapshot (if any).
| void CTurnManager::SetPlayerID | ( | int | playerId | ) |
Set the current user's player ID, which will be added into command messages.
| std::optional< JS::Value > CTurnManager::TryQuickLoad | ( | ) |
|
protected |
Returns whether we should compute a complete state hash for the given turn, instead of a quick less-complete hash.
| bool CTurnManager::Update | ( | float | simFrameLength, |
| size_t | maxTurns, | ||
| const UpdateCallback & | sendEventToAll | ||
| ) |
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.
| simFrameLength | Length of the previous frame, in simulation seconds |
| maxTurns | Maximum number of turns to simulate at once |
| 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.
|
static |
|
protected |
|
protected |
|
protected |
The turn that we have most recently executed.
|
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).
|
protected |
|
protected |
|
protected |
Commands queued at each turn (index 0 is for m_CurrentTurn+1)
|
private |
|
private |
|
protected |
The latest turn for which we have received all commands from all clients.
|
protected |
|
protected |
|
private |
|
private |
|
protected |