Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/ReplayTurnManager.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | void CReplayTurnManager::NotifyFinishedUpdate(u32 turn) | ||||
if (hash == expectedHash) | if (hash == expectedHash) | ||||
return; | return; | ||||
m_HasSyncError = true; | m_HasSyncError = true; | ||||
LOGERROR("Replay out of sync on turn %d", turn); | LOGERROR("Replay out of sync on turn %d", turn); | ||||
const ScriptInterface& scriptInterface = m_Simulation2.GetScriptInterface(); | const ScriptInterface& scriptInterface = m_Simulation2.GetScriptInterface(); | ||||
ScriptInterface::Request rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
JS::AutoValueVector paramData(rq.cx); | JS::AutoValueVector paramData(rq.cx); | ||||
paramData.append(JS::NumberValue(turn)); | paramData.append(JS::NumberValue(turn)); | ||||
JS::RootedValue hashVal(rq.cx); | JS::RootedValue hashVal(rq.cx); | ||||
scriptInterface.ToJSVal(rq, &hashVal, hash); | scriptInterface.ToJSVal(rq, &hashVal, hash); | ||||
paramData.append(hashVal); | paramData.append(hashVal); | ||||
JS::RootedValue expectedHashVal(rq.cx); | JS::RootedValue expectedHashVal(rq.cx); | ||||
scriptInterface.ToJSVal(rq, &expectedHashVal, expectedHash); | scriptInterface.ToJSVal(rq, &expectedHashVal, expectedHash); | ||||
paramData.append(expectedHashVal); | paramData.append(expectedHashVal); | ||||
g_GUI->SendEventToAll(EventNameReplayOutOfSync, paramData); | g_GUI->SendEventToAll(EventNameReplayOutOfSync, paramData); | ||||
} | } | ||||
void CReplayTurnManager::DoTurn(u32 turn) | void CReplayTurnManager::DoTurn(u32 turn) | ||||
{ | { | ||||
debug_printf("Executing turn %u of %u\n", turn, m_FinalTurn); | debug_printf("Executing turn %u of %u\n", turn, m_FinalTurn); | ||||
m_TurnLength = m_ReplayTurnLengths[turn]; | m_TurnLength = m_ReplayTurnLengths[turn]; | ||||
ScriptInterface::Request rq(m_Simulation2.GetScriptInterface()); | ScriptRequest rq(m_Simulation2.GetScriptInterface()); | ||||
// Simulate commands for that turn | // Simulate commands for that turn | ||||
for (const std::pair<player_id_t, std::string>& p : m_ReplayCommands[turn]) | for (const std::pair<player_id_t, std::string>& p : m_ReplayCommands[turn]) | ||||
{ | { | ||||
JS::RootedValue command(rq.cx); | JS::RootedValue command(rq.cx); | ||||
m_Simulation2.GetScriptInterface().ParseJSON(p.second, &command); | m_Simulation2.GetScriptInterface().ParseJSON(p.second, &command); | ||||
AddCommand(m_ClientId, p.first, command, m_CurrentTurn + 1); | AddCommand(m_ClientId, p.first, command, m_CurrentTurn + 1); | ||||
} | } | ||||
if (turn == m_FinalTurn) | if (turn == m_FinalTurn) | ||||
g_GUI->SendEventToAll(EventNameReplayFinished); | g_GUI->SendEventToAll(EventNameReplayFinished); | ||||
} | } |
Wildfire Games · Phabricator