Close #11437: Migrate old platform methods

This commit is contained in:
Michael Steenbeek 2022-02-18 21:57:00 +01:00 committed by GitHub
parent b424682934
commit 5edc561715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 613 additions and 793 deletions

View File

@ -10,7 +10,7 @@
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/cmdline/CommandLine.hpp>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
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;

View File

@ -18,7 +18,7 @@
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/cmdline/CommandLine.hpp>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ui/UiContext.h>
using namespace OpenRCT2;
@ -42,7 +42,7 @@ int main(int argc, const char** argv)
std::unique_ptr<IContext> context;
int32_t rc = EXIT_SUCCESS;
int runGame = cmdline_run(argv, argc);
core_init();
Platform::CoreInit();
RegisterBitmapReader();
if (runGame == EXITCODE_CONTINUE)
{

View File

@ -16,7 +16,7 @@
# include <jni.h>
# include <openrct2/common.h>
# include <openrct2/core/String.hpp>
# include <openrct2/platform/platform.h>
# include <openrct2/platform/Platform.h>
# include <openrct2/ui/UiContext.h>
# include <sstream>
# include <stdexcept>

View File

@ -18,7 +18,7 @@
# include <openrct2/core/String.hpp>
# include <openrct2/core/StringBuilder.h>
# include <openrct2/localisation/Localisation.h>
# include <openrct2/platform/Platform2.h>
# include <openrct2/platform/Platform.h>
# include <openrct2/ui/UiContext.h>
# include <sstream>
# include <stdexcept>

View File

@ -39,7 +39,7 @@
#include <openrct2/interface/Chat.h>
#include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/localisation/StringIds.h>
#include <openrct2/platform/Platform2.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/scripting/ScriptEngine.h>
#include <openrct2/title/TitleSequencePlayer.h>
#include <openrct2/ui/UiContext.h>

View File

@ -26,7 +26,7 @@
#include <openrct2/interface/InteractiveConsole.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/world/Banner.h>

View File

@ -29,7 +29,7 @@
#include <openrct2/interface/Screenshot.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/network/network.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Track.h>
#include <openrct2/ride/TrackPaint.h>
#include <openrct2/scenario/Scenario.h>
@ -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(); });

View File

@ -18,7 +18,7 @@
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ui/UiContext.h>
#include <openrct2/util/Util.h>
#include <vector>

View File

@ -30,7 +30,7 @@
#include <openrct2/object/ObjectRepository.h>
#include <openrct2/object/RideObject.h>
#include <openrct2/object/SceneryGroupObject.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/sprites.h>

View File

@ -25,7 +25,7 @@
#include <openrct2/object/FootpathSurfaceObject.h>
#include <openrct2/object/ObjectLimits.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/sprites.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Park.h>
@ -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)

View File

@ -18,7 +18,7 @@
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/platform/Platform2.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/RideConstruction.h>
#include <openrct2/ride/RideData.h>
#include <openrct2/ride/TrackDesign.h>
@ -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, {});

View File

@ -26,8 +26,7 @@
#include <openrct2/core/String.hpp>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/platform/Platform2.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/rct2/T6Exporter.h>
#include <openrct2/ride/TrackDesign.h>
#include <openrct2/scenario/Scenario.h>
@ -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);

View File

@ -20,7 +20,7 @@
#include <openrct2/object/ObjectList.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/object/ObjectRepository.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ui/UiContext.h>
#include <openrct2/windows/Intent.h>
#include <sstream>

View File

@ -35,7 +35,7 @@
#include <openrct2/localisation/Localisation.h>
#include <openrct2/localisation/LocalisationService.h>
#include <openrct2/network/network.h>
#include <openrct2/platform/Platform2.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/RideAudio.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/sprites.h>
@ -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();
}

View File

@ -27,7 +27,7 @@
#include <openrct2/localisation/Localisation.h>
#include <openrct2/network/network.h>
#include <openrct2/paint/tile_element/Paint.TileElement.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideConstruction.h>
#include <openrct2/ride/RideData.h>
@ -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;

View File

@ -24,7 +24,7 @@
# include <openrct2/localisation/Localisation.h>
# include <openrct2/network/ServerList.h>
# include <openrct2/network/network.h>
# include <openrct2/platform/platform.h>
# include <openrct2/platform/Platform.h>
# include <openrct2/sprites.h>
# include <openrct2/util/Util.h>
# include <tuple>

View File

@ -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 <cmath>
@ -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;

View File

