Changeset View
Changeset View
Standalone View
Standalone View
source/main.cpp
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | |||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||
#include "network/NetSession.h" | #include "network/NetSession.h" | ||||
#include "lobby/IXmppClient.h" | #include "lobby/IXmppClient.h" | ||||
#include "graphics/Camera.h" | #include "graphics/Camera.h" | ||||
#include "graphics/GameView.h" | #include "graphics/GameView.h" | ||||
#include "graphics/TextureManager.h" | #include "graphics/TextureManager.h" | ||||
#include "gui/GUIManager.h" | #include "gui/GUIManager.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "rlinterface/RLInterface.cpp" | #include "rlinterface/RLInterface.h" | ||||
#include "scriptinterface/ScriptEngine.h" | #include "scriptinterface/ScriptEngine.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/system/TurnManager.h" | #include "simulation2/system/TurnManager.h" | ||||
#include "soundmanager/ISoundManager.h" | #include "soundmanager/ISoundManager.h" | ||||
#if OS_UNIX | #if OS_UNIX | ||||
#include <unistd.h> // geteuid | #include <unistd.h> // geteuid | ||||
#endif // OS_UNIX | #endif // OS_UNIX | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | |||||
static void StartRLInterface(CmdLineArgs args) | static void StartRLInterface(CmdLineArgs args) | ||||
{ | { | ||||
std::string server_address; | std::string server_address; | ||||
CFG_GET_VAL("rlinterface.address", server_address); | CFG_GET_VAL("rlinterface.address", server_address); | ||||
if (!args.Get("rl-interface").empty()) | if (!args.Get("rl-interface").empty()) | ||||
server_address = args.Get("rl-interface"); | server_address = args.Get("rl-interface"); | ||||
g_RLInterface = new RLInterface(); | g_RLInterface = std::unique_ptr<RL::Interface>(new RL::Interface); | ||||
g_RLInterface->EnableHTTP(server_address.c_str()); | g_RLInterface->EnableHTTP(server_address.c_str()); | ||||
vladislavbelov: `g_RLInterface = std::make_unique<RL::Interface>(server_address.c_str());`, since we have C++17. | |||||
debug_printf("RL interface listening on %s\n", server_address.c_str()); | debug_printf("RL interface listening on %s\n", server_address.c_str()); | ||||
} | } | ||||
static void RunRLServer(const bool isNonVisual, const std::vector<OsPath> modsToInstall, const CmdLineArgs args) | |||||
{ | |||||
int flags = INIT_MODS; | |||||
while (!Init(args, flags)) | |||||
{ | |||||
flags &= ~INIT_MODS; | |||||
Shutdown(SHUTDOWN_FROM_CONFIG); | |||||
} | |||||
g_Shutdown = ShutdownType::None; | |||||
std::vector<CStr> installedMods; | |||||
if (!modsToInstall.empty()) | |||||
{ | |||||
Paths paths(args); | |||||
CModInstaller installer(paths.UserData() / "mods", paths.Cache()); | |||||
// Install the mods without deleting the pyromod files | |||||
for (const OsPath& modPath : modsToInstall) | |||||
installer.Install(modPath, g_ScriptRuntime, true); | |||||
installedMods = installer.GetInstalledMods(); | |||||
} | |||||
if (isNonVisual) | |||||
{ | |||||
InitNonVisual(args); | |||||
StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
g_RLInterface->TryApplyMessage(); | |||||
QuitEngine(); | |||||
} | |||||
else | |||||
{ | |||||
InitGraphics(args, 0, installedMods); | |||||
MainControllerInit(); | |||||
StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
Frame(); | |||||
} | |||||
Shutdown(0); | |||||
MainControllerShutdown(); | |||||
CXeromyces::Terminate(); | |||||
delete g_RLInterface; | |||||
} | |||||
// moved into a helper function to ensure args is destroyed before | // moved into a helper function to ensure args is destroyed before | ||||
// exit(), which may result in a memory leak. | // exit(), which may result in a memory leak. | ||||
static void RunGameOrAtlas(int argc, const char* argv[]) | static void RunGameOrAtlas(int argc, const char* argv[]) | ||||
{ | { | ||||
CmdLineArgs args(argc, argv); | CmdLineArgs args(argc, argv); | ||||
g_args = args; | g_args = args; | ||||
Show All 10 Lines | static void RunGameOrAtlas(int argc, const char* argv[]) | ||||
} | } | ||||
if (args.Has("unique-logs")) | if (args.Has("unique-logs")) | ||||
g_UniqueLogPostfix = L"_" + std::to_wstring(std::time(nullptr)) + L"_" + std::to_wstring(getpid()); | g_UniqueLogPostfix = L"_" + std::to_wstring(std::time(nullptr)) + L"_" + std::to_wstring(getpid()); | ||||
const bool isVisualReplay = args.Has("replay-visual"); | const bool isVisualReplay = args.Has("replay-visual"); | ||||
const bool isNonVisualReplay = args.Has("replay"); | const bool isNonVisualReplay = args.Has("replay"); | ||||
const bool isNonVisual = args.Has("autostart-nonvisual"); | const bool isNonVisual = args.Has("autostart-nonvisual"); | ||||
const bool isUsingRLInterface = args.Has("rl-interface"); | |||||
const OsPath replayFile( | const OsPath replayFile( | ||||
isVisualReplay ? args.Get("replay-visual") : | isVisualReplay ? args.Get("replay-visual") : | ||||
isNonVisualReplay ? args.Get("replay") : ""); | isNonVisualReplay ? args.Get("replay") : ""); | ||||
if (isVisualReplay || isNonVisualReplay) | if (isVisualReplay || isNonVisualReplay) | ||||
{ | { | ||||
if (!FileExists(replayFile)) | if (!FileExists(replayFile)) | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | if (args.Has("archivebuild")) | ||||
CXeromyces::Terminate(); | CXeromyces::Terminate(); | ||||
return; | return; | ||||
} | } | ||||
const double res = timer_Resolution(); | const double res = timer_Resolution(); | ||||
g_frequencyFilter = CreateFrequencyFilter(res, 30.0); | g_frequencyFilter = CreateFrequencyFilter(res, 30.0); | ||||
if (args.Has("rl-interface")) | |||||
{ | |||||
RunRLServer(isNonVisual, modsToInstall, args); | |||||
return; | |||||
} | |||||
// run the game | // run the game | ||||
int flags = INIT_MODS; | int flags = INIT_MODS; | ||||
do | do | ||||
{ | { | ||||
g_Shutdown = ShutdownType::None; | g_Shutdown = ShutdownType::None; | ||||
if (!Init(args, flags)) | if (!Init(args, flags)) | ||||
{ | { | ||||
Show All 13 Lines | if (!modsToInstall.empty()) | ||||
installer.Install(modPath, g_ScriptRuntime, true); | installer.Install(modPath, g_ScriptRuntime, true); | ||||
installedMods = installer.GetInstalledMods(); | installedMods = installer.GetInstalledMods(); | ||||
} | } | ||||
if (isNonVisual) | if (isNonVisual) | ||||
{ | { | ||||
InitNonVisual(args); | InitNonVisual(args); | ||||
if (isUsingRLInterface) | |||||
StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | while (g_Shutdown == ShutdownType::None) | ||||
Done Inline ActionsIt's better to add braces to the while. vladislavbelov: It's better to add braces to the `while`. | |||||
{ | |||||
if (isUsingRLInterface) | |||||
g_RLInterface->TryApplyMessage(); | |||||
Done Inline ActionsWhat's about the visual case? vladislavbelov: What's about the visual case? | |||||
Done Inline ActionsIn the visual case, the game messages are applied in the Frame function similar to when the game simulation step is called when running w/o --rl-interface (should be line 397) irishninja: In the visual case, the game messages are applied in the `Frame` function similar to when the… | |||||
else | |||||
NonVisualFrame(); | NonVisualFrame(); | ||||
} | } | ||||
} | |||||
else | else | ||||
{ | { | ||||
InitGraphics(args, 0, installedMods); | InitGraphics(args, 0, installedMods); | ||||
MainControllerInit(); | MainControllerInit(); | ||||
if (isUsingRLInterface) | |||||
StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | while (g_Shutdown == ShutdownType::None) | ||||
Frame(); | Frame(); | ||||
} | } | ||||
// Do not install mods again in case of restart (typically from the mod selector) | // Do not install mods again in case of restart (typically from the mod selector) | ||||
modsToInstall.clear(); | modsToInstall.clear(); | ||||
Shutdown(0); | Shutdown(0); | ||||
MainControllerShutdown(); | MainControllerShutdown(); | ||||
flags &= ~INIT_MODS; | flags &= ~INIT_MODS; | ||||
} while (g_Shutdown == ShutdownType::Restart); | } while (g_Shutdown == ShutdownType::Restart); | ||||
Done Inline ActionsUsing pure pointers isn't safe, are you sure that it can't be replaced by std::unique_ptr for example? vladislavbelov: Using pure pointers isn't safe, are you sure that it can't be replaced by `std::unique_ptr` for… | |||||
#if OS_MACOSX | #if OS_MACOSX | ||||
if (g_Shutdown == ShutdownType::RestartAsAtlas) | if (g_Shutdown == ShutdownType::RestartAsAtlas) | ||||
startNewAtlasProcess(); | startNewAtlasProcess(); | ||||
#else | #else | ||||
if (g_Shutdown == ShutdownType::RestartAsAtlas) | if (g_Shutdown == ShutdownType::RestartAsAtlas) | ||||
ATLAS_RunIfOnCmdLine(args, true); | ATLAS_RunIfOnCmdLine(args, true); | ||||
#endif | #endif | ||||
Show All 39 Lines |
Wildfire Games · Phabricator
g_RLInterface = std::make_unique<RL::Interface>(server_address.c_str());, since we have C++17.