diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 5d01140530..873e50a434 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -38,6 +38,7 @@ #include "object/ObjectList.h" #include "peep/Peep.h" #include "peep/Staff.h" +#include "platform/Platform2.h" #include "platform/platform.h" #include "rct1/RCT1.h" #include "ride/Ride.h" @@ -766,10 +767,8 @@ void game_autosave() } // Retrieve current time - rct2_date currentDate; - platform_get_date_local(¤tDate); - rct2_time currentTime; - platform_get_time_local(¤tTime); + auto currentDate = Platform::GetDateLocal(); + auto currentTime = Platform::GetTimeLocal(); utf8 timeName[44]; snprintf( diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index c0524a5d73..b6e0775ede 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -20,6 +20,7 @@ #include "../drawing/Drawing.h" #include "../drawing/X8DrawingEngine.h" #include "../localisation/Localisation.h" +#include "../platform/Platform2.h" #include "../platform/platform.h" #include "../util/Util.h" #include "../world/Climate.h" @@ -106,11 +107,8 @@ static std::string screenshot_get_directory() static std::pair screenshot_get_date_time() { - rct2_date date; - platform_get_date_local(&date); - - rct2_time time; - platform_get_time_local(&time); + auto date = Platform::GetDateLocal(); + auto time = Platform::GetTimeLocal(); return { date, time }; } diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index e960e33719..67f81d5723 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -10,6 +10,7 @@ #pragma once #include "../common.h" +#include "platform.h" #include #include @@ -32,6 +33,8 @@ namespace Platform std::string GetInstallPath(); std::string GetDocsPath(); std::string GetCurrentExecutablePath(); + rct2_time GetTimeLocal(); + rct2_date GetDateLocal(); #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) std::string GetEnvironmentPath(const char* name); diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index ca7b1dddf4..65f16cfe3d 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -71,31 +71,6 @@ void platform_get_time_utc(rct2_time* out_time) out_time->hour = timeinfo->tm_hour; } -void platform_get_date_local(rct2_date* out_date) -{ - assert(out_date != nullptr); - time_t rawtime; - struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - out_date->day = timeinfo->tm_mday; - out_date->month = timeinfo->tm_mon + 1; - out_date->year = timeinfo->tm_year + 1900; - out_date->day_of_week = timeinfo->tm_wday; -} - -void platform_get_time_local(rct2_time* out_time) -{ - assert(out_time != nullptr); - time_t rawtime; - struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - out_time->second = timeinfo->tm_sec; - out_time->minute = timeinfo->tm_min; - out_time->hour = timeinfo->tm_hour; -} - bool platform_file_exists(const utf8* path) { bool exists = access(path, F_OK) != -1; diff --git a/src/openrct2/platform/Shared.cpp b/src/openrct2/platform/Shared.cpp index caa711393f..aa289c1e48 100644 --- a/src/openrct2/platform/Shared.cpp +++ b/src/openrct2/platform/Shared.cpp @@ -26,7 +26,7 @@ #include "../localisation/Localisation.h" #include "../util/Util.h" #include "../world/Climate.h" -#include "platform.h" +#include "Platform2.h" #include #include @@ -64,6 +64,34 @@ static uint32_t _frequency = 0; static LARGE_INTEGER _entryTimestamp; #endif // _WIN32 +namespace Platform +{ + rct2_date GetDateLocal() + { + auto time = std::time(nullptr); + auto localTime = std::localtime(&time); + + rct2_date outDate; + outDate.day = localTime->tm_mday; + outDate.day_of_week = localTime->tm_wday; + outDate.month = localTime->tm_mon; + outDate.year = localTime->tm_year; + return outDate; + } + + rct2_time GetTimeLocal() + { + auto time = std::time(nullptr); + auto localTime = std::localtime(&time); + + rct2_time outTime; + outTime.hour = localTime->tm_hour; + outTime.minute = localTime->tm_min; + outTime.second = localTime->tm_sec; + return outTime; + } +} // namespace Platform + using update_palette_func = void (*)(const uint8_t*, int32_t, int32_t); GamePalette gPalette; diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 9fc1572d06..9aeede6826 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -55,28 +55,6 @@ # define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__) # endif -void platform_get_date_local(rct2_date* out_date) -{ - assert(out_date != nullptr); - SYSTEMTIME systime; - - GetLocalTime(&systime); - out_date->day = systime.wDay; - out_date->month = systime.wMonth; - out_date->year = systime.wYear; - out_date->day_of_week = systime.wDayOfWeek; -} - -void platform_get_time_local(rct2_time* out_time) -{ - assert(out_time != nullptr); - SYSTEMTIME systime; - GetLocalTime(&systime); - out_time->hour = systime.wHour; - out_time->minute = systime.wMinute; - out_time->second = systime.wSecond; -} - bool platform_file_exists(const utf8* path) { auto wPath = String::ToWideChar(path); diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index 2aabe7f161..80e951095a 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -88,8 +88,6 @@ void platform_toggle_windowed_mode(); void platform_refresh_video(bool recreate_window); void platform_get_date_utc(rct2_date* out_date); void platform_get_time_utc(rct2_time* out_time); -void platform_get_date_local(rct2_date* out_date); -void platform_get_time_local(rct2_time* out_time); // Platform specific definitions bool platform_file_exists(const utf8* path);