@ -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<uint32_t>(sleepTimeSec * 1000.f));
Platform::Sleep(static_cast<uint32_t>(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
{

View File

@ -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);

View File

@ -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";

View File

@ -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"

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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<RecordedPaintSession>& s)
static std::vector<RecordedPaintSession> extract_paint_session(std::string_view parkFileName)
{
core_init();
Platform::CoreInit();
gOpenRCT2Headless = true;
auto context = OpenRCT2::CreateContext();
std::vector<RecordedPaintSession> sessions;

View File

@ -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 <benchmark/benchmark.h>
# include <cstdint>
@ -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();

View File

@ -12,7 +12,7 @@
#include "../OpenRCT2.h"
#include "../core/Console.hpp"
#include "../core/String.hpp"
#include "../platform/Platform2.h"
#include "../platform/Platform.h"
#include <algorithm>
#include <cstring>

View File

@ -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"

View File

@ -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 <cstdlib>
@ -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]);

View File

@ -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)

View File

@ -11,7 +11,7 @@
#include "../core/IStream.hpp"
#include "../core/String.hpp"
#include "../platform/platform.h"
#include "../platform/Platform.h"
#include <sstream>

View File

@ -10,7 +10,7 @@
#include "Console.hpp"
#include "../Context.h"
#include "../platform/platform.h"
#include "../platform/Platform.h"
#include <cstdio>
#include <string>

View File

@ -11,7 +11,7 @@
# include "Crypt.h"
# include "../platform/Platform2.h"
# include "../platform/Platform.h"
# include "IStream.hpp"
# include <iomanip>

View File

@ -13,7 +13,7 @@
# include <sys/stat.h>
#endif
#include "../platform/Platform2.h"
#include "../platform/Platform.h"
#include "../util/Util.h"
#include "File.h"
#include "FileStream.h"

View File

@ -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)

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 <cstring>
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();
}

View File

@ -602,4 +602,7 @@ std::optional<uint32_t> GetPaletteG1Index(colour_t paletteId);
std::optional<PaletteMap> 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"

View File

@ -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"

View File

@ -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;

View File

@ -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<size_t>(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)

View File

@ -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"

View File

@ -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<std::string> 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;

View File

@ -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"

View File

@ -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"

View File

@ -314,8 +314,7 @@
<ClInclude Include="peep\RideUseSystem.h" />
<ClInclude Include="PlatformEnvironment.h" />
<ClInclude Include="platform\Crash.h" />
<ClInclude Include="platform\platform.h" />
<ClInclude Include="platform\Platform2.h" />
<ClInclude Include="platform\Platform.h" />
<ClInclude Include="profiling\Profiling.h" />
<ClInclude Include="profiling\ProfilingMacros.hpp" />
<ClInclude Include="rct12\EntryList.h" />
@ -792,9 +791,7 @@
<ClCompile Include="platform\Platform.Linux.cpp" />
<ClCompile Include="platform\Platform.Posix.cpp" />
<ClCompile Include="platform\Platform.Win32.cpp" />
<ClCompile Include="platform\Posix.cpp" />
<ClCompile Include="platform\Shared.cpp" />
<ClCompile Include="platform\Windows.cpp" />
<ClCompile Include="profiling\Profiling.cpp" />
<ClCompile Include="rct12\RCT12.cpp" />
<ClCompile Include="rct12\SawyerChunk.cpp" />
@ -955,4 +952,4 @@
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>

View File

@ -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"

View File

@ -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<uint32_t>(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<long long unsigned>(platform_get_datetime_now_utc()), tick);
static_cast<long long unsigned>(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<int32_t>(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)

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
{
log_warning("Error receiving data: %s", e.what());
}
platform_sleep(RECV_DELAY_MS);
Platform::Sleep(RECV_DELAY_MS);
}
return entries;
});

View File

@ -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"

View File

@ -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

View File

@ -9,9 +9,10 @@
#ifdef __ANDROID__
# include "Platform.h"
# include "../core/Guard.hpp"
# include "../localisation/Language.h"
# include "Platform2.h"
# include <SDL.h>
# include <jni.h>

View File

@ -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
{

View File

@ -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 <cerrno>
# include <clocale>
@ -23,20 +23,20 @@
# include <cstring>
# include <ctime>
# include <dirent.h>
# include <fcntl.h>
# include <fnmatch.h>
# include <locale>
# include <pwd.h>
# include <sys/stat.h>
# include <sys/time.h>
# 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<uint64_t>(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<uint32_t>(ts.tv_sec * 1000 + ts.tv_nsec / 1000000);
}
} // namespace Platform
#endif

View File

