mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
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:
parent
10afb7d856
commit
ef016884ab
6 changed files with 64 additions and 26 deletions
|
|
@ -77,10 +77,10 @@ const CStr CGame::EventNameSimulationUpdate = "SimulationUpdate";
|
|||
* Constructor
|
||||
*
|
||||
**/
|
||||
CGame::CGame(bool replayLog, const bool oosLog):
|
||||
CGame::CGame(bool replayLog, const SimulationDebugOptions debugOptions):
|
||||
m_World(new CWorld(*this)),
|
||||
m_Simulation2{new CSimulation2{&m_World->GetUnitManager(), *g_ScriptContext, &m_World->GetTerrain(),
|
||||
oosLog}},
|
||||
debugOptions}},
|
||||
// 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),
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "ps/CStr.h"
|
||||
#include "ps/Errors.h"
|
||||
#include "simulation2/helpers/Player.h"
|
||||
#include "simulation2/system/DebugOptions.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
|
@ -88,7 +89,7 @@ class CGame
|
|||
CTurnManager* m_TurnManager;
|
||||
|
||||
public:
|
||||
CGame(bool replayLog, const bool oosLog = false);
|
||||
CGame(bool replayLog, const SimulationDebugOptions debugOptions = {});
|
||||
~CGame();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -249,11 +249,18 @@ void CReplayPlayer::Replay(const bool serializationtest, const int rejointesttur
|
|||
MountMods(Paths(g_CmdLineArgs), g_Mods.GetEnabledMods());
|
||||
}
|
||||
|
||||
g_Game = new CGame(false, ooslog);
|
||||
if (serializationtest && rejointestturn >= 0)
|
||||
LOGERROR("serializationtest and rejointest can't be activ at the same time.");
|
||||
|
||||
SimulationDebugOptions debugOption{};
|
||||
if (serializationtest)
|
||||
g_Game->GetSimulation2()->EnableSerializationTest();
|
||||
debugOption.test = SimulationDebugOptions::SerializationTest{};
|
||||
if (rejointestturn >= 0)
|
||||
g_Game->GetSimulation2()->EnableRejoinTest(rejointestturn);
|
||||
debugOption.test = SimulationDebugOptions::RejoinTest{rejointestturn};
|
||||
if (ooslog)
|
||||
debugOption.oosLog = true;
|
||||
|
||||
g_Game = new CGame(false, debugOption);
|
||||
|
||||
ScriptRequest rq(g_Game->GetSimulation2()->GetScriptInterface());
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "lib/code_annotation.h"
|
||||
#include "lib/file/vfs/vfs_path.h"
|
||||
#include "lib/status.h"
|
||||
#include "simulation2/system/DebugOptions.h"
|
||||
#include "simulation2/system/Entity.h"
|
||||
|
||||
#include <js/TypeDecls.h>
|
||||
|
|
@ -56,12 +57,9 @@ 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,
|
||||
const bool enableOOSLog = false);
|
||||
const SimulationDebugOptions debugOptions = {});
|
||||
~CSimulation2();
|
||||
|
||||
void EnableSerializationTest();
|
||||
void EnableRejoinTest(int rejoinTestTurn);
|
||||
|
||||
/**
|
||||
* Load all scripts in the specified directory (non-recursively),
|
||||
* so they can register new component types and functions. This
|
||||
|
|
|
|||
34
source/simulation2/system/DebugOptions.h
Normal file
34
source/simulation2/system/DebugOptions.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* Copyright (C) 2025 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_SIMULATION_DEBUG_OPTIONS
|
||||
#define INCLUDED_SIMULATION_DEBUG_OPTIONS
|
||||
|
||||
#include <variant>
|
||||
|
||||
struct SimulationDebugOptions
|
||||
{
|
||||
struct SerializationTest {};
|
||||
struct RejoinTest
|
||||
{
|
||||
int turn;
|
||||
};
|
||||
std::variant<std::monostate, SerializationTest, RejoinTest> test;
|
||||
bool oosLog{false};
|
||||
};
|
||||
|
||||
#endif // INCLUDED_SIMULATION_DEBUG_OPTIONS
|
||||
Loading…
Reference in a new issue