Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/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 "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 296 Lines • ▼ Show 20 Lines | if (g_NetClient) | ||||
g_NetClient->Poll(); | g_NetClient->Poll(); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
g_GUI->TickObjects(); | g_GUI->TickObjects(); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
if (g_RLInterface) | |||||
g_RLInterface->TryApplyMessage(); | |||||
if (g_Game && g_Game->IsGameStarted() && need_update) | if (g_Game && g_Game->IsGameStarted() && need_update) | ||||
{ | { | ||||
if (!g_RLInterface) | |||||
g_Game->Update(realTimeSinceLastFrame); | g_Game->Update(realTimeSinceLastFrame); | ||||
g_Game->GetView()->Update(float(realTimeSinceLastFrame)); | g_Game->GetView()->Update(float(realTimeSinceLastFrame)); | ||||
} | } | ||||
// Immediately flush any messages produced by simulation code | // Immediately flush any messages produced by simulation code | ||||
if (g_NetClient) | if (g_NetClient) | ||||
g_NetClient->Flush(); | g_NetClient->Flush(); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | static void MainControllerInit() | ||||
in_add_handler(MainInputHandler); | in_add_handler(MainInputHandler); | ||||
} | } | ||||
static void MainControllerShutdown() | static void MainControllerShutdown() | ||||
{ | { | ||||
in_reset_handlers(); | in_reset_handlers(); | ||||
} | } | ||||
static void StartRLInterface(CmdLineArgs args) | |||||
{ | |||||
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 = new RLInterface(); | |||||
g_RLInterface->EnableHTTP(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; | ||||
if (args.Has("version")) | if (args.Has("version")) | ||||
{ | { | ||||
debug_printf("Pyrogenesis %s\n", engine_version); | debug_printf("Pyrogenesis %s\n", engine_version); | ||||
return; | return; | ||||
} | } | ||||
if (args.Has("autostart-nonvisual") && args.Get("autostart").empty()) | if (args.Has("autostart-nonvisual") && args.Get("autostart").empty() && !args.Has("rl-interface")) | ||||
{ | { | ||||
LOGERROR("-autostart-nonvisual cant be used alone. A map with -autostart=\"TYPEDIR/MAPNAME\" is needed."); | LOGERROR("-autostart-nonvisual cant be used alone. A map with -autostart=\"TYPEDIR/MAPNAME\" is needed."); | ||||
return; | return; | ||||
} | } | ||||
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()); | ||||
▲ Show 20 Lines • Show All 107 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 20 Lines • Show All 82 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator