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); | ||||
} | } | ||||
#if WITH_RLINTERFACE | |||||
static void Frame(RLInterface* service=nullptr) | |||||
#else | |||||
static void Frame() | static void Frame() | ||||
#endif | |||||
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 ? | |||||
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… | |||||
{ | { | ||||
#if WITH_RLINTERFACE | |||||
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 `=` | |||||
bool using_interface = service != nullptr; | |||||
#endif | |||||
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 | |||||
g_Profiler2.RecordFrameStart(); | g_Profiler2.RecordFrameStart(); | ||||
PROFILE2("frame"); | PROFILE2("frame"); | ||||
g_Profiler2.IncrementFrameNumber(); | g_Profiler2.IncrementFrameNumber(); | ||||
PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | PROFILE2_ATTR("%d", g_Profiler2.GetFrameNumber()); | ||||
ogl_WarnIfError(); | ogl_WarnIfError(); | ||||
// get elapsed time | // get elapsed time | ||||
▲ Show 20 Lines • Show All 54 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 WITH_RLINTERFACE | |||||
if (!using_interface) | |||||
#endif | |||||
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->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 47 Lines • ▼ Show 20 Lines | |||||
static void MainControllerInit() | static void MainControllerInit() | ||||
{ | { | ||||
// add additional input handlers only needed by this controller: | // add additional input handlers only needed by this controller: | ||||
// 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); | ||||
} | } | ||||
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… | |||||
static void MainControllerShutdown() | static void MainControllerShutdown() | ||||
{ | { | ||||
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… | |||||
in_reset_handlers(); | in_reset_handlers(); | ||||
} | } | ||||
#if WITH_RLINTERFACE | |||||
static std::unique_ptr<RLInterface> StartRLInterface(CmdLineArgs args) | |||||
{ | |||||
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::string server_address; | |||||
Done Inline ActionsShould use debug_printf like other calls in that file :) Stan: Should use debug_printf like other calls in that file :) | |||||
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); | |||||
debug_printf("RL interface listening on %s\n", server_address.c_str()); | |||||
return service; | |||||
} | |||||
Done Inline ActionsCan the other params be made const? Stan: Can the other params be made const? | |||||
static void RunRLServer(const bool isNonVisual, std::vector<OsPath> modsToInstall, CmdLineArgs args) | |||||
{ | |||||
int flags = INIT_MODS; | |||||
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 | |||||
while (!Init(args, flags)) | |||||
{ | |||||
flags &= ~INIT_MODS; | |||||
Shutdown(SHUTDOWN_FROM_CONFIG); | |||||
} | |||||
g_Shutdown = ShutdownType::None; | |||||
std::vector<CStr> installedMods; | |||||
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. | |||||
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); | |||||
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! | |||||
installedMods = installer.GetInstalledMods(); | |||||
} | |||||
if (isNonVisual) | |||||
{ | |||||
InitNonVisual(args); | |||||
std::unique_ptr<RLInterface> service = StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
Done Inline Actionsno braces Itms: no braces | |||||
{ | |||||
service.get()->ApplyEvents(); | |||||
} | |||||
QuitEngine(); | |||||
} | |||||
else | |||||
{ | |||||
InitGraphics(args, 0, installedMods); | |||||
MainControllerInit(); | |||||
std::unique_ptr<RLInterface> service = StartRLInterface(args); | |||||
while (g_Shutdown == ShutdownType::None) | |||||
Done Inline Actionsno braces Itms: no braces | |||||
{ | |||||
Frame(service.get()); | |||||
} | |||||
} | |||||
Shutdown(0); | |||||
MainControllerShutdown(); | |||||
CXeromyces::Terminate(); | |||||
} | |||||
#endif | |||||
// 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 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 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()); | ||||
const bool isVisualReplay = args.Has("replay-visual"); | const bool isVisualReplay = args.Has("replay-visual"); | ||||
▲ Show 20 Lines • Show All 106 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 WITH_RLINTERFACE | |||||
Done Inline Actions{ on newline Stan: { on newline | |||||
if (args.Has("rpc-server")) { | |||||
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… | |||||
RunRLServer(isNonVisual, modsToInstall, args); | |||||
return; | |||||
} | |||||
#endif | |||||
// run the game | // run the game | ||||
int flags = INIT_MODS; | int flags = INIT_MODS; | ||||
Done Inline ActionsNuke Stan: Nuke | |||||
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 :)