Correct handling of replays with no turns or only turn 0.

Add a comment for 3ec3f0b160.
Some style fixes.

This was SVN commit r17746.
This commit is contained in:
elexis 2016-02-09 12:09:17 +00:00
parent 4ac89001f4
commit ca9d06d6ad
2 changed files with 14 additions and 9 deletions

View File

@ -91,7 +91,7 @@ bool CNetTurnManager::WillUpdate(float simFrameLength)
{
// Keep this in sync with the return value of Update()
if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn)
if (m_CurrentTurn > m_FinalTurn)
return false;
if (m_DeltaSimTime + simFrameLength < 0)
@ -106,7 +106,7 @@ bool CNetTurnManager::WillUpdate(float simFrameLength)
bool CNetTurnManager::Update(float simFrameLength, size_t maxTurns)
{
if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn)
if (m_CurrentTurn > m_FinalTurn)
return false;
m_DeltaSimTime += simFrameLength;
@ -152,7 +152,8 @@ bool CNetTurnManager::Update(float simFrameLength, size_t maxTurns)
NotifyFinishedOwnCommands(m_CurrentTurn + COMMAND_DELAY);
m_CurrentTurn += 1; // increase the turn number now, so Update can send new commands for a subsequent turn
// Increase now, so Update can send new commands for a subsequent turn
++m_CurrentTurn;
// Clean up any destroyed entities since the last turn (e.g. placement previews
// or rally point flags generated by the GUI). (Must do this before the time warp
@ -208,7 +209,7 @@ bool CNetTurnManager::UpdateFastForward()
// (This is similar but doesn't call any Notify functions or update DeltaTime,
// it just updates the simulation state)
m_CurrentTurn += 1;
++m_CurrentTurn;
m_Simulation2.FlushDestroyedEntities();
@ -243,7 +244,7 @@ void CNetTurnManager::OnSyncError(u32 turn, const CStr& expectedHash, std::vecto
std::string hash;
ENSURE(m_Simulation2.ComputeStateHash(hash, quick));
OsPath path = psLogDir()/"oos_dump.txt";
OsPath path = psLogDir() / "oos_dump.txt";
std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc);
m_Simulation2.DumpDebugState(file);
file.close();
@ -286,7 +287,8 @@ void CNetTurnManager::Interpolate(float simFrameLength, float realFrameLength)
float offset = clamp(m_DeltaSimTime / (m_TurnLength / 1000.f) + 1.0, 0.0, 1.0);
if (m_FinalTurn > 0 && m_CurrentTurn > m_FinalTurn)
// Stop animations while still updating the selection highlight
if (m_CurrentTurn > m_FinalTurn)
simFrameLength = 0;
m_Simulation2.Interpolate(simFrameLength, offset, realFrameLength);
@ -532,10 +534,12 @@ void CNetReplayTurnManager::StoreFinalReplayTurn(u32 turn)
void CNetReplayTurnManager::NotifyFinishedUpdate(u32 turn)
{
if (turn == 1 && m_FinalTurn == 0)
g_GUI->SendEventToAll("ReplayFinished");
if (turn > m_FinalTurn)
return;
debug_printf("Executing turn %d of %d\n", turn, m_FinalTurn);
DoTurn(turn);
// Compare hash if it exists in the replay and if we didn't have an OOS already
@ -556,7 +560,8 @@ void CNetReplayTurnManager::NotifyFinishedUpdate(u32 turn)
void CNetReplayTurnManager::DoTurn(u32 turn)
{
// Save turn length
debug_printf("Executing turn %u of %u\n", turn, m_FinalTurn);
m_TurnLength = m_ReplayTurnLengths[turn];
// Simulate commands for that turn

View File

@ -162,7 +162,7 @@ int CGame::LoadVisualReplayData()
CancelLoad(L"Failed to load replay data (unrecognized content)");
}
SAFE_DELETE(m_ReplayStream);
m_FinalReplayTurn = currentTurn - 1;
m_FinalReplayTurn = currentTurn > 0 ? currentTurn - 1 : 0;
replayTurnMgr->StoreFinalReplayTurn(m_FinalReplayTurn);
return 0;
}