mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Part of #11437: Move GetDateLocal and GetTimeLocal in Platform2.h
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include "object/ObjectList.h"
|
#include "object/ObjectList.h"
|
||||||
#include "peep/Peep.h"
|
#include "peep/Peep.h"
|
||||||
#include "peep/Staff.h"
|
#include "peep/Staff.h"
|
||||||
|
#include "platform/Platform2.h"
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
#include "rct1/RCT1.h"
|
#include "rct1/RCT1.h"
|
||||||
#include "ride/Ride.h"
|
#include "ride/Ride.h"
|
||||||
@@ -766,10 +767,8 @@ void game_autosave()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve current time
|
// Retrieve current time
|
||||||
rct2_date currentDate;
|
auto currentDate = Platform::GetDateLocal();
|
||||||
platform_get_date_local(¤tDate);
|
auto currentTime = Platform::GetTimeLocal();
|
||||||
rct2_time currentTime;
|
|
||||||
platform_get_time_local(¤tTime);
|
|
||||||
|
|
||||||
utf8 timeName[44];
|
utf8 timeName[44];
|
||||||
snprintf(
|
snprintf(
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "../drawing/Drawing.h"
|
#include "../drawing/Drawing.h"
|
||||||
#include "../drawing/X8DrawingEngine.h"
|
#include "../drawing/X8DrawingEngine.h"
|
||||||
#include "../localisation/Localisation.h"
|
#include "../localisation/Localisation.h"
|
||||||
|
#include "../platform/Platform2.h"
|
||||||
#include "../platform/platform.h"
|
#include "../platform/platform.h"
|
||||||
#include "../util/Util.h"
|
#include "../util/Util.h"
|
||||||
#include "../world/Climate.h"
|
#include "../world/Climate.h"
|
||||||
@@ -106,11 +107,8 @@ static std::string screenshot_get_directory()
|
|||||||
|
|
||||||
static std::pair<rct2_date, rct2_time> screenshot_get_date_time()
|
static std::pair<rct2_date, rct2_time> screenshot_get_date_time()
|
||||||
{
|
{
|
||||||
rct2_date date;
|
auto date = Platform::GetDateLocal();
|
||||||
platform_get_date_local(&date);
|
auto time = Platform::GetTimeLocal();
|
||||||
|
|
||||||
rct2_time time;
|
|
||||||
platform_get_time_local(&time);
|
|
||||||
|
|
||||||
return { date, time };
|
return { date, time };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -32,6 +33,8 @@ namespace Platform
|
|||||||
std::string GetInstallPath();
|
std::string GetInstallPath();
|
||||||
std::string GetDocsPath();
|
std::string GetDocsPath();
|
||||||
std::string GetCurrentExecutablePath();
|
std::string GetCurrentExecutablePath();
|
||||||
|
rct2_time GetTimeLocal();
|
||||||
|
rct2_date GetDateLocal();
|
||||||
|
|
||||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
|
||||||
std::string GetEnvironmentPath(const char* name);
|
std::string GetEnvironmentPath(const char* name);
|
||||||
|
|||||||
@@ -71,31 +71,6 @@ void platform_get_time_utc(rct2_time* out_time)
|
|||||||
out_time->hour = timeinfo->tm_hour;
|
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 platform_file_exists(const utf8* path)
|
||||||
{
|
{
|
||||||
bool exists = access(path, F_OK) != -1;
|
bool exists = access(path, F_OK) != -1;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "../localisation/Localisation.h"
|
#include "../localisation/Localisation.h"
|
||||||
#include "../util/Util.h"
|
#include "../util/Util.h"
|
||||||
#include "../world/Climate.h"
|
#include "../world/Climate.h"
|
||||||
#include "platform.h"
|
#include "Platform2.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -64,6 +64,34 @@ static uint32_t _frequency = 0;
|
|||||||
static LARGE_INTEGER _entryTimestamp;
|
static LARGE_INTEGER _entryTimestamp;
|
||||||
#endif // _WIN32
|
#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);
|
using update_palette_func = void (*)(const uint8_t*, int32_t, int32_t);
|
||||||
|
|
||||||
GamePalette gPalette;
|
GamePalette gPalette;
|
||||||
|
|||||||
@@ -55,28 +55,6 @@
|
|||||||
# define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__)
|
# define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__)
|
||||||
# endif
|
# 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)
|
bool platform_file_exists(const utf8* path)
|
||||||
{
|
{
|
||||||
auto wPath = String::ToWideChar(path);
|
auto wPath = String::ToWideChar(path);
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ void platform_toggle_windowed_mode();
|
|||||||
void platform_refresh_video(bool recreate_window);
|
void platform_refresh_video(bool recreate_window);
|
||||||
void platform_get_date_utc(rct2_date* out_date);
|
void platform_get_date_utc(rct2_date* out_date);
|
||||||
void platform_get_time_utc(rct2_time* out_time);
|
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
|
// Platform specific definitions
|
||||||
bool platform_file_exists(const utf8* path);
|
bool platform_file_exists(const utf8* path);
|
||||||
|
|||||||
Reference in New Issue
Block a user