diff --git a/src/openrct2-dll/openrct2-dll.cpp b/src/openrct2-dll/openrct2-dll.cpp index b74e5af904..c9ba4c1f6d 100644 --- a/src/openrct2-dll/openrct2-dll.cpp +++ b/src/openrct2-dll/openrct2-dll.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include using namespace OpenRCT2; @@ -37,25 +38,6 @@ 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); diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index fa403c25db..c32f05b726 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -14,13 +14,12 @@ *****************************************************************************/ #pragma endregion -#ifndef _MSC_VER - #include #include #include #include #include "audio/AudioContext.h" +#include "Ui.h" #include "UiContext.h" using namespace OpenRCT2; @@ -30,7 +29,11 @@ using namespace OpenRCT2::Ui; /** * Main entry point for non-Windows sytems. Windows instead uses its own DLL proxy. */ +#ifdef _MSC_VER +int NormalisedMain(int argc, char * * argv) +#else int main(int argc, char * * argv) +#endif { core_init(); int runGame = cmdline_run((const char * *)argv, argc); @@ -38,7 +41,7 @@ int main(int argc, char * * argv) { // Run OpenRCT2 with a UI context IAudioContext * audioContext = CreateAudioContext(); - IUiContext * uiContext = CreateUiContext(); + IUiContext * uiContext = gOpenRCT2Headless ? CreateDummyUiContext() : CreateUiContext(); IContext * context = CreateContext(audioContext, uiContext); context->RunOpenRCT2(argc, argv); @@ -49,5 +52,3 @@ int main(int argc, char * * argv) } return gExitCode; } - -#endif diff --git a/src/openrct2-ui/Ui.h b/src/openrct2-ui/Ui.h new file mode 100644 index 0000000000..a4ecd9f9c7 --- /dev/null +++ b/src/openrct2-ui/Ui.h @@ -0,0 +1,19 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#ifdef _MSC_VER + int NormalisedMain(int argc, char * * argv); +#endif diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj index 37bce8edc8..9bd0b6ad68 100644 --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -64,6 +64,7 @@ + diff --git a/src/openrct2/game.c b/src/openrct2/game.c index 2a890b3392..18ad803dab 100644 --- a/src/openrct2/game.c +++ b/src/openrct2/game.c @@ -338,31 +338,34 @@ void game_update() gGameCommandNestLevel = 0; - input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false); + if (!gOpenRCT2Headless) + { + input_set_flag(INPUT_FLAG_VIEWPORT_SCROLLING, false); - // the flickering frequency is reduced by 4, compared to the original - // it was done due to inability to reproduce original frequency - // and decision that the original one looks too fast - if (gCurrentTicks % 4 == 0) - gWindowMapFlashingFlags ^= (1 << 15); + // the flickering frequency is reduced by 4, compared to the original + // it was done due to inability to reproduce original frequency + // and decision that the original one looks too fast + if (gCurrentTicks % 4 == 0) + gWindowMapFlashingFlags ^= (1 << 15); - // Handle guest map flashing - gWindowMapFlashingFlags &= ~(1 << 1); - if (gWindowMapFlashingFlags & (1 << 0)) - gWindowMapFlashingFlags |= (1 << 1); - gWindowMapFlashingFlags &= ~(1 << 0); + // Handle guest map flashing + gWindowMapFlashingFlags &= ~(1 << 1); + if (gWindowMapFlashingFlags & (1 << 0)) + gWindowMapFlashingFlags |= (1 << 1); + gWindowMapFlashingFlags &= ~(1 << 0); - // Handle staff map flashing - gWindowMapFlashingFlags &= ~(1 << 3); - if (gWindowMapFlashingFlags & (1 << 2)) - gWindowMapFlashingFlags |= (1 << 3); - gWindowMapFlashingFlags &= ~(1 << 2); + // Handle staff map flashing + gWindowMapFlashingFlags &= ~(1 << 3); + if (gWindowMapFlashingFlags & (1 << 2)) + gWindowMapFlashingFlags |= (1 << 3); + gWindowMapFlashingFlags &= ~(1 << 2); - window_map_tooltip_update_visibility(); + window_map_tooltip_update_visibility(); - // Input - gUnk141F568 = gUnk13CA740; - game_handle_input(); + // Input + gUnk141F568 = gUnk13CA740; + game_handle_input(); + } } void game_logic_update() @@ -915,8 +918,11 @@ void game_load_init() load_palette(); gfx_invalidate_screen(); - window_tile_inspector_clear_clipboard(); - window_update_all(); + + if (!gOpenRCT2Headless) { + window_tile_inspector_clear_clipboard(); + window_update_all(); + } gGameSpeed = 1; } diff --git a/src/openrct2/input.c b/src/openrct2/input.c index c3ed7e9c57..ac1e087300 100644 --- a/src/openrct2/input.c +++ b/src/openrct2/input.c @@ -1470,6 +1470,10 @@ void game_handle_keyboard_input() rct_window *w; sint32 key; + if (gOpenRCT2Headless) { + return; + } + if (!gConsoleOpen) { // Handle mouse scrolling if (_inputState == INPUT_STATE_NORMAL && gConfigGeneral.edge_scrolling) { diff --git a/src/openrct2/ui/DummyUiContext.cpp b/src/openrct2/ui/DummyUiContext.cpp new file mode 100644 index 0000000000..bc4346e015 --- /dev/null +++ b/src/openrct2/ui/DummyUiContext.cpp @@ -0,0 +1,68 @@ +#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers +/***************************************************************************** +* OpenRCT2, an open source clone of Roller Coaster Tycoon 2. +* +* OpenRCT2 is the work of many authors, a full list can be found in contributors.md +* For more information, visit https://github.com/OpenRCT2/OpenRCT2 +* +* OpenRCT2 is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* A full copy of the GNU General Public License can be found in licence.txt +*****************************************************************************/ +#pragma endregion + +#include "UiContext.h" + +namespace OpenRCT2 { namespace Ui +{ + /** + * Represents the window or screen that OpenRCT2 is presented on. + */ + class DummyUiContext final : public IUiContext + { + void CreateWindow() override { } + void CloseWindow() override { } + SDL_Window * GetWindow() override { return nullptr; } + sint32 GetWidth() override { return 0; } + sint32 GetHeight() override { return 0; } + void SetFullscreenMode(FULLSCREEN_MODE mode) override { } + std::vector GetFullscreenResolutions() override { return std::vector(); } + bool HasFocus() override { return false; } + bool IsMinimised() override { return false; } + bool IsSteamOverlayActive() override { return false; } + void ProcessMessages() override { } + void TriggerResize() override { } + + virtual void ShowMessageBox(const std::string &message) override { } + virtual std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); } + virtual std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); } + + // Input + virtual const CursorState * GetCursorState() override { return nullptr; } + virtual CURSOR_ID GetCursor() override { return CURSOR_ARROW; } + virtual void SetCursor(CURSOR_ID cursor) override { } + virtual void SetCursorVisible(bool value) override { } + virtual void GetCursorPosition(sint32 * x, sint32 * y) override { } + virtual void SetCursorPosition(sint32 x, sint32 y) override { } + virtual void SetCursorTrap(bool value) override { } + virtual const uint8 * GetKeysState() override { return nullptr; } + virtual const uint8 * GetKeysPressed() override { return nullptr; } + virtual void SetKeysPressed(uint32 keysym, uint8 scancode) override { } + + // Drawing + virtual Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override { return nullptr; } + + // Text input + virtual bool IsTextInputActive() override { return false; } + virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; } + virtual void StopTextInput() override { } + }; + + IUiContext * CreateDummyUiContext() + { + return new DummyUiContext(); + } +} } diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index ec7f60628a..aeef40d16d 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -129,5 +129,7 @@ namespace OpenRCT2 virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract; virtual void StopTextInput() abstract; }; + + IUiContext * CreateDummyUiContext(); } }