2017-03-24 18:29:45 +01:00
|
|
|
/*****************************************************************************
|
2023-01-01 11:58:01 +01:00
|
|
|
* Copyright (c) 2014-2023 OpenRCT2 developers
|
2018-06-15 14:07:34 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2017-03-24 18:29:45 +01:00
|
|
|
|
2017-06-02 20:08:03 +02:00
|
|
|
#include "Ui.h"
|
2018-06-22 23:22:29 +02:00
|
|
|
|
2020-08-25 04:35:59 +02:00
|
|
|
#include "SDLException.h"
|
2017-03-24 18:29:45 +01:00
|
|
|
#include "UiContext.h"
|
2018-06-22 23:22:29 +02:00
|
|
|
#include "audio/AudioContext.h"
|
|
|
|
#include "drawing/BitmapReader.h"
|
2017-03-24 18:29:45 +01:00
|
|
|
|
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>
|
2020-01-19 22:48:50 +01:00
|
|
|
#include <openrct2/cmdline/CommandLine.hpp>
|
2022-02-18 21:57:00 +01:00
|
|
|
#include <openrct2/platform/Platform.h>
|
2018-06-22 23:22:29 +02:00
|
|
|
#include <openrct2/ui/UiContext.h>
|
2017-06-25 19:49:04 +02:00
|
|
|
|
2017-03-24 18:29:45 +01:00
|
|
|
using namespace OpenRCT2;
|
2017-05-06 23:48:55 +02:00
|
|
|
using namespace OpenRCT2::Audio;
|
2017-03-24 18:29:45 +01:00
|
|
|
using namespace OpenRCT2::Ui;
|
|
|
|
|
2021-11-23 14:18:07 +01:00
|
|
|
template<typename T> static std::shared_ptr<T> ToShared(std::unique_ptr<T>&& src)
|
2018-04-20 20:58:59 +02:00
|
|
|
{
|
|
|
|
return std::shared_ptr<T>(std::move(src));
|
|
|
|
}
|
|
|
|
|
2017-03-24 18:29:45 +01:00
|
|
|
/**
|
2017-10-03 00:00:32 +02:00
|
|
|
* Main entry point for non-Windows systems. Windows instead uses its own DLL proxy.
|
2017-03-24 18:29:45 +01:00
|
|
|
*/
|
2018-04-13 00:07:18 +02:00
|
|
|
#if defined(_MSC_VER) && !defined(__DISABLE_DLL_PROXY__)
|
2018-06-22 23:22:29 +02:00
|
|
|
int NormalisedMain(int argc, const char** argv)
|
2017-06-02 20:08:03 +02:00
|
|
|
#else
|
2018-06-22 23:22:29 +02:00
|
|
|
int main(int argc, const char** argv)
|
2017-06-02 20:08:03 +02:00
|
|
|
#endif
|
2017-03-24 18:29:45 +01:00
|
|
|
{
|
2019-10-05 18:57:07 +02:00
|
|
|
std::unique_ptr<IContext> context;
|
2019-10-05 21:26:55 +02:00
|
|
|
int32_t rc = EXIT_SUCCESS;
|
2018-01-01 23:51:43 +01:00
|
|
|
int runGame = cmdline_run(argv, argc);
|
2022-02-18 21:57:00 +01:00
|
|
|
Platform::CoreInit();
|
2018-05-09 00:39:03 +02:00
|
|
|
RegisterBitmapReader();
|
2020-01-19 22:48:50 +01:00
|
|
|
if (runGame == EXITCODE_CONTINUE)
|
2017-05-08 22:36:35 +02:00
|
|
|
{
|
2017-06-04 00:10:20 +02:00
|
|
|
if (gOpenRCT2Headless)
|
|
|
|
{
|
|
|
|
// Run OpenRCT2 with a plain context
|
2019-10-05 18:57:07 +02:00
|
|
|
context = CreateContext();
|
2017-06-04 00:10:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Run OpenRCT2 with a UI context
|
2021-11-23 14:18:07 +01:00
|
|
|
auto env = ToShared(CreatePlatformEnvironment());
|
2020-08-25 04:35:59 +02:00
|
|
|
std::shared_ptr<IAudioContext> audioContext;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
audioContext = ToShared(CreateAudioContext());
|
|
|
|
}
|
2021-10-09 19:08:06 +02:00
|
|
|
catch (const SDLException& e)
|
2020-08-25 04:35:59 +02:00
|
|
|
{
|
2021-10-09 19:08:06 +02:00
|
|
|
log_warning("Failed to create audio context. Using dummy audio context. Error message was: %s", e.what());
|
2020-08-25 04:35:59 +02:00
|
|
|
audioContext = ToShared(CreateDummyAudioContext());
|
|
|
|
}
|
2021-11-23 14:18:07 +01:00
|
|
|
auto uiContext = ToShared(CreateUiContext(env));
|
2019-10-05 18:57:07 +02:00
|
|
|
context = CreateContext(env, audioContext, uiContext);
|
|
|
|
}
|
2019-10-05 21:26:55 +02:00
|
|
|
rc = context->RunOpenRCT2(argc, argv);
|
|
|
|
}
|
2020-01-19 22:48:50 +01:00
|
|
|
else if (runGame == EXITCODE_FAIL)
|
2019-10-05 21:26:55 +02:00
|
|
|
{
|
|
|
|
rc = EXIT_FAILURE;
|
2017-05-08 22:36:35 +02:00
|
|
|
}
|
2019-10-05 21:26:55 +02:00
|
|
|
return rc;
|
2017-03-24 18:29:45 +01:00
|
|
|
}
|
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
|