diff --git a/src/openrct2-cli/Cli.cpp b/src/openrct2-cli/Cli.cpp index a063be9185..6491a2d2b7 100644 --- a/src/openrct2-cli/Cli.cpp +++ b/src/openrct2-cli/Cli.cpp @@ -9,6 +9,7 @@ #include #include +#include #include using namespace OpenRCT2; @@ -18,16 +19,21 @@ using namespace OpenRCT2; */ int main(int argc, const char** argv) { + int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); core_init(); - if (runGame == 1) + if (runGame == EXITCODE_CONTINUE) { gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; // Run OpenRCT2 with a plain context auto context = CreateContext(); - context->RunOpenRCT2(argc, argv); + rc = context->RunOpenRCT2(argc, argv); } - return gExitCode; + else if (runGame == EXITCODE_FAIL) + { + rc = EXIT_FAILURE; + } + return rc; } diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index 22ebaeada3..ebd5bf2478 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -38,16 +39,17 @@ int NormalisedMain(int argc, const char** argv) int main(int argc, const char** argv) #endif { + std::unique_ptr context; + int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); core_init(); RegisterBitmapReader(); - if (runGame == 1) + if (runGame == EXITCODE_CONTINUE) { if (gOpenRCT2Headless) { // Run OpenRCT2 with a plain context - auto context = CreateContext(); - context->RunOpenRCT2(argc, argv); + context = CreateContext(); } else { @@ -55,12 +57,15 @@ int main(int argc, const char** argv) auto env = to_shared(CreatePlatformEnvironment()); auto audioContext = to_shared(CreateAudioContext()); auto uiContext = to_shared(CreateUiContext(env)); - auto context = CreateContext(env, audioContext, uiContext); - - context->RunOpenRCT2(argc, argv); + context = CreateContext(env, audioContext, uiContext); } + rc = context->RunOpenRCT2(argc, argv); } - return gExitCode; + else if (runGame == EXITCODE_FAIL) + { + rc = EXIT_FAILURE; + } + return rc; } #ifdef __ANDROID__ diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 987a4a7249..34acc7788d 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -243,8 +243,9 @@ namespace OpenRCT2 if (Initialise()) { Launch(); + return EXIT_SUCCESS; } - return gExitCode; + return EXIT_FAILURE; } void WriteLine(const std::string& s) override diff --git a/src/openrct2/OpenRCT2.cpp b/src/openrct2/OpenRCT2.cpp index 30dd4abcae..a6212ef2e3 100644 --- a/src/openrct2/OpenRCT2.cpp +++ b/src/openrct2/OpenRCT2.cpp @@ -9,7 +9,6 @@ #include "OpenRCT2.h" -int32_t gExitCode; int32_t gOpenRCT2StartupAction = STARTUP_ACTION_TITLE; utf8 gOpenRCT2StartupActionPath[512] = { 0 }; utf8 gExePath[MAX_PATH]; diff --git a/src/openrct2/OpenRCT2.h b/src/openrct2/OpenRCT2.h index ac57ac4e17..fea147ec55 100644 --- a/src/openrct2/OpenRCT2.h +++ b/src/openrct2/OpenRCT2.h @@ -34,9 +34,6 @@ enum SCREEN_FLAGS_EDITOR = (SCREEN_FLAGS_SCENARIO_EDITOR | SCREEN_FLAGS_TRACK_DESIGNER | SCREEN_FLAGS_TRACK_MANAGER), }; -/** The exit code for OpenRCT2 when it exits. */ -extern int32_t gExitCode; - extern int32_t gOpenRCT2StartupAction; extern utf8 gOpenRCT2StartupActionPath[512]; extern utf8 gExePath[MAX_PATH];