Pass debugOptions on construction of CSimulation2

The functions to set them explicitly are removed. This makes the
interface of `CSimulation2` smaller.

Also serializationtest and rejointest can't be active at the same time.
Add a warning about that and use a `std::variant`.
This commit is contained in:
phosit
2025-10-15 11:50:35 +02:00
parent 10afb7d856
commit ef016884ab
6 changed files with 64 additions and 26 deletions
+14 -16
View File
@@ -73,16 +73,24 @@ class CSimulation2Impl
{
public:
CSimulation2Impl(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain,
const bool enableOOSLog) :
const SimulationDebugOptions debugOptions) :
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{enableOOSLog || CConfigDB::GetIfInitialised("ooslog", false)},
m_EnableSerializationTest{CConfigDB::GetIfInitialised("serializationtest", false)},
m_EnableOOSLog{debugOptions.oosLog || CConfigDB::GetIfInitialised("ooslog", false)},
m_EnableSerializationTest{
std::holds_alternative<SimulationDebugOptions::SerializationTest>(debugOptions.test) ||
CConfigDB::GetIfInitialised("serializationtest", false)},
// Handle bogus values of the arg
m_RejoinTestTurn{std::max(CConfigDB::GetIfInitialised("rejointest", -1), -1)}
m_RejoinTestTurn{[&]
{
const auto* rejoinTestOption{
std::get_if<SimulationDebugOptions::RejoinTest>(&debugOptions.test)};
return rejoinTestOption ? rejoinTestOption->turn :
std::max(CConfigDB::GetIfInitialised("rejointest", -1), -1);
}()}
{
m_ComponentManager.LoadComponentTypes();
@@ -646,8 +654,8 @@ void CSimulation2Impl::DumpState()
////////////////////////////////////////////////////////////////
CSimulation2::CSimulation2(CUnitManager* unitManager, ScriptContext& cx, CTerrain* terrain,
const bool enableOOSLog) :
m(std::make_unique<CSimulation2Impl>(unitManager, cx, terrain, enableOOSLog))
const SimulationDebugOptions debugOptions) :
m(std::make_unique<CSimulation2Impl>(unitManager, cx, terrain, debugOptions))
{
}
@@ -655,16 +663,6 @@ CSimulation2::~CSimulation2() = default;
// Forward all method calls to the appropriate CSimulation2Impl/CComponentManager methods:
void CSimulation2::EnableSerializationTest()
{
m->m_EnableSerializationTest = true;
}
void CSimulation2::EnableRejoinTest(int rejoinTestTurn)
{
m->m_RejoinTestTurn = rejoinTestTurn;
}
entity_id_t CSimulation2::AddEntity(const std::wstring& templateName)
{
return m->m_ComponentManager.AddEntity(templateName, m->m_ComponentManager.AllocateNewEntity());