Ticket #3581: t3581_stop_simulation_after_replay_v1.patch

File t3581_stop_simulation_after_replay_v1.patch, 4.1 KB (added by elexis, 9 years ago)
  • source/network/NetTurnManager.cpp

    static std::string Hexify(const std::str  
    5959}
    6060
    6161CNetTurnManager::CNetTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay) :
    6262    m_Simulation2(simulation), m_CurrentTurn(0), m_ReadyTurn(1), m_TurnLength(defaultTurnLength), m_DeltaSimTime(0),
    6363    m_PlayerId(-1), m_ClientId(clientId), m_HasSyncError(false), m_Replay(replay),
    64     m_TimeWarpNumTurns(0)
     64    m_TimeWarpNumTurns(0), m_FinalTurn(0)
    6565{
    6666    // When we are on turn n, we schedule new commands for n+2.
    6767    // We know that all other clients have finished scheduling commands for n (else we couldn't have got here).
    6868    // We know we have not yet finished scheduling commands for n+2.
    6969    // Hence other clients can be on turn n-1, n, n+1, and no other.
    void CNetTurnManager::SetPlayerID(int pl  
    8989
    9090bool CNetTurnManager::WillUpdate(float simFrameLength)
    9191{
    9292    // Keep this in sync with the return value of Update()
    9393
     94    if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn)
     95        return false;
     96
    9497    if (m_DeltaSimTime + simFrameLength < 0)
    9598        return false;
    9699
    97100    if (m_ReadyTurn <= m_CurrentTurn)
    98101        return false;
    bool CNetTurnManager::WillUpdate(float s  
    100103    return true;
    101104}
    102105
    103106bool CNetTurnManager::Update(float simFrameLength, size_t maxTurns)
    104107{
     108
     109    if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn)
     110        return false;
     111
    105112    m_DeltaSimTime += simFrameLength;
    106113
    107114    // If the game becomes laggy, m_DeltaSimTime increases progressively.
    108115    // The engine will fast forward accordingly to catch up.
    109116    // To keep the game playable, stop fast forwarding after 2 turn lengths.
    void CNetReplayTurnManager::StoreReplayT  
    513520        m_TurnLength = m_ReplayTurnLengths[0];
    514521}
    515522
    516523void CNetReplayTurnManager::StoreFinalReplayTurn(u32 turn)
    517524{
    518     m_FinalReplayTurn = turn;
     525    m_FinalTurn = turn;
    519526}
    520527
    521528void CNetReplayTurnManager::NotifyFinishedUpdate(u32 turn)
    522529{
    523     if (turn > m_FinalReplayTurn)
     530    if (turn > m_FinalTurn)
    524531        return;
    525532
    526     debug_printf("Executing turn %d of %d\n", turn, m_FinalReplayTurn);
     533    debug_printf("Executing turn %d of %d\n", turn, m_FinalTurn);
    527534    DoTurn(turn);
    528535
    529536    // Compare hash if it exists in the replay and if we didn't have an OOS already
    530537    if (m_HasSyncError || m_ReplayHash.find(turn) == m_ReplayHash.end())
    531538        return;
    void CNetReplayTurnManager::DoTurn(u32 t  
    553560        JS::RootedValue command(m_Simulation2.GetScriptInterface().GetContext());
    554561        m_Simulation2.GetScriptInterface().ParseJSON(pair.second, &command);
    555562        AddCommand(m_ClientId, pair.first, command, m_CurrentTurn + 1);
    556563    }
    557564
    558     if (turn == m_FinalReplayTurn)
     565    if (turn == m_FinalTurn)
    559566        g_GUI->SendEventToAll("ReplayFinished");
    560567}
    561568
    562569CNetServerTurnManager::CNetServerTurnManager(CNetServerWorker& server) :
    563570    m_NetServer(server), m_ReadyTurn(1), m_TurnLength(DEFAULT_TURN_LENGTH_MP), m_HasSyncError(false)
  • source/network/NetTurnManager.h

    protected:  
    188188
    189189    bool m_HasSyncError;
    190190
    191191    IReplayLogger& m_Replay;
    192192
     193    // The number of the last turn that is allowed to be executed (used for replays)
     194    u32 m_FinalTurn;
     195
    193196private:
    194197    size_t m_TimeWarpNumTurns; // 0 if disabled
    195198    std::list<std::string> m_TimeWarpStates;
    196199    std::string m_QuickSaveState; // TODO: should implement a proper disk-based quicksave system
    197200    std::string m_QuickSaveMetadata;
    protected:  
    271274    // Contains the length of every turn
    272275    std::map<u32, u32> m_ReplayTurnLengths;
    273276
    274277    // Contains all replay hash values and weather or not the quick hash method was used
    275278    std::map<u32, std::pair<std::string, bool> > m_ReplayHash;
    276 
    277     // The number of the last turn in the replay
    278     u32 m_FinalReplayTurn;
    279 
    280279};
    281280/**
    282281 * The server-side counterpart to CNetClientTurnManager.
    283282 * Records the turn state of each client, and sends turn advancement messages
    284283 * when all clients are ready.