diff options
Diffstat (limited to 'core/os')
| -rw-r--r-- | core/os/dir_access.cpp | 8 | ||||
| -rw-r--r-- | core/os/file_access.cpp | 22 | ||||
| -rw-r--r-- | core/os/main_loop.cpp | 6 | ||||
| -rw-r--r-- | core/os/main_loop.h | 6 | ||||
| -rw-r--r-- | core/os/os.cpp | 74 | ||||
| -rw-r--r-- | core/os/os.h | 16 | ||||
| -rw-r--r-- | core/os/thread.cpp | 2 | ||||
| -rw-r--r-- | core/os/thread_dummy.cpp | 8 |
8 files changed, 94 insertions, 48 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 9f2672e038..5e1cb8ea29 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -131,7 +131,7 @@ Error DirAccess::erase_contents_recursive() { Error DirAccess::make_dir_recursive(String p_dir) { if (p_dir.length() < 1) { return OK; - }; + } String full_dir; @@ -185,7 +185,7 @@ String DirAccess::fix_path(String p_path) const { String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { return p_path.replace_first("res:/", resource_path); - }; + } return p_path.replace_first("res://", ""); } } @@ -196,7 +196,7 @@ String DirAccess::fix_path(String p_path) const { String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { return p_path.replace_first("user:/", data_dir); - }; + } return p_path.replace_first("user://", ""); } @@ -249,7 +249,7 @@ DirAccess *DirAccess::create(AccessType p_access) { } return da; -}; +} String DirAccess::get_full_path(const String &p_path, AccessType p_access) { DirAccess *d = DirAccess::create(p_access); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index f9ba8ff2d2..20b3435911 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -65,7 +65,7 @@ bool FileAccess::exists(const String &p_name) { void FileAccess::_set_access_type(AccessType p_access) { _access_type = p_access; -}; +} FileAccess *FileAccess::create_for_path(const String &p_path) { FileAccess *ret = nullptr; @@ -83,7 +83,7 @@ FileAccess *FileAccess::create_for_path(const String &p_path) { Error FileAccess::reopen(const String &p_path, int p_mode_flags) { return _open(p_path, p_mode_flags); -}; +} FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_error) { //try packed data first @@ -115,7 +115,7 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er FileAccess::CreateFunc FileAccess::get_create_func(AccessType p_access) { return create_func[p_access]; -}; +} String FileAccess::fix_path(const String &p_path) const { //helper used by file accesses that use a single filesystem @@ -129,7 +129,7 @@ String FileAccess::fix_path(const String &p_path) const { String resource_path = ProjectSettings::get_singleton()->get_resource_path(); if (resource_path != "") { return r_path.replace("res:/", resource_path); - }; + } return r_path.replace("res://", ""); } } @@ -140,7 +140,7 @@ String FileAccess::fix_path(const String &p_path) const { String data_dir = OS::get_singleton()->get_user_data_dir(); if (data_dir != "") { return r_path.replace("user:/", data_dir); - }; + } return r_path.replace("user://", ""); } @@ -215,7 +215,7 @@ float FileAccess::get_float() const { MarshallFloat m; m.i = get_32(); return m.f; -}; +} real_t FileAccess::get_real() const { if (real_is_double) { @@ -229,7 +229,7 @@ double FileAccess::get_double() const { MarshallDouble m; m.l = get_64(); return m.d; -}; +} String FileAccess::get_token() const { CharString token; @@ -447,13 +447,13 @@ void FileAccess::store_float(float p_dest) { MarshallFloat m; m.f = p_dest; store_32(m.i); -}; +} void FileAccess::store_double(double p_dest) { MarshallDouble m; m.d = p_dest; store_64(m.l); -}; +} uint64_t FileAccess::get_modified_time(const String &p_file) { if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) { @@ -503,7 +503,7 @@ void FileAccess::store_pascal_string(const String &p_string) { CharString cs = p_string.utf8(); store_32(cs.length()); store_buffer((uint8_t *)&cs[0], cs.length()); -}; +} String FileAccess::get_pascal_string() { uint32_t sl = get_32(); @@ -516,7 +516,7 @@ String FileAccess::get_pascal_string() { ret.parse_utf8(cs.ptr()); return ret; -}; +} void FileAccess::store_line(const String &p_line) { store_string(p_line); diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index dc68c2a9f9..434f6fa300 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -48,8 +48,10 @@ void MainLoop::_bind_methods() { BIND_CONSTANT(NOTIFICATION_WM_ABOUT); BIND_CONSTANT(NOTIFICATION_CRASH); BIND_CONSTANT(NOTIFICATION_OS_IME_UPDATE); - BIND_CONSTANT(NOTIFICATION_APP_RESUMED); - BIND_CONSTANT(NOTIFICATION_APP_PAUSED); + BIND_CONSTANT(NOTIFICATION_APPLICATION_RESUMED); + BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED); + BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN); + BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT); ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted"))); }; diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 90790a45a1..2c34cf193c 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -52,8 +52,10 @@ public: NOTIFICATION_WM_ABOUT = 2011, NOTIFICATION_CRASH = 2012, NOTIFICATION_OS_IME_UPDATE = 2013, - NOTIFICATION_APP_RESUMED = 2014, - NOTIFICATION_APP_PAUSED = 2015, + NOTIFICATION_APPLICATION_RESUMED = 2014, + NOTIFICATION_APPLICATION_PAUSED = 2015, + NOTIFICATION_APPLICATION_FOCUS_IN = 2016, + NOTIFICATION_APPLICATION_FOCUS_OUT = 2017, }; virtual void init(); diff --git a/core/os/os.cpp b/core/os/os.cpp index da9dabd401..dc8bd5ee69 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -41,6 +41,7 @@ #include <stdarg.h> OS *OS::singleton = nullptr; +uint64_t OS::target_ticks = 0; OS *OS::get_singleton() { return singleton; @@ -83,21 +84,13 @@ uint64_t OS::get_splash_tick_msec() const { return _msec_splash; } -uint64_t 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 { +double OS::get_unix_time() const { return 0; } -void OS::debug_break(){ - +void OS::debug_break() { // something -}; +} void OS::_set_logger(CompositeLogger *p_logger) { if (_logger) { @@ -127,7 +120,7 @@ void OS::print(const char *p_format, ...) { _logger->logv(p_format, argp, false); va_end(argp); -}; +} void OS::printerr(const char *p_format, ...) { va_list argp; @@ -136,7 +129,7 @@ void OS::printerr(const char *p_format, ...) { _logger->logv(p_format, argp, true); va_end(argp); -}; +} void OS::set_low_processor_usage_mode(bool p_enabled) { low_processor_usage_mode = p_enabled; @@ -160,7 +153,7 @@ String OS::get_executable_path() const { int OS::get_process_id() const { return -1; -}; +} void OS::vibrate_handheld(int p_duration_ms) { WARN_PRINT("vibrate_handheld() only works with Android and iOS"); @@ -170,6 +163,10 @@ bool OS::is_stdout_verbose() const { return _verbose_stdout; } +bool OS::is_stdout_debug_enabled() const { + return _debug_stdout; +} + void OS::dump_memory_to_file(const char *p_file) { //Memory::dump_static_mem_to_file(p_file); } @@ -282,12 +279,12 @@ String OS::get_cache_path() const { // Path to macOS .app bundle resources String OS::get_bundle_resource_dir() const { return "."; -}; +} // OS specific path for user:// String OS::get_user_data_dir() const { return "."; -}; +} // Absolute path to res:// String OS::get_resource_dir() const { @@ -301,7 +298,7 @@ String OS::get_system_dir(SystemDir p_dir) const { Error OS::shell_open(String p_uri) { return ERR_UNAVAILABLE; -}; +} // implement these with the canvas? @@ -346,7 +343,7 @@ String OS::get_model_name() const { void OS::set_cmdline(const char *p_execpath, const List<String> &p_args) { _execpath = p_execpath; _cmdline = p_args; -}; +} String OS::get_unique_id() const { ERR_FAIL_V(""); @@ -457,18 +454,57 @@ PackedStringArray OS::get_connected_midi_inputs() { } PackedStringArray list; - return list; + ERR_FAIL_V_MSG(list, vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name())); } void OS::open_midi_inputs() { if (MIDIDriver::get_singleton()) { MIDIDriver::get_singleton()->open(); + } else { + ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name())); } } void OS::close_midi_inputs() { if (MIDIDriver::get_singleton()) { MIDIDriver::get_singleton()->close(); + } else { + ERR_PRINT(vformat("MIDI input isn't supported on %s.", OS::get_singleton()->get_name())); + } +} + +void OS::add_frame_delay(bool p_can_draw) { + const uint32_t frame_delay = Engine::get_singleton()->get_frame_delay(); + if (frame_delay) { + // Add fixed frame delay to decrease CPU/GPU usage. This doesn't take + // the actual frame time into account. + // Due to the high fluctuation of the actual sleep duration, it's not recommended + // to use this as a FPS limiter. + delay_usec(frame_delay * 1000); + } + + // Add a dynamic frame delay to decrease CPU/GPU usage. This takes the + // previous frame time into account for a smoother result. + uint64_t dynamic_delay = 0; + if (is_in_low_processor_usage_mode() || !p_can_draw) { + dynamic_delay = get_low_processor_usage_mode_sleep_usec(); + } + const int target_fps = Engine::get_singleton()->get_target_fps(); + if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) { + // Override the low processor usage mode sleep delay if the target FPS is lower. + dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps)); + } + + if (dynamic_delay > 0) { + target_ticks += dynamic_delay; + uint64_t current_ticks = get_ticks_usec(); + + if (current_ticks < target_ticks) { + delay_usec(target_ticks - current_ticks); + } + + current_ticks = get_ticks_usec(); + target_ticks = MIN(MAX(target_ticks, current_ticks - dynamic_delay), current_ticks + dynamic_delay); } } diff --git a/core/os/os.h b/core/os/os.h index 9296e17bb2..48dae99188 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -43,12 +43,14 @@ class OS { static OS *singleton; + static uint64_t target_ticks; String _execpath; List<String> _cmdline; bool _keep_screen_on = true; // set default value to true, because this had been true before godot 2.0. bool low_processor_usage_mode = false; int low_processor_usage_mode_sleep_usec = 10000; bool _verbose_stdout = false; + bool _debug_stdout = false; String _local_clipboard; uint64_t _msec_splash; bool _no_window = false; @@ -58,7 +60,6 @@ class OS { bool _allow_layered = false; bool _use_vsync; bool _vsync_via_compositor; - bool _disable_wintab; char *last_error; @@ -148,7 +149,11 @@ public: bool is_layered_allowed() const { return _allow_layered; } bool is_hidpi_allowed() const { return _allow_hidpi; } - bool is_wintab_disabled() const { return _disable_wintab; } + + virtual int get_tablet_driver_count() const { return 0; }; + virtual String get_tablet_driver_name(int p_driver) const { return ""; }; + virtual String get_current_tablet_driver() const { return ""; }; + virtual void set_current_tablet_driver(const String &p_driver){}; void ensure_user_data_dir(); @@ -206,11 +211,11 @@ public: virtual Time get_time(bool local = false) const = 0; virtual TimeZoneInfo get_time_zone_info() const = 0; virtual String get_iso_date_time(bool local = false) 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 double get_unix_time() const; virtual void delay_usec(uint32_t p_usec) const = 0; + virtual void add_frame_delay(bool p_can_draw); + virtual uint64_t get_ticks_usec() const = 0; uint32_t get_ticks_msec() const; uint64_t get_splash_tick_msec() const; @@ -218,6 +223,7 @@ public: virtual bool is_userfs_persistent() const { return true; } bool is_stdout_verbose() const; + bool is_stdout_debug_enabled() const; virtual void disable_crash_handler() {} virtual bool is_disable_crash_handler() const { return false; } diff --git a/core/os/thread.cpp b/core/os/thread.cpp index 70f960ed2a..fc0ce3c9b4 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -63,4 +63,4 @@ Error Thread::set_name(const String &p_name) { } return ERR_UNAVAILABLE; -}; +} diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp index 9dcddcae11..2672cd7ad9 100644 --- a/core/os/thread_dummy.cpp +++ b/core/os/thread_dummy.cpp @@ -34,16 +34,16 @@ Thread *ThreadDummy::create(ThreadCreateCallback p_callback, void *p_user, const Thread::Settings &p_settings) { return memnew(ThreadDummy); -}; +} void ThreadDummy::make_default() { Thread::create_func = &ThreadDummy::create; -}; +} RWLock *RWLockDummy::create() { return memnew(RWLockDummy); -}; +} void RWLockDummy::make_default() { RWLock::create_func = &RWLockDummy::create; -}; +} |