From 00f173685a2d020772d657667ca7c75f8781e20f Mon Sep 17 00:00:00 2001 From: phosit Date: Wed, 4 Feb 2026 19:04:39 +0100 Subject: [PATCH] Use std::optional for m_RejoinTestTurn This removes a `-1` from #8468. --- source/simulation2/Simulation2.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 858f7b2120..1a28fb00de 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include @@ -85,12 +86,16 @@ public: std::holds_alternative(debugOptions.test) || CConfigDB::GetIfInitialised("serializationtest", false)}, // Handle bogus values of the arg - m_RejoinTestTurn{[&] + m_RejoinTestTurn{[&]() -> std::optional { const auto* rejoinTestOption{ std::get_if(&debugOptions.test)}; - return rejoinTestOption ? rejoinTestOption->turn : - std::max(CConfigDB::GetIfInitialised("rejointest", -1), -1); + if (rejoinTestOption) + return rejoinTestOption->turn; + const int configVal{CConfigDB::GetIfInitialised("rejointest", -1)}; + if (configVal >= 0) + return configVal; + return std::nullopt; }()} { m_ComponentManager.LoadComponentTypes(); @@ -160,7 +165,7 @@ public: // Functions and data for the serialization test mode: (see Update() for relevant comments) bool m_EnableSerializationTest{false}; - int m_RejoinTestTurn{-1}; + std::optional m_RejoinTestTurn; bool m_TestingRejoin{false}; // Secondary simulation (NB: order matters for destruction). @@ -387,7 +392,8 @@ void CSimulation2Impl::Update(int turnLength, const std::vector(m_RejoinTestTurn.value()) == m_TurnNumber; if (startRejoinTest) m_TestingRejoin = true; @@ -866,7 +872,7 @@ bool CSimulation2::DeserializeState(std::istream& stream) void CSimulation2::ActivateRejoinTest(int turn) { - if (m->m_RejoinTestTurn != -1) + if (m->m_RejoinTestTurn.has_value()) return; LOGMESSAGERENDER("Rejoin test will activate in %i turns", turn - m->m_TurnNumber); m->m_RejoinTestTurn = turn;