From f1a8b32db403853f25b06999bba766c63025e4f8 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 8 May 2017 21:36:35 +0100 Subject: [PATCH] Prevent SDL_INIT when the game does not need to launch --- src/openrct2-dll/openrct2-dll.cpp | 29 ++++++++++++++++++++--------- src/openrct2-ui/Ui.cpp | 26 +++++++++++++++++--------- src/openrct2/Context.cpp | 9 ++------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/openrct2-dll/openrct2-dll.cpp b/src/openrct2-dll/openrct2-dll.cpp index 162e47d9c5..26d67061ad 100644 --- a/src/openrct2-dll/openrct2-dll.cpp +++ b/src/openrct2-dll/openrct2-dll.cpp @@ -37,6 +37,25 @@ static char * * GetCommandLineArgs(int argc, wchar_t * * argvW); static void FreeCommandLineArgs(int argc, char * * argv); static char * ConvertUTF16toUTF8(const wchar_t * src); +static int NormalisedMain(int argc, char * * argv) +{ + core_init(); + int runGame = cmdline_run((const char * *)argv, argc); + if (runGame == 1) + { + IAudioContext * audioContext = CreateAudioContext(); + IUiContext * uiContext = CreateUiContext(); + IContext * context = CreateContext(audioContext, uiContext); + + context->RunOpenRCT2(argc, argv); + + delete context; + delete uiContext; + delete audioContext; + } + return gExitCode; +} + DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t * * argvW) { char * * argv = GetCommandLineArgs(argc, argvW); @@ -46,15 +65,7 @@ DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t * * argvW) return -1; } - IAudioContext * audioContext = CreateAudioContext(); - IUiContext * uiContext = CreateUiContext(); - IContext * context = CreateContext(audioContext, uiContext); - - int exitCode = context->RunOpenRCT2(argc, argv); - - delete context; - delete uiContext; - delete audioContext; + int exitCode = NormalisedMain(argc, argv); FreeCommandLineArgs(argc, argv); return exitCode; diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index f8939fe0ef..5276f4c04d 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include "audio/AudioContext.h" #include "UiContext.h" @@ -31,15 +32,22 @@ using namespace OpenRCT2::Ui; */ int main(int argc, char * * argv) { - // Run OpenRCT2 with a UI context - - IAudioContext * audioContext = CreateAudioContext(); - IUiContext * uiContext = CreateUiContext(); - IContext * context = CreateContext(audioContext, uiContext); - int exitCode = context->RunOpenRCT2(argc, argv); - delete uiContext; - delete context; - return exitCode; + core_init(); + int runGame = cmdline_run((const char * *)argv, argc); + if (runGame == 1) + { + // Run OpenRCT2 with a UI context + IAudioContext * audioContext = CreateAudioContext(); + IUiContext * uiContext = CreateUiContext(); + IContext * context = CreateContext(audioContext, uiContext); + + context->RunOpenRCT2(argc, argv); + + delete context; + delete uiContext; + delete audioContext; + } + return gExitCode; } #endif diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index c7f22b6c84..a53270e67f 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -124,13 +124,8 @@ namespace OpenRCT2 sint32 RunOpenRCT2(int argc, char * * argv) override { - core_init(); - int runGame = cmdline_run((const char * *)argv, argc); - if (runGame == 1) - { - Initialise(); - Launch(); - } + Initialise(); + Launch(); return gExitCode; }