@ -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 <cstring>
# include <iterator>
# include <locale>
@ -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<char*>(malloc(len + 1));
if (dst == nullptr)
{
return nullptr;
}
dst = reinterpret_cast<char*>(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<uint64_t>(fileTime.dwHighDateTime) << 32ULL)
| (static_cast<uint64_t>(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<uint32_t>(runningDelta.QuadPart / _frequency);
}
void Sleep(uint32_t ms)
{
::Sleep(ms);
}
void InitTicks()
{
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
_frequency = static_cast<uint32_t>(freq.QuadPart / 1000);
QueryPerformanceCounter(&_entryTimestamp);
}
} // namespace Platform
#endif

View File

@ -10,11 +10,26 @@
#pragma once
#include "../common.h"
#include "platform.h"
#include "../config/Config.h"
#include <ctime>
#include <string>
#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 <jni.h>
#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 <windows.h>
# 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

View File

@ -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 <AvailabilityMacros.h>
# include <CoreText/CoreText.h>
# include <Foundation/Foundation.h>
# include <mach-o/dyld.h>
# include <mach/mach_time.h>
# include <pwd.h>
namespace Platform

View File

@ -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 <cstring>
# include <ctype.h>
# include <dirent.h>
# include <errno.h>
# include <fcntl.h>
# include <fnmatch.h>
# include <libgen.h>
# include <locale.h>
# include <locale>
# include <pwd.h>
# include <stdlib.h>
# include <sys/file.h>
# include <sys/stat.h>
# include <sys/time.h>
# include <time.h>
# include <unistd.h>
// 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<uint64_t>(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

View File

@ -11,66 +11,40 @@
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#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 <algorithm>
#include <array>
#include <cstring>
#include <stdlib.h>
#include <time.h>
#ifdef __APPLE__
# include <AvailabilityMacros.h>
# include <mach/mach_time.h>
# 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<char*>(malloc(len + 1));
if (dst == nullptr)
{
return nullptr;
}
dst = reinterpret_cast<char*>(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<uint32_t>(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<uint32_t>(runningDelta.QuadPart / _frequency);
#elif defined(__APPLE__) && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200)
return static_cast<uint32_t>(((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<uint32_t>(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
}
}

View File

@ -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 <windows.h>
# include <shellapi.h>
// 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 <algorithm>
# include <array>
# include <iterator>
# include <lmcons.h>
# include <memory>
# include <psapi.h>
# include <shlobj.h>
# include <sys/stat.h>
// 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<uint64_t>(fileTime.dwHighDateTime) << 32ULL)
| (static_cast<uint64_t>(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

View File

@ -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 <string>
#include <time.h>
#ifdef __ANDROID__
# include <jni.h>
#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 <windows.h>
# 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

View File

@ -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"

View File

@ -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"

View File

@ -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)

View File

@ -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);

View File

@ -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>& 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

View File

@ -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 <algorithm>

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 <gtest/gtest.h>
#include <limits>

View File

@ -19,7 +19,7 @@
#include <openrct2/core/File.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <string>
@ -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();

View File

@ -10,7 +10,7 @@
#include <openrct2/Game.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/ParkImporter.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/world/Footpath.h>
#include <openrct2/world/Map.h>
@ -26,7 +26,7 @@ class PathfindingTestBase : public testing::Test
public:
static void SetUpTestCase()
{
core_init();
Platform::CoreInit();
gOpenRCT2Headless = true;
gOpenRCT2NoGraphics = true;

View File

@ -8,7 +8,7 @@
*****************************************************************************/
#include <gtest/gtest.h>
#include <openrct2/platform/Platform2.h>
#include <openrct2/platform/Platform.h>
TEST(platform, sanitise_filename)
{

View File

@ -21,7 +21,7 @@
#include <openrct2/entity/EntityTweener.h>
#include <openrct2/entity/Peep.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/world/MapAnimation.h>
#include <openrct2/world/Park.h>
@ -38,7 +38,7 @@ static std::unique_ptr<IContext> localStartGame(const std::string& parkPath)
{
gOpenRCT2Headless = true;
gOpenRCT2NoGraphics = true;
core_init();
Platform::CoreInit();
auto context = CreateContext();
if (!context->Initialise())

View File

@ -20,7 +20,7 @@
#include <openrct2/core/FileScanner.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <string>
@ -73,7 +73,7 @@ TEST_P(ReplayTests, RunReplay)
{
gOpenRCT2Headless = true;
gOpenRCT2NoGraphics = true;
core_init();
Platform::CoreInit();
auto testData = GetParam();
auto replayFile = testData.filePath;

View File

@ -17,7 +17,7 @@
#include <openrct2/core/File.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/ride/RideData.h>
#include <string>
@ -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);

View File

@ -29,7 +29,7 @@
#include <openrct2/network/network.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/park/ParkFile.h>
#include <openrct2/platform/platform.h>
#include <openrct2/platform/Platform.h>
#include <openrct2/ride/Ride.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/world/MapAnimation.h>
@ -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;