Remove OS.get_system_time_secs/get_system_time_msecs and change OS.get_unix_time return type to double
This commit is contained in:
parent
a8787d1ae5
commit
c6de3872f9
@ -498,18 +498,10 @@ Dictionary _OS::get_time_zone_info() const {
|
|||||||
return infod;
|
return infod;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t _OS::get_unix_time() const {
|
double _OS::get_unix_time() const {
|
||||||
return OS::get_singleton()->get_unix_time();
|
return OS::get_singleton()->get_unix_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t _OS::get_system_time_secs() const {
|
|
||||||
return OS::get_singleton()->get_system_time_secs();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t _OS::get_system_time_msecs() const {
|
|
||||||
return OS::get_singleton()->get_system_time_msecs();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _OS::delay_usec(uint32_t p_usec) const {
|
void _OS::delay_usec(uint32_t p_usec) const {
|
||||||
OS::get_singleton()->delay_usec(p_usec);
|
OS::get_singleton()->delay_usec(p_usec);
|
||||||
}
|
}
|
||||||
@ -729,8 +721,6 @@ void _OS::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
|
ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
|
||||||
ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
|
ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
|
||||||
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
|
ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
|
||||||
ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
|
ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
|
||||||
ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
|
ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
|
||||||
|
@ -199,9 +199,7 @@ public:
|
|||||||
Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
|
Dictionary get_datetime_from_unix_time(int64_t unix_time_val) const;
|
||||||
int64_t get_unix_time_from_datetime(Dictionary datetime) const;
|
int64_t get_unix_time_from_datetime(Dictionary datetime) const;
|
||||||
Dictionary get_time_zone_info() const;
|
Dictionary get_time_zone_info() const;
|
||||||
uint64_t get_unix_time() const;
|
double get_unix_time() const;
|
||||||
uint64_t get_system_time_secs() const;
|
|
||||||
uint64_t get_system_time_msecs() const;
|
|
||||||
|
|
||||||
uint64_t get_static_memory_usage() const;
|
uint64_t get_static_memory_usage() const;
|
||||||
uint64_t get_static_memory_peak_usage() const;
|
uint64_t get_static_memory_peak_usage() const;
|
||||||
|
@ -83,15 +83,7 @@ uint64_t OS::get_splash_tick_msec() const {
|
|||||||
return _msec_splash;
|
return _msec_splash;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OS::get_unix_time() const {
|
double OS::get_unix_time() const {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t OS::get_system_time_secs() const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t OS::get_system_time_msecs() const {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,9 +209,7 @@ public:
|
|||||||
virtual Time get_time(bool local = false) const = 0;
|
virtual Time get_time(bool local = false) const = 0;
|
||||||
virtual TimeZoneInfo get_time_zone_info() const = 0;
|
virtual TimeZoneInfo get_time_zone_info() const = 0;
|
||||||
virtual String get_iso_date_time(bool local = false) const;
|
virtual String get_iso_date_time(bool local = false) const;
|
||||||
virtual uint64_t get_unix_time() const;
|
virtual double get_unix_time() const;
|
||||||
virtual uint64_t get_system_time_secs() const;
|
|
||||||
virtual uint64_t get_system_time_msecs() const;
|
|
||||||
|
|
||||||
virtual void delay_usec(uint32_t p_usec) const = 0;
|
virtual void delay_usec(uint32_t p_usec) const = 0;
|
||||||
virtual uint64_t get_ticks_usec() const = 0;
|
virtual uint64_t get_ticks_usec() const = 0;
|
||||||
|
@ -325,7 +325,7 @@
|
|||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_unix_time" qualifiers="const">
|
<method name="get_unix_time" qualifiers="const">
|
||||||
<return type="int">
|
<return type="float">
|
||||||
</return>
|
</return>
|
||||||
<description>
|
<description>
|
||||||
Returns the current UNIX epoch timestamp.
|
Returns the current UNIX epoch timestamp.
|
||||||
|
@ -163,22 +163,12 @@ String OS_Unix::get_name() const {
|
|||||||
return "Unix";
|
return "Unix";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OS_Unix::get_unix_time() const {
|
double OS_Unix::get_unix_time() const {
|
||||||
return time(nullptr);
|
struct timeval tv_now;
|
||||||
|
gettimeofday(&tv_now, nullptr);
|
||||||
|
return (double)tv_now.tv_sec + double(tv_now.tv_usec) / 1000000;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t OS_Unix::get_system_time_secs() const {
|
|
||||||
struct timeval tv_now;
|
|
||||||
gettimeofday(&tv_now, nullptr);
|
|
||||||
return uint64_t(tv_now.tv_sec);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t OS_Unix::get_system_time_msecs() const {
|
|
||||||
struct timeval tv_now;
|
|
||||||
gettimeofday(&tv_now, nullptr);
|
|
||||||
return uint64_t(tv_now.tv_sec) * 1000 + uint64_t(tv_now.tv_usec) / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
OS::Date OS_Unix::get_date(bool utc) const {
|
OS::Date OS_Unix::get_date(bool utc) const {
|
||||||
time_t t = time(nullptr);
|
time_t t = time(nullptr);
|
||||||
struct tm *lt;
|
struct tm *lt;
|
||||||
|
@ -77,9 +77,7 @@ public:
|
|||||||
virtual Time get_time(bool utc) const;
|
virtual Time get_time(bool utc) const;
|
||||||
virtual TimeZoneInfo get_time_zone_info() const;
|
virtual TimeZoneInfo get_time_zone_info() const;
|
||||||
|
|
||||||
virtual uint64_t get_unix_time() const;
|
virtual double get_unix_time() const;
|
||||||
virtual uint64_t get_system_time_secs() const;
|
|
||||||
virtual uint64_t get_system_time_msecs() const;
|
|
||||||
|
|
||||||
virtual void delay_usec(uint32_t p_usec) const;
|
virtual void delay_usec(uint32_t p_usec) const;
|
||||||
virtual uint64_t get_ticks_usec() const;
|
virtual uint64_t get_ticks_usec() const;
|
||||||
|
@ -343,55 +343,21 @@ OS::TimeZoneInfo OS_Windows::get_time_zone_info() const {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OS_Windows::get_unix_time() const {
|
double OS_Windows::get_unix_time() const {
|
||||||
FILETIME ft;
|
// 1 Windows tick is 100ns
|
||||||
SYSTEMTIME st;
|
const uint64_t WINDOWS_TICKS_PER_SECOND = 10000000;
|
||||||
GetSystemTime(&st);
|
const uint64_t TICKS_TO_UNIX_EPOCH = 116444736000000000LL;
|
||||||
SystemTimeToFileTime(&st, &ft);
|
|
||||||
|
|
||||||
SYSTEMTIME ep;
|
|
||||||
ep.wYear = 1970;
|
|
||||||
ep.wMonth = 1;
|
|
||||||
ep.wDayOfWeek = 4;
|
|
||||||
ep.wDay = 1;
|
|
||||||
ep.wHour = 0;
|
|
||||||
ep.wMinute = 0;
|
|
||||||
ep.wSecond = 0;
|
|
||||||
ep.wMilliseconds = 0;
|
|
||||||
FILETIME fep;
|
|
||||||
SystemTimeToFileTime(&ep, &fep);
|
|
||||||
|
|
||||||
// Type punning through unions (rather than pointer cast) as per:
|
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime#remarks
|
|
||||||
ULARGE_INTEGER ft_punning;
|
|
||||||
ft_punning.LowPart = ft.dwLowDateTime;
|
|
||||||
ft_punning.HighPart = ft.dwHighDateTime;
|
|
||||||
|
|
||||||
ULARGE_INTEGER fep_punning;
|
|
||||||
fep_punning.LowPart = fep.dwLowDateTime;
|
|
||||||
fep_punning.HighPart = fep.dwHighDateTime;
|
|
||||||
|
|
||||||
return (ft_punning.QuadPart - fep_punning.QuadPart) / 10000000;
|
|
||||||
};
|
|
||||||
|
|
||||||
uint64_t OS_Windows::get_system_time_secs() const {
|
|
||||||
return get_system_time_msecs() / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t OS_Windows::get_system_time_msecs() const {
|
|
||||||
const uint64_t WINDOWS_TICK = 10000;
|
|
||||||
const uint64_t MSEC_TO_UNIX_EPOCH = 11644473600000LL;
|
|
||||||
|
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
GetSystemTime(&st);
|
GetSystemTime(&st);
|
||||||
FILETIME ft;
|
FILETIME ft;
|
||||||
SystemTimeToFileTime(&st, &ft);
|
SystemTimeToFileTime(&st, &ft);
|
||||||
uint64_t ret;
|
uint64_t ticks_time;
|
||||||
ret = ft.dwHighDateTime;
|
ticks_time = ft.dwHighDateTime;
|
||||||
ret <<= 32;
|
ticks_time <<= 32;
|
||||||
ret |= ft.dwLowDateTime;
|
ticks_time |= ft.dwLowDateTime;
|
||||||
|
|
||||||
return (uint64_t)(ret / WINDOWS_TICK - MSEC_TO_UNIX_EPOCH);
|
return (double)(ticks_time - TICKS_TO_UNIX_EPOCH) / WINDOWS_TICKS_PER_SECOND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OS_Windows::delay_usec(uint32_t p_usec) const {
|
void OS_Windows::delay_usec(uint32_t p_usec) const {
|
||||||
|
@ -129,9 +129,7 @@ public:
|
|||||||
virtual Date get_date(bool utc) const;
|
virtual Date get_date(bool utc) const;
|
||||||
virtual Time get_time(bool utc) const;
|
virtual Time get_time(bool utc) const;
|
||||||
virtual TimeZoneInfo get_time_zone_info() const;
|
virtual TimeZoneInfo get_time_zone_info() const;
|
||||||
virtual uint64_t get_unix_time() const;
|
virtual double get_unix_time() const;
|
||||||
virtual uint64_t get_system_time_secs() const;
|
|
||||||
virtual uint64_t get_system_time_msecs() const;
|
|
||||||
|
|
||||||
virtual Error set_cwd(const String &p_cwd);
|
virtual Error set_cwd(const String &p_cwd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user