From 10afb7d856f4889ad6c4e6e856a9eeb8a82297b3 Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 15 Oct 2025 10:58:33 +0200 Subject: [PATCH] Pass ooslog-activate flag on construction This deduplicates the activation logic and removes the only `m_EnableOOSLog` mutation. --- source/ps/Game.cpp | 5 +++-- source/ps/Game.h | 2 +- source/ps/Replay.cpp | 4 +--- source/simulation2/Simulation2.cpp | 21 ++++++--------------- source/simulation2/Simulation2.h | 4 ++-- 5 files changed, 13 insertions(+), 23 deletions(-) diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index e612effa19..10f4639702 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -77,9 +77,10 @@ const CStr CGame::EventNameSimulationUpdate = "SimulationUpdate"; * Constructor * **/ -CGame::CGame(bool replayLog): +CGame::CGame(bool replayLog, const bool oosLog): m_World(new CWorld(*this)), - m_Simulation2{new CSimulation2{&m_World->GetUnitManager(), *g_ScriptContext, &m_World->GetTerrain()}}, + m_Simulation2{new CSimulation2{&m_World->GetUnitManager(), *g_ScriptContext, &m_World->GetTerrain(), + oosLog}}, // TODO: we need to remove that global dependency. Maybe the game view // should be created outside only if needed. m_GameView(CRenderer::IsInitialised() ? new CGameView(g_VideoMode.GetBackendDevice(), this) : nullptr), diff --git a/source/ps/Game.h b/source/ps/Game.h index 4b5e3eb6c4..fb8d05fd42 100644 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -88,7 +88,7 @@ class CGame CTurnManager* m_TurnManager; public: - CGame(bool replayLog); + CGame(bool replayLog, const bool oosLog = false); ~CGame(); /** diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index 19aadb4088..771f85699b 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -249,13 +249,11 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur MountMods(Paths(g_CmdLineArgs), g_Mods.GetEnabledMods()); } - g_Game = new CGame(false); + g_Game = new CGame(false, ooslog); if (serializationtest) g_Game->GetSimulation2()->EnableSerializationTest(); if (rejointestturn >= 0) g_Game->GetSimulation2()->EnableRejoinTest(rejointestturn); - if (ooslog) - g_Game->GetSimulation2()->EnableOOSLog(); ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface()); JS::RootedValue attribs(rq.cx); diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index eeb85ca5ee..ba6259e326 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -72,13 +72,14 @@ class CSimulation2Impl { public: - CSimulation2Impl(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain) : + CSimulation2Impl(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain, + const bool enableOOSLog) : m_SimContext{terrain, unitManager}, m_ComponentManager{m_SimContext, cx}, m_InitAttributes{cx.GetGeneralJSContext()}, m_MapSettings{cx.GetGeneralJSContext()}, // Tests won't have config initialised - m_EnableOOSLog{CConfigDB::GetIfInitialised("ooslog", false)}, + m_EnableOOSLog{enableOOSLog || CConfigDB::GetIfInitialised("ooslog", false)}, m_EnableSerializationTest{CConfigDB::GetIfInitialised("serializationtest", false)}, // Handle bogus values of the arg m_RejoinTestTurn{std::max(CConfigDB::GetIfInitialised("rejointest", -1), -1)} @@ -644,8 +645,9 @@ void CSimulation2Impl::DumpState() //////////////////////////////////////////////////////////////// -CSimulation2::CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain) : - m(std::make_unique(unitManager, cx, terrain)) +CSimulation2::CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain, + const bool enableOOSLog) : + m(std::make_unique(unitManager, cx, terrain, enableOOSLog)) { } @@ -663,17 +665,6 @@ void CSimulation2::EnableRejoinTest(int rejoinTestTurn) m->m_RejoinTestTurn = rejoinTestTurn; } -void CSimulation2::EnableOOSLog() -{ - if (m->m_EnableOOSLog) - return; - - m->m_EnableOOSLog = true; - m->m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs"); - - debug_printf("Writing ooslogs to %s\n", m->m_OOSLogPath.string8().c_str()); -} - entity_id_t CSimulation2::AddEntity(const std::wstring& templateName) { return m->m_ComponentManager.AddEntity(templateName, m->m_ComponentManager.AllocateNewEntity()); diff --git a/source/simulation2/Simulation2.h b/source/simulation2/Simulation2.h index 1774ed94d4..39a9423869 100644 --- a/source/simulation2/Simulation2.h +++ b/source/simulation2/Simulation2.h @@ -55,12 +55,12 @@ class CSimulation2 public: // TODO: CUnitManager should probably be handled automatically by this // module, but for now we'll have it passed in externally instead - CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain); + CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain, + const bool enableOOSLog = false); ~CSimulation2(); void EnableSerializationTest(); void EnableRejoinTest(int rejoinTestTurn); - void EnableOOSLog(); /** * Load all scripts in the specified directory (non-recursively),