Merge pull request #24485 from volzhs/system-time-ms

Added OS.get_system_time_msecs()
This commit is contained in:
Rémi Verschelde 2018-12-20 11:31:16 +01:00 committed by GitHub
commit a8faa55042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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(); 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);
@ -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_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_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); ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon);

View file

@ -281,6 +281,7 @@ public:
Dictionary get_time_zone_info() const; Dictionary get_time_zone_info() const;
uint64_t get_unix_time() const; uint64_t get_unix_time() const;
uint64_t get_system_time_secs() 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_usage() const;
int get_static_memory_peak_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 { uint64_t OS::get_system_time_secs() const {
return 0; return 0;
} }
uint64_t OS::get_system_time_msecs() const {
return 0;
}
void OS::debug_break(){ void OS::debug_break(){
// something // something

View file

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

View file

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

View file

@ -202,6 +202,12 @@ uint64_t OS_Unix::get_system_time_secs() const {
return uint64_t(tv_now.tv_sec); 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 { OS::Date OS_Unix::get_date(bool utc) const {
time_t t = time(NULL); time_t t = time(NULL);

View file

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

View file

@ -2142,8 +2142,13 @@ uint64_t OS_Windows::get_unix_time() const {
uint64_t OS_Windows::get_system_time_secs() const { uint64_t OS_Windows::get_system_time_secs() const {
const uint64_t WINDOWS_TICK = 10000000; return get_system_time_msecs() / 1000;
const uint64_t SEC_TO_UNIX_EPOCH = 11644473600LL; }
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);
@ -2154,7 +2159,7 @@ uint64_t OS_Windows::get_system_time_secs() const {
ret <<= 32; ret <<= 32;
ret |= ft.dwLowDateTime; 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 { 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 TimeZoneInfo get_time_zone_info() const;
virtual uint64_t get_unix_time() const; virtual uint64_t get_unix_time() const;
virtual uint64_t get_system_time_secs() const; virtual uint64_t get_system_time_secs() const;
virtual uint64_t get_system_time_msecs() const;
virtual bool can_draw() const; virtual bool can_draw() const;
virtual Error set_cwd(const String &p_cwd); virtual Error set_cwd(const String &p_cwd);