diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 939a41601a..bdaafd8889 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -181,6 +181,11 @@ std::wstring SetCursor(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), std::wstr return old; } +bool IsVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) +{ + return g_Game ? g_Game->IsVisualReplay() : false; +} + int GetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) { if (g_Game) @@ -978,6 +983,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) // Misc functions scriptInterface.RegisterFunction("SetCursor"); + scriptInterface.RegisterFunction("IsVisualReplay"); scriptInterface.RegisterFunction("GetPlayerID"); scriptInterface.RegisterFunction("SetPlayerID"); scriptInterface.RegisterFunction("OpenURL"); diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 0330a351a5..c4d6727215 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -72,7 +72,7 @@ CGame::CGame(bool disableGraphics, bool replayLog): m_SimRate(1.0f), m_PlayerID(-1), m_IsSavedGame(false), - m_IsReplay(false), + m_IsVisualReplay(false), m_ReplayStream(NULL) { // TODO: should use CDummyReplayLogger unless activated by cmd-line arg, perhaps? @@ -120,9 +120,9 @@ void CGame::SetTurnManager(CNetTurnManager* turnManager) m_TurnManager->SetPlayerID(m_PlayerID); } -int CGame::LoadReplayData() +int CGame::LoadVisualReplayData() { - ENSURE(m_IsReplay); + ENSURE(m_IsVisualReplay); ENSURE(!m_ReplayPath.empty()); ENSURE(m_ReplayStream); @@ -167,9 +167,9 @@ int CGame::LoadReplayData() return 0; } -bool CGame::StartReplay(const std::string& replayPath) +bool CGame::StartVisualReplay(const std::string& replayPath) { - m_IsReplay = true; + m_IsVisualReplay = true; ScriptInterface& scriptInterface = m_Simulation2->GetScriptInterface(); SetTurnManager(new CNetReplayTurnManager(*m_Simulation2, GetReplayLogger())); @@ -250,8 +250,8 @@ void CGame::RegisterInit(const JS::HandleValue attribs, const std::string& saved if (m_IsSavedGame) RegMemFun(this, &CGame::LoadInitialState, L"Loading game", 1000); - if (m_IsReplay) - RegMemFun(this, &CGame::LoadReplayData, L"Loading replay data", 1000); + if (m_IsVisualReplay) + RegMemFun(this, &CGame::LoadVisualReplayData, L"Loading visual replay data", 1000); LDR_EndRegistering(); } diff --git a/source/ps/Game.h b/source/ps/Game.h index 0971def8d9..f4eadf2c67 100644 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -77,7 +77,7 @@ public: void StartGame(JS::MutableHandleValue attribs, const std::string& savedState); PSRETURN ReallyStartGame(); - bool StartReplay(const std::string& replayPath); + bool StartVisualReplay(const std::string& replayPath); /** * Periodic heartbeat that controls the process. performs all per-frame updates. @@ -115,6 +115,14 @@ public: return m_GameStarted; } + /** + * Get m_IsVisualReplay. + * + * @return bool the value of m_IsVisualReplay. + **/ + inline bool IsVisualReplay() + { return m_IsVisualReplay; } + /** * Get the pointer to the game world object. * @@ -175,9 +183,9 @@ private: std::string m_InitialSavedState; // valid between RegisterInit and LoadInitialState bool m_IsSavedGame; // true if loading a saved game; false for a new game - int LoadReplayData(); + int LoadVisualReplayData(); std::string m_ReplayPath; - bool m_IsReplay; + bool m_IsVisualReplay; std::istream* m_ReplayStream; u32 m_FinalReplayTurn; }; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 08a33312eb..abb05c12a9 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -1478,13 +1478,12 @@ bool VisualReplay(const std::string replayFile) g_Game = new CGame(false, false); g_Game->SetPlayerID(-1); - g_Game->StartReplay(replayFile); + g_Game->StartVisualReplay(replayFile); // TODO: Non progressive load can fail - need a decent way to handle this LDR_NonprogressiveLoad(); - PSRETURN ret = g_Game->ReallyStartGame(); - ENSURE(ret == PSRETURN_OK); + PSRETURN ret = g_Game->ReallyStartGame(); ENSURE(ret == PSRETURN_OK); ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface();