diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/dir_access.cpp | 5 | ||||
-rw-r--r-- | core/os/dir_access.h | 3 | ||||
-rw-r--r-- | core/os/input.cpp | 2 | ||||
-rw-r--r-- | core/os/input.h | 2 | ||||
-rw-r--r-- | core/os/input_event.cpp | 78 | ||||
-rw-r--r-- | core/os/input_event.h | 13 | ||||
-rw-r--r-- | core/os/mutex.h | 2 | ||||
-rw-r--r-- | core/os/semaphore.cpp | 14 | ||||
-rw-r--r-- | core/os/semaphore.h | 31 | ||||
-rw-r--r-- | core/os/thread_dummy.cpp | 8 | ||||
-rw-r--r-- | core/os/thread_dummy.h | 12 |
11 files changed, 94 insertions, 76 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index f65fc00077..642c86be2f 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -66,6 +66,11 @@ int DirAccess::get_current_drive() { return 0; } +bool DirAccess::drives_are_shortcuts() { + + return false; +} + static Error _erase_recursive(DirAccess *da) { List<String> dirs; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 55a6d53f72..aac6c67f0a 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -76,9 +76,10 @@ public: virtual int get_drive_count() = 0; virtual String get_drive(int p_drive) = 0; virtual int get_current_drive(); + virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir) = 0; ///< can be relative or absolute, return false on success - virtual String get_current_dir() = 0; ///< return current dir location + virtual String get_current_dir(bool p_include_drive = true) = 0; ///< return current dir location virtual Error make_dir(String p_dir) = 0; virtual Error make_dir_recursive(String p_dir); virtual Error erase_contents_recursive(); //super dangerous, use with care! diff --git a/core/os/input.cpp b/core/os/input.cpp index 6f0392fec9..1768b851df 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -57,7 +57,7 @@ Input::MouseMode Input::get_mouse_mode() const { void Input::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_key_pressed", "scancode"), &Input::is_key_pressed); + ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &Input::is_action_pressed); diff --git a/core/os/input.h b/core/os/input.h index 8df3b1c5a9..55e0511080 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -79,7 +79,7 @@ public: static Input *get_singleton(); - virtual bool is_key_pressed(int p_scancode) const = 0; + virtual bool is_key_pressed(int p_keycode) const = 0; virtual bool is_mouse_button_pressed(int p_button) const = 0; virtual bool is_joy_button_pressed(int p_device, int p_button) const = 0; virtual bool is_action_pressed(const StringName &p_action) const = 0; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 3cb9c2c1c2..204a36bf56 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -237,19 +237,31 @@ bool InputEventKey::is_pressed() const { return pressed; } -void InputEventKey::set_scancode(uint32_t p_scancode) { +void InputEventKey::set_keycode(uint32_t p_keycode) { - scancode = p_scancode; + keycode = p_keycode; } -uint32_t InputEventKey::get_scancode() const { - return scancode; +uint32_t InputEventKey::get_keycode() const { + + return keycode; +} + +void InputEventKey::set_physical_keycode(uint32_t p_keycode) { + + physical_keycode = p_keycode; +} + +uint32_t InputEventKey::get_physical_keycode() const { + + return physical_keycode; } void InputEventKey::set_unicode(uint32_t p_unicode) { unicode = p_unicode; } + uint32_t InputEventKey::get_unicode() const { return unicode; @@ -259,14 +271,30 @@ void InputEventKey::set_echo(bool p_enable) { echo = p_enable; } + bool InputEventKey::is_echo() const { return echo; } -uint32_t InputEventKey::get_scancode_with_modifiers() const { +uint32_t InputEventKey::get_keycode_with_modifiers() const { - uint32_t sc = scancode; + uint32_t sc = keycode; + if (get_control()) + sc |= KEY_MASK_CTRL; + if (get_alt()) + sc |= KEY_MASK_ALT; + if (get_shift()) + sc |= KEY_MASK_SHIFT; + if (get_metakey()) + sc |= KEY_MASK_META; + + return sc; +} + +uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { + + uint32_t sc = physical_keycode; if (get_control()) sc |= KEY_MASK_CTRL; if (get_alt()) @@ -281,7 +309,7 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const { String InputEventKey::as_text() const { - String kc = keycode_get_string(scancode); + String kc = keycode_get_string(keycode); if (kc == String()) return kc; @@ -306,10 +334,18 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed if (key.is_null()) return false; - uint32_t code = get_scancode_with_modifiers(); - uint32_t event_code = key->get_scancode_with_modifiers(); + bool match = false; + if (get_keycode() == 0) { + uint32_t code = get_physical_keycode_with_modifiers(); + uint32_t event_code = key->get_physical_keycode_with_modifiers(); - bool match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code); + match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code); + } else { + uint32_t code = get_keycode_with_modifiers(); + uint32_t event_code = key->get_keycode_with_modifiers(); + + match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code); + } if (match) { if (p_pressed != NULL) *p_pressed = key->is_pressed(); @@ -325,8 +361,8 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { if (key.is_null()) return false; - uint32_t code = get_scancode_with_modifiers(); - uint32_t event_code = key->get_scancode_with_modifiers(); + uint32_t code = get_keycode_with_modifiers(); + uint32_t event_code = key->get_keycode_with_modifiers(); return code == event_code; } @@ -335,26 +371,32 @@ void InputEventKey::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed); - ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode); - ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode); + ClassDB::bind_method(D_METHOD("set_keycode", "keycode"), &InputEventKey::set_keycode); + ClassDB::bind_method(D_METHOD("get_keycode"), &InputEventKey::get_keycode); + + ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode); + ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode); ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode); ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode); ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo); - ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers); + ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers); + ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo"); } InputEventKey::InputEventKey() { pressed = false; - scancode = 0; + keycode = 0; + physical_keycode = 0; unicode = 0; ///unicode echo = false; } diff --git a/core/os/input_event.h b/core/os/input_event.h index c6b04bcfa5..c105fcd1c1 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -256,7 +256,8 @@ class InputEventKey : public InputEventWithModifiers { bool pressed; /// otherwise release - uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks + uint32_t keycode; ///< check keyboard.h , KeyCode enum, without modifier masks + uint32_t physical_keycode; uint32_t unicode; ///unicode bool echo; /// true if this is an echo key @@ -268,8 +269,11 @@ public: void set_pressed(bool p_pressed); virtual bool is_pressed() const; - void set_scancode(uint32_t p_scancode); - uint32_t get_scancode() const; + void set_keycode(uint32_t p_keycode); + uint32_t get_keycode() const; + + void set_physical_keycode(uint32_t p_keycode); + uint32_t get_physical_keycode() const; void set_unicode(uint32_t p_unicode); uint32_t get_unicode() const; @@ -277,7 +281,8 @@ public: void set_echo(bool p_enable); virtual bool is_echo() const; - uint32_t get_scancode_with_modifiers() const; + uint32_t get_keycode_with_modifiers() const; + uint32_t get_physical_keycode_with_modifiers() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; diff --git a/core/os/mutex.h b/core/os/mutex.h index 6cf8ee7c40..8d7b378d60 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -34,7 +34,7 @@ #include "core/error_list.h" #include "core/typedefs.h" -#if !(defined NO_THREADS) +#if !defined(NO_THREADS) #include <mutex> diff --git a/core/os/semaphore.cpp b/core/os/semaphore.cpp index 2c20f234d0..93f1e2dff4 100644 --- a/core/os/semaphore.cpp +++ b/core/os/semaphore.cpp @@ -29,17 +29,3 @@ /*************************************************************************/ #include "semaphore.h" - -#include "core/error_macros.h" - -SemaphoreOld *(*SemaphoreOld::create_func)() = 0; - -SemaphoreOld *SemaphoreOld::create() { - - ERR_FAIL_COND_V(!create_func, 0); - - return create_func(); -} - -SemaphoreOld::~SemaphoreOld() { -} diff --git a/core/os/semaphore.h b/core/os/semaphore.h index f16a15a6db..6f194d4887 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -34,30 +34,32 @@ #include "core/error_list.h" #include "core/typedefs.h" +#if !defined(NO_THREADS) + #include <condition_variable> #include <mutex> class Semaphore { private: - std::mutex mutex_; - std::condition_variable condition_; - unsigned long count_ = 0; // Initialized as locked. + mutable std::mutex mutex_; + mutable std::condition_variable condition_; + mutable unsigned long count_ = 0; // Initialized as locked. public: - _ALWAYS_INLINE_ void post() { + _ALWAYS_INLINE_ void post() const { std::lock_guard<decltype(mutex_)> lock(mutex_); ++count_; condition_.notify_one(); } - _ALWAYS_INLINE_ void wait() { + _ALWAYS_INLINE_ void wait() const { std::unique_lock<decltype(mutex_)> lock(mutex_); while (!count_) // Handle spurious wake-ups. condition_.wait(lock); --count_; } - _ALWAYS_INLINE_ bool try_wait() { + _ALWAYS_INLINE_ bool try_wait() const { std::lock_guard<decltype(mutex_)> lock(mutex_); if (count_) { --count_; @@ -67,18 +69,15 @@ public: } }; -class SemaphoreOld { -protected: - static SemaphoreOld *(*create_func)(); +#else +class Semaphore { public: - virtual Error wait() = 0; ///< wait until semaphore has positive value, then decrement and pass - virtual Error post() = 0; ///< unlock the semaphore, incrementing the value - virtual int get() const = 0; ///< get semaphore value - - static SemaphoreOld *create(); ///< Create a mutex - - virtual ~SemaphoreOld(); + _ALWAYS_INLINE_ void post() const {} + _ALWAYS_INLINE_ void wait() const {} + _ALWAYS_INLINE_ bool try_wait() const { return true; } }; #endif + +#endif diff --git a/core/os/thread_dummy.cpp b/core/os/thread_dummy.cpp index 097c90c1fb..9dcddcae11 100644 --- a/core/os/thread_dummy.cpp +++ b/core/os/thread_dummy.cpp @@ -40,14 +40,6 @@ void ThreadDummy::make_default() { Thread::create_func = &ThreadDummy::create; }; -SemaphoreOld *SemaphoreDummy::create() { - return memnew(SemaphoreDummy); -}; - -void SemaphoreDummy::make_default() { - SemaphoreOld::create_func = &SemaphoreDummy::create; -}; - RWLock *RWLockDummy::create() { return memnew(RWLockDummy); }; diff --git a/core/os/thread_dummy.h b/core/os/thread_dummy.h index c0976ec299..da8188f983 100644 --- a/core/os/thread_dummy.h +++ b/core/os/thread_dummy.h @@ -45,18 +45,6 @@ public: static void make_default(); }; -class SemaphoreDummy : public SemaphoreOld { - - static SemaphoreOld *create(); - -public: - virtual Error wait() { return OK; }; - virtual Error post() { return OK; }; - virtual int get() const { return 0; }; ///< get semaphore value - - static void make_default(); -}; - class RWLockDummy : public RWLock { static RWLock *create(); |