Pass ooslog-activate flag on construction

This deduplicates the activation logic and removes the only
`m_EnableOOSLog` mutation.
This commit is contained in:
phosit 2025-10-15 10:58:33 +02:00
parent 0fe18e1d84
commit 10afb7d856
No known key found for this signature in database
GPG key ID: C9430B600671C268
5 changed files with 13 additions and 23 deletions

View file

@ -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),

View file

@ -88,7 +88,7 @@ class CGame
CTurnManager* m_TurnManager;
public:
CGame(bool replayLog);
CGame(bool replayLog, const bool oosLog = false);
~CGame();
/**

View file

@ -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);

View file

@ -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<CSimulation2Impl>(unitManager, cx, terrain))
CSimulation2::CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain,
const bool enableOOSLog) :
m(std::make_unique<CSimulation2Impl>(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());

View file

@ -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),