mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
Fix #5537: SDL_Init(SDL_INIT_VIDEO) is called even when using --headless option
Create a dummy UI context and use that if headless is enabled. Some extra guards added to deal with the return values from the dummy class. It may be temporary until the window and input code is moved to openrct2ui.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#include <openrct2-ui/audio/AudioContext.h>
|
||||
#include <openrct2-ui/Ui.h>
|
||||
#include <openrct2-ui/UiContext.h>
|
||||
|
||||
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);
|
||||
|
||||
@@ -14,13 +14,12 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
#include <openrct2/audio/AudioContext.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/ui/UiContext.h>
|
||||
#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
|
||||
|
||||
19
src/openrct2-ui/Ui.h
Normal file
19
src/openrct2-ui/Ui.h
Normal file
@@ -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
|
||||
@@ -64,6 +64,7 @@
|
||||
<ClInclude Include="drawing\engines\opengl\TextureCache.h" />
|
||||
<ClInclude Include="SDLException.h" />
|
||||
<ClInclude Include="TextComposition.h" />
|
||||
<ClInclude Include="Ui.h" />
|
||||
<ClInclude Include="UiContext.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
68
src/openrct2/ui/DummyUiContext.cpp
Normal file
68
src/openrct2/ui/DummyUiContext.cpp
Normal file
@@ -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<Resolution> GetFullscreenResolutions() override { return std::vector<Resolution>(); }
|
||||
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();
|
||||
}
|
||||
} }
|
||||
@@ -129,5 +129,7 @@ namespace OpenRCT2
|
||||
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract;
|
||||
virtual void StopTextInput() abstract;
|
||||
};
|
||||
|
||||
IUiContext * CreateDummyUiContext();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user