diff options
Diffstat (limited to 'core/object')
-rw-r--r-- | core/object/ref_counted.h | 10 | ||||
-rw-r--r-- | core/object/script_language.cpp | 47 | ||||
-rw-r--r-- | core/object/script_language.h | 14 | ||||
-rw-r--r-- | core/object/worker_thread_pool.cpp | 4 |
4 files changed, 70 insertions, 5 deletions
diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 58706fb9a9..3386514706 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -242,8 +242,11 @@ public: template <class T> struct PtrToArg<Ref<T>> { _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { + if (p_ptr == nullptr) { + return Ref<T>(); + } // p_ptr points to a RefCounted object - return Ref<T>(const_cast<T *>(reinterpret_cast<const T *>(p_ptr))); + return Ref<T>(const_cast<T *>(*reinterpret_cast<T *const *>(p_ptr))); } typedef Ref<T> EncodeT; @@ -259,8 +262,11 @@ struct PtrToArg<const Ref<T> &> { typedef Ref<T> EncodeT; _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { + if (p_ptr == nullptr) { + return Ref<T>(); + } // p_ptr points to a RefCounted object - return Ref<T>((T *)p_ptr); + return Ref<T>(*((T *const *)p_ptr)); } }; diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 71f40660f4..6f047d80aa 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -34,7 +34,6 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" -#include "core/variant/typed_array.h" #include <stdint.h> @@ -461,6 +460,52 @@ void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const void ScriptLanguage::frame() { } +TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics(const String &p_base) { + // Return characacteristics of the match found by order of importance. + // Matches will be ranked by a lexicographical order on the vector returned by this function. + // The lower values indicate better matches and that they should go before in the order of appearance. + if (last_matches == matches) { + return charac; + } + charac.clear(); + // Ensure base is not empty and at the same time that matches is not empty too. + if (p_base.length() == 0) { + last_matches = matches; + charac.push_back(location); + return charac; + } + charac.push_back(matches.size()); + charac.push_back((matches[0].first == 0) ? 0 : 1); + charac.push_back(location); + const char32_t *target_char = &p_base[0]; + int bad_case = 0; + for (const Pair<int, int> &match_segment : matches) { + const char32_t *string_to_complete_char = &display[match_segment.first]; + for (int j = 0; j < match_segment.second; j++, string_to_complete_char++, target_char++) { + if (*string_to_complete_char != *target_char) { + bad_case++; + } + } + } + charac.push_back(bad_case); + charac.push_back(matches[0].first); + last_matches = matches; + return charac; +} + +void ScriptLanguage::CodeCompletionOption::clear_characteristics() { + charac = TypedArray<int>(); +} + +TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_cached_characteristics() const { + // Only returns the cached value and warns if it was not updated since the last change of matches. + if (last_matches != matches) { + WARN_PRINT("Characteristics are not up to date."); + } + + return charac; +} + bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { if (script->is_placeholder_fallback_enabled()) { return false; diff --git a/core/object/script_language.h b/core/object/script_language.h index 696c9a94a5..829f01fbcc 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -35,6 +35,7 @@ #include "core/io/resource.h" #include "core/templates/pair.h" #include "core/templates/rb_map.h" +#include "core/variant/typed_array.h" class ScriptLanguage; template <typename T> @@ -305,8 +306,8 @@ public: virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; } virtual bool overrides_external_editor() { return false; } - /* Keep enum in Sync with: */ - /* /scene/gui/code_edit.h - CodeEdit::CodeCompletionKind */ + // Keep enums in sync with: + // scene/gui/code_edit.h - CodeEdit::CodeCompletionKind enum CodeCompletionKind { CODE_COMPLETION_KIND_CLASS, CODE_COMPLETION_KIND_FUNCTION, @@ -321,6 +322,7 @@ public: CODE_COMPLETION_KIND_MAX }; + // scene/gui/code_edit.h - CodeEdit::CodeCompletionLocation enum CodeCompletionLocation { LOCATION_LOCAL = 0, LOCATION_PARENT_MASK = 1 << 8, @@ -336,6 +338,7 @@ public: Ref<Resource> icon; Variant default_value; Vector<Pair<int, int>> matches; + Vector<Pair<int, int>> last_matches; int location = LOCATION_OTHER; CodeCompletionOption() {} @@ -346,6 +349,13 @@ public: kind = p_kind; location = p_location; } + + TypedArray<int> get_option_characteristics(const String &p_base); + void clear_characteristics(); + TypedArray<int> get_option_cached_characteristics() const; + + private: + TypedArray<int> charac; }; virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; } diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index afe6ecd1b3..d285be3e70 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -31,6 +31,7 @@ #include "worker_thread_pool.h" #include "core/os/os.h" +#include "core/os/thread_safe.h" void WorkerThreadPool::Task::free_template_userdata() { ERR_FAIL_COND(!template_userdata); @@ -178,6 +179,9 @@ void WorkerThreadPool::_process_task(Task *p_task) { if (post) { task_available_semaphore.post(); } + + // Engine/user tasks can set-and-forget, so we must be sure it's back to normal by the end of the task. + set_current_thread_safe_for_nodes(false); } } |