Changeset View
Standalone View
source/main.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | |||||
#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 "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" | ||||
#if WITH_RLINTERFACE | |||||
Stan: Sort it in Alphabetical order :) | |||||
#include "rlinterface/RLInterface.cpp" | |||||
#endif | |||||
#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 | ||||
#if MSC_VERSION | #if MSC_VERSION | ||||
#include <process.h> | #include <process.h> | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | static void RendererIncrementalLoad() | ||||
double startTime = timer_Time(); | double startTime = timer_Time(); | ||||
bool more; | bool more; | ||||
do { | do { | ||||
more = g_Renderer.GetTextureManager().MakeProgress(); | more = g_Renderer.GetTextureManager().MakeProgress(); | ||||
} | } | ||||
while (more && timer_Time() - startTime < maxTime); | while (more && timer_Time() - startTime < maxTime); | ||||
} | } | ||||
static void Frame() | #if WITH_RLINTERFACE | ||||
static void Frame(bool using_interface=false, RLInterface* service=nullptr) | |||||
Done Inline ActionsI guess using interface would be when service!= nullptr which would remove the extra param ? Stan: I guess using interface would be when service!= nullptr which would remove the extra param ? | |||||
#else | |||||
static void Frame(bool using_interface=false) | |||||
#endif | |||||
Done Inline ActionsMissing spaces beside = Stan: Missing spaces beside = | |||||
Done Inline ActionsEven though it's generally considered bad practice, I would suggest matching the logic of the rest of main.cpp and use a g_RLInterface. To be honest the main reason is that I'm uncomfortable with overloading Frame: this file is mostly C so I'm perturbed to see C++ ? If you follow the suggestion you can just replace if (using_interface) by if (g_RLInterface) which would match the style of the surrounding code. The only thing to keep in mind is to free the pointer manually at the end of RunRLServer. Itms: Even though it's generally considered bad practice, I would suggest matching the logic of the… | |||||
{ | { | ||||
g_Profiler2.RecordFrameStart(); | g_Profiler2.RecordFrameStart(); | ||||
Done Inline ActionsI think you can check for the pointer directly below. wraitii: I think you can check for the pointer directly below.
Spaces around `=` | |||||
PROFILE2("frame"); | PROFILE2("frame"); | ||||
g_Profiler2.IncrementFrameNumber(); | g_Profiler2.IncrementFrameNumber(); | ||||
Done Inline ActionsI'd duplicate a little more and put just one #if. wraitii: I'd duplicate a little more and put just one #if. | |||||
Done Inline ActionsI removed the compile flag and then removed the #if entirely irishninja: I removed the compile flag and then removed the `#if` entirely | |||||
PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
// get elapsed time | // get elapsed time | ||||
const double time = timer_Time(); | const double time = timer_Time(); | ||||
g_frequencyFilter->Update(time); | g_frequencyFilter->Update(time); | ||||
// .. old method - "exact" but contains jumps | // .. old method - "exact" but contains jumps | ||||
▲ Show 20 Lines • Show All 51 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 WITH_RLINTERFACE | |||||
if (using_interface) | |||||
service->ApplyEvents(); | |||||
#endif | |||||
if (g_Game && g_Game->IsGameStarted() && need_update) | if (g_Game && g_Game->IsGameStarted() && need_update) | ||||
{ | { | ||||
if (!using_interface) | |||||
g_Game->Update(realTimeSinceLastFrame); | g_Game->Update(realTimeSinceLastFrame); | ||||
Done Inline ActionsAs above, I'd duplicate a little more and put juste one #if wraitii: As above, I'd duplicate a little more and put juste one #if | |||||
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(); | ||||
// Keep us connected to any XMPP servers | // Keep us connected to any XMPP servers | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static void MainControllerInit() | ||||
// must be registered after gui_handler. Should mayhap even be last. | // must be registered after gui_handler. Should mayhap even be last. | ||||
in_add_handler(MainInputHandler); | in_add_handler(MainInputHandler); | ||||
} | } | ||||
static void MainControllerShutdown() | static void MainControllerShutdown() | ||||
{ | { | ||||
in_reset_handlers(); | in_reset_handlers(); | ||||
} | } | ||||
Done Inline ActionsYou might want to make that config option :) Stan: You might want to make that config option :) | |||||
Done Inline ActionsSo far, I have made it configurable via the command line (like --rpc-server=0.0.0.0:50050). Is that what you meant or did you have something else in mind? irishninja: So far, I have made it configurable via the command line (like `--rpc-server=0.0.0.0:50050`). | |||||
Done Inline ActionsI had something else in mind. All the default options are in a config file called default.cfg in the binaries/data/config folder. See this example for loading the variable in js code and adding an option in the game menu https://code.wildfiregames.com/D2176 Here is an example (likely not the best) for doing it in cpp https://code.wildfiregames.com/D1217 Stan: I had something else in mind. All the default options are in a config file called default.cfg… | |||||
#if WITH_RLINTERFACE | |||||
static std::unique_ptr<RLInterface> StartRLInterface(CmdLineArgs args) | |||||
Done Inline ActionsI have to remove these curly braces to match the coding conventions (note to self). I am used to a different style guide :) irishninja: I have to remove these curly braces to match the coding conventions (note to self). I am used… | |||||
{ | |||||
Done Inline ActionsDo you need it to be a std::string? I'm not sure whether we shouldn't use Cstr instead Stan: Do you need it to be a std::string? I'm not sure whether we shouldn't use Cstr instead | |||||
std::cout << "Starting RL Interface..." << std::endl; | |||||
Done Inline ActionsShould use debug_printf like other calls in that file :) Stan: Should use debug_printf like other calls in that file :) | |||||
std::string server_address; | |||||
CFG_GET_VAL("rlinterface.address", server_address); | |||||
if (!args.Get("rpc-server").empty()) | |||||
server_address = args.Get("rpc-server"); | |||||
std::unique_ptr<RLInterface> service(new RLInterface); | |||||
service.get()->Listen(server_address); | |||||
return service; | |||||
} | |||||
#endif | |||||
Done Inline ActionsCan the other params be made const? Stan: Can the other params be made const? | |||||
// 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. | ||||
Done Inline ActionsCan you explain why we need such a loop? Code below uses if Stan: Can you explain why we need such a loop? Code below uses if | |||||
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")) | ||||
{ | { | ||||
Done Inline ActionsI wonder if we need to support installing mods and launching the rl interface at the same time. I guess we do. Stan: I wonder if we need to support installing mods and launching the rl interface at the same time. | |||||
debug_printf("Pyrogenesis %s\n", engine_version); | debug_printf("Pyrogenesis %s\n", engine_version); | ||||
return; | return; | ||||
} | } | ||||
#if WITH_RLINTERFACE | |||||
if (args.Has("autostart-nonvisual") && args.Get("autostart").empty() && !args.Has("rpc-server")) | |||||
#else | |||||
if (args.Has("autostart-nonvisual") && args.Get("autostart").empty()) | if (args.Has("autostart-nonvisual") && args.Get("autostart").empty()) | ||||
#endif | |||||
Not Done Inline ActionsShouldn't this line be outside the conditional, after the installation? Itms: Shouldn't this line be outside the conditional, after the installation? | |||||
Done Inline ActionsThis is actually based on https://github.com/0ad/0ad/blob/master/source/main.cpp#L617-L627 but I can certainly change it, if you would like. irishninja: This is actually based on https://github.com/0ad/0ad/blob/master/source/main.cpp#L617-L627 but… | |||||
Not Done Inline ActionsOh I'm sorry I read too fast, I thought it was the activated mods or something. In this case installedMods is not used in your code. you don't need to call GetInstalledMods and you don't need the vector itself, unless you decide to print a log message listing the installed mods. Itms: Oh I'm sorry I read too fast, I thought it was the activated mods or something.
In this case… | |||||
Done Inline ActionsI believe it is used on line 517 with the call to InitGraphics (basically copied from the RunGameOrAtlas function). Should I remove it? irishninja: I believe it is used on line 517 with the call to `InitGraphics` (basically copied from the… | |||||
Done Inline Actionsahhh sorry I can't read :) looks good to me then! Itms: ahhh sorry I can't read :) looks good to me then! | |||||
{ | { | ||||
Not Done Inline ActionsThis seems un-necessary? wraitii: This seems un-necessary? | |||||
Done Inline ActionsThis is required for running headless and not specifying an initial map (as this is configured by the agent itself). irishninja: This is required for running headless and not specifying an initial map (as this is configured… | |||||
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()); | ||||
Done Inline Actionsno braces Itms: no braces | |||||
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 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)) | ||||
Done Inline Actionsno braces Itms: no braces | |||||
{ | { | ||||
debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.string8().c_str()); | debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.string8().c_str()); | ||||
return; | return; | ||||
} | } | ||||
if (DirectoryExists(replayFile)) | if (DirectoryExists(replayFile)) | ||||
{ | { | ||||
debug_printf("ERROR: The requested replay file '%s' is a directory!\n", replayFile.string8().c_str()); | debug_printf("ERROR: The requested replay file '%s' is a directory!\n", replayFile.string8().c_str()); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 88 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); | ||||
// run the game | // run the game | ||||
Done Inline Actions{ on newline Stan: { on newline | |||||
int flags = INIT_MODS; | int flags = INIT_MODS; | ||||
Done Inline ActionsMaybe you could display a nice error message as well ? Something along the lines of "rpc-server is not available" I believe there is a similar message for atlas. Stan: Maybe you could display a nice error message as well ?
Something along the lines of "rpc… | |||||
Done Inline ActionsNuke Stan: Nuke | |||||
#if WITH_RLINTERFACE | |||||
if (args.Has("rpc-server")) { | |||||
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); | |||||
std::unique_ptr<RLInterface> service = StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
{ | |||||
service.get()->ApplyEvents(); | |||||
} | |||||
QuitEngine(); | |||||
} | |||||
else | |||||
{ | |||||
InitGraphics(args, 0, installedMods); | |||||
MainControllerInit(); | |||||
std::unique_ptr<RLInterface> service = StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
{ | |||||
Frame(true, service.get()); | |||||
} | |||||
} | |||||
Shutdown(0); | |||||
MainControllerShutdown(); | |||||
CXeromyces::Terminate(); | |||||
return; | |||||
} | |||||
#endif | |||||
do | do | ||||
{ | { | ||||
g_Shutdown = ShutdownType::None; | g_Shutdown = ShutdownType::None; | ||||
if (!Init(args, flags)) | if (!Init(args, flags)) | ||||
{ | { | ||||
flags &= ~INIT_MODS; | flags &= ~INIT_MODS; | ||||
Shutdown(SHUTDOWN_FROM_CONFIG); | Shutdown(SHUTDOWN_FROM_CONFIG); | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
Sort it in Alphabetical order :)