1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #include "Ui.h"
11 
12 #include "UiContext.h"
13 #include "audio/AudioContext.h"
14 #include "drawing/BitmapReader.h"
15 
16 #include <openrct2/Context.h>
17 #include <openrct2/OpenRCT2.h>
18 #include <openrct2/PlatformEnvironment.h>
19 #include <openrct2/audio/AudioContext.h>
20 #include <openrct2/cmdline/CommandLine.hpp>
21 #include <openrct2/platform/platform.h>
22 #include <openrct2/ui/UiContext.h>
23 
24 using namespace OpenRCT2;
25 using namespace OpenRCT2::Audio;
26 using namespace OpenRCT2::Ui;
27 
to_shared(std::unique_ptr<T> && src)28 template<typename T> static std::shared_ptr<T> to_shared(std::unique_ptr<T>&& src)
29 {
30     return std::shared_ptr<T>(std::move(src));
31 }
32 
33 /**
34  * Main entry point for non-Windows systems. Windows instead uses its own DLL proxy.
35  */
36 #if defined(_MSC_VER) && !defined(__DISABLE_DLL_PROXY__)
NormalisedMain(int argc,const char ** argv)37 int NormalisedMain(int argc, const char** argv)
38 #else
39 int main(int argc, const char** argv)
40 #endif
41 {
42     std::unique_ptr<IContext> context;
43     int32_t rc = EXIT_SUCCESS;
44     int runGame = cmdline_run(argv, argc);
45     core_init();
46     RegisterBitmapReader();
47     if (runGame == EXITCODE_CONTINUE)
48     {
49         if (gOpenRCT2Headless)
50         {
51             // Run OpenRCT2 with a plain context
52             context = CreateContext();
53         }
54         else
55         {
56             // Run OpenRCT2 with a UI context
57             auto env = to_shared(CreatePlatformEnvironment());
58             auto audioContext = to_shared(CreateAudioContext());
59             auto uiContext = to_shared(CreateUiContext(env));
60             context = CreateContext(env, audioContext, uiContext);
61         }
62         rc = context->RunOpenRCT2(argc, argv);
63     }
64     else if (runGame == EXITCODE_FAIL)
65     {
66         rc = EXIT_FAILURE;
67     }
68     return rc;
69 }
70 
71 #ifdef __ANDROID__
72 extern "C" {
SDL_main(int argc,const char * argv[])73 int SDL_main(int argc, const char* argv[])
74 {
75     return main(argc, argv);
76 }
77 }
78 #endif
79