1
0
forked from 0ad/0ad

Make the RLInterface local

refs: #4211

Comments By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5103
This was SVN commit r27908.
This commit is contained in:
phosit 2023-10-28 21:11:25 +00:00
parent f40942f6b3
commit 968e55704a
3 changed files with 16 additions and 19 deletions

View File

@ -360,7 +360,7 @@ static void RendererIncrementalLoad()
while (more && timer_Time() - startTime < maxTime);
}
static void Frame()
static void Frame(RL::Interface* rlInterface)
{
g_Profiler2.RecordFrameStart();
PROFILE2("frame");
@ -425,12 +425,12 @@ static void Frame()
g_GUI->TickObjects();
if (g_RLInterface)
g_RLInterface->TryApplyMessage();
if (rlInterface)
rlInterface->TryApplyMessage();
if (g_Game && g_Game->IsGameStarted() && needUpdate)
{
if (!g_RLInterface)
if (!rlInterface)
g_Game->Update(realTimeSinceLastFrame);
g_Game->GetView()->Update(float(realTimeSinceLastFrame));
@ -488,16 +488,19 @@ static void MainControllerShutdown()
in_reset_handlers();
}
static void StartRLInterface(CmdLineArgs args)
static std::optional<RL::Interface> CreateRLInterface(const 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<RL::Interface>(server_address.c_str());
debug_printf("RL interface listening on %s\n", server_address.c_str());
return std::make_optional<RL::Interface>(server_address.c_str());
}
// moved into a helper function to ensure args is destroyed before
@ -526,7 +529,6 @@ static void RunGameOrAtlas(const PS::span<const char* const> argv)
const bool isVisualReplay = args.Has("replay-visual");
const bool isNonVisualReplay = args.Has("replay");
const bool isVisual = !args.Has("autostart-nonvisual");
const bool isUsingRLInterface = args.Has("rl-interface");
const OsPath replayFile(
isVisualReplay ? args.Get("replay-visual") :
@ -676,14 +678,14 @@ static void RunGameOrAtlas(const PS::span<const char* const> argv)
else if (!InitNonVisual(args))
g_Shutdown = ShutdownType::Quit;
if (isUsingRLInterface && g_Shutdown == ShutdownType::None)
StartRLInterface(args);
std::optional<RL::Interface> rlInterface{g_Shutdown == ShutdownType::None ?
CreateRLInterface(args) : std::nullopt};
while (g_Shutdown == ShutdownType::None)
if (isVisual)
Frame();
else if(isUsingRLInterface)
g_RLInterface->TryApplyMessage();
Frame(rlInterface ? &*rlInterface : nullptr);
else if(rlInterface)
rlInterface->TryApplyMessage();
else
NonVisualFrame();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 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
@ -38,9 +38,6 @@
#include <sstream>
#include <tuple>
// Globally accessible pointer to the RL Interface.
std::unique_ptr<RL::Interface> g_RLInterface;
namespace RL
{
Interface::Interface(const char* server_address) : m_GameMessage({GameMessageType::None})

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 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
@ -162,6 +162,4 @@ private:
}
extern std::unique_ptr<RL::Interface> g_RLInterface;
#endif // INCLUDED_RLINTERFACE