Ticket #3309: t3309_fix_very_fast_forward_v1.patch

File t3309_fix_very_fast_forward_v1.patch, 3.4 KB (added by elexis, 9 years ago)

Resets m_DeltaSimTime to zero when changing the game speed and also sets back the next turn to currentTurn + 1. Works.

  • binaries/data/mods/public/simulation/data/game_speeds.json

     
    2222            "Speed": 1.0,
    2323            "Default": true
    2424        },
    2525        {
    2626            "Name": "Fast (1.25x)",
    27             "Speed": 1.25
     27            "Speed": 10
    2828        },
    2929        {
    3030            "Name": "Very Fast (1.5x)",
    31             "Speed": 1.5
     31            "Speed": 15
    3232        },
    3333        {
    3434            "Name": "Insane (2x)",
    35             "Speed": 2.0
     35            "Speed": 20
    3636        }
    3737    ]
    3838}
  • source/network/NetTurnManager.cpp

     
    6969    // So they can be sending us commands scheduled for n+1, n+2, n+3.
    7070    // So we need a 3-element buffer:
    7171    m_QueuedCommands.resize(COMMAND_DELAY + 1);
    7272}
    7373
     74void CNetTurnManager::ResetDeltaSimTime()
     75{
     76    m_DeltaSimTime = 0;
     77    m_ReadyTurn = m_CurrentTurn + 1;
     78}
    7479void CNetTurnManager::ResetState(u32 newCurrentTurn, u32 newReadyTurn)
    7580{
    7681    m_CurrentTurn = newCurrentTurn;
    7782    m_ReadyTurn = newReadyTurn;
    7883    m_DeltaSimTime = 0;
  • source/network/NetTurnManager.h

     
    6060     */
    6161    CNetTurnManager(CSimulation2& simulation, u32 defaultTurnLength, int clientId, IReplayLogger& replay);
    6262
    6363    virtual ~CNetTurnManager() { }
    6464
     65    /**
     66     * Called when changing the simulation rate. Stops the simulation from trying to keep up with
     67     * too high fast forward speeds, so that the simulation rate will be changed immediately.
     68     */
     69    void ResetDeltaSimTime();
     70
    6571    void ResetState(u32 newCurrentTurn, u32 newReadyTurn);
    6672
    6773    /**
    6874     * Set the current user's player ID, which will be added into command messages.
    6975     */
  • source/ps/Game.cpp

     
    256256        RegMemFun(this, &CGame::LoadReplayData, L"Loading replay data", 1000);
    257257
    258258    LDR_EndRegistering();
    259259}
    260260
     261void CGame::SetSimRate(float simRate)
     262{
     263    if (isfinite(simRate))
     264    {
     265        m_SimRate = std::max(simRate, 0.0f);
     266        m_TurnManager->ResetDeltaSimTime();
     267    }
     268}
     269
    261270int CGame::LoadInitialState()
    262271{
    263272    ENSURE(m_IsSavedGame);
    264273    ENSURE(!m_InitialSavedState.empty());
    265274
  • source/ps/Game.h

     
    137137     * @return CSimulation2 * the value of m_Simulation2.
    138138     **/
    139139    inline CSimulation2 *GetSimulation2()
    140140    {   return m_Simulation2; }
    141141
     142
     143    inline float GetSimRate()
     144    {   return m_SimRate; }
     145
    142146    /**
    143147     * Set the simulation scale multiplier.
    144148     *
    145149     * @param simRate Float value to set m_SimRate to.
    146150     *                      Because m_SimRate is also used to
    147151     *                      scale TimeSinceLastFrame it must be
    148152     *                      clamped to 0.0f.
    149153     **/
    150     inline void SetSimRate(float simRate)
    151     {   if (isfinite(simRate)) m_SimRate = std::max(simRate, 0.0f); }
    152 
    153     inline float GetSimRate()
    154     {   return m_SimRate; }
     154    void SetSimRate(float simRate);
    155155
    156156    /**
    157157     * Replace the current turn manager.
    158158     * This class will take ownership of the pointer.
    159159     */