Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -353,7 +353,7 @@ while (more && timer_Time() - startTime < maxTime); } -static void Frame() +static void Frame(std::optional& rlInterface) { g_Profiler2.RecordFrameStart(); PROFILE2("frame"); @@ -419,12 +419,12 @@ g_GUI->TickObjects(); - if (g_RLInterface) - g_RLInterface->TryApplyMessage(); + if (rlInterface) + rlInterface->TryApplyMessage(); if (g_Game && g_Game->IsGameStarted() && need_update) { - if (!g_RLInterface) + if (!rlInterface) g_Game->Update(realTimeSinceLastFrame); g_Game->GetView()->Update(float(realTimeSinceLastFrame)); @@ -482,16 +482,19 @@ in_reset_handlers(); } -static void StartRLInterface(CmdLineArgs args) +static std::optional StartRLInterface(CmdLineArgs args) { + if (!args.Has("rl-interface")) + return std::nullopt; + std::string server_address; CFG_GET_VAL("rlinterface.address", server_address); if (!args.Get("rl-interface").empty()) server_address = args.Get("rl-interface"); - g_RLInterface = std::make_unique(server_address.c_str()); debug_printf("RL interface listening on %s\n", server_address.c_str()); + return std::make_optional(server_address.c_str()); } // moved into a helper function to ensure args is destroyed before @@ -520,7 +523,6 @@ const bool isVisualReplay = args.Has("replay-visual"); const bool isNonVisualReplay = args.Has("replay"); const bool isNonVisual = args.Has("autostart-nonvisual"); - const bool isUsingRLInterface = args.Has("rl-interface"); const OsPath replayFile( isVisualReplay ? args.Get("replay-visual") : @@ -666,25 +668,26 @@ { if (!InitNonVisual(args)) g_Shutdown = ShutdownType::Quit; - else if (isUsingRLInterface) - StartRLInterface(args); - - while (g_Shutdown == ShutdownType::None) + else { - if (isUsingRLInterface) - g_RLInterface->TryApplyMessage(); - else - NonVisualFrame(); + std::optional rlInterface{StartRLInterface(args)}; + while (g_Shutdown == ShutdownType::None) + { + if (rlInterface) + rlInterface->TryApplyMessage(); + else + NonVisualFrame(); + } } } else { InitGraphics(args, 0, installedMods); MainControllerInit(); - if (isUsingRLInterface) - StartRLInterface(args); + + std::optional rlInterface{StartRLInterface(args)}; while (g_Shutdown == ShutdownType::None) - Frame(); + Frame(rlInterface); } // Do not install mods again in case of restart (typically from the mod selector) Index: source/rlinterface/RLInterface.h =================================================================== --- source/rlinterface/RLInterface.h +++ source/rlinterface/RLInterface.h @@ -162,6 +162,4 @@ } -extern std::unique_ptr g_RLInterface; - #endif // INCLUDED_RLINTERFACE Index: source/rlinterface/RLInterface.cpp =================================================================== --- source/rlinterface/RLInterface.cpp +++ source/rlinterface/RLInterface.cpp @@ -38,9 +38,6 @@ #include #include -// Globally accessible pointer to the RL Interface. -std::unique_ptr g_RLInterface; - namespace RL { Interface::Interface(const char* server_address) : m_GameMessage({GameMessageType::None})