OpenRCT2/src/openrct2-ui/Ui.cpp

89 lines
2.6 KiB
C++
Raw Permalink Normal View History

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "Ui.h"
2018-06-22 23:22:29 +02:00
#include "SDLException.h"
#include "UiContext.h"
2018-06-22 23:22:29 +02:00
#include "audio/AudioContext.h"
#include "drawing/BitmapReader.h"
2022-07-29 18:45:10 +02:00
#include <memory>
2018-06-22 23:22:29 +02:00
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/command_line/CommandLine.hpp>
#include <openrct2/platform/Platform.h>
2018-06-22 23:22:29 +02:00
#include <openrct2/ui/UiContext.h>
using namespace OpenRCT2;
2017-05-06 23:48:55 +02:00
using namespace OpenRCT2::Audio;
using namespace OpenRCT2::Ui;
template<typename T> static std::shared_ptr<T> ToShared(std::unique_ptr<T>&& src)
{
return std::shared_ptr<T>(std::move(src));
}
/**
2017-10-03 00:00:32 +02:00
* Main entry point for non-Windows systems. Windows instead uses its own DLL proxy.
*/
#if defined(_MSC_VER) && !defined(__DISABLE_DLL_PROXY__)
2018-06-22 23:22:29 +02:00
int NormalisedMain(int argc, const char** argv)
#else
2018-06-22 23:22:29 +02:00
int main(int argc, const char** argv)
#endif
{
2019-10-05 18:57:07 +02:00
std::unique_ptr<IContext> context;
int32_t rc = EXIT_SUCCESS;
int runGame = CommandLineRun(argv, argc);
2018-05-09 00:39:03 +02:00
RegisterBitmapReader();
2020-01-19 22:48:50 +01:00
if (runGame == EXITCODE_CONTINUE)
{
if (gOpenRCT2Headless)
{
// Run OpenRCT2 with a plain context
2019-10-05 18:57:07 +02:00
context = CreateContext();
}
else
{
// Run OpenRCT2 with a UI context
auto env = ToShared(CreatePlatformEnvironment());
std::shared_ptr<IAudioContext> audioContext;
try
{
audioContext = ToShared(CreateAudioContext());
}
catch (const SDLException& e)
{
LOG_WARNING("Failed to create audio context. Using dummy audio context. Error message was: %s", e.what());
audioContext = ToShared(CreateDummyAudioContext());
}
auto uiContext = ToShared(CreateUiContext(env));
2019-10-05 18:57:07 +02:00
context = CreateContext(env, audioContext, uiContext);
}
rc = context->RunOpenRCT2(argc, argv);
}
2020-01-19 22:48:50 +01:00
else if (runGame == EXITCODE_FAIL)
{
rc = EXIT_FAILURE;
}
return rc;
}
2017-06-15 14:22:15 +02:00
#ifdef __ANDROID__
extern "C" {
2018-06-22 23:22:29 +02:00
int SDL_main(int argc, const char* argv[])
2017-06-15 14:22:15 +02:00
{
return main(argc, argv);
}
}
#endif