Added OS.get_system_time_msecs()

This commit is contained in:
volzhs 2018-12-20 06:18:52 +09:00
parent 26058376aa
commit 84d060c768
9 changed files with 33 additions and 3 deletions

View File

@ -827,6 +827,10 @@ 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 {
OS::get_singleton()->delay_usec(p_usec);
@ -1182,6 +1186,7 @@ void _OS::_bind_methods() {
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_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("set_icon", "icon"), &_OS::set_icon);

View File

@ -281,6 +281,7 @@ public:
Dictionary get_time_zone_info() const;
uint64_t get_unix_time() const;
uint64_t get_system_time_secs() const;
uint64_t get_system_time_msecs() const;
int get_static_memory_usage() const;
int get_static_memory_peak_usage() const;

View File

@ -61,6 +61,9 @@ uint64_t OS::get_unix_time() const {
uint64_t OS::get_system_time_secs() const {
return 0;
}
uint64_t OS::get_system_time_msecs() const {
return 0;
}
void OS::debug_break(){
// something

View File

@ -328,6 +328,7 @@ public:
virtual TimeZoneInfo get_time_zone_info() const = 0;
virtual uint64_t 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 uint64_t get_ticks_usec() const = 0;

View File

@ -381,6 +381,13 @@
Returns the epoch time of the operating system in seconds.
</description>
</method>
<method name="get_system_time_msecs" qualifiers="const">
<return type="int">
</return>
<description>
Returns the epoch time of the operating system in milliseconds.
</description>
</method>
<method name="get_ticks_msec" qualifiers="const">
<return type="int">
</return>

View File

@ -202,6 +202,12 @@ uint64_t OS_Unix::get_system_time_secs() const {
return uint64_t(tv_now.tv_sec);
}
uint64_t OS_Unix::get_system_time_msecs() const {
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
return uint64_t(tv_now.tv_sec * 1000 + tv_now.tv_usec / 1000);
}
OS::Date OS_Unix::get_date(bool utc) const {
time_t t = time(NULL);

View File

@ -84,6 +84,7 @@ public:
virtual uint64_t 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 uint64_t get_ticks_usec() const;

View File

@ -2142,8 +2142,13 @@ uint64_t OS_Windows::get_unix_time() const {
uint64_t OS_Windows::get_system_time_secs() const {
const uint64_t WINDOWS_TICK = 10000000;
const uint64_t SEC_TO_UNIX_EPOCH = 11644473600LL;
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;
GetSystemTime(&st);
@ -2154,7 +2159,7 @@ uint64_t OS_Windows::get_system_time_secs() const {
ret <<= 32;
ret |= ft.dwLowDateTime;
return (uint64_t)(ret / WINDOWS_TICK - SEC_TO_UNIX_EPOCH);
return (uint64_t)(ret / WINDOWS_TICK - MSEC_TO_UNIX_EPOCH);
}
void OS_Windows::delay_usec(uint32_t p_usec) const {

View File

@ -254,6 +254,7 @@ public:
virtual TimeZoneInfo get_time_zone_info() const;
virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const;
virtual uint64_t get_system_time_msecs() const;
virtual bool can_draw() const;
virtual Error set_cwd(const String &p_cwd);