Ticket #3581: t3581_stop_simulation_after_replay_v1.patch
File t3581_stop_simulation_after_replay_v1.patch, 4.1 KB (added by , 9 years ago) |
---|
-
source/network/NetTurnManager.cpp
static std::string Hexify(const std::str 59 59 } 60 60 61 61 CNetTurnManager::CNetTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay) : 62 62 m_Simulation2(simulation), m_CurrentTurn(0), m_ReadyTurn(1), m_TurnLength(defaultTurnLength), m_DeltaSimTime(0), 63 63 m_PlayerId(-1), m_ClientId(clientId), m_HasSyncError(false), m_Replay(replay), 64 m_TimeWarpNumTurns(0) 64 m_TimeWarpNumTurns(0), m_FinalTurn(0) 65 65 { 66 66 // When we are on turn n, we schedule new commands for n+2. 67 67 // We know that all other clients have finished scheduling commands for n (else we couldn't have got here). 68 68 // We know we have not yet finished scheduling commands for n+2. 69 69 // Hence other clients can be on turn n-1, n, n+1, and no other. … … void CNetTurnManager::SetPlayerID(int pl 89 89 90 90 bool CNetTurnManager::WillUpdate(float simFrameLength) 91 91 { 92 92 // Keep this in sync with the return value of Update() 93 93 94 if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn) 95 return false; 96 94 97 if (m_DeltaSimTime + simFrameLength < 0) 95 98 return false; 96 99 97 100 if (m_ReadyTurn <= m_CurrentTurn) 98 101 return false; … … bool CNetTurnManager::WillUpdate(float s 100 103 return true; 101 104 } 102 105 103 106 bool CNetTurnManager::Update(float simFrameLength, size_t maxTurns) 104 107 { 108 109 if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn) 110 return false; 111 105 112 m_DeltaSimTime += simFrameLength; 106 113 107 114 // If the game becomes laggy, m_DeltaSimTime increases progressively. 108 115 // The engine will fast forward accordingly to catch up. 109 116 // To keep the game playable, stop fast forwarding after 2 turn lengths. … … void CNetReplayTurnManager::StoreReplayT 513 520 m_TurnLength = m_ReplayTurnLengths[0]; 514 521 } 515 522 516 523 void CNetReplayTurnManager::StoreFinalReplayTurn(u32 turn) 517 524 { 518 m_Final ReplayTurn = turn;525 m_FinalTurn = turn; 519 526 } 520 527 521 528 void CNetReplayTurnManager::NotifyFinishedUpdate(u32 turn) 522 529 { 523 if (turn > m_Final ReplayTurn)530 if (turn > m_FinalTurn) 524 531 return; 525 532 526 debug_printf("Executing turn %d of %d\n", turn, m_Final ReplayTurn);533 debug_printf("Executing turn %d of %d\n", turn, m_FinalTurn); 527 534 DoTurn(turn); 528 535 529 536 // Compare hash if it exists in the replay and if we didn't have an OOS already 530 537 if (m_HasSyncError || m_ReplayHash.find(turn) == m_ReplayHash.end()) 531 538 return; … … void CNetReplayTurnManager::DoTurn(u32 t 553 560 JS::RootedValue command(m_Simulation2.GetScriptInterface().GetContext()); 554 561 m_Simulation2.GetScriptInterface().ParseJSON(pair.second, &command); 555 562 AddCommand(m_ClientId, pair.first, command, m_CurrentTurn + 1); 556 563 } 557 564 558 if (turn == m_Final ReplayTurn)565 if (turn == m_FinalTurn) 559 566 g_GUI->SendEventToAll("ReplayFinished"); 560 567 } 561 568 562 569 CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server) : 563 570 m_NetServer(server), m_ReadyTurn(1), m_TurnLength(DEFAULT_TURN_LENGTH_MP), m_HasSyncError(false) -
source/network/NetTurnManager.h
protected: 188 188 189 189 bool m_HasSyncError; 190 190 191 191 IReplayLogger& m_Replay; 192 192 193 // The number of the last turn that is allowed to be executed (used for replays) 194 u32 m_FinalTurn; 195 193 196 private: 194 197 size_t m_TimeWarpNumTurns; // 0 if disabled 195 198 std::list<std::string> m_TimeWarpStates; 196 199 std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system 197 200 std::string m_QuickSaveMetadata; … … protected: 271 274 // Contains the length of every turn 272 275 std::map<u32, u32> m_ReplayTurnLengths; 273 276 274 277 // Contains all replay hash values and weather or not the quick hash method was used 275 278 std::map<u32, std::pair<std::string, bool> > m_ReplayHash; 276 277 // The number of the last turn in the replay278 u32 m_FinalReplayTurn;279 280 279 }; 281 280 /** 282 281 * The server-side counterpart to CNetClientTurnManager. 283 282 * Records the turn state of each client, and sends turn advancement messages 284 283 * when all clients are ready.