diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-12-20 11:31:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 11:31:16 +0100 |
commit | a8faa5504279f867adb6f50f768d3cf00594dc4f (patch) | |
tree | f4751774263c4b2dc184044436539274ce3504a1 | |
parent | b3f6e54cc61086fc3a3d2af170a86ea6a6eebf73 (diff) | |
parent | 84d060c768c10145374d48ebd2b3f00430c73638 (diff) |
Merge pull request #24485 from volzhs/system-time-ms
Added OS.get_system_time_msecs()
-rw-r--r-- | core/bind/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/bind/core_bind.h | 1 | ||||
-rw-r--r-- | core/os/os.cpp | 3 | ||||
-rw-r--r-- | core/os/os.h | 1 | ||||
-rw-r--r-- | doc/classes/OS.xml | 7 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 6 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 1 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 11 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 1 |
9 files changed, 33 insertions, 3 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 8641af84d9..6f4561d8e6 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -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); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 4cdf09d522..39704286b6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -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; diff --git a/core/os/os.cpp b/core/os/os.cpp index 7547b6a042..ea60a03373 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -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 diff --git a/core/os/os.h b/core/os/os.h index 05ec3ac424..046686ff51 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -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; diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index ac865de3cd..82f5928074 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -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> diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 279274734f..12a1263042 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -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); diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index b702454603..94a8d040cd 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -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; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index e1cbbcc66b..dff87b2c5d 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -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 { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index d09ade4daa..e12e465dd3 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -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); |