From 5edc5617152bf360015120dfd6eaf7595b19d6ee Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Fri, 18 Feb 2022 21:57:00 +0100 Subject: [PATCH] Close #11437: Migrate old platform methods --- src/openrct2-cli/Cli.cpp | 4 +- src/openrct2-ui/Ui.cpp | 4 +- src/openrct2-ui/UiContext.Android.cpp | 2 +- src/openrct2-ui/UiContext.Linux.cpp | 2 +- src/openrct2-ui/UiContext.cpp | 2 +- src/openrct2-ui/input/MouseInput.cpp | 2 +- src/openrct2-ui/input/Shortcuts.cpp | 4 +- src/openrct2-ui/windows/Changelog.cpp | 2 +- .../windows/EditorObjectSelection.cpp | 2 +- src/openrct2-ui/windows/Footpath.cpp | 4 +- src/openrct2-ui/windows/InstallTrack.cpp | 4 +- src/openrct2-ui/windows/LoadSave.cpp | 11 +- src/openrct2-ui/windows/ObjectLoadError.cpp | 2 +- src/openrct2-ui/windows/Options.cpp | 6 +- src/openrct2-ui/windows/RideConstruction.cpp | 8 +- src/openrct2-ui/windows/ServerList.cpp | 2 +- src/openrct2/CmdlineSprite.cpp | 6 +- src/openrct2/Context.cpp | 13 +- src/openrct2/Context.h | 7 + src/openrct2/Game.cpp | 4 +- src/openrct2/GameState.cpp | 2 +- src/openrct2/PlatformEnvironment.cpp | 3 +- src/openrct2/actions/GameAction.cpp | 4 +- src/openrct2/cmdline/BenchSpriteSort.cpp | 4 +- src/openrct2/cmdline/BenchUpdate.cpp | 5 +- src/openrct2/cmdline/CommandLine.cpp | 2 +- src/openrct2/cmdline/RootCommands.cpp | 2 +- src/openrct2/cmdline/SimulateCommands.cpp | 4 +- src/openrct2/config/Config.cpp | 8 +- src/openrct2/config/IniWriter.cpp | 2 +- src/openrct2/core/Console.cpp | 2 +- src/openrct2/core/Crypt.CNG.cpp | 2 +- src/openrct2/core/File.cpp | 2 +- src/openrct2/core/Path.cpp | 5 +- src/openrct2/core/ZipAndroid.cpp | 3 +- src/openrct2/drawing/Drawing.Sprite.cpp | 2 +- src/openrct2/drawing/Drawing.String.cpp | 2 +- src/openrct2/drawing/Drawing.cpp | 30 ++- src/openrct2/drawing/Drawing.h | 3 + src/openrct2/drawing/NewDrawing.cpp | 2 +- src/openrct2/drawing/TTF.cpp | 3 +- src/openrct2/interface/Chat.cpp | 6 +- src/openrct2/interface/InteractiveConsole.cpp | 2 +- src/openrct2/interface/Screenshot.cpp | 8 +- src/openrct2/interface/StdInOutConsole.cpp | 2 +- src/openrct2/interface/Window.cpp | 2 +- src/openrct2/libopenrct2.vcxproj | 7 +- src/openrct2/localisation/Language.cpp | 2 +- src/openrct2/network/NetworkBase.cpp | 28 +-- src/openrct2/network/NetworkConnection.cpp | 8 +- .../network/NetworkServerAdvertiser.cpp | 11 +- src/openrct2/network/ServerList.cpp | 4 +- src/openrct2/object/ObjectRepository.cpp | 2 +- src/openrct2/platform/Crash.cpp | 2 +- src/openrct2/platform/Platform.Android.cpp | 3 +- src/openrct2/platform/Platform.Linux.cpp | 3 +- src/openrct2/platform/Platform.Posix.cpp | 161 +++++++++++++- src/openrct2/platform/Platform.Win32.cpp | 203 +++++++++++++++++- .../platform/{Platform2.h => Platform.h} | 68 +++++- src/openrct2/platform/Platform.macOS.mm | 4 +- src/openrct2/platform/Posix.cpp | 171 --------------- src/openrct2/platform/Shared.cpp | 157 ++------------ src/openrct2/platform/Windows.cpp | 201 ----------------- src/openrct2/platform/platform.h | 108 ---------- src/openrct2/ride/Track.cpp | 2 +- src/openrct2/ride/Vehicle.cpp | 2 +- src/openrct2/scenario/Scenario.cpp | 6 +- src/openrct2/scenario/ScenarioRepository.cpp | 8 +- src/openrct2/scripting/ScriptEngine.cpp | 4 +- src/openrct2/title/TitleSequenceManager.cpp | 2 +- src/openrct2/util/SawyerCoding.cpp | 2 +- src/openrct2/util/Util.cpp | 2 +- src/openrct2/world/MapGen.cpp | 2 +- test/tests/IniWriterTest.cpp | 2 +- test/tests/MultiLaunch.cpp | 4 +- test/tests/Pathfinding.cpp | 4 +- test/tests/Platform.cpp | 2 +- test/tests/PlayTests.cpp | 4 +- test/tests/ReplayTests.cpp | 4 +- test/tests/RideRatings.cpp | 4 +- test/tests/S6ImportExportTests.cpp | 6 +- 81 files changed, 613 insertions(+), 793 deletions(-) rename src/openrct2/platform/{Platform2.h => Platform.h} (67%) delete mode 100644 src/openrct2/platform/Posix.cpp delete mode 100644 src/openrct2/platform/Windows.cpp delete mode 100644 src/openrct2/platform/platform.h diff --git a/src/openrct2-cli/Cli.cpp b/src/openrct2-cli/Cli.cpp index 1492858ff8..394a7355f8 100644 --- a/src/openrct2-cli/Cli.cpp +++ b/src/openrct2-cli/Cli.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include using namespace OpenRCT2; @@ -21,7 +21,7 @@ int main(int argc, const char** argv) { int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); - core_init(); + Platform::CoreInit(); if (runGame == EXITCODE_CONTINUE) { gOpenRCT2Headless = true; diff --git a/src/openrct2-ui/Ui.cpp b/src/openrct2-ui/Ui.cpp index 50ad0cd8aa..64dde8124a 100644 --- a/src/openrct2-ui/Ui.cpp +++ b/src/openrct2-ui/Ui.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include using namespace OpenRCT2; @@ -42,7 +42,7 @@ int main(int argc, const char** argv) std::unique_ptr context; int32_t rc = EXIT_SUCCESS; int runGame = cmdline_run(argv, argc); - core_init(); + Platform::CoreInit(); RegisterBitmapReader(); if (runGame == EXITCODE_CONTINUE) { diff --git a/src/openrct2-ui/UiContext.Android.cpp b/src/openrct2-ui/UiContext.Android.cpp index 4ba2a368fb..24c4c22623 100644 --- a/src/openrct2-ui/UiContext.Android.cpp +++ b/src/openrct2-ui/UiContext.Android.cpp @@ -16,7 +16,7 @@ # include # include # include -# include +# include # include # include # include diff --git a/src/openrct2-ui/UiContext.Linux.cpp b/src/openrct2-ui/UiContext.Linux.cpp index 10fbe927f1..dc5aea4315 100644 --- a/src/openrct2-ui/UiContext.Linux.cpp +++ b/src/openrct2-ui/UiContext.Linux.cpp @@ -18,7 +18,7 @@ # include # include # include -# include +# include # include # include # include diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index d1bae7aa3b..84237663f3 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 46fd632d71..9cdda62427 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index 6abe903f2e..401bd826c0 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -774,7 +774,7 @@ void ShortcutManager::RegisterDefaultShortcuts() } }); - RegisterShortcut(ShortcutId::ScaleToggleWindowMode, STR_SHORTCUT_WINDOWED_MODE_TOGGLE, "ALT+RETURN", []() { platform_toggle_windowed_mode(); }); + RegisterShortcut(ShortcutId::ScaleToggleWindowMode, STR_SHORTCUT_WINDOWED_MODE_TOGGLE, "ALT+RETURN", []() { ToggleWindowedMode(); }); RegisterShortcut(ShortcutId::InterfaceScaleIncrease, STR_SHORTCUT_SCALE_UP, []() { ShortcutScaleUp(); }); RegisterShortcut(ShortcutId::InterfaceScaleDecrease, STR_SHORTCUT_SCALE_DOWN, []() { ShortcutScaleDown(); }); diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 4184f895b3..483a3d4962 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 93dd81d7da..a766157493 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index fb0779af99..3c8d0fca17 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -470,7 +470,7 @@ static void WindowFootpathUpdateProvisionalPathForBridgeMode(rct_window* w) widget_invalidate(w, WIDX_CONSTRUCT); } - auto curTime = platform_get_ticks(); + auto curTime = Platform::GetTicks(); // Update little directional arrow on provisional bridge mode path if (_footpathConstructionNextArrowPulse < curTime) diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index 842ab40607..bfa042c8a9 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -432,7 +432,7 @@ static void WindowInstallTrackDesign(rct_window* w) { auto env = OpenRCT2::GetContext()->GetPlatformEnvironment(); auto destPath = env->GetDirectoryPath(OpenRCT2::DIRBASE::USER, OpenRCT2::DIRID::TRACK); - if (!platform_ensure_directory_exists(destPath.c_str())) + if (!Platform::EnsureDirectoryExists(destPath.c_str())) { log_error("Unable to create directory '%s'", destPath.c_str()); context_show_error(STR_CANT_SAVE_TRACK_DESIGN, STR_NONE, {}); diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index cdce0b983b..2bc69b1188 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -26,8 +26,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -416,7 +415,7 @@ static u8string Browse(bool isSave) desc.Title = language_get_string(title); utf8 outPath[MAX_PATH]; - if (platform_open_common_file_dialog(outPath, desc, std::size(outPath))) + if (ContextOpenCommonFileDialog(outPath, desc, std::size(outPath))) { // When the given save type was given, Windows still interprets a filename with a dot in its name as a custom extension, // meaning files like "My Coaster v1.2" will not get the .td6 extension by default. @@ -579,7 +578,7 @@ static void WindowLoadsaveTextinput(rct_window* w, rct_widgetindex widgetIndex, safe_strcpy(path, _directory, sizeof(path)); safe_strcat_path(path, text, sizeof(path)); - if (!platform_ensure_directory_exists(path)) + if (!Platform::EnsureDirectoryExists(path)) { context_show_error(STR_UNABLE_TO_CREATE_FOLDER, STR_NONE, {}); return; @@ -830,7 +829,7 @@ static void WindowLoadsavePopulateList(rct_window* w, int32_t includeNewItem, co window_loadsave_widgets[WIDX_NEW_FILE].type = includeNewItem ? WindowWidgetType::Button : WindowWidgetType::Empty; window_loadsave_widgets[WIDX_NEW_FOLDER].type = includeNewItem ? WindowWidgetType::Button : WindowWidgetType::Empty; - int32_t drives = platform_get_drives(); + int32_t drives = Platform::GetDrives(); if (str_is_null_or_empty(directory) && drives) { // List Windows drives @@ -919,7 +918,7 @@ static void WindowLoadsavePopulateList(rct_window* w, int32_t includeNewItem, co LoadSaveListItem newListItem; newListItem.path = scanner->GetPath(); newListItem.type = TYPE_FILE; - newListItem.date_modified = platform_file_get_modified_time(newListItem.path.c_str()); + newListItem.date_modified = Platform::FileGetModifiedTime(newListItem.path.c_str()); // Cache a human-readable version of the modified date. newListItem.date_formatted = Platform::FormatShortDate(newListItem.date_modified); diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index 5ac427aa73..2a242c65b3 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 7ff4b12b5c..0f6df129e6 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -700,7 +700,7 @@ private: break; case WIDX_MINIMIZE_FOCUS_LOSS: gConfigGeneral.minimize_fullscreen_focus_loss ^= 1; - platform_refresh_video(false); + RefreshVideo(false); config_save_default(); Invalidate(); break; @@ -843,7 +843,7 @@ private: gConfigGeneral.drawing_engine = dstEngine; bool recreate_window = drawing_engine_requires_new_window(srcEngine, dstEngine); - platform_refresh_video(recreate_window); + RefreshVideo(recreate_window); config_save_default(); Invalidate(); } diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 435cd3c88d..fa1a4cd299 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -2297,7 +2297,7 @@ void UpdateGhostTrackAndArrow() } } // update flashing arrow - auto curTime = platform_get_ticks(); + auto curTime = Platform::GetTicks(); if (_rideConstructionNextArrowPulse >= curTime) break; _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; @@ -2321,7 +2321,7 @@ void UpdateGhostTrackAndArrow() } case RideConstructionState::Selected: { - auto curTime = platform_get_ticks(); + auto curTime = Platform::GetTicks(); if (_rideConstructionNextArrowPulse >= curTime) break; _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; @@ -2344,7 +2344,7 @@ void UpdateGhostTrackAndArrow() case RideConstructionState::MazeMove: case RideConstructionState::MazeFill: { - auto curTime = platform_get_ticks(); + auto curTime = Platform::GetTicks(); if (_rideConstructionNextArrowPulse >= curTime) break; _rideConstructionNextArrowPulse = curTime + ARROW_PULSE_DURATION; diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 19ef5e79d1..2be7336f67 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -24,7 +24,7 @@ # include # include # include -# include +# include # include # include # include diff --git a/src/openrct2/CmdlineSprite.cpp b/src/openrct2/CmdlineSprite.cpp index 2eb5a2e5eb..b3a68580a7 100644 --- a/src/openrct2/CmdlineSprite.cpp +++ b/src/openrct2/CmdlineSprite.cpp @@ -20,7 +20,7 @@ #include "object/ObjectLimits.h" #include "object/ObjectManager.h" #include "object/ObjectRepository.h" -#include "platform/platform.h" +#include "platform/Platform.h" #include "util/Util.h" #include @@ -362,7 +362,7 @@ int32_t cmdline_for_sprite(const char** argv, int32_t argc) safe_strcpy(outputPath, argv[2], MAX_PATH); path_end_with_separator(outputPath, MAX_PATH); - if (!platform_ensure_directory_exists(outputPath)) + if (!Platform::EnsureDirectoryExists(outputPath)) { fprintf(stderr, "Unable to create directory.\n"); return -1; @@ -455,7 +455,7 @@ int32_t cmdline_for_sprite(const char** argv, int32_t argc) safe_strcpy(outputPath, argv[2], MAX_PATH); path_end_with_separator(outputPath, MAX_PATH); - if (!platform_ensure_directory_exists(outputPath)) + if (!Platform::EnsureDirectoryExists(outputPath)) { fprintf(stderr, "Unable to create directory.\n"); return -1; diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index f912fd3770..f97fb504c9 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -57,8 +57,7 @@ #include "object/ObjectRepository.h" #include "paint/Painter.h" #include "platform/Crash.h" -#include "platform/Platform2.h" -#include "platform/platform.h" +#include "platform/Platform.h" #include "profiling/Profiling.h" #include "ride/TrackData.h" #include "ride/TrackDesignRepository.h" @@ -402,7 +401,7 @@ namespace OpenRCT2 } // TODO add configuration option to allow multiple instances - // if (!gOpenRCT2Headless && !platform_lock_single_instance()) { + // if (!gOpenRCT2Headless && !Platform::LockSingleInstance()) { // log_fatal("OpenRCT2 is already running."); // return false; // } //This comment was relocated so it would stay where it was in relation to the following lines of code. @@ -1052,7 +1051,7 @@ namespace OpenRCT2 if (_ticksAccumulator < GAME_UPDATE_TIME_MS) { const auto sleepTimeSec = (GAME_UPDATE_TIME_MS - _ticksAccumulator); - platform_sleep(static_cast(sleepTimeSec * 1000.f)); + Platform::Sleep(static_cast(sleepTimeSec * 1000.f)); return; } @@ -1188,7 +1187,7 @@ namespace OpenRCT2 for (const auto& dirId : dirIds) { auto path = _env->GetDirectoryPath(dirBase, dirId); - if (!platform_ensure_directory_exists(path.c_str())) + if (!Platform::EnsureDirectoryExists(path.c_str())) log_error("Unable to create directory '%s'.", path.c_str()); } } @@ -1225,7 +1224,7 @@ namespace OpenRCT2 if (!Path::DirectoryExists(dstDirectory.c_str())) { Console::WriteLine("Creating directory '%s'", dstDirectory.c_str()); - if (!platform_ensure_directory_exists(dstDirectory.c_str())) + if (!Platform::EnsureDirectoryExists(dstDirectory.c_str())) { Console::Error::WriteLine("Could not create directory %s.", dstDirectory.c_str()); break; @@ -1515,7 +1514,7 @@ const utf8* context_get_path_legacy(int32_t pathId) return result; } -bool platform_open_common_file_dialog(utf8* outFilename, OpenRCT2::Ui::FileDialogDesc& desc, size_t outSize) +bool ContextOpenCommonFileDialog(utf8* outFilename, OpenRCT2::Ui::FileDialogDesc& desc, size_t outSize) { try { diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index 5da731bebf..a35bc8758e 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -34,6 +34,12 @@ struct rct_window; using rct_windowclass = uint8_t; struct NewVersionInfo; +struct TTFFontDescriptor; +namespace OpenRCT2::Ui +{ + struct FileDialogDesc; +} + struct CursorState { ScreenCoordsXY position; @@ -280,3 +286,4 @@ void context_quit(); const utf8* context_get_path_legacy(int32_t pathId); bool context_load_park_from_file(const utf8* path); bool context_load_park_from_stream(void* stream); +bool ContextOpenCommonFileDialog(utf8* outFilename, OpenRCT2::Ui::FileDialogDesc& desc, size_t outSize); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 434b6c9283..9965eb8cc7 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -40,7 +40,7 @@ #include "network/network.h" #include "object/Object.h" #include "object/ObjectList.h" -#include "platform/Platform2.h" +#include "platform/Platform.h" #include "ride/Ride.h" #include "ride/RideRatings.h" #include "ride/Station.h" @@ -687,7 +687,7 @@ void game_autosave() auto env = GetContext()->GetPlatformEnvironment(); auto autosaveDir = Path::Combine(env->GetDirectoryPath(DIRBASE::USER, subDirectory), "autosave"); - platform_ensure_directory_exists(autosaveDir.c_str()); + Platform::EnsureDirectoryExists(autosaveDir.c_str()); auto path = Path::Combine(autosaveDir, timeName); auto backupFileName = u8string("autosave") + fileExtension + ".bak"; diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 6845573bd3..34f1bf8a81 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -26,7 +26,7 @@ #include "localisation/Localisation.h" #include "management/NewsItem.h" #include "network/network.h" -#include "platform/Platform2.h" +#include "platform/Platform.h" #include "profiling/Profiling.h" #include "ride/Vehicle.h" #include "scenario/Scenario.h" diff --git a/src/openrct2/PlatformEnvironment.cpp b/src/openrct2/PlatformEnvironment.cpp index 3641ca4255..fc9e89aff5 100644 --- a/src/openrct2/PlatformEnvironment.cpp +++ b/src/openrct2/PlatformEnvironment.cpp @@ -13,8 +13,7 @@ #include "config/Config.h" #include "core/Path.hpp" #include "core/String.hpp" -#include "platform/Platform2.h" -#include "platform/platform.h" +#include "platform/Platform.h" using namespace OpenRCT2; diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index e024d4906a..e9a991585b 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -18,7 +18,7 @@ #include "../localisation/Formatter.h" #include "../localisation/Localisation.h" #include "../network/network.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../profiling/Profiling.h" #include "../scenario/Scenario.h" #include "../scripting/Duktape.hpp" @@ -418,7 +418,7 @@ namespace GameActions // Allow autosave to commence if (gLastAutoSaveUpdate == AUTOSAVE_PAUSE) { - gLastAutoSaveUpdate = platform_get_ticks(); + gLastAutoSaveUpdate = Platform::GetTicks(); } } diff --git a/src/openrct2/cmdline/BenchSpriteSort.cpp b/src/openrct2/cmdline/BenchSpriteSort.cpp index 1c8704f292..af2fe3d251 100644 --- a/src/openrct2/cmdline/BenchSpriteSort.cpp +++ b/src/openrct2/cmdline/BenchSpriteSort.cpp @@ -23,7 +23,7 @@ # include "../interface/Viewport.h" # include "../localisation/Localisation.h" # include "../paint/Paint.h" -# include "../platform/Platform2.h" +# include "../platform/Platform.h" # include "../util/Util.h" # include "../world/Climate.h" # include "../world/Map.h" @@ -70,7 +70,7 @@ static void fixup_pointers(std::vector& s) static std::vector extract_paint_session(std::string_view parkFileName) { - core_init(); + Platform::CoreInit(); gOpenRCT2Headless = true; auto context = OpenRCT2::CreateContext(); std::vector sessions; diff --git a/src/openrct2/cmdline/BenchUpdate.cpp b/src/openrct2/cmdline/BenchUpdate.cpp index 61cc0681dc..3114bb1b20 100644 --- a/src/openrct2/cmdline/BenchUpdate.cpp +++ b/src/openrct2/cmdline/BenchUpdate.cpp @@ -15,8 +15,7 @@ # include "../GameState.h" # include "../OpenRCT2.h" # include "../core/File.h" -# include "../platform/Platform2.h" -# include "../platform/platform.h" +# include "../platform/Platform.h" # include # include @@ -119,7 +118,7 @@ static int CmdlineForBenchSpriteSort(int argc, const char* const* argv) if (::benchmark::ReportUnrecognizedArguments(argc, &argv_for_benchmark[0])) return -1; - core_init(); + Platform::CoreInit(); gOpenRCT2Headless = true; ::benchmark::RunSpecifiedBenchmarks(); diff --git a/src/openrct2/cmdline/CommandLine.cpp b/src/openrct2/cmdline/CommandLine.cpp index a5e41a01c5..da0aae363e 100644 --- a/src/openrct2/cmdline/CommandLine.cpp +++ b/src/openrct2/cmdline/CommandLine.cpp @@ -12,7 +12,7 @@ #include "../OpenRCT2.h" #include "../core/Console.hpp" #include "../core/String.hpp" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include #include diff --git a/src/openrct2/cmdline/RootCommands.cpp b/src/openrct2/cmdline/RootCommands.cpp index f25ffa29a1..c1e8d2276a 100644 --- a/src/openrct2/cmdline/RootCommands.cpp +++ b/src/openrct2/cmdline/RootCommands.cpp @@ -23,7 +23,7 @@ #include "../object/ObjectRepository.h" #include "../park/ParkFile.h" #include "../platform/Crash.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../scripting/ScriptEngine.h" #include "CommandLine.hpp" diff --git a/src/openrct2/cmdline/SimulateCommands.cpp b/src/openrct2/cmdline/SimulateCommands.cpp index 26a1ff0ea5..e4e932405a 100644 --- a/src/openrct2/cmdline/SimulateCommands.cpp +++ b/src/openrct2/cmdline/SimulateCommands.cpp @@ -14,7 +14,7 @@ #include "../core/Console.hpp" #include "../entity/EntityRegistry.h" #include "../network/network.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "CommandLine.hpp" #include @@ -39,7 +39,7 @@ static exitcode_t HandleSimulate(CommandLineArgEnumerator* argEnumerator) return EXITCODE_FAIL; } - core_init(); + Platform::CoreInit(); const char* inputPath = argv[0]; uint32_t ticks = atol(argv[1]); diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 57968cde5b..b801be7fa3 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -26,7 +26,7 @@ #include "../localisation/StringIds.h" #include "../network/network.h" #include "../paint/VirtualFloor.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../rct1/Limits.h" #include "../scenario/Scenario.h" #include "../ui/UiContext.h" @@ -644,7 +644,7 @@ namespace Config auto steamPath = Platform::GetSteamPath(); if (!steamPath.empty()) { - std::string location = Path::Combine(steamPath, platform_get_rct1_steam_dir()); + std::string location = Path::Combine(steamPath, Platform::GetRCT1SteamDir()); if (RCT1DataPresentAtLocation(location)) { return location; @@ -693,7 +693,7 @@ namespace Config auto steamPath = Platform::GetSteamPath(); if (!steamPath.empty()) { - std::string location = Path::Combine(steamPath, platform_get_rct2_steam_dir()); + std::string location = Path::Combine(steamPath, Platform::GetRCT2SteamDir()); if (Platform::OriginalGameDataExists(location)) { return location; @@ -725,7 +725,7 @@ namespace Config const auto userHomePath = Platform::GetFolderPath(SPECIAL_FOLDER::USER_HOME); desc.InitialDirectory = userHomePath.c_str(); - return platform_open_common_file_dialog(installerPath, desc, 4096); + return ContextOpenCommonFileDialog(installerPath, desc, 4096); } static bool ExtractGogInstaller(u8string_view installerPath, u8string_view targetPath) diff --git a/src/openrct2/config/IniWriter.cpp b/src/openrct2/config/IniWriter.cpp index d539c02160..6e2823d7f9 100644 --- a/src/openrct2/config/IniWriter.cpp +++ b/src/openrct2/config/IniWriter.cpp @@ -11,7 +11,7 @@ #include "../core/IStream.hpp" #include "../core/String.hpp" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include diff --git a/src/openrct2/core/Console.cpp b/src/openrct2/core/Console.cpp index a5170934b7..c08d30db62 100644 --- a/src/openrct2/core/Console.cpp +++ b/src/openrct2/core/Console.cpp @@ -10,7 +10,7 @@ #include "Console.hpp" #include "../Context.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include #include diff --git a/src/openrct2/core/Crypt.CNG.cpp b/src/openrct2/core/Crypt.CNG.cpp index bb7a620078..b4d041d75d 100644 --- a/src/openrct2/core/Crypt.CNG.cpp +++ b/src/openrct2/core/Crypt.CNG.cpp @@ -11,7 +11,7 @@ # include "Crypt.h" -# include "../platform/Platform2.h" +# include "../platform/Platform.h" # include "IStream.hpp" # include diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index 5f4484659c..8ceba99085 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -13,7 +13,7 @@ # include #endif -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../util/Util.h" #include "File.h" #include "FileStream.h" diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 0d17f49567..303e45cef0 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -10,8 +10,7 @@ #include "Path.hpp" #include "../localisation/Language.h" -#include "../platform/Platform2.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../util/Util.h" #include "File.h" #include "FileSystem.hpp" @@ -56,7 +55,7 @@ namespace Path void CreateDirectory(u8string_view path) { - platform_ensure_directory_exists(u8string(path).c_str()); + Platform::EnsureDirectoryExists(u8string(path).c_str()); } bool DirectoryExists(u8string_view path) diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index ae58016dad..9b25747b57 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -9,8 +9,7 @@ #ifdef __ANDROID__ -# include "../platform/Platform2.h" -# include "../platform/platform.h" +# include "../platform/Platform.h" # include "IStream.hpp" # include "MemoryStream.h" # include "Zip.h" diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index 3369f5a438..3a4d0897e6 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -15,7 +15,7 @@ #include "../config/Config.h" #include "../core/FileStream.h" #include "../core/Path.hpp" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../sprites.h" #include "../ui/UiContext.h" #include "../util/Util.h" diff --git a/src/openrct2/drawing/Drawing.String.cpp b/src/openrct2/drawing/Drawing.String.cpp index fe7d7aa4fe..308c2379c0 100644 --- a/src/openrct2/drawing/Drawing.String.cpp +++ b/src/openrct2/drawing/Drawing.String.cpp @@ -19,7 +19,7 @@ #include "../localisation/Formatting.h" #include "../localisation/Localisation.h" #include "../localisation/LocalisationService.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../sprites.h" #include "../util/Util.h" #include "TTF.h" diff --git a/src/openrct2/drawing/Drawing.cpp b/src/openrct2/drawing/Drawing.cpp index 5d5cf48c28..b5a62fbf6f 100644 --- a/src/openrct2/drawing/Drawing.cpp +++ b/src/openrct2/drawing/Drawing.cpp @@ -13,9 +13,10 @@ #include "../Game.h" #include "../OpenRCT2.h" #include "../common.h" +#include "../config/Config.h" #include "../core/Guard.hpp" #include "../object/Object.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../sprites.h" #include "../util/Util.h" #include "../world/Climate.h" @@ -25,6 +26,8 @@ #include +GamePalette gPalette; + const PaletteMap& PaletteMap::GetDefault() { static bool initialised = false; @@ -836,3 +839,28 @@ void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colo drawing_engine_set_palette(gPalette); } } + +void RefreshVideo(bool recreateWindow) +{ + if (recreateWindow) + { + context_recreate_window(); + } + else + { + drawing_engine_dispose(); + drawing_engine_init(); + drawing_engine_resize(); + } + + drawing_engine_set_palette(gPalette); + gfx_invalidate_screen(); +} + +void ToggleWindowedMode() +{ + int32_t targetMode = gConfigGeneral.fullscreen_mode == 0 ? 2 : 0; + context_set_fullscreen_mode(targetMode); + gConfigGeneral.fullscreen_mode = targetMode; + config_save_default(); +} diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 36f308f089..69abfb9052 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -602,4 +602,7 @@ std::optional GetPaletteG1Index(colour_t paletteId); std::optional GetPaletteMapForColour(colour_t paletteId); void UpdatePalette(const uint8_t* colours, int32_t start_index, int32_t num_colours); +void RefreshVideo(bool recreateWindow); +void ToggleWindowedMode(); + #include "NewDrawing.h" diff --git a/src/openrct2/drawing/NewDrawing.cpp b/src/openrct2/drawing/NewDrawing.cpp index e27913ffc9..1d65d3e303 100644 --- a/src/openrct2/drawing/NewDrawing.cpp +++ b/src/openrct2/drawing/NewDrawing.cpp @@ -15,7 +15,7 @@ #include "../interface/Screenshot.h" #include "../localisation/StringIds.h" #include "../paint/Painter.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../ui/UiContext.h" #include "../world/Location.hpp" #include "IDrawingContext.h" diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 005cb0746c..d16af1428b 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -23,8 +23,7 @@ # include "../core/String.hpp" # include "../localisation/Localisation.h" # include "../localisation/LocalisationService.h" -# include "../platform/Platform2.h" -# include "../platform/platform.h" +# include "../platform/Platform.h" # include "TTF.h" static bool _ttfInitialised = false; diff --git a/src/openrct2/interface/Chat.cpp b/src/openrct2/interface/Chat.cpp index d4e2c9f0d4..f42769453f 100644 --- a/src/openrct2/interface/Chat.cpp +++ b/src/openrct2/interface/Chat.cpp @@ -17,7 +17,7 @@ #include "../localisation/Formatting.h" #include "../localisation/Localisation.h" #include "../network/network.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../util/Util.h" #include "../world/Location.hpp" @@ -164,7 +164,7 @@ void chat_draw(rct_drawpixelinfo* dpi, uint8_t chatBackgroundColor) for (int32_t i = 0; i < CHAT_HISTORY_SIZE; i++, screenCoords.y -= stringHeight) { uint32_t expireTime = chat_history_get_time(i) + 10000; - if (!gChatOpen && platform_get_ticks() > expireTime) + if (!gChatOpen && Platform::GetTicks() > expireTime) { break; } @@ -224,7 +224,7 @@ void chat_history_add(std::string_view s) int32_t index = _chatHistoryIndex % CHAT_HISTORY_SIZE; std::fill_n(_chatHistory[index], CHAT_INPUT_SIZE, 0x00); std::memcpy(_chatHistory[index], buffer.c_str(), std::min(buffer.size(), CHAT_INPUT_SIZE - 1)); - _chatHistoryTime[index] = platform_get_ticks(); + _chatHistoryTime[index] = Platform::GetTicks(); _chatHistoryIndex++; // Log to file (src only as logging does its own timestamp) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 2e07c59e17..1207e20369 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -44,7 +44,7 @@ #include "../object/ObjectList.h" #include "../object/ObjectManager.h" #include "../object/ObjectRepository.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../ride/RideData.h" diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 3b398a5adb..e3f49ac55e 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -24,7 +24,7 @@ #include "../drawing/X8DrawingEngine.h" #include "../localisation/Formatter.h" #include "../localisation/Localisation.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../util/Util.h" #include "../world/Climate.h" #include "../world/Map.h" @@ -128,7 +128,7 @@ static std::string screenshot_get_formatted_date_time() static std::optional screenshot_get_next_path() { auto screenshotDirectory = screenshot_get_directory(); - if (!platform_ensure_directory_exists(screenshotDirectory.c_str())) + if (!Platform::EnsureDirectoryExists(screenshotDirectory.c_str())) { log_error("Unable to save screenshots in OpenRCT2 screenshot directory."); return std::nullopt; @@ -529,7 +529,7 @@ int32_t cmdline_for_gfxbench(const char** argv, int32_t argc) return -1; } - core_init(); + Platform::CoreInit(); int32_t iterationCount = 5; if (argc == 2) { @@ -626,7 +626,7 @@ int32_t cmdline_for_screenshot(const char** argv, int32_t argc, ScreenshotOption rct_drawpixelinfo dpi; try { - core_init(); + Platform::CoreInit(); bool customLocation = false; bool centreMapX = false; bool centreMapY = false; diff --git a/src/openrct2/interface/StdInOutConsole.cpp b/src/openrct2/interface/StdInOutConsole.cpp index 95bb45a52f..f3b5b48179 100644 --- a/src/openrct2/interface/StdInOutConsole.cpp +++ b/src/openrct2/interface/StdInOutConsole.cpp @@ -14,7 +14,7 @@ #include "../Context.h" #include "../OpenRCT2.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../scripting/ScriptEngine.h" #include "InteractiveConsole.h" diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 66306ec60c..801c51cec9 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -21,7 +21,7 @@ #include "../interface/Cursors.h" #include "../localisation/Localisation.h" #include "../localisation/StringIds.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../ride/RideAudio.h" #include "../scenario/Scenario.h" #include "../sprites.h" diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index ec9bcc3eb0..a5d8a1181e 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -314,8 +314,7 @@ - - + @@ -792,9 +791,7 @@ - - @@ -955,4 +952,4 @@ - \ No newline at end of file + diff --git a/src/openrct2/localisation/Language.cpp b/src/openrct2/localisation/Language.cpp index 9794823c31..ed3aa5c9cf 100644 --- a/src/openrct2/localisation/Language.cpp +++ b/src/openrct2/localisation/Language.cpp @@ -13,7 +13,7 @@ #include "../interface/FontFamilies.h" #include "../interface/Fonts.h" #include "../object/ObjectManager.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "LanguagePack.h" #include "Localisation.h" #include "LocalisationService.h" diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 0132a08ad1..63ad89d4ec 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -26,7 +26,7 @@ #include "../localisation/Formatter.h" #include "../localisation/Formatting.h" #include "../park/ParkFile.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../scenario/Scenario.h" #include "../scripting/ScriptEngine.h" #include "../ui/UiContext.h" @@ -285,7 +285,7 @@ bool NetworkBase::BeginClient(const std::string& host, uint16_t port) Console::WriteLine("Key generated, saving private bits as %s", keyPath.c_str()); const auto keysDirectory = network_get_keys_directory(); - if (!platform_ensure_directory_exists(keysDirectory.c_str())) + if (!Platform::EnsureDirectoryExists(keysDirectory.c_str())) { log_error("Unable to create directory %s.", keysDirectory.c_str()); return false; @@ -458,7 +458,7 @@ void NetworkBase::Update() _closeLock = true; // Update is not necessarily called per game tick, maintain our own delta time - uint32_t ticks = platform_get_ticks(); + uint32_t ticks = Platform::GetTicks(); _currentDeltaTime = std::max(ticks - _lastUpdateTime, 1); _lastUpdateTime = ticks; @@ -517,7 +517,7 @@ void NetworkBase::UpdateServer() } } - uint32_t ticks = platform_get_ticks(); + uint32_t ticks = Platform::GetTicks(); if (ticks > last_ping_sent_time + 3000) { Server_Send_PING(); @@ -574,7 +574,7 @@ void NetworkBase::UpdateClient() intent.putExtra(INTENT_EXTRA_CALLBACK, []() -> void { ::GetContext()->GetNetwork().Close(); }); context_open_intent(&intent); - server_connect_time = platform_get_ticks(); + server_connect_time = Platform::GetTicks(); } break; } @@ -640,7 +640,7 @@ void NetworkBase::UpdateClient() } else { - uint32_t ticks = platform_get_ticks(); + uint32_t ticks = Platform::GetTicks(); if (ticks - _lastSentHeartbeat >= 3000) { Client_Send_HEARTBEAT(*_serverConnection); @@ -1049,7 +1049,7 @@ std::string NetworkBase::BeginLog(const std::string& directory, const std::strin throw std::runtime_error("strftime failed"); } - platform_ensure_directory_exists(Path::Combine(directory, midName).c_str()); + Platform::EnsureDirectoryExists(Path::Combine(directory, midName).c_str()); return Path::Combine(directory, midName, filename); } @@ -1544,11 +1544,11 @@ void NetworkBase::Client_Send_PING() void NetworkBase::Server_Send_PING() { - last_ping_sent_time = platform_get_ticks(); + last_ping_sent_time = Platform::GetTicks(); NetworkPacket packet(NetworkCommand::Ping); for (auto& client_connection : client_connection_list) { - client_connection->PingTime = platform_get_ticks(); + client_connection->PingTime = Platform::GetTicks(); } SendPacketToClients(packet, true); } @@ -2439,12 +2439,12 @@ void NetworkBase::Client_Handle_GAMESTATE(NetworkConnection& connection, Network std::string outputPath = GetContext().GetPlatformEnvironment()->GetDirectoryPath(DIRBASE::USER, DIRID::LOG_DESYNCS); - platform_ensure_directory_exists(outputPath.c_str()); + Platform::EnsureDirectoryExists(outputPath.c_str()); char uniqueFileName[128] = {}; snprintf( uniqueFileName, sizeof(uniqueFileName), "desync_%llu_%u.txt", - static_cast(platform_get_datetime_now_utc()), tick); + static_cast(Platform::GetDatetimeNowUTC()), tick); std::string outputFile = Path::Combine(outputPath, uniqueFileName); @@ -3023,7 +3023,7 @@ void NetworkBase::Client_Handle_PING([[maybe_unused]] NetworkConnection& connect void NetworkBase::Server_Handle_PING(NetworkConnection& connection, [[maybe_unused]] NetworkPacket& packet) { - int32_t ping = platform_get_ticks() - connection.PingTime; + int32_t ping = Platform::GetTicks() - connection.PingTime; if (ping < 0) { ping = 0; @@ -3312,7 +3312,7 @@ int32_t network_get_player_last_action(uint32_t index, int32_t time) auto& network = OpenRCT2::GetContext()->GetNetwork(); Guard::IndexInRange(index, network.player_list); - if (time && platform_get_ticks() > network.player_list[index]->LastActionTime + time) + if (time && Platform::GetTicks() > network.player_list[index]->LastActionTime + time) { return -999; } @@ -3325,7 +3325,7 @@ void network_set_player_last_action(uint32_t index, GameCommand command) Guard::IndexInRange(index, network.player_list); network.player_list[index]->LastAction = static_cast(NetworkActions::FindCommand(command)); - network.player_list[index]->LastActionTime = platform_get_ticks(); + network.player_list[index]->LastActionTime = Platform::GetTicks(); } CoordsXYZ network_get_player_last_action_coord(uint32_t index) diff --git a/src/openrct2/network/NetworkConnection.cpp b/src/openrct2/network/NetworkConnection.cpp index 88892a8cb3..286ac7439f 100644 --- a/src/openrct2/network/NetworkConnection.cpp +++ b/src/openrct2/network/NetworkConnection.cpp @@ -13,7 +13,7 @@ # include "../core/String.hpp" # include "../localisation/Localisation.h" -# include "../platform/platform.h" +# include "../platform/Platform.h" # include "Socket.h" # include "network.h" @@ -83,7 +83,7 @@ NetworkReadPacket NetworkConnection::ReadPacket() if (InboundPacket.Data.size() == header.Size) { // Received complete packet. - _lastPacketTime = platform_get_ticks(); + _lastPacketTime = Platform::GetTicks(); RecordPacketStats(InboundPacket, false); @@ -171,13 +171,13 @@ void NetworkConnection::SendQueuedPackets() void NetworkConnection::ResetLastPacketTime() noexcept { - _lastPacketTime = platform_get_ticks(); + _lastPacketTime = Platform::GetTicks(); } bool NetworkConnection::ReceivedPacketRecently() const noexcept { # ifndef DEBUG - if (platform_get_ticks() > _lastPacketTime + 7000) + if (Platform::GetTicks() > _lastPacketTime + 7000) { return false; } diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index 73036fe73b..bfc40f8a64 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -20,8 +20,7 @@ # include "../entity/Guest.h" # include "../localisation/Date.h" # include "../management/Finance.h" -# include "../platform/Platform2.h" -# include "../platform/platform.h" +# include "../platform/Platform.h" # include "../util/Util.h" # include "../world/Map.h" # include "../world/Park.h" @@ -144,7 +143,7 @@ private: switch (_status) { case ADVERTISE_STATUS::UNREGISTERED: - if (_lastAdvertiseTime == 0 || platform_get_ticks() > _lastAdvertiseTime + MASTER_SERVER_REGISTER_TIME) + if (_lastAdvertiseTime == 0 || Platform::GetTicks() > _lastAdvertiseTime + MASTER_SERVER_REGISTER_TIME) { if (_lastAdvertiseTime == 0) { @@ -154,7 +153,7 @@ private: } break; case ADVERTISE_STATUS::REGISTERED: - if (platform_get_ticks() > _lastHeartbeatTime + MASTER_SERVER_HEARTBEAT_TIME) + if (Platform::GetTicks() > _lastHeartbeatTime + MASTER_SERVER_HEARTBEAT_TIME) { SendHeartbeat(); } @@ -167,7 +166,7 @@ private: void SendRegistration(bool forceIPv4) { - _lastAdvertiseTime = platform_get_ticks(); + _lastAdvertiseTime = Platform::GetTicks(); // Send the registration request Http::Request request; @@ -211,7 +210,7 @@ private: request.body = body.dump(); request.header["Content-Type"] = "application/json"; - _lastHeartbeatTime = platform_get_ticks(); + _lastHeartbeatTime = Platform::GetTicks(); Http::DoAsync(request, [&](Http::Response response) -> void { if (response.status != Http::Status::Ok) { diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index da2ea80b2c..5bc07ef011 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -22,7 +22,7 @@ # include "../core/Memory.hpp" # include "../core/Path.hpp" # include "../core/String.hpp" -# include "../platform/Platform2.h" +# include "../platform/Platform.h" # include "Socket.h" # include "network.h" @@ -286,7 +286,7 @@ std::future> ServerList::FetchLocalServerListAsync( { log_warning("Error receiving data: %s", e.what()); } - platform_sleep(RECV_DELAY_MS); + Platform::Sleep(RECV_DELAY_MS); } return entries; }); diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 50df317bdc..30a62b725c 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -29,7 +29,7 @@ #include "../localisation/LocalisationService.h" #include "../object/Object.h" #include "../park/Legacy.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../rct12/SawyerChunkReader.h" #include "../rct12/SawyerChunkWriter.h" #include "../scenario/ScenarioRepository.h" diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 4f53dfcda1..b3ff4fc0c6 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -41,7 +41,7 @@ # include "../scenario/Scenario.h" # include "../util/SawyerCoding.h" # include "../util/Util.h" -# include "platform.h" +# include "Platform.h" # define WSZ(x) L"" x diff --git a/src/openrct2/platform/Platform.Android.cpp b/src/openrct2/platform/Platform.Android.cpp index 0d4676f85c..4342ec07b8 100644 --- a/src/openrct2/platform/Platform.Android.cpp +++ b/src/openrct2/platform/Platform.Android.cpp @@ -9,9 +9,10 @@ #ifdef __ANDROID__ +# include "Platform.h" + # include "../core/Guard.hpp" # include "../localisation/Language.h" -# include "Platform2.h" # include # include diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index 8a32dd8fd6..deb634480a 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -31,8 +31,7 @@ # include "../OpenRCT2.h" # include "../core/Path.hpp" # include "../localisation/Language.h" -# include "Platform2.h" -# include "platform.h" +# include "Platform.h" namespace Platform { diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index 7108b2a2c4..6f9f1765d3 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -9,13 +9,13 @@ #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) -# include "platform.h" +# include "Platform.h" # include "../core/Memory.hpp" # include "../core/Path.hpp" # include "../core/String.hpp" # include "../localisation/Date.h" -# include "Platform2.h" +# include "../util/Util.h" # include # include @@ -23,20 +23,20 @@ # include # include # include +# include # include # include # include # include +# include -# define FILE_BUFFER_SIZE 4096 +// The name of the mutex used to prevent multiple instances of the game from running +static constexpr u8string_view SINGLE_INSTANCE_MUTEX_NAME = u8"openrct2.lock"; + +static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; namespace Platform { - uint32_t GetTicks() - { - return platform_get_ticks(); - } - std::string GetEnvironmentVariable(std::string_view name) { return String::ToStd(getenv(std::string(name).c_str())); @@ -306,6 +306,151 @@ namespace Platform return false; # endif // __EMSCRIPTEN__ } + + // Implement our own version of getumask(), as it is documented being + // "a vaporware GNU extension". + static mode_t openrct2_getumask() + { + mode_t mask = umask(0); + umask(mask); + return 0777 & ~mask; // Keep in mind 0777 is octal + } + + bool EnsureDirectoryExists(u8string_view path) + { + mode_t mask = openrct2_getumask(); + char buffer[MAX_PATH]; + safe_strcpy(buffer, u8string(path).c_str(), sizeof(buffer)); + + log_verbose("Create directory: %s", buffer); + for (char* p = buffer + 1; *p != '\0'; p++) + { + if (*p == '/') + { + // Temporarily truncate + *p = '\0'; + + log_verbose("mkdir(%s)", buffer); + if (mkdir(buffer, mask) != 0) + { + if (errno != EEXIST) + { + return false; + } + } + + // Restore truncation + *p = '/'; + } + } + + log_verbose("mkdir(%s)", buffer); + if (mkdir(buffer, mask) != 0) + { + if (errno != EEXIST) + { + return false; + } + } + + return true; + } + + bool LockSingleInstance() + { + auto pidFilePath = Path::Combine(_userDataDirectoryPath, SINGLE_INSTANCE_MUTEX_NAME); + + // We will never close this file manually. The operating system will + // take care of that, because flock keeps the lock as long as the + // file is open and closes it automatically on file close. + // This is intentional. + int32_t pidFile = open(pidFilePath.c_str(), O_CREAT | O_RDWR, 0666); + + if (pidFile == -1) + { + log_warning("Cannot open lock file for writing."); + return false; + } + + struct flock lock; + + lock.l_start = 0; + lock.l_len = 0; + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + + if (fcntl(pidFile, F_SETLK, &lock) == -1) + { + if (errno == EWOULDBLOCK) + { + log_warning("Another OpenRCT2 session has been found running."); + return false; + } + log_error("flock returned an uncatched errno: %d", errno); + return false; + } + return true; + } + + int32_t GetDrives() + { + // POSIX systems do not know drives. Return 0. + return 0; + } + + time_t FileGetModifiedTime(u8string_view path) + { + struct stat buf; + if (stat(u8string(path).c_str(), &buf) == 0) + { + return buf.st_mtime; + } + return 100; + } + + datetime64 GetDatetimeNowUTC() + { + const datetime64 epochAsTicks = 621355968000000000; + + struct timeval tv; + gettimeofday(&tv, NULL); + + // Epoch starts from: 1970-01-01T00:00:00Z + // Convert to ticks from 0001-01-01T00:00:00Z + uint64_t utcEpochTicks = static_cast(tv.tv_sec) * 10000000ULL + tv.tv_usec * 10; + datetime64 utcNow = epochAsTicks + utcEpochTicks; + return utcNow; + } + + u8string GetRCT1SteamDir() + { + return u8"app_285310" PATH_SEPARATOR u8"depot_285311"; + } + + u8string GetRCT2SteamDir() + { + return u8"app_285330" PATH_SEPARATOR u8"depot_285331"; + } + + void Sleep(uint32_t ms) + { + usleep(ms * 1000); + } + + void InitTicks() + { + } + + uint32_t GetTicks() + { + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + { + log_fatal("clock_gettime failed"); + exit(-1); + } + return static_cast(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 5435a76d74..f9bcb4d0e8 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -7,6 +7,12 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#if defined(__MINGW32__) && !defined(WINVER) && !defined(_WIN32_WINNT) +// 0x0600 == vista +# define WINVER 0x0600 +# define _WIN32_WINNT 0x0600 +#endif // __MINGW32__ + #ifdef _WIN32 // Windows.h needs to be included first @@ -36,9 +42,9 @@ # include "../core/String.hpp" # include "../localisation/Date.h" # include "../localisation/Language.h" -# include "Platform2.h" -# include "platform.h" +# include "Platform.h" +# include # include # include @@ -46,9 +52,37 @@ # define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__) # endif -# if _WIN32_WINNT >= 0x0600 -constexpr wchar_t SOFTWARE_CLASSES[] = L"Software\\Classes"; -# endif +// Native resource IDs +# include "../../../resources/resource.h" + +// Enable visual styles +# pragma comment( \ + linker, \ + "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +static uint32_t _frequency = 0; +static LARGE_INTEGER _entryTimestamp; + +// The name of the mutex used to prevent multiple instances of the game from running +static constexpr char SINGLE_INSTANCE_MUTEX_NAME[] = "RollerCoaster Tycoon 2_GSKMUTEX"; + +# define SOFTWARE_CLASSES L"Software\\Classes" +# define MUI_CACHE L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" + +char* strndup(const char* src, size_t size) +{ + size_t len = strnlen(src, size); + char* dst = reinterpret_cast(malloc(len + 1)); + + if (dst == nullptr) + { + return nullptr; + } + + dst = reinterpret_cast(std::memcpy(dst, src, len)); + dst[len] = '\0'; + return dst; +} namespace Platform { @@ -59,11 +93,6 @@ namespace Platform # endif static std::string WIN32_GetModuleFileNameW(HMODULE hModule); - uint32_t GetTicks() - { - return platform_get_ticks(); - } - std::string GetEnvironmentVariable(std::string_view name) { std::wstring result; @@ -859,6 +888,160 @@ namespace Platform return Path::Combine("C:\\Windows\\Fonts\\", font.filename); # endif } + + bool EnsureDirectoryExists(u8string_view path) + { + if (Path::DirectoryExists(path)) + return 1; + + auto wPath = String::ToWideChar(path); + auto success = CreateDirectoryW(wPath.c_str(), nullptr); + return success != FALSE; + } + + bool LockSingleInstance() + { + HANDLE mutex, status; + + // Check if operating system mutex exists + mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, SINGLE_INSTANCE_MUTEX_NAME); + if (mutex == nullptr) + { + // Create new mutex + status = CreateMutex(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME); + if (status == nullptr) + log_error("unable to create mutex"); + + return true; + } + + // Already running + CloseHandle(mutex); + return false; + } + + int32_t GetDrives() + { + return GetLogicalDrives(); + } + + u8string GetRCT1SteamDir() + { + return u8"Rollercoaster Tycoon Deluxe"; + } + + u8string GetRCT2SteamDir() + { + return u8"Rollercoaster Tycoon 2"; + } + + time_t FileGetModifiedTime(u8string_view path) + { + WIN32_FILE_ATTRIBUTE_DATA data{}; + auto wPath = String::ToWideChar(path); + auto result = GetFileAttributesExW(wPath.c_str(), GetFileExInfoStandard, &data); + if (result != FALSE) + { + FILETIME localFileTime{}; + result = FileTimeToLocalFileTime(&data.ftLastWriteTime, &localFileTime); + if (result != FALSE) + { + ULARGE_INTEGER ull{}; + ull.LowPart = localFileTime.dwLowDateTime; + ull.HighPart = localFileTime.dwHighDateTime; + return ull.QuadPart / 10000000ULL - 11644473600ULL; + } + } + return 0; + } + + datetime64 GetDatetimeNowUTC() + { + // Get file time + FILETIME fileTime; + GetSystemTimeAsFileTime(&fileTime); + uint64_t fileTime64 = (static_cast(fileTime.dwHighDateTime) << 32ULL) + | (static_cast(fileTime.dwLowDateTime)); + + // File time starts from: 1601-01-01T00:00:00Z + // Convert to start from: 0001-01-01T00:00:00Z + datetime64 utcNow = fileTime64 - 504911232000000000ULL; + return utcNow; + } + + bool SetupUriProtocol() + { +# if _WIN32_WINNT >= 0x0600 + log_verbose("Setting up URI protocol..."); + + // [HKEY_CURRENT_USER\Software\Classes] + HKEY hRootKey; + if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS) + { + // [hRootKey\openrct2] + HKEY hClassKey; + if (RegCreateKeyA(hRootKey, "openrct2", &hClassKey) == ERROR_SUCCESS) + { + if (RegSetValueA(hClassKey, nullptr, REG_SZ, "URL:openrct2", 0) == ERROR_SUCCESS) + { + if (RegSetKeyValueA(hClassKey, nullptr, "URL Protocol", REG_SZ, "", 0) == ERROR_SUCCESS) + { + // [hRootKey\openrct2\shell\open\command] + wchar_t exePath[MAX_PATH]; + GetModuleFileNameW(nullptr, exePath, MAX_PATH); + + wchar_t buffer[512]; + swprintf_s(buffer, std::size(buffer), L"\"%s\" handle-uri \"%%1\"", exePath); + if (RegSetValueW(hClassKey, L"shell\\open\\command", REG_SZ, buffer, 0) == ERROR_SUCCESS) + { + // Not compulsory, but gives the application a nicer name + // [HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache] + HKEY hMuiCacheKey; + if (RegCreateKeyW(hRootKey, MUI_CACHE, &hMuiCacheKey) == ERROR_SUCCESS) + { + swprintf_s(buffer, std::size(buffer), L"%s.FriendlyAppName", exePath); + // mingw-w64 used to define RegSetKeyValueW's signature incorrectly + // You need at least mingw-w64 5.0 including this commit: + // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/da9341980a4b70be3563ac09b5927539e7da21f7/ + RegSetKeyValueW(hMuiCacheKey, nullptr, buffer, REG_SZ, L"OpenRCT2", sizeof(L"OpenRCT2")); + } + + log_verbose("URI protocol setup successful"); + return true; + } + } + } + } + } +# endif + + log_verbose("URI protocol setup failed"); + return false; + } + + uint32_t GetTicks() + { + LARGE_INTEGER pfc; + QueryPerformanceCounter(&pfc); + + LARGE_INTEGER runningDelta; + runningDelta.QuadPart = pfc.QuadPart - _entryTimestamp.QuadPart; + + return static_cast(runningDelta.QuadPart / _frequency); + } + + void Sleep(uint32_t ms) + { + ::Sleep(ms); + } + + void InitTicks() + { + LARGE_INTEGER freq; + QueryPerformanceFrequency(&freq); + _frequency = static_cast(freq.QuadPart / 1000); + QueryPerformanceCounter(&_entryTimestamp); + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform.h similarity index 67% rename from src/openrct2/platform/Platform2.h rename to src/openrct2/platform/Platform.h index ebb3dc4e5a..5aa9a04351 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform.h @@ -10,11 +10,26 @@ #pragma once #include "../common.h" -#include "platform.h" +#include "../config/Config.h" #include #include +#ifdef _WIN32 +# define PATH_SEPARATOR u8"\\" +# define PLATFORM_NEWLINE u8"\r\n" +#else +# define PATH_SEPARATOR u8"/" +# define PLATFORM_NEWLINE u8"\n" +#endif +#ifdef __ANDROID__ +# include +#endif // __ANDROID__ + +#ifndef MAX_PATH +# define MAX_PATH 260 +#endif + enum class SPECIAL_FOLDER { USER_CACHE, @@ -25,9 +40,25 @@ enum class SPECIAL_FOLDER RCT2_DISCORD, }; +struct rct2_date +{ + uint8_t day; + uint8_t month; + int16_t year; + uint8_t day_of_week; +}; + +struct rct2_time +{ + uint8_t hour; + uint8_t minute; + uint8_t second; +}; + namespace Platform { - uint32_t GetTicks(); + // Called very early in the program before parsing commandline arguments. + void CoreInit(); std::string GetEnvironmentVariable(std::string_view name); std::string GetFolderPath(SPECIAL_FOLDER folder); std::string GetInstallPath(); @@ -78,6 +109,7 @@ namespace Platform std::string_view extension, std::string_view fileTypeText, std::string_view commandText, std::string_view commandArgs, const uint32_t iconIndex); void RemoveFileAssociations(); + bool SetupUriProtocol(); #endif #ifdef __ANDROID__ void AndroidInitClassLoader(); @@ -89,6 +121,21 @@ namespace Platform bool HandleSpecialCommandLineArgument(const char* argument); u8string StrDecompToPrecomp(u8string_view input); bool RequireNewWindow(bool openGL); + + bool EnsureDirectoryExists(u8string_view path); + // Returns the bitmask of the GetLogicalDrives function for windows, 0 for other systems + int32_t GetDrives(); + time_t FileGetModifiedTime(u8string_view path); + + bool LockSingleInstance(); + + u8string GetRCT1SteamDir(); + u8string GetRCT2SteamDir(); + datetime64 GetDatetimeNowUTC(); + uint32_t GetTicks(); + + void Sleep(uint32_t ms); + void InitTicks(); } // namespace Platform #ifdef __ANDROID__ @@ -102,3 +149,20 @@ public: }; #endif // __ANDROID__ + +#ifdef _WIN32 +# ifndef NOMINMAX +# define NOMINMAX +# endif +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +# undef CreateDirectory +# undef CreateWindow +# undef GetMessage + +// This function cannot be marked as 'static', even though it may seem to be, +// as it requires external linkage, which 'static' prevents +__declspec(dllexport) int32_t StartOpenRCT2(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int32_t nCmdShow); +#endif // _WIN32 diff --git a/src/openrct2/platform/Platform.macOS.mm b/src/openrct2/platform/Platform.macOS.mm index fcd48f4ee5..5148cd0dd7 100644 --- a/src/openrct2/platform/Platform.macOS.mm +++ b/src/openrct2/platform/Platform.macOS.mm @@ -13,15 +13,17 @@ # include "../core/Path.hpp" # include "../core/String.hpp" # include "../localisation/Language.h" -# include "Platform2.h" +# include "Platform.h" // undefine `interface` and `abstract`, because it's causing conflicts with Objective-C's keywords # undef interface # undef abstract +# include # include # include # include +# include # include namespace Platform diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp deleted file mode 100644 index 22207df36e..0000000000 --- a/src/openrct2/platform/Posix.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2020 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. - *****************************************************************************/ - -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) - -# include "../OpenRCT2.h" -# include "../config/Config.h" -# include "../core/FileSystem.hpp" -# include "../core/Path.hpp" -# include "../core/String.hpp" -# include "../localisation/Date.h" -# include "../localisation/Language.h" -# include "../util/Util.h" -# include "Platform2.h" - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -// The name of the mutex used to prevent multiple instances of the game from running -# define SINGLE_INSTANCE_MUTEX_NAME "openrct2.lock" - -static utf8 _userDataDirectoryPath[MAX_PATH] = { 0 }; - -// Implement our own version of getumask(), as it is documented being -// "a vaporware GNU extension". -static mode_t openrct2_getumask() -{ - mode_t mask = umask(0); - umask(mask); - return 0777 & ~mask; // Keep in mind 0777 is octal -} - -bool platform_ensure_directory_exists(const utf8* path) -{ - mode_t mask = openrct2_getumask(); - char buffer[MAX_PATH]; - safe_strcpy(buffer, path, sizeof(buffer)); - - log_verbose("Create directory: %s", buffer); - for (char* p = buffer + 1; *p != '\0'; p++) - { - if (*p == '/') - { - // Temporarily truncate - *p = '\0'; - - log_verbose("mkdir(%s)", buffer); - if (mkdir(buffer, mask) != 0) - { - if (errno != EEXIST) - { - return false; - } - } - - // Restore truncation - *p = '/'; - } - } - - log_verbose("mkdir(%s)", buffer); - if (mkdir(buffer, mask) != 0) - { - if (errno != EEXIST) - { - return false; - } - } - - return true; -} - -bool platform_lock_single_instance() -{ - char pidFilePath[MAX_PATH]; - - safe_strcpy(pidFilePath, _userDataDirectoryPath, sizeof(pidFilePath)); - safe_strcat_path(pidFilePath, SINGLE_INSTANCE_MUTEX_NAME, sizeof(pidFilePath)); - - // We will never close this file manually. The operating system will - // take care of that, because flock keeps the lock as long as the - // file is open and closes it automatically on file close. - // This is intentional. - int32_t pidFile = open(pidFilePath, O_CREAT | O_RDWR, 0666); - - if (pidFile == -1) - { - log_warning("Cannot open lock file for writing."); - return false; - } - - struct flock lock; - - lock.l_start = 0; - lock.l_len = 0; - lock.l_type = F_WRLCK; - lock.l_whence = SEEK_SET; - - if (fcntl(pidFile, F_SETLK, &lock) == -1) - { - if (errno == EWOULDBLOCK) - { - log_warning("Another OpenRCT2 session has been found running."); - return false; - } - log_error("flock returned an uncatched errno: %d", errno); - return false; - } - return true; -} - -int32_t platform_get_drives() -{ - // POSIX systems do not know drives. Return 0. - return 0; -} - -time_t platform_file_get_modified_time(const utf8* path) -{ - struct stat buf; - if (stat(path, &buf) == 0) - { - return buf.st_mtime; - } - return 100; -} - -datetime64 platform_get_datetime_now_utc() -{ - const datetime64 epochAsTicks = 621355968000000000; - - struct timeval tv; - gettimeofday(&tv, NULL); - - // Epoch starts from: 1970-01-01T00:00:00Z - // Convert to ticks from 0001-01-01T00:00:00Z - uint64_t utcEpochTicks = static_cast(tv.tv_sec) * 10000000ULL + tv.tv_usec * 10; - datetime64 utcNow = epochAsTicks + utcEpochTicks; - return utcNow; -} - -std::string platform_get_rct1_steam_dir() -{ - return "app_285310" PATH_SEPARATOR "depot_285311"; -} - -std::string platform_get_rct2_steam_dir() -{ - return "app_285330" PATH_SEPARATOR "depot_285331"; -} - -#endif diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index 02c75c6313..ebb3c9ed18 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -11,66 +11,40 @@ #ifdef _WIN32 # include -#else -# include #endif #include "../Context.h" #include "../Game.h" -#include "../OpenRCT2.h" #include "../config/Config.h" #include "../core/File.h" -#include "../core/FileSystem.hpp" #include "../core/Path.hpp" -#include "../core/String.hpp" -#include "../drawing/Drawing.h" -#include "../drawing/LightFX.h" -#include "../localisation/Currency.h" #include "../localisation/Localisation.h" -#include "../util/Util.h" -#include "../world/Climate.h" -#include "Platform2.h" +#include "Platform.h" #include #include #include -#include #include -#ifdef __APPLE__ -# include -# include -# ifndef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -# error Missing __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ define -# endif -#endif - -#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) -static mach_timebase_info_data_t _mach_base_info = {}; -#endif - -#ifdef _WIN32 -char* strndup(const char* src, size_t size) -{ - size_t len = strnlen(src, size); - char* dst = reinterpret_cast(malloc(len + 1)); - - if (dst == nullptr) - { - return nullptr; - } - - dst = reinterpret_cast(std::memcpy(dst, src, len)); - dst[len] = '\0'; - return dst; -} - -static uint32_t _frequency = 0; -static LARGE_INTEGER _entryTimestamp; -#endif // _WIN32 - namespace Platform { + void CoreInit() + { + static bool initialised = false; + if (!initialised) + { + initialised = true; + +#ifdef __ANDROID__ + Platform::AndroidInitClassLoader(); +#endif // __ANDROID__ + + InitTicks(); + bitcount_init(); + mask_init(); + } + } + CurrencyType GetCurrencyValue(const char* currCode) { if (currCode == nullptr || strlen(currCode) < 3) @@ -145,98 +119,3 @@ namespace Platform } #endif } // namespace Platform - -GamePalette gPalette; - -void platform_toggle_windowed_mode() -{ - int32_t targetMode = gConfigGeneral.fullscreen_mode == 0 ? 2 : 0; - context_set_fullscreen_mode(targetMode); - gConfigGeneral.fullscreen_mode = targetMode; - config_save_default(); -} - -void platform_refresh_video(bool recreate_window) -{ - if (recreate_window) - { - context_recreate_window(); - } - else - { - drawing_engine_dispose(); - drawing_engine_init(); - drawing_engine_resize(); - } - - drawing_engine_set_palette(gPalette); - gfx_invalidate_screen(); -} - -static void platform_ticks_init() -{ -#ifdef _WIN32 - LARGE_INTEGER freq; - QueryPerformanceFrequency(&freq); - _frequency = static_cast(freq.QuadPart / 1000); - QueryPerformanceCounter(&_entryTimestamp); -#endif -} - -uint32_t platform_get_ticks() -{ -#ifdef _WIN32 - LARGE_INTEGER pfc; - QueryPerformanceCounter(&pfc); - - LARGE_INTEGER runningDelta; - runningDelta.QuadPart = pfc.QuadPart - _entryTimestamp.QuadPart; - - return static_cast(runningDelta.QuadPart / _frequency); -#elif defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) - return static_cast(((mach_absolute_time() * _mach_base_info.numer) / _mach_base_info.denom) / 1000000); -#else - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - { - log_fatal("clock_gettime failed"); - exit(-1); - } - return static_cast(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); -#endif -} - -void platform_sleep(uint32_t ms) -{ -#ifdef _WIN32 - Sleep(ms); -#else - usleep(ms * 1000); -#endif -} - -void core_init() -{ - static bool initialised = false; - if (!initialised) - { - initialised = true; - -#ifdef __ANDROID__ - Platform::AndroidInitClassLoader(); -#endif // __ANDROID__ - - platform_ticks_init(); - bitcount_init(); - mask_init(); - -#if defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200) - kern_return_t ret = mach_timebase_info(&_mach_base_info); - if (ret != 0) - { - log_fatal("Unable to get mach_timebase_info."); - exit(-1); - } -#endif - } -} diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp deleted file mode 100644 index 724ad8f724..0000000000 --- a/src/openrct2/platform/Windows.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2020 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. - *****************************************************************************/ - -#if defined(__MINGW32__) && !defined(WINVER) && !defined(_WIN32_WINNT) -// 0x0600 == vista -# define WINVER 0x0600 -# define _WIN32_WINNT 0x0600 -#endif // __MINGW32__ - -#ifdef _WIN32 - -// Windows.h needs to be included first -// clang-format off -# include -# include -// clang-format on - -// Then the rest -# include "../OpenRCT2.h" -# include "../Version.h" -# include "../config/Config.h" -# include "../core/Path.hpp" -# include "../core/String.hpp" -# include "../localisation/Date.h" -# include "../localisation/Language.h" -# include "../rct2/RCT2.h" -# include "../util/Util.h" -# include "Platform2.h" -# include "platform.h" - -# include -# include -# include -# include -# include -# include -# include -# include - -// Native resource IDs -# include "../../../resources/resource.h" - -// Enable visual styles -# pragma comment( \ - linker, \ - "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") - -// The name of the mutex used to prevent multiple instances of the game from running -# define SINGLE_INSTANCE_MUTEX_NAME "RollerCoaster Tycoon 2_GSKMUTEX" - -# define OPENRCT2_DLL_MODULE_NAME "openrct2.dll" - -# if _WIN32_WINNT < 0x600 -# define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__) -# endif - -bool platform_ensure_directory_exists(const utf8* path) -{ - if (Path::DirectoryExists(path)) - return 1; - - auto wPath = String::ToWideChar(path); - auto success = CreateDirectoryW(wPath.c_str(), nullptr); - return success != FALSE; -} - -bool platform_lock_single_instance() -{ - HANDLE mutex, status; - - // Check if operating system mutex exists - mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, SINGLE_INSTANCE_MUTEX_NAME); - if (mutex == nullptr) - { - // Create new mutex - status = CreateMutex(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME); - if (status == nullptr) - log_error("unable to create mutex"); - - return true; - } - - // Already running - CloseHandle(mutex); - return false; -} - -int32_t platform_get_drives() -{ - return GetLogicalDrives(); -} - -std::string platform_get_rct1_steam_dir() -{ - return "Rollercoaster Tycoon Deluxe"; -} - -std::string platform_get_rct2_steam_dir() -{ - return "Rollercoaster Tycoon 2"; -} - -time_t platform_file_get_modified_time(const utf8* path) -{ - WIN32_FILE_ATTRIBUTE_DATA data{}; - auto wPath = String::ToWideChar(path); - auto result = GetFileAttributesExW(wPath.c_str(), GetFileExInfoStandard, &data); - if (result != FALSE) - { - FILETIME localFileTime{}; - result = FileTimeToLocalFileTime(&data.ftLastWriteTime, &localFileTime); - if (result != FALSE) - { - ULARGE_INTEGER ull{}; - ull.LowPart = localFileTime.dwLowDateTime; - ull.HighPart = localFileTime.dwHighDateTime; - return ull.QuadPart / 10000000ULL - 11644473600ULL; - } - } - return 0; -} - -datetime64 platform_get_datetime_now_utc() -{ - // Get file time - FILETIME fileTime; - GetSystemTimeAsFileTime(&fileTime); - uint64_t fileTime64 = (static_cast(fileTime.dwHighDateTime) << 32ULL) - | (static_cast(fileTime.dwLowDateTime)); - - // File time starts from: 1601-01-01T00:00:00Z - // Convert to start from: 0001-01-01T00:00:00Z - datetime64 utcNow = fileTime64 - 504911232000000000ULL; - return utcNow; -} - -/////////////////////////////////////////////////////////////////////////////// -// URI protocol association setup -/////////////////////////////////////////////////////////////////////////////// - -# define SOFTWARE_CLASSES L"Software\\Classes" -# define MUI_CACHE L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" - -bool platform_setup_uri_protocol() -{ -# if _WIN32_WINNT >= 0x0600 - log_verbose("Setting up URI protocol..."); - - // [HKEY_CURRENT_USER\Software\Classes] - HKEY hRootKey; - if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS) - { - // [hRootKey\openrct2] - HKEY hClassKey; - if (RegCreateKeyA(hRootKey, "openrct2", &hClassKey) == ERROR_SUCCESS) - { - if (RegSetValueA(hClassKey, nullptr, REG_SZ, "URL:openrct2", 0) == ERROR_SUCCESS) - { - if (RegSetKeyValueA(hClassKey, nullptr, "URL Protocol", REG_SZ, "", 0) == ERROR_SUCCESS) - { - // [hRootKey\openrct2\shell\open\command] - wchar_t exePath[MAX_PATH]; - GetModuleFileNameW(nullptr, exePath, MAX_PATH); - - wchar_t buffer[512]; - swprintf_s(buffer, std::size(buffer), L"\"%s\" handle-uri \"%%1\"", exePath); - if (RegSetValueW(hClassKey, L"shell\\open\\command", REG_SZ, buffer, 0) == ERROR_SUCCESS) - { - // Not compulsory, but gives the application a nicer name - // [HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache] - HKEY hMuiCacheKey; - if (RegCreateKeyW(hRootKey, MUI_CACHE, &hMuiCacheKey) == ERROR_SUCCESS) - { - swprintf_s(buffer, std::size(buffer), L"%s.FriendlyAppName", exePath); - // mingw-w64 used to define RegSetKeyValueW's signature incorrectly - // You need at least mingw-w64 5.0 including this commit: - // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/da9341980a4b70be3563ac09b5927539e7da21f7/ - RegSetKeyValueW(hMuiCacheKey, nullptr, buffer, REG_SZ, L"OpenRCT2", sizeof(L"OpenRCT2")); - } - - log_verbose("URI protocol setup successful"); - return true; - } - } - } - } - } -# endif - - log_verbose("URI protocol setup failed"); - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -#endif diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h deleted file mode 100644 index 269d07c0a2..0000000000 --- a/src/openrct2/platform/platform.h +++ /dev/null @@ -1,108 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014-2020 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. - *****************************************************************************/ - -#pragma once - -#include "../common.h" -#include "../config/Config.h" - -#include -#include - -#ifdef __ANDROID__ -# include -#endif // __ANDROID__ - -struct TTFFontDescriptor; -namespace OpenRCT2::Ui -{ - struct FileDialogDesc; -} - -#ifndef MAX_PATH -# define MAX_PATH 260 -#endif - -#define INVALID_HANDLE (-1) - -#ifdef _WIN32 -# define PATH_SEPARATOR "\\" -# define PLATFORM_NEWLINE "\r\n" -#else -# define PATH_SEPARATOR "/" -# define PLATFORM_NEWLINE "\n" -#endif - -struct resolution_t -{ - int32_t width, height; -}; - -struct file_info -{ - const char* path; - uint64_t size; - uint64_t last_modified; -}; - -struct rct2_date -{ - uint8_t day; - uint8_t month; - int16_t year; - uint8_t day_of_week; -}; - -struct rct2_time -{ - uint8_t hour; - uint8_t minute; - uint8_t second; -}; - -// Platform shared definitions -void platform_toggle_windowed_mode(); -void platform_refresh_video(bool recreate_window); - -// Platform specific definitions -time_t platform_file_get_modified_time(const utf8* path); -bool platform_ensure_directory_exists(const utf8* path); -bool platform_lock_single_instance(); - -// Returns the bitmask of the GetLogicalDrives function for windows, 0 for other systems -int32_t platform_get_drives(); -uint32_t platform_get_ticks(); -void platform_sleep(uint32_t ms); -bool platform_open_common_file_dialog(utf8* outFilename, OpenRCT2::Ui::FileDialogDesc& desc, size_t outSize); -std::string platform_get_rct1_steam_dir(); -std::string platform_get_rct2_steam_dir(); - -datetime64 platform_get_datetime_now_utc(); - -// Called very early in the program before parsing commandline arguments. -void core_init(); - -// Windows specific definitions -#ifdef _WIN32 -# ifndef NOMINMAX -# define NOMINMAX -# endif -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -# include -# undef CreateDirectory -# undef CreateWindow -# undef GetMessage - -bool platform_setup_uri_protocol(); -// This function cannot be marked as 'static', even though it may seem to be, -// as it requires external linkage, which 'static' prevents -__declspec(dllexport) int32_t StartOpenRCT2(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int32_t nCmdShow); -#endif // _WIN32 diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index a764f41934..daa7435256 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -17,7 +17,7 @@ #include "../localisation/Localisation.h" #include "../management/Finance.h" #include "../network/network.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../rct1/RCT1.h" #include "../util/SawyerCoding.h" #include "../util/Util.h" diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bb9098aba2..4b2d791f2a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -24,7 +24,7 @@ #include "../localisation/Formatter.h" #include "../localisation/Localisation.h" #include "../management/NewsItem.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../profiling/Profiling.h" #include "../rct12/RCT12.h" #include "../scenario/Scenario.h" diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index ceba5554f7..c3259fe1e5 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -38,7 +38,7 @@ #include "../object/Object.h" #include "../object/ObjectList.h" #include "../object/ObjectManager.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../profiling/Profiling.h" #include "../rct1/RCT1.h" #include "../rct12/RCT12.h" @@ -93,7 +93,7 @@ void scenario_begin() game_load_init(); // Set the scenario pseudo-random seeds - Random::Rct2::Seed s{ 0x1234567F ^ platform_get_ticks(), 0x789FABCD ^ platform_get_ticks() }; + Random::Rct2::Seed s{ 0x1234567F ^ Platform::GetTicks(), 0x789FABCD ^ Platform::GetTicks() }; gScenarioRand.seed(s); gParkFlags &= ~PARK_FLAGS_NO_MONEY; @@ -262,7 +262,7 @@ void scenario_autosave_check() return; // Milliseconds since last save - uint32_t timeSinceSave = platform_get_ticks() - gLastAutoSaveUpdate; + uint32_t timeSinceSave = Platform::GetTicks() - gLastAutoSaveUpdate; bool shouldSave = false; switch (gConfigGeneral.autosave_frequency) diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index bec928aa3f..54dd575e06 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -25,7 +25,7 @@ #include "../localisation/Language.h" #include "../localisation/Localisation.h" #include "../localisation/LocalisationService.h" -#include "../platform/Platform2.h" +#include "../platform/Platform.h" #include "../rct12/RCT12.h" #include "../rct12/SawyerChunkReader.h" #include "Scenario.h" @@ -464,14 +464,14 @@ public: if (highscore == nullptr) { highscore = InsertHighscore(); - highscore->timestamp = platform_get_datetime_now_utc(); + highscore->timestamp = Platform::GetDatetimeNowUTC(); scenario->highscore = highscore; } else { if (!String::IsNullOrEmpty(highscore->name)) { - highscore->timestamp = platform_get_datetime_now_utc(); + highscore->timestamp = Platform::GetDatetimeNowUTC(); } SafeFree(highscore->fileName); SafeFree(highscore->name); @@ -531,7 +531,7 @@ private: void ConvertMegaPark(const std::string& srcPath, const std::string& dstPath) { auto directory = Path::GetDirectory(dstPath); - platform_ensure_directory_exists(directory.c_str()); + Platform::EnsureDirectoryExists(directory.c_str()); auto mpdat = File::ReadAllBytes(srcPath); diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 71c44c2f17..1b49413019 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -22,7 +22,7 @@ # include "../core/FileScanner.h" # include "../core/Path.hpp" # include "../interface/InteractiveConsole.h" -# include "../platform/Platform2.h" +# include "../platform/Platform.h" # include "Duktape.hpp" # include "bindings/entity/ScEntity.hpp" # include "bindings/entity/ScGuest.hpp" @@ -1290,7 +1290,7 @@ void ScriptEngine::RemoveInterval(const std::shared_ptr& plugin, Interva void ScriptEngine::UpdateIntervals() { - uint32_t timestamp = platform_get_ticks(); + uint32_t timestamp = Platform::GetTicks(); if (timestamp < _lastIntervalTimestamp) { // timestamp has wrapped, subtract all intervals by the remaining amount before wrap diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index 982f3f5608..9845907dac 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -19,7 +19,7 @@ #include "../core/Path.hpp" #include "../core/String.hpp" #include "../localisation/Localisation.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "TitleSequence.h" #include diff --git a/src/openrct2/util/SawyerCoding.cpp b/src/openrct2/util/SawyerCoding.cpp index 0456aa6a9c..26adf55b68 100644 --- a/src/openrct2/util/SawyerCoding.cpp +++ b/src/openrct2/util/SawyerCoding.cpp @@ -10,7 +10,7 @@ #include "SawyerCoding.h" #include "../core/Numerics.hpp" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../scenario/Scenario.h" #include "Util.h" diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 63d81e80f6..861033004c 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -14,7 +14,7 @@ #include "../core/Path.hpp" #include "../interface/Window.h" #include "../localisation/Localisation.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../title/TitleScreen.h" #include "zlib.h" diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index d08004b745..98b3df6f95 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -21,7 +21,7 @@ #include "../object/ObjectManager.h" #include "../object/TerrainEdgeObject.h" #include "../object/TerrainSurfaceObject.h" -#include "../platform/platform.h" +#include "../platform/Platform.h" #include "../util/Util.h" #include "Map.h" #include "MapHelpers.h" diff --git a/test/tests/IniWriterTest.cpp b/test/tests/IniWriterTest.cpp index a50988f9f2..7345ebd382 100644 --- a/test/tests/IniWriterTest.cpp +++ b/test/tests/IniWriterTest.cpp @@ -11,7 +11,7 @@ #include "openrct2/config/ConfigEnum.hpp" #include "openrct2/core/MemoryStream.h" -#include "openrct2/platform/platform.h" +#include "openrct2/platform/Platform.h" #include #include diff --git a/test/tests/MultiLaunch.cpp b/test/tests/MultiLaunch.cpp index b3a37db893..cf3c889293 100644 --- a/test/tests/MultiLaunch.cpp +++ b/test/tests/MultiLaunch.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include @@ -34,7 +34,7 @@ TEST(MultiLaunchTest, all) gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); for (int i = 0; i < 3; i++) { auto context = CreateContext(); diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index d49face68e..5b893429e9 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -26,7 +26,7 @@ class PathfindingTestBase : public testing::Test public: static void SetUpTestCase() { - core_init(); + Platform::CoreInit(); gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; diff --git a/test/tests/Platform.cpp b/test/tests/Platform.cpp index 4724d6735d..9ca0863bd0 100644 --- a/test/tests/Platform.cpp +++ b/test/tests/Platform.cpp @@ -8,7 +8,7 @@ *****************************************************************************/ #include -#include +#include TEST(platform, sanitise_filename) { diff --git a/test/tests/PlayTests.cpp b/test/tests/PlayTests.cpp index 1664002918..297227756b 100644 --- a/test/tests/PlayTests.cpp +++ b/test/tests/PlayTests.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ static std::unique_ptr localStartGame(const std::string& parkPath) { gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); auto context = CreateContext(); if (!context->Initialise()) diff --git a/test/tests/ReplayTests.cpp b/test/tests/ReplayTests.cpp index 88c5a6a581..18cadcfddd 100644 --- a/test/tests/ReplayTests.cpp +++ b/test/tests/ReplayTests.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -73,7 +73,7 @@ TEST_P(ReplayTests, RunReplay) { gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); auto testData = GetParam(); auto replayFile = testData.filePath; diff --git a/test/tests/RideRatings.cpp b/test/tests/RideRatings.cpp index fc6c920354..ece0c11bf6 100644 --- a/test/tests/RideRatings.cpp +++ b/test/tests/RideRatings.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -61,7 +61,7 @@ TEST_F(RideRatings, all) gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); auto context = CreateContext(); bool initialised = context->Initialise(); ASSERT_TRUE(initialised); diff --git a/test/tests/S6ImportExportTests.cpp b/test/tests/S6ImportExportTests.cpp index 536da6cc09..0dbd01ecd4 100644 --- a/test/tests/S6ImportExportTests.cpp +++ b/test/tests/S6ImportExportTests.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -187,7 +187,7 @@ TEST(S6ImportExportBasic, all) gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); MemoryStream importBuffer; MemoryStream exportBuffer; @@ -233,7 +233,7 @@ TEST(S6ImportExportAdvanceTicks, all) gOpenRCT2Headless = true; gOpenRCT2NoGraphics = true; - core_init(); + Platform::CoreInit(); MemoryStream importBuffer; MemoryStream exportBuffer;