diff options
232 files changed, 5538 insertions, 2500 deletions
diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index 95d216deb3..a002d92ab4 100644 --- a/.github/workflows/linux_builds.yml +++ b/.github/workflows/linux_builds.yml @@ -32,11 +32,11 @@ jobs: proj-conv: true artifact: true - - name: Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, float=64, use_asan=yes, use_ubsan=yes, linker=gold) + - name: Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold) cache-name: linux-editor-double-sanitizers target: editor tests: true - sconsflags: dev_build=yes float=64 use_asan=yes use_ubsan=yes linker=gold + sconsflags: dev_build=yes precision=double use_asan=yes use_ubsan=yes linker=gold proj-test: true # Can be turned off for PRs that intentionally break compat with godot-cpp, # until both the upstream PR and the matching godot-cpp changes are merged. diff --git a/.gitignore b/.gitignore index 15c1e50277..18c7c706ba 100644 --- a/.gitignore +++ b/.gitignore @@ -242,6 +242,8 @@ xcuserdata/ [Rr]eleases/ x64/ x86/ +# Not build results, this is Theora source code. +!thirdparty/libtheora/x86/ [Ww][Ii][Nn]32/ [Aa][Rr][Mm]/ [Aa][Rr][Mm]64/ diff --git a/SConstruct b/SConstruct index 03043ee110..1eb6c0adc8 100644 --- a/SConstruct +++ b/SConstruct @@ -179,7 +179,7 @@ opts.Add(BoolVariable("production", "Set defaults to build Godot for use in prod # Components opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True)) -opts.Add(EnumVariable("float", "Floating-point precision", "32", ("32", "64"))) +opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double"))) opts.Add(BoolVariable("minizip", "Enable ZIP archive support using minizip", True)) opts.Add(BoolVariable("xaudio2", "Enable the XAudio2 audio driver", False)) opts.Add(BoolVariable("vulkan", "Enable the vulkan rendering driver", True)) @@ -442,7 +442,7 @@ if env_base["no_editor_splash"]: if not env_base["deprecated"]: env_base.Append(CPPDEFINES=["DISABLE_DEPRECATED"]) -if env_base["float"] == "64": +if env_base["precision"] == "double": env_base.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"]) if selected_platform in platform_list: @@ -747,7 +747,7 @@ if selected_platform in platform_list: if env.dev_build: suffix += ".dev" - if env_base["float"] == "64": + if env_base["precision"] == "double": suffix += ".double" suffix += "." + env["arch"] diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 6219ea70e4..20445a8b03 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -923,6 +923,35 @@ void ResourceLoader::clear_translation_remaps() { } } +void ResourceLoader::clear_thread_load_tasks() { + thread_load_mutex->lock(); + + for (KeyValue<String, ResourceLoader::ThreadLoadTask> &E : thread_load_tasks) { + switch (E.value.status) { + case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_LOADED: { + E.value.resource = Ref<Resource>(); + } break; + + case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_IN_PROGRESS: { + if (E.value.thread != nullptr) { + E.value.thread->wait_to_finish(); + memdelete(E.value.thread); + E.value.thread = nullptr; + } + E.value.resource = Ref<Resource>(); + } break; + + case ResourceLoader::ThreadLoadStatus::THREAD_LOAD_FAILED: + default: { + // do nothing + } + } + } + thread_load_tasks.clear(); + + thread_load_mutex->unlock(); +} + void ResourceLoader::load_path_remaps() { if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) { return; diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 243670b2d0..af10098bd8 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -219,6 +219,8 @@ public: static void load_translation_remaps(); static void clear_translation_remaps(); + static void clear_thread_load_tasks(); + static void set_load_callback(ResourceLoadedCallback p_callback); static ResourceLoaderImport import; diff --git a/core/object/object.h b/core/object/object.h index 3ad8391dd6..446550f91f 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -556,6 +556,7 @@ public: CONNECT_PERSIST = 2, // hint for scene to save this connection CONNECT_ONE_SHOT = 4, CONNECT_REFERENCE_COUNTED = 8, + CONNECT_INHERITED = 16, // Used in editor builds. }; struct Connection { diff --git a/core/os/os.cpp b/core/os/os.cpp index 055385579f..6d567ffd43 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -374,6 +374,16 @@ bool OS::has_feature(const String &p_feature) { #endif // DEBUG_ENABLED #endif // TOOLS_ENABLED +#ifdef REAL_T_IS_DOUBLE + if (p_feature == "double") { + return true; + } +#else + if (p_feature == "single") { + return true; + } +#endif // REAL_T_IS_DOUBLE + if (sizeof(void *) == 8 && p_feature == "64") { return true; } diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 6c4e8ba450..53891a9823 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -38,6 +38,7 @@ #include "core/templates/search_array.h" #include "core/templates/vector.h" #include "core/variant/callable.h" +#include "core/variant/dictionary.h" #include "core/variant/variant.h" class ArrayPrivate { @@ -201,16 +202,21 @@ uint32_t Array::recursive_hash(int recursion_count) const { } bool Array::_assign(const Array &p_array) { + bool can_convert = p_array._p->typed.type == Variant::NIL; + can_convert |= _p->typed.type == Variant::STRING && p_array._p->typed.type == Variant::STRING_NAME; + can_convert |= _p->typed.type == Variant::STRING_NAME && p_array._p->typed.type == Variant::STRING; + if (_p->typed.type != Variant::OBJECT && _p->typed.type == p_array._p->typed.type) { //same type or untyped, just reference, should be fine _ref(p_array); } else if (_p->typed.type == Variant::NIL) { //from typed to untyped, must copy, but this is cheap anyway _p->array = p_array._p->array; - } else if (p_array._p->typed.type == Variant::NIL) { //from untyped to typed, must try to check if they are all valid + } else if (can_convert) { //from untyped to typed, must try to check if they are all valid if (_p->typed.type == Variant::OBJECT) { //for objects, it needs full validation, either can be converted or fail for (int i = 0; i < p_array._p->array.size(); i++) { - if (!_p->typed.validate(p_array._p->array[i], "assign")) { + const Variant &element = p_array._p->array[i]; + if (element.get_type() != Variant::OBJECT || !_p->typed.validate_object(element, "assign")) { return false; } } @@ -255,16 +261,20 @@ void Array::operator=(const Array &p_array) { void Array::push_back(const Variant &p_value) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - ERR_FAIL_COND(!_p->typed.validate(p_value, "push_back")); - _p->array.push_back(p_value); + Variant value = p_value; + ERR_FAIL_COND(!_p->typed.validate(value, "push_back")); + _p->array.push_back(value); } void Array::append_array(const Array &p_array) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - for (int i = 0; i < p_array.size(); ++i) { - ERR_FAIL_COND(!_p->typed.validate(p_array[i], "append_array")); + + Vector<Variant> validated_array = p_array._p->array; + for (int i = 0; i < validated_array.size(); ++i) { + ERR_FAIL_COND(!_p->typed.validate(validated_array.write[i], "append_array")); } - _p->array.append_array(p_array._p->array); + + _p->array.append_array(validated_array); } Error Array::resize(int p_new_size) { @@ -274,20 +284,23 @@ Error Array::resize(int p_new_size) { Error Array::insert(int p_pos, const Variant &p_value) { ERR_FAIL_COND_V_MSG(_p->read_only, ERR_LOCKED, "Array is in read-only state."); - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "insert"), ERR_INVALID_PARAMETER); - return _p->array.insert(p_pos, p_value); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "insert"), ERR_INVALID_PARAMETER); + return _p->array.insert(p_pos, value); } void Array::fill(const Variant &p_value) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - ERR_FAIL_COND(!_p->typed.validate(p_value, "fill")); - _p->array.fill(p_value); + Variant value = p_value; + ERR_FAIL_COND(!_p->typed.validate(value, "fill")); + _p->array.fill(value); } void Array::erase(const Variant &p_value) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - ERR_FAIL_COND(!_p->typed.validate(p_value, "erase")); - _p->array.erase(p_value); + Variant value = p_value; + ERR_FAIL_COND(!_p->typed.validate(value, "erase")); + _p->array.erase(value); } Variant Array::front() const { @@ -306,15 +319,34 @@ Variant Array::pick_random() const { } int Array::find(const Variant &p_value, int p_from) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find"), -1); - return _p->array.find(p_value, p_from); + if (_p->array.size() == 0) { + return -1; + } + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "find"), -1); + + int ret = -1; + + if (p_from < 0 || size() == 0) { + return ret; + } + + for (int i = p_from; i < size(); i++) { + if (StringLikeVariantComparator::compare(_p->array[i], value)) { + ret = i; + break; + } + } + + return ret; } int Array::rfind(const Variant &p_value, int p_from) const { if (_p->array.size() == 0) { return -1; } - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "rfind"), -1); if (p_from < 0) { // Relative offset from the end @@ -326,7 +358,7 @@ int Array::rfind(const Variant &p_value, int p_from) const { } for (int i = p_from; i >= 0; i--) { - if (_p->array[i] == p_value) { + if (StringLikeVariantComparator::compare(_p->array[i], value)) { return i; } } @@ -335,14 +367,15 @@ int Array::rfind(const Variant &p_value, int p_from) const { } int Array::count(const Variant &p_value) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "count"), 0); if (_p->array.size() == 0) { return 0; } int amount = 0; for (int i = 0; i < _p->array.size(); i++) { - if (_p->array[i] == p_value) { + if (StringLikeVariantComparator::compare(_p->array[i], value)) { amount++; } } @@ -351,9 +384,10 @@ int Array::count(const Variant &p_value) const { } bool Array::has(const Variant &p_value) const { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "use 'has'"), false); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "use 'has'"), false); - return _p->array.find(p_value, 0) != -1; + return find(value) != -1; } void Array::remove_at(int p_pos) { @@ -363,9 +397,10 @@ void Array::remove_at(int p_pos) { void Array::set(int p_idx, const Variant &p_value) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - ERR_FAIL_COND(!_p->typed.validate(p_value, "set")); + Variant value = p_value; + ERR_FAIL_COND(!_p->typed.validate(value, "set")); - operator[](p_idx) = p_value; + operator[](p_idx) = value; } const Variant &Array::get(int p_idx) const { @@ -588,15 +623,17 @@ void Array::shuffle() { } int Array::bsearch(const Variant &p_value, bool p_before) { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "binary search"), -1); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "binary search"), -1); SearchArray<Variant, _ArrayVariantSort> avs; - return avs.bisect(_p->array.ptrw(), _p->array.size(), p_value, p_before); + return avs.bisect(_p->array.ptrw(), _p->array.size(), value, p_before); } int Array::bsearch_custom(const Variant &p_value, const Callable &p_callable, bool p_before) { - ERR_FAIL_COND_V(!_p->typed.validate(p_value, "custom binary search"), -1); + Variant value = p_value; + ERR_FAIL_COND_V(!_p->typed.validate(value, "custom binary search"), -1); - return _p->array.bsearch_custom<CallableComparator>(p_value, p_before, p_callable); + return _p->array.bsearch_custom<CallableComparator>(value, p_before, p_callable); } void Array::reverse() { @@ -606,8 +643,9 @@ void Array::reverse() { void Array::push_front(const Variant &p_value) { ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); - ERR_FAIL_COND(!_p->typed.validate(p_value, "push_front")); - _p->array.insert(0, p_value); + Variant value = p_value; + ERR_FAIL_COND(!_p->typed.validate(value, "push_front")); + _p->array.insert(0, value); } Variant Array::pop_back() { diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h index 427a337aab..9976fce47f 100644 --- a/core/variant/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -74,22 +74,37 @@ struct ContainerTypeValidate { return true; } - _FORCE_INLINE_ bool validate(const Variant &p_variant, const char *p_operation = "use") { + // Coerces String and StringName into each other when needed. + _FORCE_INLINE_ bool validate(Variant &inout_variant, const char *p_operation = "use") { if (type == Variant::NIL) { return true; } - if (type != p_variant.get_type()) { - if (p_variant.get_type() == Variant::NIL && type == Variant::OBJECT) { + if (type != inout_variant.get_type()) { + if (inout_variant.get_type() == Variant::NIL && type == Variant::OBJECT) { + return true; + } + if (type == Variant::STRING && inout_variant.get_type() == Variant::STRING_NAME) { + inout_variant = String(inout_variant); + return true; + } else if (type == Variant::STRING_NAME && inout_variant.get_type() == Variant::STRING) { + inout_variant = StringName(inout_variant); return true; } - ERR_FAIL_V_MSG(false, "Attempted to " + String(p_operation) + " a variable of type '" + Variant::get_type_name(p_variant.get_type()) + "' into a " + where + " of type '" + Variant::get_type_name(type) + "'."); + ERR_FAIL_V_MSG(false, "Attempted to " + String(p_operation) + " a variable of type '" + Variant::get_type_name(inout_variant.get_type()) + "' into a " + where + " of type '" + Variant::get_type_name(type) + "'."); } if (type != Variant::OBJECT) { return true; } + + return validate_object(inout_variant, p_operation); + } + + _FORCE_INLINE_ bool validate_object(const Variant &p_variant, const char *p_operation = "use") { + ERR_FAIL_COND_V(p_variant.get_type() != Variant::OBJECT, false); + #ifdef DEBUG_ENABLED ObjectID object_id = p_variant; if (object_id == ObjectID()) { diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index c1cb782a57..77d9fb0bc2 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -42,7 +42,7 @@ struct DictionaryPrivate { SafeRefCount refcount; Variant *read_only = nullptr; // If enabled, a pointer is used to a temporary value that is used to return read-only values. - HashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map; + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator> variant_map; }; void Dictionary::get_key_list(List<Variant> *p_keys) const { @@ -100,24 +100,12 @@ Variant &Dictionary::operator[](const Variant &p_key) { } const Variant &Dictionary::operator[](const Variant &p_key) const { - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - return _p->variant_map[sn->operator String()]; - } else { - return _p->variant_map[p_key]; - } + // Will not insert key, so no conversion is necessary. + return _p->variant_map[p_key]; } const Variant *Dictionary::getptr(const Variant &p_key) const { - HashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstIterator E; - - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - E = ((const HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); - } else { - E = ((const HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); - } - + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(p_key)); if (!E) { return nullptr; } @@ -125,14 +113,7 @@ const Variant *Dictionary::getptr(const Variant &p_key) const { } Variant *Dictionary::getptr(const Variant &p_key) { - HashMap<Variant, Variant, VariantHasher, VariantComparator>::Iterator E; - - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - E = ((HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); - } else { - E = ((HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); - } + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E(_p->variant_map.find(p_key)); if (!E) { return nullptr; } @@ -145,14 +126,7 @@ Variant *Dictionary::getptr(const Variant &p_key) { } Variant Dictionary::get_valid(const Variant &p_key) const { - HashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstIterator E; - - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - E = ((const HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(sn->operator String()); - } else { - E = ((const HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key); - } + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(p_key)); if (!E) { return Variant(); @@ -178,12 +152,7 @@ bool Dictionary::is_empty() const { } bool Dictionary::has(const Variant &p_key) const { - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - return _p->variant_map.has(sn->operator String()); - } else { - return _p->variant_map.has(p_key); - } + return _p->variant_map.has(p_key); } bool Dictionary::has_all(const Array &p_keys) const { @@ -206,12 +175,7 @@ Variant Dictionary::find_key(const Variant &p_value) const { bool Dictionary::erase(const Variant &p_key) { ERR_FAIL_COND_V_MSG(_p->read_only, false, "Dictionary is in read-only state."); - if (p_key.get_type() == Variant::STRING_NAME) { - const StringName *sn = VariantInternal::get_string_name(&p_key); - return _p->variant_map.erase(sn->operator String()); - } else { - return _p->variant_map.erase(p_key); - } + return _p->variant_map.erase(p_key); } bool Dictionary::operator==(const Dictionary &p_dictionary) const { @@ -238,7 +202,7 @@ bool Dictionary::recursive_equal(const Dictionary &p_dictionary, int recursion_c } recursion_count++; for (const KeyValue<Variant, Variant> &this_E : _p->variant_map) { - HashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstIterator other_E = ((const HashMap<Variant, Variant, VariantHasher, VariantComparator> *)&p_dictionary._p->variant_map)->find(this_E.key); + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key)); if (!other_E || !this_E.value.hash_compare(other_E->value, recursion_count)) { return false; } @@ -360,7 +324,7 @@ const Variant *Dictionary::next(const Variant *p_key) const { } return nullptr; } - HashMap<Variant, Variant, VariantHasher, VariantComparator>::Iterator E = _p->variant_map.find(*p_key); + HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E = _p->variant_map.find(*p_key); if (!E) { return nullptr; diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index c1166a0a14..39b7cbee0d 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -940,7 +940,7 @@ bool Variant::is_zero() const { return reinterpret_cast<const Signal *>(_data._mem)->is_null(); } case STRING_NAME: { - return *reinterpret_cast<const StringName *>(_data._mem) != StringName(); + return *reinterpret_cast<const StringName *>(_data._mem) == StringName(); } case NODE_PATH: { return reinterpret_cast<const NodePath *>(_data._mem)->is_empty(); @@ -3491,6 +3491,19 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const } } +bool StringLikeVariantComparator::compare(const Variant &p_lhs, const Variant &p_rhs) { + if (p_lhs.hash_compare(p_rhs)) { + return true; + } + if (p_lhs.get_type() == Variant::STRING && p_rhs.get_type() == Variant::STRING_NAME) { + return *VariantInternal::get_string(&p_lhs) == *VariantInternal::get_string_name(&p_rhs); + } + if (p_lhs.get_type() == Variant::STRING_NAME && p_rhs.get_type() == Variant::STRING) { + return *VariantInternal::get_string_name(&p_lhs) == *VariantInternal::get_string(&p_rhs); + } + return false; +} + bool Variant::is_ref_counted() const { return type == OBJECT && _get_obj().id.is_ref_counted(); } diff --git a/core/variant/variant.h b/core/variant/variant.h index c5be609184..f7221e206f 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -797,6 +797,10 @@ struct VariantComparator { static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); } }; +struct StringLikeVariantComparator { + static bool compare(const Variant &p_lhs, const Variant &p_rhs); +}; + Variant::ObjData &Variant::_get_obj() { return *reinterpret_cast<ObjData *>(&_data._mem[0]); } diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 2cb80dcab4..ac569941bf 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -73,6 +73,30 @@ static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); } +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_variant_args_ret_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals); +} + +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_method_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_variant_args_retc_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals); +} + +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_variant_args_dv(&converted, method, p_args, p_argcount, r_error, p_defvals); +} + +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_variant_argsc_dv(&converted, method, p_args, p_argcount, r_error, p_defvals); +} + template <class R, class T, class... P> static _FORCE_INLINE_ void vc_method_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, p_defvals, r_error); @@ -102,6 +126,29 @@ static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Vari call_with_validated_variant_argsc(base, method, p_args); } +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_validated_variant_args_ret_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_validated_variant_args_retc_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_validated_variant_args_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { + T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); + call_with_validated_variant_argsc_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + template <class R, class T, class... P> static _FORCE_INLINE_ void vc_validated_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) { call_with_validated_variant_args_static_retc(base, method, p_args, r_ret); @@ -142,6 +189,30 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args); } +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + T converted(*reinterpret_cast<From *>(p_base)); + call_with_ptr_args_ret(&converted, method, p_args, r_ret); +} + +template <class From, class R, class T, class... P> +static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + T converted(*reinterpret_cast<From *>(p_base)); + call_with_ptr_args_retc(&converted, method, p_args, r_ret); +} + +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { + T converted(*reinterpret_cast<From *>(p_base)); + call_with_ptr_args(&converted, method, p_args); +} + +template <class From, class T, class... P> +static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { + T converted(*reinterpret_cast<From *>(p_base)); + call_with_ptr_argsc(&converted, method, p_args); +} + template <class R, class T, class... P> static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) { return sizeof...(P); @@ -337,6 +408,46 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con } \ }; +#define CONVERT_METHOD_CLASS(m_class, m_method_name, m_method_ptr) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + vc_convert_method_call<m_class>(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + vc_convert_validated_call<m_class>(m_method_ptr, base, p_args, r_ret); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + vc_convert_ptrcall<m_class>(m_method_ptr, p_base, p_args, r_ret); \ + } \ + static int get_argument_count() { \ + return vc_get_argument_count(m_method_ptr); \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return vc_get_argument_type(m_method_ptr, p_arg); \ + } \ + static Variant::Type get_return_type() { \ + return vc_get_return_type(m_method_ptr); \ + } \ + static bool has_return_type() { \ + return vc_has_return_type(m_method_ptr); \ + } \ + static bool is_const() { \ + return vc_is_const(m_method_ptr); \ + } \ + static bool is_static() { \ + return false; \ + } \ + static bool is_vararg() { \ + return false; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; + template <class R, class... P> static _FORCE_INLINE_ void vc_static_ptrcall(R (*method)(P...), const void **p_args, void *r_ret) { call_with_ptr_args_static_method_ret<R, P...>(method, p_args, r_ret); @@ -1422,6 +1533,16 @@ int Variant::get_enum_value(Variant::Type p_type, StringName p_enum_name, String #endif #ifdef DEBUG_METHODS_ENABLED +#define bind_convert_method(m_type_from, m_type_to, m_method, m_arg_names, m_default_args) \ + CONVERT_METHOD_CLASS(m_type_from, m_method, &m_type_to::m_method); \ + register_builtin_method<Method_##m_type_from##_##m_method>(m_arg_names, m_default_args); +#else +#define bind_convert_method(m_type_from, m_type_to, m_method, m_arg_names, m_default_args) \ + CONVERT_METHOD_CLASS(m_type_from, m_method, &m_type_to ::m_method); \ + register_builtin_method<Method_##m_type_from##_##m_method>(sarray(), m_default_args); +#endif + +#ifdef DEBUG_METHODS_ENABLED #define bind_static_method(m_type, m_method, m_arg_names, m_default_args) \ STATIC_METHOD_CLASS(m_type, m_method, m_type::m_method); \ register_builtin_method<Method_##m_type##_##m_method>(m_arg_names, m_default_args); @@ -1442,6 +1563,16 @@ int Variant::get_enum_value(Variant::Type p_type, StringName p_enum_name, String #endif #ifdef DEBUG_METHODS_ENABLED +#define bind_convert_methodv(m_type_from, m_type_to, m_name, m_method, m_arg_names, m_default_args) \ + CONVERT_METHOD_CLASS(m_type_from, m_name, m_method); \ + register_builtin_method<Method_##m_type_from##_##m_name>(m_arg_names, m_default_args); +#else +#define bind_convert_methodv(m_type_from, m_type_to, m_name, m_method, m_arg_names, m_default_args) \ + CONVERT_METHOD_CLASS(m_type_from, m_name, m_method); \ + register_builtin_method<Method_##m_type_from##_##m_name>(sarray(), m_default_args); +#endif + +#ifdef DEBUG_METHODS_ENABLED #define bind_function(m_type, m_name, m_method, m_arg_names, m_default_args) \ FUNCTION_CLASS(m_type, m_name, m_method, true); \ register_builtin_method<Method_##m_type##_##m_name>(m_arg_names, m_default_args); @@ -1461,6 +1592,14 @@ int Variant::get_enum_value(Variant::Type p_type, StringName p_enum_name, String register_builtin_method<Method_##m_type##_##m_name>(sarray(), m_default_args); #endif +#define bind_string_method(m_method, m_arg_names, m_default_args) \ + bind_method(String, m_method, m_arg_names, m_default_args); \ + bind_convert_method(StringName, String, m_method, m_arg_names, m_default_args); + +#define bind_string_methodv(m_name, m_method, m_arg_names, m_default_args) \ + bind_methodv(String, m_name, m_method, m_arg_names, m_default_args); \ + bind_convert_methodv(StringName, String, m_name, m_method, m_arg_names, m_default_args); + #define bind_custom(m_type, m_name, m_method, m_has_return, m_ret_type) \ VARARG_CLASS(m_type, m_name, m_method, m_has_return, m_ret_type) \ register_builtin_method<Method_##m_type##_##m_name>(sarray(), Vector<Variant>()); @@ -1477,108 +1616,108 @@ static void _register_variant_builtin_methods() { /* String */ - bind_method(String, casecmp_to, sarray("to"), varray()); - bind_method(String, nocasecmp_to, sarray("to"), varray()); - bind_method(String, naturalnocasecmp_to, sarray("to"), varray()); - bind_method(String, length, sarray(), varray()); - bind_method(String, substr, sarray("from", "len"), varray(-1)); - bind_method(String, get_slice, sarray("delimiter", "slice"), varray()); - bind_method(String, get_slicec, sarray("delimiter", "slice"), varray()); - bind_method(String, get_slice_count, sarray("delimiter"), varray()); - bind_methodv(String, find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0)); - bind_method(String, count, sarray("what", "from", "to"), varray(0, 0)); - bind_method(String, countn, sarray("what", "from", "to"), varray(0, 0)); - bind_method(String, findn, sarray("what", "from"), varray(0)); - bind_method(String, rfind, sarray("what", "from"), varray(-1)); - bind_method(String, rfindn, sarray("what", "from"), varray(-1)); - bind_method(String, match, sarray("expr"), varray()); - bind_method(String, matchn, sarray("expr"), varray()); - bind_methodv(String, begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray()); - bind_method(String, ends_with, sarray("text"), varray()); - bind_method(String, is_subsequence_of, sarray("text"), varray()); - bind_method(String, is_subsequence_ofn, sarray("text"), varray()); - bind_method(String, bigrams, sarray(), varray()); - bind_method(String, similarity, sarray("text"), varray()); - - bind_method(String, format, sarray("values", "placeholder"), varray("{_}")); - bind_methodv(String, replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray()); - bind_method(String, replacen, sarray("what", "forwhat"), varray()); - bind_method(String, repeat, sarray("count"), varray()); - bind_method(String, insert, sarray("position", "what"), varray()); - bind_method(String, capitalize, sarray(), varray()); - bind_method(String, to_camel_case, sarray(), varray()); - bind_method(String, to_pascal_case, sarray(), varray()); - bind_method(String, to_snake_case, sarray(), varray()); - bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); - bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); - bind_method(String, split_floats, sarray("delimiter", "allow_empty"), varray(true)); - bind_method(String, join, sarray("parts"), varray()); - - bind_method(String, to_upper, sarray(), varray()); - bind_method(String, to_lower, sarray(), varray()); - - bind_method(String, left, sarray("length"), varray()); - bind_method(String, right, sarray("length"), varray()); - - bind_method(String, strip_edges, sarray("left", "right"), varray(true, true)); - bind_method(String, strip_escapes, sarray(), varray()); - bind_method(String, lstrip, sarray("chars"), varray()); - bind_method(String, rstrip, sarray("chars"), varray()); - bind_method(String, get_extension, sarray(), varray()); - bind_method(String, get_basename, sarray(), varray()); - bind_method(String, path_join, sarray("file"), varray()); - bind_method(String, unicode_at, sarray("at"), varray()); - bind_method(String, indent, sarray("prefix"), varray()); - bind_method(String, dedent, sarray(), varray()); + bind_string_method(casecmp_to, sarray("to"), varray()); + bind_string_method(nocasecmp_to, sarray("to"), varray()); + bind_string_method(naturalnocasecmp_to, sarray("to"), varray()); + bind_string_method(length, sarray(), varray()); + bind_string_method(substr, sarray("from", "len"), varray(-1)); + bind_string_method(get_slice, sarray("delimiter", "slice"), varray()); + bind_string_method(get_slicec, sarray("delimiter", "slice"), varray()); + bind_string_method(get_slice_count, sarray("delimiter"), varray()); + bind_string_methodv(find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0)); + bind_string_method(count, sarray("what", "from", "to"), varray(0, 0)); + bind_string_method(countn, sarray("what", "from", "to"), varray(0, 0)); + bind_string_method(findn, sarray("what", "from"), varray(0)); + bind_string_method(rfind, sarray("what", "from"), varray(-1)); + bind_string_method(rfindn, sarray("what", "from"), varray(-1)); + bind_string_method(match, sarray("expr"), varray()); + bind_string_method(matchn, sarray("expr"), varray()); + bind_string_methodv(begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray()); + bind_string_method(ends_with, sarray("text"), varray()); + bind_string_method(is_subsequence_of, sarray("text"), varray()); + bind_string_method(is_subsequence_ofn, sarray("text"), varray()); + bind_string_method(bigrams, sarray(), varray()); + bind_string_method(similarity, sarray("text"), varray()); + + bind_string_method(format, sarray("values", "placeholder"), varray("{_}")); + bind_string_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray()); + bind_string_method(replacen, sarray("what", "forwhat"), varray()); + bind_string_method(repeat, sarray("count"), varray()); + bind_string_method(insert, sarray("position", "what"), varray()); + bind_string_method(capitalize, sarray(), varray()); + bind_string_method(to_camel_case, sarray(), varray()); + bind_string_method(to_pascal_case, sarray(), varray()); + bind_string_method(to_snake_case, sarray(), varray()); + bind_string_method(split, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); + bind_string_method(rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); + bind_string_method(split_floats, sarray("delimiter", "allow_empty"), varray(true)); + bind_string_method(join, sarray("parts"), varray()); + + bind_string_method(to_upper, sarray(), varray()); + bind_string_method(to_lower, sarray(), varray()); + + bind_string_method(left, sarray("length"), varray()); + bind_string_method(right, sarray("length"), varray()); + + bind_string_method(strip_edges, sarray("left", "right"), varray(true, true)); + bind_string_method(strip_escapes, sarray(), varray()); + bind_string_method(lstrip, sarray("chars"), varray()); + bind_string_method(rstrip, sarray("chars"), varray()); + bind_string_method(get_extension, sarray(), varray()); + bind_string_method(get_basename, sarray(), varray()); + bind_string_method(path_join, sarray("file"), varray()); + bind_string_method(unicode_at, sarray("at"), varray()); + bind_string_method(indent, sarray("prefix"), varray()); + bind_string_method(dedent, sarray(), varray()); bind_method(String, hash, sarray(), varray()); - bind_method(String, md5_text, sarray(), varray()); - bind_method(String, sha1_text, sarray(), varray()); - bind_method(String, sha256_text, sarray(), varray()); - bind_method(String, md5_buffer, sarray(), varray()); - bind_method(String, sha1_buffer, sarray(), varray()); - bind_method(String, sha256_buffer, sarray(), varray()); - bind_method(String, is_empty, sarray(), varray()); - bind_methodv(String, contains, static_cast<bool (String::*)(const String &) const>(&String::contains), sarray("what"), varray()); - - bind_method(String, is_absolute_path, sarray(), varray()); - bind_method(String, is_relative_path, sarray(), varray()); - bind_method(String, simplify_path, sarray(), varray()); - bind_method(String, get_base_dir, sarray(), varray()); - bind_method(String, get_file, sarray(), varray()); - bind_method(String, xml_escape, sarray("escape_quotes"), varray(false)); - bind_method(String, xml_unescape, sarray(), varray()); - bind_method(String, uri_encode, sarray(), varray()); - bind_method(String, uri_decode, sarray(), varray()); - bind_method(String, c_escape, sarray(), varray()); - bind_method(String, c_unescape, sarray(), varray()); - bind_method(String, json_escape, sarray(), varray()); - - bind_method(String, validate_node_name, sarray(), varray()); - - bind_method(String, is_valid_identifier, sarray(), varray()); - bind_method(String, is_valid_int, sarray(), varray()); - bind_method(String, is_valid_float, sarray(), varray()); - bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false)); - bind_method(String, is_valid_html_color, sarray(), varray()); - bind_method(String, is_valid_ip_address, sarray(), varray()); - bind_method(String, is_valid_filename, sarray(), varray()); - - bind_method(String, to_int, sarray(), varray()); - bind_method(String, to_float, sarray(), varray()); - bind_method(String, hex_to_int, sarray(), varray()); - bind_method(String, bin_to_int, sarray(), varray()); - - bind_method(String, lpad, sarray("min_length", "character"), varray(" ")); - bind_method(String, rpad, sarray("min_length", "character"), varray(" ")); - bind_method(String, pad_decimals, sarray("digits"), varray()); - bind_method(String, pad_zeros, sarray("digits"), varray()); - bind_method(String, trim_prefix, sarray("prefix"), varray()); - bind_method(String, trim_suffix, sarray("suffix"), varray()); - - bind_method(String, to_ascii_buffer, sarray(), varray()); - bind_method(String, to_utf8_buffer, sarray(), varray()); - bind_method(String, to_utf16_buffer, sarray(), varray()); - bind_method(String, to_utf32_buffer, sarray(), varray()); + bind_string_method(md5_text, sarray(), varray()); + bind_string_method(sha1_text, sarray(), varray()); + bind_string_method(sha256_text, sarray(), varray()); + bind_string_method(md5_buffer, sarray(), varray()); + bind_string_method(sha1_buffer, sarray(), varray()); + bind_string_method(sha256_buffer, sarray(), varray()); + bind_string_method(is_empty, sarray(), varray()); + bind_string_methodv(contains, static_cast<bool (String::*)(const String &) const>(&String::contains), sarray("what"), varray()); + + bind_string_method(is_absolute_path, sarray(), varray()); + bind_string_method(is_relative_path, sarray(), varray()); + bind_string_method(simplify_path, sarray(), varray()); + bind_string_method(get_base_dir, sarray(), varray()); + bind_string_method(get_file, sarray(), varray()); + bind_string_method(xml_escape, sarray("escape_quotes"), varray(false)); + bind_string_method(xml_unescape, sarray(), varray()); + bind_string_method(uri_encode, sarray(), varray()); + bind_string_method(uri_decode, sarray(), varray()); + bind_string_method(c_escape, sarray(), varray()); + bind_string_method(c_unescape, sarray(), varray()); + bind_string_method(json_escape, sarray(), varray()); + + bind_string_method(validate_node_name, sarray(), varray()); + + bind_string_method(is_valid_identifier, sarray(), varray()); + bind_string_method(is_valid_int, sarray(), varray()); + bind_string_method(is_valid_float, sarray(), varray()); + bind_string_method(is_valid_hex_number, sarray("with_prefix"), varray(false)); + bind_string_method(is_valid_html_color, sarray(), varray()); + bind_string_method(is_valid_ip_address, sarray(), varray()); + bind_string_method(is_valid_filename, sarray(), varray()); + + bind_string_method(to_int, sarray(), varray()); + bind_string_method(to_float, sarray(), varray()); + bind_string_method(hex_to_int, sarray(), varray()); + bind_string_method(bin_to_int, sarray(), varray()); + + bind_string_method(lpad, sarray("min_length", "character"), varray(" ")); + bind_string_method(rpad, sarray("min_length", "character"), varray(" ")); + bind_string_method(pad_decimals, sarray("digits"), varray()); + bind_string_method(pad_zeros, sarray("digits"), varray()); + bind_string_method(trim_prefix, sarray("prefix"), varray()); + bind_string_method(trim_suffix, sarray("suffix"), varray()); + + bind_string_method(to_ascii_buffer, sarray(), varray()); + bind_string_method(to_utf8_buffer, sarray(), varray()); + bind_string_method(to_utf16_buffer, sarray(), varray()); + bind_string_method(to_utf32_buffer, sarray(), varray()); bind_static_method(String, num_scientific, sarray("number"), varray()); bind_static_method(String, num, sarray("number", "decimals"), varray(-1)); diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index 25bc241e9b..d4e6dfb4d1 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -229,6 +229,20 @@ public: static Variant::Type get_return_type() { return GetTypeInfo<Vector4>::VARIANT_TYPE; } }; +#define register_string_op(m_op_type, m_op_code) \ + do { \ + register_op<m_op_type<String, String>>(m_op_code, Variant::STRING, Variant::STRING); \ + register_op<m_op_type<String, StringName>>(m_op_code, Variant::STRING, Variant::STRING_NAME); \ + register_op<m_op_type<StringName, String>>(m_op_code, Variant::STRING_NAME, Variant::STRING); \ + register_op<m_op_type<StringName, StringName>>(m_op_code, Variant::STRING_NAME, Variant::STRING_NAME); \ + } while (false) + +#define register_string_modulo_op(m_class, m_type) \ + do { \ + register_op<OperatorEvaluatorStringFormat<String, m_class>>(Variant::OP_MODULE, Variant::STRING, m_type); \ + register_op<OperatorEvaluatorStringFormat<StringName, m_class>>(Variant::OP_MODULE, Variant::STRING_NAME, m_type); \ + } while (false) + void Variant::_register_variant_operators() { memset(operator_return_type_table, 0, sizeof(operator_return_type_table)); memset(operator_evaluator_table, 0, sizeof(operator_evaluator_table)); @@ -239,7 +253,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAdd<double, int64_t, double>>(Variant::OP_ADD, Variant::INT, Variant::FLOAT); register_op<OperatorEvaluatorAdd<double, double, int64_t>>(Variant::OP_ADD, Variant::FLOAT, Variant::INT); register_op<OperatorEvaluatorAdd<double, double, double>>(Variant::OP_ADD, Variant::FLOAT, Variant::FLOAT); - register_op<OperatorEvaluatorAdd<String, String, String>>(Variant::OP_ADD, Variant::STRING, Variant::STRING); + register_string_op(OperatorEvaluatorStringConcat, Variant::OP_ADD); register_op<OperatorEvaluatorAdd<Vector2, Vector2, Vector2>>(Variant::OP_ADD, Variant::VECTOR2, Variant::VECTOR2); register_op<OperatorEvaluatorAdd<Vector2i, Vector2i, Vector2i>>(Variant::OP_ADD, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorAdd<Vector3, Vector3, Vector3>>(Variant::OP_ADD, Variant::VECTOR3, Variant::VECTOR3); @@ -415,46 +429,46 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorModNZ<Vector4i, Vector4i, Vector4i>>(Variant::OP_MODULE, Variant::VECTOR4I, Variant::VECTOR4I); register_op<OperatorEvaluatorModNZ<Vector4i, Vector4i, int64_t>>(Variant::OP_MODULE, Variant::VECTOR4I, Variant::INT); - register_op<OperatorEvaluatorStringModNil>(Variant::OP_MODULE, Variant::STRING, Variant::NIL); - - register_op<OperatorEvaluatorStringModT<bool>>(Variant::OP_MODULE, Variant::STRING, Variant::BOOL); - register_op<OperatorEvaluatorStringModT<int64_t>>(Variant::OP_MODULE, Variant::STRING, Variant::INT); - register_op<OperatorEvaluatorStringModT<double>>(Variant::OP_MODULE, Variant::STRING, Variant::FLOAT); - register_op<OperatorEvaluatorStringModT<String>>(Variant::OP_MODULE, Variant::STRING, Variant::STRING); - register_op<OperatorEvaluatorStringModT<Vector2>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR2); - register_op<OperatorEvaluatorStringModT<Vector2i>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR2I); - register_op<OperatorEvaluatorStringModT<Rect2>>(Variant::OP_MODULE, Variant::STRING, Variant::RECT2); - register_op<OperatorEvaluatorStringModT<Rect2i>>(Variant::OP_MODULE, Variant::STRING, Variant::RECT2I); - register_op<OperatorEvaluatorStringModT<Vector3>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR3); - register_op<OperatorEvaluatorStringModT<Vector3i>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR3I); - register_op<OperatorEvaluatorStringModT<Vector4>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR4); - register_op<OperatorEvaluatorStringModT<Vector4i>>(Variant::OP_MODULE, Variant::STRING, Variant::VECTOR4I); - register_op<OperatorEvaluatorStringModT<Transform2D>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM2D); - register_op<OperatorEvaluatorStringModT<Plane>>(Variant::OP_MODULE, Variant::STRING, Variant::PLANE); - register_op<OperatorEvaluatorStringModT<Quaternion>>(Variant::OP_MODULE, Variant::STRING, Variant::QUATERNION); - register_op<OperatorEvaluatorStringModT<::AABB>>(Variant::OP_MODULE, Variant::STRING, Variant::AABB); - register_op<OperatorEvaluatorStringModT<Basis>>(Variant::OP_MODULE, Variant::STRING, Variant::BASIS); - register_op<OperatorEvaluatorStringModT<Transform3D>>(Variant::OP_MODULE, Variant::STRING, Variant::TRANSFORM3D); - register_op<OperatorEvaluatorStringModT<Projection>>(Variant::OP_MODULE, Variant::STRING, Variant::PROJECTION); - - register_op<OperatorEvaluatorStringModT<Color>>(Variant::OP_MODULE, Variant::STRING, Variant::COLOR); - register_op<OperatorEvaluatorStringModT<StringName>>(Variant::OP_MODULE, Variant::STRING, Variant::STRING_NAME); - register_op<OperatorEvaluatorStringModT<NodePath>>(Variant::OP_MODULE, Variant::STRING, Variant::NODE_PATH); - register_op<OperatorEvaluatorStringModObject>(Variant::OP_MODULE, Variant::STRING, Variant::OBJECT); - register_op<OperatorEvaluatorStringModT<Callable>>(Variant::OP_MODULE, Variant::STRING, Variant::CALLABLE); - register_op<OperatorEvaluatorStringModT<Signal>>(Variant::OP_MODULE, Variant::STRING, Variant::SIGNAL); - register_op<OperatorEvaluatorStringModT<Dictionary>>(Variant::OP_MODULE, Variant::STRING, Variant::DICTIONARY); - register_op<OperatorEvaluatorStringModArray>(Variant::OP_MODULE, Variant::STRING, Variant::ARRAY); - - register_op<OperatorEvaluatorStringModT<PackedByteArray>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_BYTE_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedInt32Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_INT32_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedInt64Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_INT64_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedFloat32Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_FLOAT32_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedFloat64Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_FLOAT64_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedStringArray>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_STRING_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedVector2Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_VECTOR2_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedVector3Array>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_VECTOR3_ARRAY); - register_op<OperatorEvaluatorStringModT<PackedColorArray>>(Variant::OP_MODULE, Variant::STRING, Variant::PACKED_COLOR_ARRAY); + register_string_modulo_op(void, Variant::NIL); + + register_string_modulo_op(bool, Variant::BOOL); + register_string_modulo_op(int64_t, Variant::INT); + register_string_modulo_op(double, Variant::FLOAT); + register_string_modulo_op(String, Variant::STRING); + register_string_modulo_op(Vector2, Variant::VECTOR2); + register_string_modulo_op(Vector2i, Variant::VECTOR2I); + register_string_modulo_op(Rect2, Variant::RECT2); + register_string_modulo_op(Rect2i, Variant::RECT2I); + register_string_modulo_op(Vector3, Variant::VECTOR3); + register_string_modulo_op(Vector3i, Variant::VECTOR3I); + register_string_modulo_op(Vector4, Variant::VECTOR4); + register_string_modulo_op(Vector4i, Variant::VECTOR4I); + register_string_modulo_op(Transform2D, Variant::TRANSFORM2D); + register_string_modulo_op(Plane, Variant::PLANE); + register_string_modulo_op(Quaternion, Variant::QUATERNION); + register_string_modulo_op(::AABB, Variant::AABB); + register_string_modulo_op(Basis, Variant::BASIS); + register_string_modulo_op(Transform3D, Variant::TRANSFORM3D); + register_string_modulo_op(Projection, Variant::PROJECTION); + + register_string_modulo_op(Color, Variant::COLOR); + register_string_modulo_op(StringName, Variant::STRING_NAME); + register_string_modulo_op(NodePath, Variant::NODE_PATH); + register_string_modulo_op(Object, Variant::OBJECT); + register_string_modulo_op(Callable, Variant::CALLABLE); + register_string_modulo_op(Signal, Variant::SIGNAL); + register_string_modulo_op(Dictionary, Variant::DICTIONARY); + register_string_modulo_op(Array, Variant::ARRAY); + + register_string_modulo_op(PackedByteArray, Variant::PACKED_BYTE_ARRAY); + register_string_modulo_op(PackedInt32Array, Variant::PACKED_INT32_ARRAY); + register_string_modulo_op(PackedInt64Array, Variant::PACKED_INT64_ARRAY); + register_string_modulo_op(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY); + register_string_modulo_op(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY); + register_string_modulo_op(PackedStringArray, Variant::PACKED_STRING_ARRAY); + register_string_modulo_op(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY); + register_string_modulo_op(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY); + register_string_modulo_op(PackedColorArray, Variant::PACKED_COLOR_ARRAY); register_op<OperatorEvaluatorPow<int64_t, int64_t, int64_t>>(Variant::OP_POWER, Variant::INT, Variant::INT); register_op<OperatorEvaluatorPow<double, int64_t, double>>(Variant::OP_POWER, Variant::INT, Variant::FLOAT); @@ -498,7 +512,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorEqual<int64_t, double>>(Variant::OP_EQUAL, Variant::INT, Variant::FLOAT); register_op<OperatorEvaluatorEqual<double, int64_t>>(Variant::OP_EQUAL, Variant::FLOAT, Variant::INT); register_op<OperatorEvaluatorEqual<double, double>>(Variant::OP_EQUAL, Variant::FLOAT, Variant::FLOAT); - register_op<OperatorEvaluatorEqual<String, String>>(Variant::OP_EQUAL, Variant::STRING, Variant::STRING); + register_string_op(OperatorEvaluatorEqual, Variant::OP_EQUAL); register_op<OperatorEvaluatorEqual<Vector2, Vector2>>(Variant::OP_EQUAL, Variant::VECTOR2, Variant::VECTOR2); register_op<OperatorEvaluatorEqual<Vector2i, Vector2i>>(Variant::OP_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorEqual<Rect2, Rect2>>(Variant::OP_EQUAL, Variant::RECT2, Variant::RECT2); @@ -516,10 +530,6 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorEqual<Projection, Projection>>(Variant::OP_EQUAL, Variant::PROJECTION, Variant::PROJECTION); register_op<OperatorEvaluatorEqual<Color, Color>>(Variant::OP_EQUAL, Variant::COLOR, Variant::COLOR); - register_op<OperatorEvaluatorEqual<StringName, String>>(Variant::OP_EQUAL, Variant::STRING_NAME, Variant::STRING); - register_op<OperatorEvaluatorEqual<String, StringName>>(Variant::OP_EQUAL, Variant::STRING, Variant::STRING_NAME); - register_op<OperatorEvaluatorEqual<StringName, StringName>>(Variant::OP_EQUAL, Variant::STRING_NAME, Variant::STRING_NAME); - register_op<OperatorEvaluatorEqual<NodePath, NodePath>>(Variant::OP_EQUAL, Variant::NODE_PATH, Variant::NODE_PATH); register_op<OperatorEvaluatorEqual<::RID, ::RID>>(Variant::OP_EQUAL, Variant::RID, Variant::RID); @@ -621,7 +631,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorNotEqual<int64_t, double>>(Variant::OP_NOT_EQUAL, Variant::INT, Variant::FLOAT); register_op<OperatorEvaluatorNotEqual<double, int64_t>>(Variant::OP_NOT_EQUAL, Variant::FLOAT, Variant::INT); register_op<OperatorEvaluatorNotEqual<double, double>>(Variant::OP_NOT_EQUAL, Variant::FLOAT, Variant::FLOAT); - register_op<OperatorEvaluatorNotEqual<String, String>>(Variant::OP_NOT_EQUAL, Variant::STRING, Variant::STRING); + register_string_op(OperatorEvaluatorNotEqual, Variant::OP_NOT_EQUAL); register_op<OperatorEvaluatorNotEqual<Vector2, Vector2>>(Variant::OP_NOT_EQUAL, Variant::VECTOR2, Variant::VECTOR2); register_op<OperatorEvaluatorNotEqual<Vector2i, Vector2i>>(Variant::OP_NOT_EQUAL, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorNotEqual<Rect2, Rect2>>(Variant::OP_NOT_EQUAL, Variant::RECT2, Variant::RECT2); @@ -639,10 +649,6 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorNotEqual<Projection, Projection>>(Variant::OP_NOT_EQUAL, Variant::PROJECTION, Variant::PROJECTION); register_op<OperatorEvaluatorNotEqual<Color, Color>>(Variant::OP_NOT_EQUAL, Variant::COLOR, Variant::COLOR); - register_op<OperatorEvaluatorNotEqual<StringName, String>>(Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::STRING); - register_op<OperatorEvaluatorNotEqual<String, StringName>>(Variant::OP_NOT_EQUAL, Variant::STRING, Variant::STRING_NAME); - register_op<OperatorEvaluatorNotEqual<StringName, StringName>>(Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::STRING_NAME); - register_op<OperatorEvaluatorNotEqual<NodePath, NodePath>>(Variant::OP_NOT_EQUAL, Variant::NODE_PATH, Variant::NODE_PATH); register_op<OperatorEvaluatorNotEqual<::RID, ::RID>>(Variant::OP_NOT_EQUAL, Variant::RID, Variant::RID); @@ -895,10 +901,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorNotFloat>(Variant::OP_NOT, Variant::FLOAT, Variant::NIL); register_op<OperatorEvaluatorNotObject>(Variant::OP_NOT, Variant::OBJECT, Variant::NIL); - register_op<OperatorEvaluatorInStringFind<String>>(Variant::OP_IN, Variant::STRING, Variant::STRING); - register_op<OperatorEvaluatorInStringFind<StringName>>(Variant::OP_IN, Variant::STRING_NAME, Variant::STRING); - register_op<OperatorEvaluatorInStringNameFind<String>>(Variant::OP_IN, Variant::STRING, Variant::STRING_NAME); - register_op<OperatorEvaluatorInStringNameFind<StringName>>(Variant::OP_IN, Variant::STRING_NAME, Variant::STRING_NAME); + register_string_op(OperatorEvaluatorInStringFind, Variant::OP_IN); register_op<OperatorEvaluatorInDictionaryHasNil>(Variant::OP_IN, Variant::NIL, Variant::DICTIONARY); register_op<OperatorEvaluatorInDictionaryHas<bool>>(Variant::OP_IN, Variant::BOOL, Variant::DICTIONARY); @@ -996,6 +999,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorInArrayFind<float, PackedFloat64Array>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_FLOAT64_ARRAY); register_op<OperatorEvaluatorInArrayFind<String, PackedStringArray>>(Variant::OP_IN, Variant::STRING, Variant::PACKED_STRING_ARRAY); + register_op<OperatorEvaluatorInArrayFind<StringName, PackedStringArray>>(Variant::OP_IN, Variant::STRING_NAME, Variant::PACKED_STRING_ARRAY); register_op<OperatorEvaluatorInArrayFind<Vector2, PackedVector2Array>>(Variant::OP_IN, Variant::VECTOR2, Variant::PACKED_VECTOR2_ARRAY); register_op<OperatorEvaluatorInArrayFind<Vector3, PackedVector3Array>>(Variant::OP_IN, Variant::VECTOR3, Variant::PACKED_VECTOR3_ARRAY); @@ -1006,6 +1010,9 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorObjectHasPropertyStringName>(Variant::OP_IN, Variant::STRING_NAME, Variant::OBJECT); } +#undef register_string_op +#undef register_string_modulo_op + void Variant::_unregister_variant_operators() { } diff --git a/core/variant/variant_op.h b/core/variant/variant_op.h index 34858540ec..ea4216322c 100644 --- a/core/variant/variant_op.h +++ b/core/variant/variant_op.h @@ -875,7 +875,33 @@ public: static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; } }; -class OperatorEvaluatorStringModNil { +template <class Left, class Right> +class OperatorEvaluatorStringConcat { +public: + static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { + const String a(*VariantGetInternalPtr<Left>::get_ptr(&p_left)); + const String b(*VariantGetInternalPtr<Right>::get_ptr(&p_right)); + *r_ret = a + b; + r_valid = true; + } + static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { + const String a(*VariantGetInternalPtr<Left>::get_ptr(left)); + const String b(*VariantGetInternalPtr<Right>::get_ptr(right)); + *VariantGetInternalPtr<String>::get_ptr(r_ret) = a + b; + } + static void ptr_evaluate(const void *left, const void *right, void *r_ret) { + const String a(PtrToArg<Left>::convert(left)); + const String b(PtrToArg<Right>::convert(right)); + PtrToArg<String>::encode(a + b, r_ret); + } + static Variant::Type get_return_type() { return Variant::STRING; } +}; + +template <class S, class T> +class OperatorEvaluatorStringFormat; + +template <class S> +class OperatorEvaluatorStringFormat<S, void> { public: _FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) { Array values; @@ -888,22 +914,22 @@ public: return a; } static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, &r_valid); + *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), &r_valid); } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { bool valid = true; - String result = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), &valid); + String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), &valid); ERR_FAIL_COND_MSG(!valid, result); *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), nullptr), r_ret); + PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), nullptr), r_ret); } static Variant::Type get_return_type() { return Variant::STRING; } }; -class OperatorEvaluatorStringModArray { +template <class S> +class OperatorEvaluatorStringFormat<S, Array> { public: _FORCE_INLINE_ static String do_mod(const String &s, const Array &p_values, bool *r_valid) { String a = s.sprintf(p_values, r_valid); @@ -913,22 +939,22 @@ public: return a; } static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid); + *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid); } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { bool valid = true; - String result = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid); + String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid); ERR_FAIL_COND_MSG(!valid, result); *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret); + PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret); } static Variant::Type get_return_type() { return Variant::STRING; } }; -class OperatorEvaluatorStringModObject { +template <class S> +class OperatorEvaluatorStringFormat<S, Object> { public: _FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) { Array values; @@ -941,23 +967,22 @@ public: return a; } static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, p_right.get_validated_object(), &r_valid); + *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), p_right.get_validated_object(), &r_valid); } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { bool valid = true; - String result = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), right->get_validated_object(), &valid); + String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), right->get_validated_object(), &valid); ERR_FAIL_COND_MSG(!valid, result); *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret); + PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret); } static Variant::Type get_return_type() { return Variant::STRING; } }; -template <class T> -class OperatorEvaluatorStringModT { +template <class S, class T> +class OperatorEvaluatorStringFormat { public: _FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) { Array values; @@ -969,17 +994,16 @@ public: return a; } static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { - const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); - *r_ret = do_mod(a, *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid); + *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid); } static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { bool valid = true; - String result = do_mod(*VariantGetInternalPtr<String>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid); + String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid); ERR_FAIL_COND_MSG(!valid, result); *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; } static void ptr_evaluate(const void *left, const void *right, void *r_ret) { - PtrToArg<String>::encode(do_mod(PtrToArg<String>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret); + PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret); } static Variant::Type get_return_type() { return Variant::STRING; } }; @@ -1288,8 +1312,11 @@ public: //// +template <class Left, class Right> +class OperatorEvaluatorInStringFind; + template <class Left> -class OperatorEvaluatorInStringFind { +class OperatorEvaluatorInStringFind<Left, String> { public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(&p_left); @@ -1310,7 +1337,7 @@ public: }; template <class Left> -class OperatorEvaluatorInStringNameFind { +class OperatorEvaluatorInStringFind<Left, StringName> { public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(&p_left); diff --git a/doc/classes/AudioStreamRandomizer.xml b/doc/classes/AudioStreamRandomizer.xml index 5490770b7d..9b58d78af5 100644 --- a/doc/classes/AudioStreamRandomizer.xml +++ b/doc/classes/AudioStreamRandomizer.xml @@ -78,13 +78,13 @@ </members> <constants> <constant name="PLAYBACK_RANDOM_NO_REPEATS" value="0" enum="PlaybackMode"> - Pick a stream at random according to the probability weights chosen for each stream, but avoid playing the same stream twice in a row whenever possible. + Pick a stream at random according to the probability weights chosen for each stream, but avoid playing the same stream twice in a row whenever possible. If only 1 sound is present in the pool, the same sound will always play, effectively allowing repeats to occur. </constant> <constant name="PLAYBACK_RANDOM" value="1" enum="PlaybackMode"> - Pick a stream at random according to the probability weights chosen for each stream. + Pick a stream at random according to the probability weights chosen for each stream. If only 1 sound is present in the pool, the same sound will always play. </constant> <constant name="PLAYBACK_SEQUENTIAL" value="2" enum="PlaybackMode"> - Play streams in the order they appear in the stream pool. + Play streams in the order they appear in the stream pool. If only 1 sound is present in the pool, the same sound will always play. </constant> </constants> </class> diff --git a/doc/classes/BackBufferCopy.xml b/doc/classes/BackBufferCopy.xml index 3c811e6226..b2c5a1756f 100644 --- a/doc/classes/BackBufferCopy.xml +++ b/doc/classes/BackBufferCopy.xml @@ -4,8 +4,8 @@ Copies a region of the screen (or the whole screen) to a buffer so it can be accessed in your shader scripts through the [code]texture(SCREEN_TEXTURE, ...)[/code] function. </brief_description> <description> - Node for back-buffering the currently-displayed screen. The region defined in the BackBufferCopy node is buffered with the content of the screen it covers, or the entire screen according to the copy mode set. Use the [code]texture(SCREEN_TEXTURE, ...)[/code] function in your shader scripts to access the buffer. - [b]Note:[/b] Since this node inherits from [Node2D] (and not [Control]), anchors and margins won't apply to child [Control]-derived nodes. This can be problematic when resizing the window. To avoid this, add [Control]-derived nodes as [i]siblings[/i] to the BackBufferCopy node instead of adding them as children. + Node for back-buffering the currently-displayed screen. The region defined in the [BackBufferCopy] node is buffered with the content of the screen it covers, or the entire screen according to the copy mode set. Use the [code]texture(SCREEN_TEXTURE, ...)[/code] function in your shader scripts to access the buffer. + [b]Note:[/b] Since this node inherits from [Node2D] (and not [Control]), anchors and margins won't apply to child [Control]-derived nodes. This can be problematic when resizing the window. To avoid this, add [Control]-derived nodes as [i]siblings[/i] to the [BackBufferCopy] node instead of adding them as children. </description> <tutorials> </tutorials> @@ -14,18 +14,18 @@ Buffer mode. See [enum CopyMode] constants. </member> <member name="rect" type="Rect2" setter="set_rect" getter="get_rect" default="Rect2(-100, -100, 200, 200)"> - The area covered by the BackBufferCopy. Only used if [member copy_mode] is [constant COPY_MODE_RECT]. + The area covered by the [BackBufferCopy]. Only used if [member copy_mode] is [constant COPY_MODE_RECT]. </member> </members> <constants> <constant name="COPY_MODE_DISABLED" value="0" enum="CopyMode"> - Disables the buffering mode. This means the BackBufferCopy node will directly use the portion of screen it covers. + Disables the buffering mode. This means the [BackBufferCopy] node will directly use the portion of screen it covers. </constant> <constant name="COPY_MODE_RECT" value="1" enum="CopyMode"> - BackBufferCopy buffers a rectangular region. + [BackBufferCopy] buffers a rectangular region. </constant> <constant name="COPY_MODE_VIEWPORT" value="2" enum="CopyMode"> - BackBufferCopy buffers the entire screen. + [BackBufferCopy] buffers the entire screen. </constant> </constants> </class> diff --git a/doc/classes/CollisionObject2D.xml b/doc/classes/CollisionObject2D.xml index ee69015ae1..3ed2c9d3de 100644 --- a/doc/classes/CollisionObject2D.xml +++ b/doc/classes/CollisionObject2D.xml @@ -157,7 +157,7 @@ <param index="0" name="owner_id" type="int" /> <param index="1" name="shape_id" type="int" /> <description> - Returns the [Shape2D] with the given id from the given shape owner. + Returns the [Shape2D] with the given ID from the given shape owner. </description> </method> <method name="shape_owner_get_shape_count" qualifiers="const"> @@ -172,7 +172,7 @@ <param index="0" name="owner_id" type="int" /> <param index="1" name="shape_id" type="int" /> <description> - Returns the child index of the [Shape2D] with the given id from the given shape owner. + Returns the child index of the [Shape2D] with the given ID from the given shape owner. </description> </method> <method name="shape_owner_get_transform" qualifiers="const"> diff --git a/doc/classes/CollisionObject3D.xml b/doc/classes/CollisionObject3D.xml index f10136521a..c302963b92 100644 --- a/doc/classes/CollisionObject3D.xml +++ b/doc/classes/CollisionObject3D.xml @@ -130,7 +130,7 @@ <param index="0" name="owner_id" type="int" /> <param index="1" name="shape_id" type="int" /> <description> - Returns the [Shape3D] with the given id from the given shape owner. + Returns the [Shape3D] with the given ID from the given shape owner. </description> </method> <method name="shape_owner_get_shape_count" qualifiers="const"> @@ -145,7 +145,7 @@ <param index="0" name="owner_id" type="int" /> <param index="1" name="shape_id" type="int" /> <description> - Returns the child index of the [Shape3D] with the given id from the given shape owner. + Returns the child index of the [Shape3D] with the given ID from the given shape owner. </description> </method> <method name="shape_owner_get_transform" qualifiers="const"> diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 8a38deeebe..fd6aab6a49 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -1071,7 +1071,8 @@ Tells the parent [Container] nodes how they should resize and place the node on the Y axis. Use one of the [enum SizeFlags] constants to change the flags. See the constants to learn what each does. </member> <member name="theme" type="Theme" setter="set_theme" getter="get_theme"> - The [Theme] resource this node and all its [Control] children use. If a child node has its own [Theme] resource set, theme items are merged with child's definitions having higher priority. + The [Theme] resource this node and all its [Control] and [Window] children use. If a child node has its own [Theme] resource set, theme items are merged with child's definitions having higher priority. + [b]Note:[/b] [Window] styles will have no effect unless the window is embedded. </member> <member name="theme_type_variation" type="StringName" setter="set_theme_type_variation" getter="get_theme_type_variation" default="&"""> The name of a theme type variation used by this [Control] to look up its own theme items. When empty, the class name of the node is used (e.g. [code]Button[/code] for the [Button] control), as well as the class names of all parent classes (in order of inheritance). diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index c59bfbfe4f..29135376c5 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -719,6 +719,12 @@ [b]Note:[/b] This method is implemented on macOS, Windows and Linux (X11). </description> </method> + <method name="is_touchscreen_available" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if touch events are available (Android or iOS), the capability is detected on the Webplatform or if [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse] is [code]true[/code]. + </description> + </method> <method name="keyboard_get_current_layout" qualifiers="const"> <return type="int" /> <description> @@ -889,13 +895,6 @@ Returns [code]true[/code] if the screen should never be turned off by the operating system's power-saving measures. See also [method screen_set_keep_on]. </description> </method> - <method name="screen_is_touchscreen" qualifiers="const"> - <return type="bool" /> - <param index="0" name="screen" type="int" default="-1" /> - <description> - Returns [code]true[/code] if the screen can send touch events or if [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse] is [code]true[/code]. - </description> - </method> <method name="screen_set_keep_on"> <return type="void" /> <param index="0" name="enable" type="bool" /> @@ -1156,14 +1155,14 @@ <return type="Vector2i" /> <param index="0" name="window_id" type="int" default="0" /> <description> - Returns the position of the given window to on the screen. + Returns the position of the client area of the given window on the screen. </description> </method> - <method name="window_get_real_size" qualifiers="const"> + <method name="window_get_position_with_decorations" qualifiers="const"> <return type="Vector2i" /> <param index="0" name="window_id" type="int" default="0" /> <description> - Returns the size of the window specified by [param window_id] (in pixels), including the borders drawn by the operating system. See also [method window_get_size]. + Returns the position of the given window on the screen including the borders drawn by the operating system. See also [method window_get_position]. </description> </method> <method name="window_get_safe_title_margins" qualifiers="const"> @@ -1177,7 +1176,14 @@ <return type="Vector2i" /> <param index="0" name="window_id" type="int" default="0" /> <description> - Returns the size of the window specified by [param window_id] (in pixels), excluding the borders drawn by the operating system. This is also called the "client area". See also [method window_get_real_size], [method window_set_size] and [method window_get_position]. + Returns the size of the window specified by [param window_id] (in pixels), excluding the borders drawn by the operating system. This is also called the "client area". See also [method window_get_size_with_decorations], [method window_set_size] and [method window_get_position]. + </description> + </method> + <method name="window_get_size_with_decorations" qualifiers="const"> + <return type="Vector2i" /> + <param index="0" name="window_id" type="int" default="0" /> + <description> + Returns the size of the window specified by [param window_id] (in pixels), including the borders drawn by the operating system. See also [method window_get_size]. </description> </method> <method name="window_get_vsync_mode" qualifiers="const"> @@ -1634,14 +1640,17 @@ Maximized window mode, i.e. [Window] will occupy whole screen area except task bar and still display its borders. Normally happens when the minimize button is pressed. </constant> <constant name="WINDOW_MODE_FULLSCREEN" value="3" enum="WindowMode"> - Full screen window mode. Note that this is not [i]exclusive[/i] full screen. On Windows and Linux (X11), a borderless window is used to emulate full screen. On macOS, a new desktop is used to display the running project. - Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode. + Full screen mode with full multi-window support. + Full screen window cover the entire display area of a screen, have no border or decorations. Display video mode is not changed. + [b]Note:[/b] Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode. </constant> <constant name="WINDOW_MODE_EXCLUSIVE_FULLSCREEN" value="4" enum="WindowMode"> - Exclusive full screen window mode. This mode is implemented on Windows and macOS only. On other platforms, it is equivalent to [constant WINDOW_MODE_FULLSCREEN]. - [b]On Windows:[/b] Only one window in exclusive full screen mode can be visible on a given screen at a time. If multiple windows are in exclusive full screen mode for the same screen, the last one being set to this mode takes precedence. - [b]On macOS:[/b] Exclusive full-screen mode prevents Dock and Menu from showing up when the mouse pointer is hovering the edge of the screen. - Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode. + A single window full screen mode. This mode has less overhead, but only one window can be open on a given screen at a time (opening a child window or application switching will trigger a full screen transition). + Full screen window cover the entire display area of a screen, have no border or decorations. Display video mode is not changed. + [b]On Windows:[/b] Depending on video driver, full screen transition might cause screens to go black for a moment. + [b]On macOS:[/b] Exclusive full screen mode prevents Dock and Menu from showing up when the mouse pointer is hovering the edge of the screen. + [b]On Linux (X11):[/b] Exclusive full screen mode bypasses compositor. + [b]Note:[/b] Regardless of the platform, enabling full screen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling full screen mode. </constant> <constant name="WINDOW_FLAG_RESIZE_DISABLED" value="0" enum="WindowFlags"> The window can't be resizing by dragging its resize grip. It's still possible to resize the window using [method window_set_size]. This flag is ignored for full screen windows. diff --git a/doc/classes/NavigationServer2D.xml b/doc/classes/NavigationServer2D.xml index 981ab8a5e1..ab59add092 100644 --- a/doc/classes/NavigationServer2D.xml +++ b/doc/classes/NavigationServer2D.xml @@ -167,6 +167,13 @@ Returns the navigation layers for this [code]link[/code]. </description> </method> + <method name="link_get_owner_id" qualifiers="const"> + <return type="int" /> + <param index="0" name="link" type="RID" /> + <description> + Returns the [code]ObjectID[/code] of the object which manages this link. + </description> + </method> <method name="link_get_start_location" qualifiers="const"> <return type="Vector2" /> <param index="0" name="link" type="RID" /> @@ -228,6 +235,14 @@ Set the links's navigation layers. This allows selecting links from a path request (when using [method NavigationServer2D.map_get_path]). </description> </method> + <method name="link_set_owner_id" qualifiers="const"> + <return type="void" /> + <param index="0" name="link" type="RID" /> + <param index="1" name="owner_id" type="int" /> + <description> + Set the [code]ObjectID[/code] of the object which manages this link. + </description> + </method> <method name="link_set_start_location" qualifiers="const"> <return type="void" /> <param index="0" name="link" type="RID" /> @@ -426,6 +441,13 @@ Returns the region's navigation layers. </description> </method> + <method name="region_get_owner_id" qualifiers="const"> + <return type="int" /> + <param index="0" name="region" type="RID" /> + <description> + Returns the [code]ObjectID[/code] of the object which manages this region. + </description> + </method> <method name="region_get_travel_cost" qualifiers="const"> <return type="float" /> <param index="0" name="region" type="RID" /> @@ -475,6 +497,14 @@ Sets the navigation mesh for the region. </description> </method> + <method name="region_set_owner_id" qualifiers="const"> + <return type="void" /> + <param index="0" name="region" type="RID" /> + <param index="1" name="owner_id" type="int" /> + <description> + Set the [code]ObjectID[/code] of the object which manages this region. + </description> + </method> <method name="region_set_transform" qualifiers="const"> <return type="void" /> <param index="0" name="region" type="RID" /> diff --git a/doc/classes/NavigationServer3D.xml b/doc/classes/NavigationServer3D.xml index 943aa03ef7..27a07eda90 100644 --- a/doc/classes/NavigationServer3D.xml +++ b/doc/classes/NavigationServer3D.xml @@ -167,6 +167,13 @@ Returns the navigation layers for this [code]link[/code]. </description> </method> + <method name="link_get_owner_id" qualifiers="const"> + <return type="int" /> + <param index="0" name="link" type="RID" /> + <description> + Returns the [code]ObjectID[/code] of the object which manages this link. + </description> + </method> <method name="link_get_start_location" qualifiers="const"> <return type="Vector3" /> <param index="0" name="link" type="RID" /> @@ -228,6 +235,14 @@ Set the links's navigation layers. This allows selecting links from a path request (when using [method NavigationServer3D.map_get_path]). </description> </method> + <method name="link_set_owner_id" qualifiers="const"> + <return type="void" /> + <param index="0" name="link" type="RID" /> + <param index="1" name="owner_id" type="int" /> + <description> + Set the [code]ObjectID[/code] of the object which manages this link. + </description> + </method> <method name="link_set_start_location" qualifiers="const"> <return type="void" /> <param index="0" name="link" type="RID" /> @@ -476,6 +491,13 @@ Returns the region's navigation layers. </description> </method> + <method name="region_get_owner_id" qualifiers="const"> + <return type="int" /> + <param index="0" name="region" type="RID" /> + <description> + Returns the [code]ObjectID[/code] of the object which manages this region. + </description> + </method> <method name="region_get_travel_cost" qualifiers="const"> <return type="float" /> <param index="0" name="region" type="RID" /> @@ -525,6 +547,14 @@ Sets the navigation mesh for the region. </description> </method> + <method name="region_set_owner_id" qualifiers="const"> + <return type="void" /> + <param index="0" name="region" type="RID" /> + <param index="1" name="owner_id" type="int" /> + <description> + Set the [code]ObjectID[/code] of the object which manages this region. + </description> + </method> <method name="region_set_transform" qualifiers="const"> <return type="void" /> <param index="0" name="region" type="RID" /> diff --git a/doc/classes/PhysicsPointQueryParameters2D.xml b/doc/classes/PhysicsPointQueryParameters2D.xml index e49d2a9f5f..76dc816dab 100644 --- a/doc/classes/PhysicsPointQueryParameters2D.xml +++ b/doc/classes/PhysicsPointQueryParameters2D.xml @@ -10,7 +10,7 @@ </tutorials> <members> <member name="canvas_instance_id" type="int" setter="set_canvas_instance_id" getter="get_canvas_instance_id" default="0"> - If different from [code]0[/code], restricts the query to a specific canvas layer specified by its instance id. See [method Object.get_instance_id]. + If different from [code]0[/code], restricts the query to a specific canvas layer specified by its instance ID. See [method Object.get_instance_id]. </member> <member name="collide_with_areas" type="bool" setter="set_collide_with_areas" getter="is_collide_with_areas_enabled" default="false"> If [code]true[/code], the query will take [Area2D]s into account. diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index a69163f429..6810b0e8e4 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -206,7 +206,7 @@ <return type="int" /> <param index="0" name="index" type="int" /> <description> - Returns the id of the item at the given [param index]. [code]id[/code] can be manually assigned, while index can not. + Returns the ID of the item at the given [param index]. [code]id[/code] can be manually assigned, while index can not. </description> </method> <method name="get_item_indent" qualifiers="const"> diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 1f0a8d91fa..dce9d5a55c 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2299,6 +2299,9 @@ <member name="xr/openxr/reference_space" type="int" setter="" getter="" default=""1""> Specify the default reference space. </member> + <member name="xr/openxr/submit_depth_buffer" type="bool" setter="" getter="" default="false"> + If [code]true[/code], OpenXR will manage the depth buffer and use the depth buffer for advanced reprojection provided this is supported by the XR runtime. Note that some rendering features in Godot can't be used with this feature. + </member> <member name="xr/openxr/view_configuration" type="int" setter="" getter="" default=""1""> Specify the view configuration with which to configure OpenXR setting up either Mono or Stereo rendering. </member> diff --git a/doc/classes/RenderingDevice.xml b/doc/classes/RenderingDevice.xml index 8afe6eb935..797231ac5e 100644 --- a/doc/classes/RenderingDevice.xml +++ b/doc/classes/RenderingDevice.xml @@ -425,7 +425,7 @@ <param index="5" name="multisample_state" type="RDPipelineMultisampleState" /> <param index="6" name="stencil_state" type="RDPipelineDepthStencilState" /> <param index="7" name="color_blend_state" type="RDPipelineColorBlendState" /> - <param index="8" name="dynamic_state_flags" type="int" default="0" /> + <param index="8" name="dynamic_state_flags" type="int" enum="RenderingDevice.PipelineDynamicStateFlags" default="0" /> <param index="9" name="for_render_pass" type="int" default="0" /> <param index="10" name="specialization_constants" type="RDPipelineSpecializationConstant[]" default="[]" /> <description> @@ -1453,19 +1453,19 @@ </constant> <constant name="BLEND_OP_MAX" value="5" enum="BlendOperation"> </constant> - <constant name="DYNAMIC_STATE_LINE_WIDTH" value="1" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_LINE_WIDTH" value="1" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_DEPTH_BIAS" value="2" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_DEPTH_BIAS" value="2" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_BLEND_CONSTANTS" value="4" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_BLEND_CONSTANTS" value="4" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_DEPTH_BOUNDS" value="8" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_DEPTH_BOUNDS" value="8" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_STENCIL_COMPARE_MASK" value="16" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_STENCIL_COMPARE_MASK" value="16" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_STENCIL_WRITE_MASK" value="32" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_STENCIL_WRITE_MASK" value="32" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> - <constant name="DYNAMIC_STATE_STENCIL_REFERENCE" value="64" enum="PipelineDynamicStateFlags"> + <constant name="DYNAMIC_STATE_STENCIL_REFERENCE" value="64" enum="PipelineDynamicStateFlags" is_bitfield="true"> </constant> <constant name="INITIAL_ACTION_CLEAR" value="0" enum="InitialAction"> </constant> diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 2ffa4dc50b..fc05f67416 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -1295,13 +1295,13 @@ <method name="get_test_cube"> <return type="RID" /> <description> - Returns the id of the test cube. Creates one if none exists. + Returns the ID of the test cube. Creates one if none exists. </description> </method> <method name="get_test_texture"> <return type="RID" /> <description> - Returns the id of the test texture. Creates one if none exists. + Returns the ID of the test texture. Creates one if none exists. </description> </method> <method name="get_video_adapter_api_version" qualifiers="const"> @@ -1335,7 +1335,7 @@ <method name="get_white_texture"> <return type="RID" /> <description> - Returns the id of a white texture. Creates one if none exists. + Returns the ID of a white texture. Creates one if none exists. </description> </method> <method name="gi_set_use_half_resolution"> diff --git a/doc/classes/SceneTree.xml b/doc/classes/SceneTree.xml index 070b98f21d..bd5b656e1a 100644 --- a/doc/classes/SceneTree.xml +++ b/doc/classes/SceneTree.xml @@ -308,6 +308,7 @@ </constant> <constant name="GROUP_CALL_UNIQUE" value="4" enum="GroupCallFlags"> Call a group only once even if the call is executed many times. + [b]Note:[/b] Arguments are not taken into account when deciding whether the call is unique or not. Therefore when the same method is called with different arguments, only the first call will be performed. </constant> </constants> </class> diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 7e76a134ff..d5624aeaa2 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -185,16 +185,16 @@ [gdscript] print("Team".find("I")) # Prints -1 - print("Potato".find("t")) # Prints 2 - print("Potato".find("t", 3)) # Prints 4 - print("Potato".find("t", 5)) # Prints -1 + print("Potato".find("t")) # Prints 2 + print("Potato".find("t", 3)) # Prints 4 + print("Potato".find("t", 5)) # Prints -1 [/gdscript] [csharp] GD.Print("Team".Find("I")); // Prints -1 - GD.Print("Potato".Find("t")); // Prints 2 - GD.print("Potato".Find("t", 3)); // Prints 4 - GD.print("Potato".Find("t", 5)); // Prints -1 + GD.Print("Potato".Find("t")); // Prints 2 + GD.print("Potato".Find("t", 3)); // Prints 4 + GD.print("Potato".Find("t", 5)); // Prints -1 [/csharp] [/codeblocks] [b]Note:[/b] If you just want to know whether the string contains [param what], use [method contains]. In GDScript, you may also use the [code]in[/code] operator. @@ -1062,6 +1062,12 @@ Appends [param right] at the end of this [String], also known as a string concatenation. </description> </operator> + <operator name="operator +"> + <return type="String" /> + <param index="0" name="right" type="StringName" /> + <description> + </description> + </operator> <operator name="operator <"> <return type="bool" /> <param index="0" name="right" type="String" /> diff --git a/doc/classes/StringName.xml b/doc/classes/StringName.xml index 02e9c62cd6..e3cb6517f3 100644 --- a/doc/classes/StringName.xml +++ b/doc/classes/StringName.xml @@ -7,6 +7,8 @@ [StringName]s are immutable strings designed for general-purpose representation of unique names (also called "string interning"). [StringName] ensures that only one instance of a given name exists (so two [StringName]s with the same value are the same object). Comparing them is much faster than with regular [String]s, because only the pointers are compared, not the whole strings. You will usually just pass a [String] to methods expecting a [StringName] and it will be automatically converted, but you may occasionally want to construct a [StringName] ahead of time with [StringName] or, in GDScript, the literal syntax [code]&"example"[/code]. See also [NodePath], which is a similar concept specifically designed to store pre-parsed node paths. + Some string methods have corresponding variations. Variations suffixed with [code]n[/code] ([method countn], [method findn], [method replacen], etc.) are [b]case-insensitive[/b] (they make no distinction between uppercase and lowercase letters). Method variations prefixed with [code]r[/code] ([method rfind], [method rsplit], etc.) are reversed, and start from the end of the string, instead of the beginning. + [b]Note:[/b] In a boolean context, a [StringName] will evaluate to [code]false[/code] if it is empty ([code]StringName("")[/code]). Otherwise, a [StringName] will always evaluate to [code]true[/code]. </description> <tutorials> </tutorials> @@ -33,10 +35,897 @@ </constructor> </constructors> <methods> + <method name="begins_with" qualifiers="const"> + <return type="bool" /> + <param index="0" name="text" type="String" /> + <description> + Returns [code]true[/code] if the string begins with the given [param text]. See also [method ends_with]. + </description> + </method> + <method name="bigrams" qualifiers="const"> + <return type="PackedStringArray" /> + <description> + Returns an array containing the bigrams (pairs of consecutive characters) of this string. + [codeblock] + print("Get up!".bigrams()) # Prints ["Ge", "et", "t ", " u", "up", "p!"] + [/codeblock] + </description> + </method> + <method name="bin_to_int" qualifiers="const"> + <return type="int" /> + <description> + Converts the string representing a binary number into an [int]. The string may optionally be prefixed with [code]"0b"[/code], and an additional [code]-[/code] prefix for negative numbers. + [codeblocks] + [gdscript] + print("101".bin_to_int()) # Prints 5 + print("0b101".bin_to_int()) # Prints 5 + print("-0b10".bin_to_int()) # Prints -2 + [/gdscript] + [csharp] + GD.Print("101".BinToInt()); // Prints 5 + GD.Print("0b101".BinToInt()); // Prints 5 + GD.Print("-0b10".BinToInt()); // Prints -2 + [/csharp] + [/codeblocks] + </description> + </method> + <method name="c_escape" qualifiers="const"> + <return type="String" /> + <description> + Returns a copy of the string with special characters escaped using the C language standard. + </description> + </method> + <method name="c_unescape" qualifiers="const"> + <return type="String" /> + <description> + Returns a copy of the string with escaped characters replaced by their meanings. Supported escape sequences are [code]\'[/code], [code]\"[/code], [code]\\[/code], [code]\a[/code], [code]\b[/code], [code]\f[/code], [code]\n[/code], [code]\r[/code], [code]\t[/code], [code]\v[/code]. + [b]Note:[/b] Unlike the GDScript parser, this method doesn't support the [code]\uXXXX[/code] escape sequence. + </description> + </method> + <method name="capitalize" qualifiers="const"> + <return type="String" /> + <description> + Changes the appearance of the string: replaces underscores ([code]_[/code]) with spaces, adds spaces before uppercase letters in the middle of a word, converts all letters to lowercase, then converts the first one and each one following a space to uppercase. + [codeblocks] + [gdscript] + "move_local_x".capitalize() # Returns "Move Local X" + "sceneFile_path".capitalize() # Returns "Scene File Path" + [/gdscript] + [csharp] + "move_local_x".Capitalize(); // Returns "Move Local X" + "sceneFile_path".Capitalize(); // Returns "Scene File Path" + [/csharp] + [/codeblocks] + [b]Note:[/b] This method not the same as the default appearance of properties in the Inspector dock, as it does not capitalize acronyms ([code]"2D"[/code], [code]"FPS"[/code], [code]"PNG"[/code], etc.) as you may expect. + </description> + </method> + <method name="casecmp_to" qualifiers="const"> + <return type="int" /> + <param index="0" name="to" type="String" /> + <description> + Performs a case-sensitive comparison to another string. Returns [code]-1[/code] if less than, [code]1[/code] if greater than, or [code]0[/code] if equal. "Less than" and "greater than" are determined by the [url=https://en.wikipedia.org/wiki/List_of_Unicode_characters]Unicode code points[/url] of each string, which roughly matches the alphabetical order. + With different string lengths, returns [code]1[/code] if this string is longer than the [param to] string, or [code]-1[/code] if shorter. Note that the length of empty strings is [i]always[/i] [code]0[/code]. + To get a [bool] result from a string comparison, use the [code]==[/code] operator instead. See also [method nocasecmp_to] and [method naturalnocasecmp_to]. + </description> + </method> + <method name="contains" qualifiers="const"> + <return type="bool" /> + <param index="0" name="what" type="String" /> + <description> + Returns [code]true[/code] if the string contains [param what]. In GDScript, this corresponds to the [code]in[/code] operator. + [codeblocks] + [gdscript] + print("Node".contains("de")) # Prints true + print("team".contains("I")) # Prints false + print("I" in "team") # Prints false + [/gdscript] + [csharp] + GD.Print("Node".Contains("de")); // Prints true + GD.Print("team".Contains("I")); // Prints false + [/csharp] + [/codeblocks] + If you need to know where [param what] is within the string, use [method find]. + </description> + </method> + <method name="count" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="0" /> + <param index="2" name="to" type="int" default="0" /> + <description> + Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions. If [param to] is 0, the search continues until the end of the string. + </description> + </method> + <method name="countn" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="0" /> + <param index="2" name="to" type="int" default="0" /> + <description> + Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions, [b]ignoring case[/b]. If [param to] is 0, the search continues until the end of the string. + </description> + </method> + <method name="dedent" qualifiers="const"> + <return type="String" /> + <description> + Returns a copy of the string with indentation (leading tabs and spaces) removed. See also [method indent] to add indentation. + </description> + </method> + <method name="ends_with" qualifiers="const"> + <return type="bool" /> + <param index="0" name="text" type="String" /> + <description> + Returns [code]true[/code] if the string ends with the given [param text]. See also [method begins_with]. + </description> + </method> + <method name="find" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="0" /> + <description> + Returns the index of the [b]first[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the end of the string. + [codeblocks] + [gdscript] + print("Team".find("I")) # Prints -1 + + print("Potato".find("t")) # Prints 2 + print("Potato".find("t", 3)) # Prints 4 + print("Potato".find("t", 5)) # Prints -1 + [/gdscript] + [csharp] + GD.Print("Team".Find("I")); // Prints -1 + + GD.Print("Potato".Find("t")); // Prints 2 + GD.print("Potato".Find("t", 3)); // Prints 4 + GD.print("Potato".Find("t", 5)); // Prints -1 + [/csharp] + [/codeblocks] + [b]Note:[/b] If you just want to know whether the string contains [param what], use [method contains]. In GDScript, you may also use the [code]in[/code] operator. + </description> + </method> + <method name="findn" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="0" /> + <description> + Returns the index of the [b]first[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the end of the string. + </description> + </method> + <method name="format" qualifiers="const"> + <return type="String" /> + <param index="0" name="values" type="Variant" /> + <param index="1" name="placeholder" type="String" default=""{_}"" /> + <description> + Formats the string by replacing all occurrences of [param placeholder] with the elements of [param values]. + [param values] can be a [Dictionary] or an [Array]. Any underscores in [param placeholder] will be replaced with the corresponding keys in advance. Array elements use their index as keys. + [codeblock] + # Prints "Waiting for Godot is a play by Samuel Beckett, and Godot Engine is named after it." + var use_array_values = "Waiting for {0} is a play by {1}, and {0} Engine is named after it." + print(use_array_values.format(["Godot", "Samuel Beckett"])) + + # Prints "User 42 is Godot." + print("User {id} is {name}.".format({"id": 42, "name": "Godot"})) + [/codeblock] + Some additional handling is performed when [param values] is an [Array]. If [param placeholder] does not contain an underscore, the elements of the [param values] array will be used to replace one occurrence of the placeholder in order; If an element of [param values] is another 2-element array, it'll be interpreted as a key-value pair. + [codeblock] + # Prints "User 42 is Godot." + print("User {} is {}.".format([42, "Godot"], "{}")) + print("User {id} is {name}.".format([["id", 42], ["name", "Godot"]])) + [/codeblock] + See also the [url=$DOCS_URL/tutorials/scripting/gdscript/gdscript_format_string.html]GDScript format string[/url] tutorial. + </description> + </method> + <method name="get_base_dir" qualifiers="const"> + <return type="String" /> + <description> + If the string is a valid file path, returns the base directory name. + [codeblock] + var dir_path = "/path/to/file.txt".get_basename() # dir_path is "/path/to" + [/codeblock] + </description> + </method> + <method name="get_basename" qualifiers="const"> + <return type="String" /> + <description> + If the string is a valid file path, returns the full file path, without the extension. + [codeblock] + var base = "/path/to/file.txt".get_basename() # base is "/path/to/file" + [/codeblock] + </description> + </method> + <method name="get_extension" qualifiers="const"> + <return type="String" /> + <description> + If the string is a valid file name or path, returns the file extension without the leading period ([code].[/code]). Otherwise, returns an empty string. + [codeblock] + var a = "/path/to/file.txt".get_extension() # a is "txt" + var b = "cool.txt".get_extension() # b is "txt" + var c = "cool.font.tres".get_extension() # c is "tres" + var d = ".pack1".get_extension() # d is "pack1" + + var e = "file.txt.".get_extension() # e is "" + var f = "file.txt..".get_extension() # f is "" + var g = "txt".get_extension() # g is "" + var h = "".get_extension() # h is "" + [/codeblock] + </description> + </method> + <method name="get_file" qualifiers="const"> + <return type="String" /> + <description> + If the string is a valid file path, returns the file name, including the extension. + [codeblock] + var file = "/path/to/icon.png".get_file() # file is "icon.png" + [/codeblock] + </description> + </method> + <method name="get_slice" qualifiers="const"> + <return type="String" /> + <param index="0" name="delimiter" type="String" /> + <param index="1" name="slice" type="int" /> + <description> + Splits the string using a [param delimiter] and returns the substring at index [param slice]. Returns an empty string if the [param slice] does not exist. + This is faster than [method split], if you only need one substring. + [b]Example:[/b] + [codeblock] + print("i/am/example/hi".get_slice("/", 2)) # Prints "example" + [/codeblock] + </description> + </method> + <method name="get_slice_count" qualifiers="const"> + <return type="int" /> + <param index="0" name="delimiter" type="String" /> + <description> + Returns the total number of slices when the string is split with the given [param delimiter] (see [method split]). + </description> + </method> + <method name="get_slicec" qualifiers="const"> + <return type="String" /> + <param index="0" name="delimiter" type="int" /> + <param index="1" name="slice" type="int" /> + <description> + Splits the string using a Unicode character with code [param delimiter] and returns the substring at index [param slice]. Returns an empty string if the [param slice] does not exist. + This is faster than [method split], if you only need one substring. + </description> + </method> <method name="hash" qualifiers="const"> <return type="int" /> <description> - Returns the 32-bit hash value representing the [StringName]'s contents. + Returns the 32-bit hash value representing the string's contents. + [b]Note:[/b] Strings with equal hash values are [i]not[/i] guaranteed to be the same, as a result of hash collisions. On the countrary, strings with different hash values are guaranteed to be different. + </description> + </method> + <method name="hex_to_int" qualifiers="const"> + <return type="int" /> + <description> + Converts the string representing a hexadecimal number into an [int]. The string may be optionally prefixed with [code]"0x"[/code], and an additional [code]-[/code] prefix for negative numbers. + [codeblocks] + [gdscript] + print("0xff".hex_to_int()) # Prints 255 + print("ab".hex_to_int()) # Prints 171 + [/gdscript] + [csharp] + GD.Print("0xff".HexToInt()); // Prints 255 + GD.Print("ab".HexToInt()); // Prints 171 + [/csharp] + [/codeblocks] + </description> + </method> + <method name="indent" qualifiers="const"> + <return type="String" /> + <param index="0" name="prefix" type="String" /> + <description> + Indents every line of the string with the given [param prefix]. Empty lines are not indented. See also [method dedent] to remove indentation. + For example, the string can be indented with two tabulations using [code]"\t\t"[/code], or four spaces using [code]" "[/code]. + </description> + </method> + <method name="insert" qualifiers="const"> + <return type="String" /> + <param index="0" name="position" type="int" /> + <param index="1" name="what" type="String" /> + <description> + Inserts [param what] at the given [param position] in the string. + </description> + </method> + <method name="is_absolute_path" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if the string is a path to a file or directory, and its starting point is explicitly defined. This method is the opposite of [method is_relative_path]. + This includes all paths starting with [code]"res://"[/code], [code]"user://"[/code], [code]"C:\"[/code], [code]"/"[/code], etc. + </description> + </method> + <method name="is_empty" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if the string's length is [code]0[/code] ([code]""[/code]). See also [method length]. + </description> + </method> + <method name="is_relative_path" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if the string is a path, and its starting point is dependent on context. The path could begin from the current directory, or the current [Node] (if the string is derived from a [NodePath]), and may sometimes be prefixed with [code]"./"[/code]. This method is the opposite of [method is_absolute_path]. + </description> + </method> + <method name="is_subsequence_of" qualifiers="const"> + <return type="bool" /> + <param index="0" name="text" type="String" /> + <description> + Returns [code]true[/code] if all characters of this string can be found in [param text] in their original order. + [codeblock] + var text = "Wow, incredible!" + + print("inedible".is_subsequence_of(text)) # Prints true + print("Word!".is_subsequence_of(text)) # Prints true + print("Window".is_subsequence_of(text)) # Prints false + print("".is_subsequence_of(text)) # Prints true + [/codeblock] + </description> + </method> + <method name="is_subsequence_ofn" qualifiers="const"> + <return type="bool" /> + <param index="0" name="text" type="String" /> + <description> + Returns [code]true[/code] if all characters of this string can be found in [param text] in their original order, [b]ignoring case[/b]. + </description> + </method> + <method name="is_valid_filename" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string does not contain characters that are not allowed in file names ([code]:[/code] [code]/[/code] [code]\[/code] [code]?[/code] [code]*[/code] [code]"[/code] [code]|[/code] [code]%[/code] [code]<[/code] [code]>[/code]). + </description> + </method> + <method name="is_valid_float" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string represents a valid floating-point number. A valid float may contain only digits, one decimal point ([code].[/code]), and the exponent letter ([code]e[/code]). It may also be prefixed with a positive ([code]+[/code]) or negative ([code]-[/code]) sign. Any valid integer is also a valid float (see [method is_valid_int]). See also [method to_float]. + [codeblock] + print("1.7".is_valid_float()) # Prints true + print("24".is_valid_float()) # Prints true + print("7e3".is_valid_float()) # Prints true + print("Hello".is_valid_float()) # Prints false + [/codeblock] + </description> + </method> + <method name="is_valid_hex_number" qualifiers="const"> + <return type="bool" /> + <param index="0" name="with_prefix" type="bool" default="false" /> + <description> + Returns [code]true[/code] if this string is a valid hexadecimal number. A valid hexadecimal number only contains digits or letters [code]A[/code] to [code]F[/code] (either uppercase or lowercase), and may be prefixed with a positive ([code]+[/code]) or negative ([code]-[/code]) sign. + If [param with_prefix] is [code]true[/code], the hexadecimal number needs to prefixed by [code]"0x"[/code] to be considered valid. + [codeblock] + print("A08E".is_valid_hex_number()) # Prints true + print("-AbCdEf".is_valid_hex_number()) # Prints true + print("2.5".is_valid_hex_number()) # Prints false + + print("0xDEADC0DE".is_valid_hex_number(true)) # Prints true + [/codeblock] + </description> + </method> + <method name="is_valid_html_color" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string is a valid color in hexadecimal HTML notation. The string must be a hexadecimal value (see [method is_valid_hex_number]) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign ([code]#[/code]). Other HTML notations for colors, such as names or [code]hsl()[/code], are not considered valid. See also [method Color.html]. + </description> + </method> + <method name="is_valid_identifier" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]), and the first character may not be a digit. + [codeblock] + print("node_2d".is_valid_identifier()) # Prints true + print("TYPE_FLOAT".is_valid_identifier()) # Prints true + print("1st_method".is_valid_identifier()) # Prints false + print("MyMethod#2".is_valid_identifier()) # Prints false + [/codeblock] + </description> + </method> + <method name="is_valid_int" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string represents a valid integer. A valid integer only contains digits, and may be prefixed with a positive ([code]+[/code]) or negative ([code]-[/code]) sign. See also [method to_int]. + [codeblock] + print("7".is_valid_int()) # Prints true + print("1.65".is_valid_int()) # Prints false + print("Hi".is_valid_int()) # Prints false + print("+3".is_valid_int()) # Prints true + print("-12".is_valid_int()) # Prints true + [/codeblock] + </description> + </method> + <method name="is_valid_ip_address" qualifiers="const"> + <return type="bool" /> + <description> + Returns [code]true[/code] if this string represents a well-formatted IPv4 or IPv6 address. This method considers [url=https://en.wikipedia.org/wiki/Reserved_IP_addresses]reserved IP addresses[/url] such as [code]"0.0.0.0"[/code] and [code]"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"[/code] as valid. + </description> + </method> + <method name="join" qualifiers="const"> + <return type="String" /> + <param index="0" name="parts" type="PackedStringArray" /> + <description> + Returns the concatenation of [param parts]' elements, with each element separated by the string calling this method. This method is the opposite of [method split]. + [b]Example:[/b] + [codeblocks] + [gdscript] + var fruits = ["Apple", "Orange", "Pear", "Kiwi"] + + print(", ".join(fruits)) # Prints "Apple, Orange, Pear, Kiwi" + print("---".join(fruits)) # Prints "Apple---Orange---Pear---Kiwi" + [/gdscript] + [csharp] + var fruits = new string[] {"Apple", "Orange", "Pear", "Kiwi"}; + + // In C#, this method is static. + GD.Print(string.Join(", ", fruits); // Prints "Apple, Orange, Pear, Kiwi" + GD.Print(string.Join("---", fruits)); // Prints "Apple---Orange---Pear---Kiwi" + [/csharp] + [/codeblocks] + </description> + </method> + <method name="json_escape" qualifiers="const"> + <return type="String" /> + <description> + Returns a copy of the string with special characters escaped using the JSON standard. Because it closely matches the C standard, it is possible to use [method c_unescape] to unescape the string, if necessary. + </description> + </method> + <method name="left" qualifiers="const"> + <return type="String" /> + <param index="0" name="length" type="int" /> + <description> + Returns the first [param length] characters from the beginning of the string. If [param length] is negative, strips the last [param length] characters from the string's end. + [codeblock] + print("Hello World!".left(3)) # Prints "Hel" + print("Hello World!".left(-4)) # Prints "Hello Wo" + [/codeblock] + </description> + </method> + <method name="length" qualifiers="const"> + <return type="int" /> + <description> + Returns the number of characters in the string. Empty strings ([code]""[/code]) always return [code]0[/code]. See also [method is_empty]. + </description> + </method> + <method name="lpad" qualifiers="const"> + <return type="String" /> + <param index="0" name="min_length" type="int" /> + <param index="1" name="character" type="String" default="" "" /> + <description> + Formats the string to be at least [param min_length] long by adding [param character]s to the left of the string, if necessary. See also [method rpad]. + </description> + </method> + <method name="lstrip" qualifiers="const"> + <return type="String" /> + <param index="0" name="chars" type="String" /> + <description> + Removes a set of characters defined in [param chars] from the string's beginning. See also [method rstrip]. + [b]Note:[/b] [param chars] is not a prefix. Use [method trim_prefix] to remove a single prefix, rather than a set of characters. + </description> + </method> + <method name="match" qualifiers="const"> + <return type="bool" /> + <param index="0" name="expr" type="String" /> + <description> + Does a simple expression match, where [code]*[/code] matches zero or more arbitrary characters and [code]?[/code] matches any single character except a period ([code].[/code]). An empty string or empty expression always evaluates to [code]false[/code]. + </description> + </method> + <method name="matchn" qualifiers="const"> + <return type="bool" /> + <param index="0" name="expr" type="String" /> + <description> + Does a simple [b]case-insensitive[/b] expression match, where [code]*[/code] matches zero or more arbitrary characters and [code]?[/code] matches any single character except a period ([code].[/code]). An empty string or empty expression always evaluates to [code]false[/code]. + </description> + </method> + <method name="md5_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/MD5]MD5 hash[/url] of the string as a [PackedByteArray]. + </description> + </method> + <method name="md5_text" qualifiers="const"> + <return type="String" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/MD5]MD5 hash[/url] of the string as another [String]. + </description> + </method> + <method name="naturalnocasecmp_to" qualifiers="const"> + <return type="int" /> + <param index="0" name="to" type="String" /> + <description> + Performs a [b]case-insensitive[/b], [i]natural order[/i] comparison to another string. Returns [code]-1[/code] if less than, [code]1[/code] if greater than, or [code]0[/code] if equal. "Less than" or "greater than" are determined by the [url=https://en.wikipedia.org/wiki/List_of_Unicode_characters]Unicode code points[/url] of each string, which roughly matches the alphabetical order. Internally, lowercase characters are converted to uppercase for the comparison. + When used for sorting, natural order comparison orders sequences of numbers by the combined value of each digit as is often expected, instead of the single digit's value. A sorted sequence of numbered strings will be [code]["1", "2", "3", ...][/code], not [code]["1", "10", "2", "3", ...][/code]. + With different string lengths, returns [code]1[/code] if this string is longer than the [param to] string, or [code]-1[/code] if shorter. Note that the length of empty strings is [i]always[/i] [code]0[/code]. + To get a [bool] result from a string comparison, use the [code]==[/code] operator instead. See also [method nocasecmp_to] and [method casecmp_to]. + </description> + </method> + <method name="nocasecmp_to" qualifiers="const"> + <return type="int" /> + <param index="0" name="to" type="String" /> + <description> + Performs a [b]case-insensitive[/b] comparison to another string. Returns [code]-1[/code] if less than, [code]1[/code] if greater than, or [code]0[/code] if equal. "Less than" or "greater than" are determined by the [url=https://en.wikipedia.org/wiki/List_of_Unicode_characters]Unicode code points[/url] of each string, which roughly matches the alphabetical order. Internally, lowercase characters are converted to uppercase for the comparison. + With different string lengths, returns [code]1[/code] if this string is longer than the [param to] string, or [code]-1[/code] if shorter. Note that the length of empty strings is [i]always[/i] [code]0[/code]. + To get a [bool] result from a string comparison, use the [code]==[/code] operator instead. See also [method casecmp_to] and [method naturalnocasecmp_to]. + </description> + </method> + <method name="pad_decimals" qualifiers="const"> + <return type="String" /> + <param index="0" name="digits" type="int" /> + <description> + Formats the string representing a number to have an exact number of [param digits] [i]after[/i] the decimal point. + </description> + </method> + <method name="pad_zeros" qualifiers="const"> + <return type="String" /> + <param index="0" name="digits" type="int" /> + <description> + Formats the string representing a number to have an exact number of [param digits] [i]before[/i] the decimal point. + </description> + </method> + <method name="path_join" qualifiers="const"> + <return type="String" /> + <param index="0" name="file" type="String" /> + <description> + Concatenates [param file] at the end of the string as a subpath, adding [code]/[/code] if necessary. + [b]Example:[/b] [code]"this/is".path_join("path") == "this/is/path"[/code]. + </description> + </method> + <method name="repeat" qualifiers="const"> + <return type="String" /> + <param index="0" name="count" type="int" /> + <description> + Repeats this string a number of times. [param count] needs to be greater than [code]0[/code]. Otherwise, returns an empty string. + </description> + </method> + <method name="replace" qualifiers="const"> + <return type="String" /> + <param index="0" name="what" type="String" /> + <param index="1" name="forwhat" type="String" /> + <description> + Replaces all occurrences of [param what] inside the string with the given [param forwhat]. + </description> + </method> + <method name="replacen" qualifiers="const"> + <return type="String" /> + <param index="0" name="what" type="String" /> + <param index="1" name="forwhat" type="String" /> + <description> + Replaces all [b]case-insensitive[/b] occurrences of [param what] inside the string with the given [param forwhat]. + </description> + </method> + <method name="rfind" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="-1" /> + <description> + Returns the index of the [b]last[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method find]. + </description> + </method> + <method name="rfindn" qualifiers="const"> + <return type="int" /> + <param index="0" name="what" type="String" /> + <param index="1" name="from" type="int" default="-1" /> + <description> + Returns the index of the [b]last[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method findn]. + </description> + </method> + <method name="right" qualifiers="const"> + <return type="String" /> + <param index="0" name="length" type="int" /> + <description> + Returns the last [param length] characters from the end of the string. If [param length] is negative, strips the first [param length] characters from the string's beginning. + [codeblock] + print("Hello World!".right(3)) # Prints "ld!" + print("Hello World!".right(-4)) # Prints "o World!" + [/codeblock] + </description> + </method> + <method name="rpad" qualifiers="const"> + <return type="String" /> + <param index="0" name="min_length" type="int" /> + <param index="1" name="character" type="String" default="" "" /> + <description> + Formats the string to be at least [param min_length] long, by adding [param character]s to the right of the string, if necessary. See also [method lpad]. + </description> + </method> + <method name="rsplit" qualifiers="const"> + <return type="PackedStringArray" /> + <param index="0" name="delimiter" type="String" default="""" /> + <param index="1" name="allow_empty" type="bool" default="true" /> + <param index="2" name="maxsplit" type="int" default="0" /> + <description> + Splits the string using a [param delimiter] and returns an array of the substrings, starting from the end of the string. The splits in the returned array appear in the same order as the original string. If [param delimiter] is an empty string, each substring will be a single character. + If [param allow_empty] is [code]false[/code], empty strings between adjacent delimiters are excluded from the array. + If [param maxsplit] is greater than [code]0[/code], the number of splits may not exceed [param maxsplit]. By default, the entire string is split, which is mostly identical to [method split]. + [b]Example:[/b] + [codeblocks] + [gdscript] + var some_string = "One,Two,Three,Four" + var some_array = some_string.rsplit(",", true, 1) + + print(some_array.size()) # Prints 2 + print(some_array[0]) # Prints "One,Two,Three" + print(some_array[1]) # Prints "Four" + [/gdscript] + [csharp] + // In C#, there is no String.RSplit() method. + [/csharp] + [/codeblocks] + </description> + </method> + <method name="rstrip" qualifiers="const"> + <return type="String" /> + <param index="0" name="chars" type="String" /> + <description> + Removes a set of characters defined in [param chars] from the string's end. See also [method lstrip]. + [b]Note:[/b] [param chars] is not a suffix. Use [method trim_suffix] to remove a single suffix, rather than a set of characters. + </description> + </method> + <method name="sha1_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/SHA-1]SHA-1[/url] hash of the string as a [PackedByteArray]. + </description> + </method> + <method name="sha1_text" qualifiers="const"> + <return type="String" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/SHA-1]SHA-1[/url] hash of the string as another [String]. + </description> + </method> + <method name="sha256_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/SHA-2]SHA-256[/url] hash of the string as a [PackedByteArray]. + </description> + </method> + <method name="sha256_text" qualifiers="const"> + <return type="String" /> + <description> + Returns the [url=https://en.wikipedia.org/wiki/SHA-2]SHA-256[/url] hash of the string as another [String]. + </description> + </method> + <method name="similarity" qualifiers="const"> + <return type="float" /> + <param index="0" name="text" type="String" /> + <description> + Returns the similarity index ([url=https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient]Sorensen-Dice coefficient[/url]) of this string compared to another. A result of [code]1.0[/code] means totally similar, while [code]0.0[/code] means totally dissimilar. + [codeblock] + print("ABC123".similarity("ABC123")) # Prints 1.0 + print("ABC123".similarity("XYZ456")) # Prints 0.0 + print("ABC123".similarity("123ABC")) # Prints 0.8 + print("ABC123".similarity("abc123")) # Prints 0.4 + [/codeblock] + </description> + </method> + <method name="simplify_path" qualifiers="const"> + <return type="String" /> + <description> + If the string is a valid file path, converts the string into a canonical path. This is the shortest possible path, without [code]"./"[/code], and all the unnecessary [code]".."[/code] and [code]"/"[/code]. + [codeblock] + var simple_path = "./path/to///../file".simplify_path() + print(simple_path) # Prints "path/file" + [/codeblock] + </description> + </method> + <method name="split" qualifiers="const"> + <return type="PackedStringArray" /> + <param index="0" name="delimiter" type="String" default="""" /> + <param index="1" name="allow_empty" type="bool" default="true" /> + <param index="2" name="maxsplit" type="int" default="0" /> + <description> + Splits the string using a [param delimiter] and returns an array of the substrings. If [param delimiter] is an empty string, each substring will be a single character. This method is the opposite of [method join]. + If [param allow_empty] is [code]false[/code], empty strings between adjacent delimiters are excluded from the array. + If [param maxsplit] is greater than [code]0[/code], the number of splits may not exceed [param maxsplit]. By default, the entire string is split. + [b]Example:[/b] + [codeblocks] + [gdscript] + var some_array = "One,Two,Three,Four".split(",", true, 2) + + print(some_array.size()) # Prints 3 + print(some_array[0]) # Prints "One" + print(some_array[1]) # Prints "Two" + print(some_array[2]) # Prints "Three,Four" + [/gdscript] + [csharp] + // C#'s `Split()` does not support the `maxsplit` parameter. + var someArray = "One,Two,Three".Split(","); + + GD.Print(someArray[0]); // Prints "One" + GD.Print(someArray[1]); // Prints "Two" + GD.Print(someArray[2]); // Prints "Three" + [/csharp] + [/codeblocks] + [b]Note:[/b] If you only need one substring from the array, consider using [method get_slice] which is faster. If you need to split strings with more complex rules, use the [RegEx] class instead. + </description> + </method> + <method name="split_floats" qualifiers="const"> + <return type="PackedFloat64Array" /> + <param index="0" name="delimiter" type="String" /> + <param index="1" name="allow_empty" type="bool" default="true" /> + <description> + Splits the string into floats by using a [param delimiter] and returns a [PackedFloat64Array]. + If [param allow_empty] is [code]false[/code], empty or invalid [float] conversions between adjacent delimiters are excluded. + [codeblock] + var a = "1,2,4.5".split_floats(",") # a is [1.0, 2.0, 4.5] + var c = "1| ||4.5".split_floats("|") # c is [1.0, 0.0, 0.0, 4.5] + var b = "1| ||4.5".split_floats("|", false) # b is [1.0, 4.5] + [/codeblock] + </description> + </method> + <method name="strip_edges" qualifiers="const"> + <return type="String" /> + <param index="0" name="left" type="bool" default="true" /> + <param index="1" name="right" type="bool" default="true" /> + <description> + Strips all non-printable characters from the beginning and the end of the string. These include spaces, tabulations ([code]\t[/code]), and newlines ([code]\n[/code] [code]\r[/code]). + If [param left] is [code]false[/code], ignores the string's beginning. Likewise, if [param right] is [code]false[/code], ignores the string's end. + </description> + </method> + <method name="strip_escapes" qualifiers="const"> + <return type="String" /> + <description> + Strips all escape characters from the string. These include all non-printable control characters of the first page of the ASCII table (values from 0 to 31), such as tabulation ([code]\t[/code]) and newline ([code]\n[/code], [code]\r[/code]) characters, but [i]not[/i] spaces. + </description> + </method> + <method name="substr" qualifiers="const"> + <return type="String" /> + <param index="0" name="from" type="int" /> + <param index="1" name="len" type="int" default="-1" /> + <description> + Returns part of the string from the position [param from] with length [param len]. If [param len] is [code]-1[/code] (as by default), returns the rest of the string starting from the given position. + </description> + </method> + <method name="to_ascii_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Converts the string to an [url=https://en.wikipedia.org/wiki/ASCII]ASCII[/url]/Latin-1 encoded [PackedByteArray]. This method is slightly faster than [method to_utf8_buffer], but replaces all unsupported characters with spaces. + </description> + </method> + <method name="to_camel_case" qualifiers="const"> + <return type="String" /> + <description> + Returns the string converted to [code]camelCase[/code]. + </description> + </method> + <method name="to_float" qualifiers="const"> + <return type="float" /> + <description> + Converts the string representing a decimal number into a [float]. This method stops on the first non-number character, except the first decimal point ([code].[/code]) and the exponent letter ([code]e[/code]). See also [method is_valid_float]. + [codeblock] + var a = "12.35".to_float() # a is 12.35 + var b = "1.2.3".to_float() # b is 1.2 + var c = "12xy3".to_float() # c is 12.0 + var d = "1e3".to_float() # d is 1000.0 + var e = "Hello!".to_int() # e is 0.0 + [/codeblock] + </description> + </method> + <method name="to_int" qualifiers="const"> + <return type="int" /> + <description> + Converts the string representing an integer number into an [int]. This method removes any non-number character and stops at the first decimal point ([code].[/code]). See also [method is_valid_int]. + [codeblock] + var a = "123".to_int() # a is 123 + var b = "x1y2z3".to_int() # b is 123 + var c = "-1.2.3".to_int() # c is -1 + var d = "Hello!".to_int() # d is 0 + [/codeblock] + </description> + </method> + <method name="to_lower" qualifiers="const"> + <return type="String" /> + <description> + Returns the string converted to lowercase. + </description> + </method> + <method name="to_pascal_case" qualifiers="const"> + <return type="String" /> + <description> + Returns the string converted to [code]PascalCase[/code]. + </description> + </method> + <method name="to_snake_case" qualifiers="const"> + <return type="String" /> + <description> + Returns the string converted to [code]snake_case[/code]. + </description> + </method> + <method name="to_upper" qualifiers="const"> + <return type="String" /> + <description> + Returns the string converted to uppercase. + </description> + </method> + <method name="to_utf16_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Converts the string to a [url=https://en.wikipedia.org/wiki/UTF-16]UTF-16[/url] encoded [PackedByteArray]. + </description> + </method> + <method name="to_utf32_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Converts the string to a [url=https://en.wikipedia.org/wiki/UTF-32]UTF-32[/url] encoded [PackedByteArray]. + </description> + </method> + <method name="to_utf8_buffer" qualifiers="const"> + <return type="PackedByteArray" /> + <description> + Converts the string to a [url=https://en.wikipedia.org/wiki/UTF-8]UTF-8[/url] encoded [PackedByteArray]. This method is slightly slower than [method to_ascii_buffer], but supports all UTF-8 characters. For most cases, prefer using this method. + </description> + </method> + <method name="trim_prefix" qualifiers="const"> + <return type="String" /> + <param index="0" name="prefix" type="String" /> + <description> + Removes the given [param prefix] from the start of the string, or returns the string unchanged. + </description> + </method> + <method name="trim_suffix" qualifiers="const"> + <return type="String" /> + <param index="0" name="suffix" type="String" /> + <description> + Removes the given [param suffix] from the end of the string, or returns the string unchanged. + </description> + </method> + <method name="unicode_at" qualifiers="const"> + <return type="int" /> + <param index="0" name="at" type="int" /> + <description> + Returns the character code at position [param at]. + </description> + </method> + <method name="uri_decode" qualifiers="const"> + <return type="String" /> + <description> + Decodes the string from its URL-encoded format. This method is meant to properly decode the parameters in a URL when receiving an HTTP request. + [codeblocks] + [gdscript] + var url = "$DOCS_URL/?highlight=Godot%20Engine%3%docs" + print(url.uri_decode()) # Prints "$DOCS_URL/?hightlight=Godot Engine:docs" + [/gdscript] + [csharp] + var url = "$DOCS_URL/?highlight=Godot%20Engine%3%docs" + GD.Print(url.URIDecode()) // Prints "$DOCS_URL/?hightlight=Godot Engine:docs" + [/csharp] + [/codeblocks] + </description> + </method> + <method name="uri_encode" qualifiers="const"> + <return type="String" /> + <description> + Encodes the string to URL-friendly format. This method is meant to properly encode the parameters in a URL when sending an HTTP request. + [codeblocks] + [gdscript] + var prefix = "$DOCS_URL/?hightlight=" + var url = prefix + "Godot Engine:docs".uri_encode() + + print(url) # Prints "$DOCS_URL/?highlight=Godot%20Engine%3%docs" + [/gdscript] + [csharp] + var prefix = "$DOCS_URL/?hightlight="; + var url = prefix + "Godot Engine:docs".URIEncode(); + + GD.Print(url); // Prints "$DOCS_URL/?highlight=Godot%20Engine%3%docs" + [/csharp] + [/codeblocks] + </description> + </method> + <method name="validate_node_name" qualifiers="const"> + <return type="String" /> + <description> + Removes all characters that are not allowed in [member Node.name] from the string ([code].[/code] [code]:[/code] [code]@[/code] [code]/[/code] [code]"[/code] [code]%[/code]). + </description> + </method> + <method name="xml_escape" qualifiers="const"> + <return type="String" /> + <param index="0" name="escape_quotes" type="bool" default="false" /> + <description> + Returns a copy of the string with special characters escaped using the XML standard. If [param escape_quotes] is [code]true[/code], the single quote ([code]'[/code]) and double quote ([code]"[/code]) characters are also escaped. + </description> + </method> + <method name="xml_unescape" qualifiers="const"> + <return type="String" /> + <description> + Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard. </description> </method> </methods> @@ -55,6 +944,24 @@ Returns [code]true[/code] if the [StringName] and [param right] do not refer to the same name. Comparisons between [StringName]s are much faster than regular [String] comparisons. </description> </operator> + <operator name="operator %"> + <return type="String" /> + <param index="0" name="right" type="Variant" /> + <description> + </description> + </operator> + <operator name="operator +"> + <return type="String" /> + <param index="0" name="right" type="String" /> + <description> + </description> + </operator> + <operator name="operator +"> + <return type="String" /> + <param index="0" name="right" type="StringName" /> + <description> + </description> + </operator> <operator name="operator <"> <return type="bool" /> <param index="0" name="right" type="StringName" /> diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml index b3e55b5cd0..4fc6ee3312 100644 --- a/doc/classes/TextServer.xml +++ b/doc/classes/TextServer.xml @@ -235,7 +235,7 @@ <param index="1" name="size" type="Vector2i" /> <param index="2" name="glyph" type="int" /> <description> - Returns resource id of the cache texture containing the glyph. + Returns resource ID of the cache texture containing the glyph. [b]Note:[/b] If there are pending glyphs to render, calling this function might trigger the texture cache update. </description> </method> diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml index 01246f0c2e..e9e2a738d3 100644 --- a/doc/classes/TileMap.xml +++ b/doc/classes/TileMap.xml @@ -174,7 +174,7 @@ Creates a new [TileMapPattern] from the given layer and set of cells. </description> </method> - <method name="get_surrounding_tiles"> + <method name="get_surrounding_cells"> <return type="Vector2i[]" /> <param index="0" name="coords" type="Vector2i" /> <description> diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml index 6a016c3ebd..629c271417 100644 --- a/doc/classes/Tree.xml +++ b/doc/classes/Tree.xml @@ -70,7 +70,7 @@ <return type="int" /> <param index="0" name="position" type="Vector2" /> <description> - Returns the button id at [param position], or -1 if no button is there. + Returns the button ID at [param position], or -1 if no button is there. </description> </method> <method name="get_column_at_position" qualifiers="const"> diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index a8ffef427f..ec6b166e57 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -78,7 +78,7 @@ <param index="0" name="column" type="int" /> <param index="1" name="id" type="int" /> <description> - Returns the button index if there is a button with id [param id] in column [param column], otherwise returns -1. + Returns the button index if there is a button with ID [param id] in column [param column], otherwise returns -1. </description> </method> <method name="get_button_count" qualifiers="const"> @@ -93,7 +93,7 @@ <param index="0" name="column" type="int" /> <param index="1" name="button_idx" type="int" /> <description> - Returns the id for the button at index [param button_idx] in column [param column]. + Returns the ID for the button at index [param button_idx] in column [param column]. </description> </method> <method name="get_button_tooltip_text" qualifiers="const"> diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index 1cd73688ee..c47933ccb7 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -5,7 +5,7 @@ </brief_description> <description> 2-element structure that can be used to represent positions in 2D space or any other pair of numeric values. - It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]float=64[/code]. + It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]precision=double[/code]. See [Vector2i] for its integer counterpart. [b]Note:[/b] In a boolean context, a Vector2 will evaluate to [code]false[/code] if it's equal to [code]Vector2(0, 0)[/code]. Otherwise, a Vector2 will always evaluate to [code]true[/code]. </description> diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml index 1d7eda6bb9..c961825ab3 100644 --- a/doc/classes/Vector3.xml +++ b/doc/classes/Vector3.xml @@ -5,7 +5,7 @@ </brief_description> <description> 3-element structure that can be used to represent positions in 3D space or any other triplet of numeric values. - It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]float=64[/code]. + It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]precision=double[/code]. See [Vector3i] for its integer counterpart. [b]Note:[/b] In a boolean context, a Vector3 will evaluate to [code]false[/code] if it's equal to [code]Vector3(0, 0, 0)[/code]. Otherwise, a Vector3 will always evaluate to [code]true[/code]. </description> diff --git a/doc/classes/Vector4.xml b/doc/classes/Vector4.xml index d15ae35b59..c811817bdc 100644 --- a/doc/classes/Vector4.xml +++ b/doc/classes/Vector4.xml @@ -5,7 +5,7 @@ </brief_description> <description> 4-element structure that can be used to represent any quadruplet of numeric values. - It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]float=64[/code]. + It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike [float] which is always 64-bit. If double precision is needed, compile the engine with the option [code]precision=double[/code]. See [Vector4i] for its integer counterpart. [b]Note:[/b] In a boolean context, a Vector4 will evaluate to [code]false[/code] if it's equal to [code]Vector4(0, 0, 0, 0)[/code]. Otherwise, a Vector4 will always evaluate to [code]true[/code]. </description> diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 8707ef003a..16ca486e4a 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -10,6 +10,66 @@ <tutorials> </tutorials> <methods> + <method name="add_theme_color_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="color" type="Color" /> + <description> + Creates a local override for a theme [Color] with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_color_override]. + See also [method get_theme_color] and [method Control.add_theme_color_override] for more details. + </description> + </method> + <method name="add_theme_constant_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="constant" type="int" /> + <description> + Creates a local override for a theme constant with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_constant_override]. + See also [method get_theme_constant]. + </description> + </method> + <method name="add_theme_font_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="font" type="Font" /> + <description> + Creates a local override for a theme [Font] with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_font_override]. + See also [method get_theme_font]. + </description> + </method> + <method name="add_theme_font_size_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="font_size" type="int" /> + <description> + Creates a local override for a theme font size with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_font_size_override]. + See also [method get_theme_font_size]. + </description> + </method> + <method name="add_theme_icon_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="texture" type="Texture2D" /> + <description> + Creates a local override for a theme icon with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_icon_override]. + See also [method get_theme_icon]. + </description> + </method> + <method name="add_theme_stylebox_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <param index="1" name="stylebox" type="StyleBox" /> + <description> + Creates a local override for a theme [StyleBox] with the specified [param name]. Local overrides always take precedence when fetching theme items for the control. An override can be removed with [method remove_theme_stylebox_override]. + See also [method get_theme_stylebox] and [method Control.add_theme_stylebox_override] for more details. + </description> + </method> + <method name="begin_bulk_theme_override"> + <return type="void" /> + <description> + Prevents [code]*_theme_*_override[/code] methods from emitting [constant NOTIFICATION_THEME_CHANGED] until [method end_bulk_theme_override] is called. + </description> + </method> <method name="can_draw" qualifiers="const"> <return type="bool" /> <description> @@ -22,6 +82,12 @@ Requests an update of the [Window] size to fit underlying [Control] nodes. </description> </method> + <method name="end_bulk_theme_override"> + <return type="void" /> + <description> + Ends a bulk theme override update. See [method begin_bulk_theme_override]. + </description> + </method> <method name="get_contents_minimum_size" qualifiers="const"> <return type="Vector2" /> <description> @@ -41,7 +107,13 @@ Returns layout direction and text writing direction. </description> </method> - <method name="get_real_size" qualifiers="const"> + <method name="get_position_with_decorations" qualifiers="const"> + <return type="Vector2i" /> + <description> + Returns the window's position including its border. + </description> + </method> + <method name="get_size_with_decorations" qualifiers="const"> <return type="Vector2i" /> <description> Returns the window's size including its border. @@ -52,7 +124,7 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the [Color] at [param name] if the theme has [param theme_type]. + Returns a [Color] from the first matching [Theme] in the tree if that [Theme] has a color item with the specified [param name] and [param theme_type]. See [method Control.get_theme_color] for more details. </description> </method> @@ -61,29 +133,29 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the constant at [param name] if the theme has [param theme_type]. + Returns a constant from the first matching [Theme] in the tree if that [Theme] has a constant item with the specified [param name] and [param theme_type]. See [method Control.get_theme_color] for more details. </description> </method> <method name="get_theme_default_base_scale" qualifiers="const"> <return type="float" /> <description> - Returns the default base scale defined in the attached [Theme]. - See [member Theme.default_base_scale] for more details. + Returns the default base scale value from the first matching [Theme] in the tree if that [Theme] has a valid [member Theme.default_base_scale] value. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_default_font" qualifiers="const"> <return type="Font" /> <description> - Returns the default [Font] defined in the attached [Theme]. - See [member Theme.default_font] for more details. + Returns the default font from the first matching [Theme] in the tree if that [Theme] has a valid [member Theme.default_font] value. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_default_font_size" qualifiers="const"> <return type="int" /> <description> - Returns the default font size defined in the attached [Theme]. - See [member Theme.default_font_size] for more details. + Returns the default font size value from the first matching [Theme] in the tree if that [Theme] has a valid [member Theme.default_font_size] value. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_font" qualifiers="const"> @@ -91,8 +163,8 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the [Font] at [param name] if the theme has [param theme_type]. - See [method Control.get_theme_color] for more details. + Returns a [Font] from the first matching [Theme] in the tree if that [Theme] has a font item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_font_size" qualifiers="const"> @@ -100,8 +172,8 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the font size at [param name] if the theme has [param theme_type]. - See [method Control.get_theme_color] for more details. + Returns a font size from the first matching [Theme] in the tree if that [Theme] has a font size item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_icon" qualifiers="const"> @@ -109,8 +181,8 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the icon at [param name] if the theme has [param theme_type]. - See [method Control.get_theme_color] for more details. + Returns an icon from the first matching [Theme] in the tree if that [Theme] has an icon item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. </description> </method> <method name="get_theme_stylebox" qualifiers="const"> @@ -118,8 +190,8 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns the [StyleBox] at [param name] if the theme has [param theme_type]. - See [method Control.get_theme_color] for more details. + Returns a [StyleBox] from the first matching [Theme] in the tree if that [Theme] has a stylebox item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. </description> </method> <method name="grab_focus"> @@ -139,7 +211,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if [Color] with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a color item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_color_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme [Color] with the specified [param name] in this [Control] node. + See [method add_theme_color_override]. </description> </method> <method name="has_theme_constant" qualifiers="const"> @@ -147,7 +228,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if constant with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a constant item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_constant_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme constant with the specified [param name] in this [Control] node. + See [method add_theme_constant_override]. </description> </method> <method name="has_theme_font" qualifiers="const"> @@ -155,7 +245,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if [Font] with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a font item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_font_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme [Font] with the specified [param name] in this [Control] node. + See [method add_theme_font_override]. </description> </method> <method name="has_theme_font_size" qualifiers="const"> @@ -163,7 +262,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if font size with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a font size item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_font_size_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme font size with the specified [param name] in this [Control] node. + See [method add_theme_font_size_override]. </description> </method> <method name="has_theme_icon" qualifiers="const"> @@ -171,7 +279,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if icon with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has an icon item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_icon_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme icon with the specified [param name] in this [Control] node. + See [method add_theme_icon_override]. </description> </method> <method name="has_theme_stylebox" qualifiers="const"> @@ -179,7 +296,16 @@ <param index="0" name="name" type="StringName" /> <param index="1" name="theme_type" type="StringName" default="""" /> <description> - Returns [code]true[/code] if [StyleBox] with [param name] is in [param theme_type]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a stylebox item with the specified [param name] and [param theme_type]. + See [method Control.get_theme_color] for details. + </description> + </method> + <method name="has_theme_stylebox_override" qualifiers="const"> + <return type="bool" /> + <param index="0" name="name" type="StringName" /> + <description> + Returns [code]true[/code] if there is a local override for a theme [StyleBox] with the specified [param name] in this [Control] node. + See [method add_theme_stylebox_override]. </description> </method> <method name="hide"> @@ -258,6 +384,48 @@ If the [Window] is embedded, has the same effect as [method popup]. </description> </method> + <method name="remove_theme_color_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme [Color] with the specified [param name] previously added by [method add_theme_color_override] or via the Inspector dock. + </description> + </method> + <method name="remove_theme_constant_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme constant with the specified [param name] previously added by [method add_theme_constant_override] or via the Inspector dock. + </description> + </method> + <method name="remove_theme_font_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme [Font] with the specified [param name] previously added by [method add_theme_font_override] or via the Inspector dock. + </description> + </method> + <method name="remove_theme_font_size_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme font size with the specified [param name] previously added by [method add_theme_font_size_override] or via the Inspector dock. + </description> + </method> + <method name="remove_theme_icon_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme icon with the specified [param name] previously added by [method add_theme_icon_override] or via the Inspector dock. + </description> + </method> + <method name="remove_theme_stylebox_override"> + <return type="void" /> + <param index="0" name="name" type="StringName" /> + <description> + Removes a local override for a theme [StyleBox] with the specified [param name] previously added by [method add_theme_stylebox_override] or via the Inspector dock. + </description> + </method> <method name="request_attention"> <return type="void" /> <description> @@ -367,8 +535,8 @@ The window's size in pixels. </member> <member name="theme" type="Theme" setter="set_theme" getter="get_theme"> - The [Theme] resource that determines the style of the underlying [Control] nodes. - [Window] styles will have no effect unless the window is embedded. + The [Theme] resource this node and all its [Control] and [Window] children use. If a child node has its own [Theme] resource set, theme items are merged with child's definitions having higher priority. + [b]Note:[/b] [Window] styles will have no effect unless the window is embedded. </member> <member name="theme_type_variation" type="StringName" setter="set_theme_type_variation" getter="get_theme_type_variation" default="&"""> The name of a theme type variation used by this [Window] to look up its own theme items. See [member Control.theme_type_variation] for more details. diff --git a/doc/classes/XRInterfaceExtension.xml b/doc/classes/XRInterfaceExtension.xml index 0fe54e947f..5ad67a7ea9 100644 --- a/doc/classes/XRInterfaceExtension.xml +++ b/doc/classes/XRInterfaceExtension.xml @@ -24,7 +24,7 @@ <method name="_get_camera_feed_id" qualifiers="virtual const"> <return type="int" /> <description> - Returns the camera feed id for the [CameraFeed] registered with the [CameraServer] that should be presented as the background on an AR capable device (if applicable). + Returns the camera feed ID for the [CameraFeed] registered with the [CameraServer] that should be presented as the background on an AR capable device (if applicable). </description> </method> <method name="_get_camera_transform" qualifiers="virtual"> diff --git a/doc/classes/float.xml b/doc/classes/float.xml index a196021249..755ce1200d 100644 --- a/doc/classes/float.xml +++ b/doc/classes/float.xml @@ -5,7 +5,7 @@ </brief_description> <description> The [float] built-in type is a 64-bit double-precision floating-point number, equivalent to [code]double[/code] in C++. This type has 14 reliable decimal digits of precision. The [float] type can be stored in [Variant], which is the generic type used by the engine. The maximum value of [float] is approximately [code]1.79769e308[/code], and the minimum is approximately [code]-1.79769e308[/code]. - Many methods and properties in the engine use 32-bit single-precision floating-point numbers instead, equivalent to [code]float[/code] in C++, which have 6 reliable decimal digits of precision. For data structures such as [Vector2] and [Vector3], Godot uses 32-bit floating-point numbers by default, but it can be changed to use 64-bit doubles if Godot is compiled with the [code]float=64[/code] option. + Many methods and properties in the engine use 32-bit single-precision floating-point numbers instead, equivalent to [code]float[/code] in C++, which have 6 reliable decimal digits of precision. For data structures such as [Vector2] and [Vector3], Godot uses 32-bit floating-point numbers by default, but it can be changed to use 64-bit doubles if Godot is compiled with the [code]precision=double[/code] option. Math done using the [float] type is not guaranteed to be exact or deterministic, and will often result in small errors. You should usually use the [method @GlobalScope.is_equal_approx] and [method @GlobalScope.is_zero_approx] methods instead of [code]==[/code] to compare [float] values for equality. </description> <tutorials> diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index e5d4077393..c7e7227916 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -454,7 +454,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_ update_skeletons = false; } // Canvas group begins here, render until before this item - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, false); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, r_sdf_used); item_count = 0; if (ci->canvas_group_owner->canvas_group->mode != RS::CANVAS_GROUP_MODE_TRANSPARENT) { @@ -485,7 +485,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_ mesh_storage->update_mesh_instances(); update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, true); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, r_sdf_used, true); item_count = 0; if (ci->canvas_group->blur_mipmaps) { @@ -504,7 +504,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_ } //render anything pending, including clearing if no items - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, false); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, r_sdf_used); item_count = 0; texture_storage->render_target_copy_to_back_buffer(p_to_render_target, back_buffer_rect, backbuffer_gen_mipmaps); @@ -530,7 +530,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_ mesh_storage->update_mesh_instances(); update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, false); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, starting_index, r_sdf_used); //then reset item_count = 0; } @@ -549,7 +549,7 @@ void RasterizerCanvasGLES3::canvas_render_items(RID p_to_render_target, Item *p_ state.current_buffer = (state.current_buffer + 1) % state.canvas_instance_data_buffers.size(); } -void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, uint32_t &r_last_index, bool p_to_backbuffer) { +void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, uint32_t &r_last_index, bool &r_sdf_used, bool p_to_backbuffer) { GLES3::MaterialStorage *material_storage = GLES3::MaterialStorage::get_singleton(); canvas_begin(p_to_render_target, p_to_backbuffer); @@ -617,7 +617,7 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou GLES3::CanvasShaderData::BlendMode blend_mode = shader_data_cache ? shader_data_cache->blend_mode : GLES3::CanvasShaderData::BLEND_MODE_MIX; - _record_item_commands(ci, p_to_render_target, p_canvas_transform_inverse, current_clip, blend_mode, p_lights, index, batch_broken); + _record_item_commands(ci, p_to_render_target, p_canvas_transform_inverse, current_clip, blend_mode, p_lights, index, batch_broken, r_sdf_used); } if (index == 0) { @@ -749,7 +749,7 @@ void RasterizerCanvasGLES3::_render_items(RID p_to_render_target, int p_item_cou r_last_index += index; } -void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_render_target, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, GLES3::CanvasShaderData::BlendMode p_blend_mode, Light *p_lights, uint32_t &r_index, bool &r_batch_broken) { +void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_render_target, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, GLES3::CanvasShaderData::BlendMode p_blend_mode, Light *p_lights, uint32_t &r_index, bool &r_batch_broken, bool &r_sdf_used) { RenderingServer::CanvasItemTextureFilter texture_filter = p_item->texture_filter == RS::CANVAS_ITEM_TEXTURE_FILTER_DEFAULT ? state.default_filter : p_item->texture_filter; if (texture_filter != state.canvas_instance_batches[state.current_batch_index].filter) { @@ -1145,6 +1145,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend } else { particles_storage->particles_set_canvas_sdf_collision(pt->particles, false, Transform2D(), Rect2(), 0); } + r_sdf_used |= particles_storage->particles_has_collision(particles); } state.canvas_instance_batches[state.current_batch_index].command = c; diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 0a03d43d07..bd87973404 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -351,8 +351,8 @@ public: void _prepare_canvas_texture(RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, uint32_t &r_index, Size2 &r_texpixel_size); void canvas_render_items(RID p_to_render_target, Item *p_item_list, const Color &p_modulate, Light *p_light_list, Light *p_directional_list, const Transform2D &p_canvas_transform, RS::CanvasItemTextureFilter p_default_filter, RS::CanvasItemTextureRepeat p_default_repeat, bool p_snap_2d_vertices_to_pixel, bool &r_sdf_used) override; - void _render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, uint32_t &r_last_index, bool p_to_backbuffer = false); - void _record_item_commands(const Item *p_item, RID p_render_target, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, GLES3::CanvasShaderData::BlendMode p_blend_mode, Light *p_lights, uint32_t &r_index, bool &r_break_batch); + void _render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, uint32_t &r_last_index, bool &r_sdf_used, bool p_to_backbuffer = false); + void _record_item_commands(const Item *p_item, RID p_render_target, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, GLES3::CanvasShaderData::BlendMode p_blend_mode, Light *p_lights, uint32_t &r_index, bool &r_break_batch, bool &r_sdf_used); void _render_batch(Light *p_lights, uint32_t p_index); bool _bind_material(GLES3::CanvasMaterialData *p_material_data, CanvasShaderGLES3::ShaderVariant p_variant, uint64_t p_specialization); void _new_batch(bool &r_batch_broken, uint32_t &r_index); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 247b89658a..b75fdf5f71 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2210,10 +2210,13 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params, glBindVertexArray(vertex_array_gl); } prev_vertex_array_gl = vertex_array_gl; + + // Invalidate the previous index array + prev_index_array_gl = 0; } bool use_index_buffer = index_array_gl != 0; - if (prev_index_array_gl != index_array_gl || prev_vertex_array_gl != vertex_array_gl) { + if (prev_index_array_gl != index_array_gl) { if (index_array_gl != 0) { // Bind index each time so we can use LODs glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_array_gl); diff --git a/drivers/gles3/storage/utilities.cpp b/drivers/gles3/storage/utilities.cpp index fe900c7cfb..02a110e3e5 100644 --- a/drivers/gles3/storage/utilities.cpp +++ b/drivers/gles3/storage/utilities.cpp @@ -156,6 +156,9 @@ bool Utilities::free(RID p_rid) { } else if (GLES3::ParticlesStorage::get_singleton()->owns_particles_collision_instance(p_rid)) { GLES3::ParticlesStorage::get_singleton()->particles_collision_instance_free(p_rid); return true; + } else if (GLES3::MeshStorage::get_singleton()->owns_skeleton(p_rid)) { + GLES3::MeshStorage::get_singleton()->skeleton_free(p_rid); + return true; } else { return false; } diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 7f5bac30f1..277d1e7b06 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -6460,7 +6460,7 @@ Vector<uint8_t> RenderingDeviceVulkan::buffer_get_data(RID p_buffer) { /**** RENDER PIPELINE ****/ /*************************/ -RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const Vector<PipelineSpecializationConstant> &p_specialization_constants) { +RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags, uint32_t p_for_render_pass, const Vector<PipelineSpecializationConstant> &p_specialization_constants) { _THREAD_SAFE_METHOD_ // Needs a shader. @@ -6746,31 +6746,31 @@ RID RenderingDeviceVulkan::render_pipeline_create(RID p_shader, FramebufferForma dynamic_states.push_back(VK_DYNAMIC_STATE_VIEWPORT); // Viewport and scissor are always dynamic. dynamic_states.push_back(VK_DYNAMIC_STATE_SCISSOR); - if (p_dynamic_state_flags & DYNAMIC_STATE_LINE_WIDTH) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_LINE_WIDTH)) { dynamic_states.push_back(VK_DYNAMIC_STATE_LINE_WIDTH); } - if (p_dynamic_state_flags & DYNAMIC_STATE_DEPTH_BIAS) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_DEPTH_BIAS)) { dynamic_states.push_back(VK_DYNAMIC_STATE_DEPTH_BIAS); } - if (p_dynamic_state_flags & DYNAMIC_STATE_BLEND_CONSTANTS) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_BLEND_CONSTANTS)) { dynamic_states.push_back(VK_DYNAMIC_STATE_BLEND_CONSTANTS); } - if (p_dynamic_state_flags & DYNAMIC_STATE_DEPTH_BOUNDS) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_DEPTH_BOUNDS)) { dynamic_states.push_back(VK_DYNAMIC_STATE_DEPTH_BOUNDS); } - if (p_dynamic_state_flags & DYNAMIC_STATE_STENCIL_COMPARE_MASK) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_STENCIL_COMPARE_MASK)) { dynamic_states.push_back(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK); } - if (p_dynamic_state_flags & DYNAMIC_STATE_STENCIL_WRITE_MASK) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_STENCIL_WRITE_MASK)) { dynamic_states.push_back(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK); } - if (p_dynamic_state_flags & DYNAMIC_STATE_STENCIL_REFERENCE) { + if (p_dynamic_state_flags.has_flag(DYNAMIC_STATE_STENCIL_REFERENCE)) { dynamic_states.push_back(VK_DYNAMIC_STATE_STENCIL_REFERENCE); } diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h index c6e1830e90..031f662d56 100644 --- a/drivers/vulkan/rendering_device_vulkan.h +++ b/drivers/vulkan/rendering_device_vulkan.h @@ -1132,7 +1132,7 @@ public: /**** RENDER PIPELINE ****/ /*************************/ - virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()); + virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()); virtual bool render_pipeline_is_valid(RID p_pipeline); /**************************/ diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 7ffec0835b..530708f3e5 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1592,7 +1592,7 @@ void AnimationBezierTrackEdit::duplicate_selection() { } Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Duplicate Keys")); + undo_redo->create_action(TTR("Animation Duplicate Keys")); List<Pair<int, real_t>> new_selection_values; @@ -1638,7 +1638,7 @@ void AnimationBezierTrackEdit::duplicate_selection() { void AnimationBezierTrackEdit::delete_selection() { if (selection.size()) { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Delete Keys")); + undo_redo->create_action(TTR("Animation Delete Keys")); for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->get().first, E->get().second); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index ecc465ef64..2ee06a0dbd 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -137,7 +137,7 @@ public: setting = true; Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Change Keyframe Time"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Time"), UndoRedo::MERGE_ENDS); Variant val = animation->track_get_key_value(track, key); float trans = animation->track_get_key_transition(track, key); @@ -165,7 +165,7 @@ public: float prev_val = animation->track_get_key_transition(track, key); setting = true; Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Change Transition"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Transition"), UndoRedo::MERGE_ENDS); undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", track, key, val); undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", track, key, prev_val); undo_redo->add_do_method(this, "_update_obj", animation); @@ -221,7 +221,7 @@ public: } setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); Variant prev = animation->track_get_key_value(track, key); undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, value); undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, prev); @@ -281,9 +281,9 @@ public: } if (mergeable) { - undo_redo->create_action(TTR("Anim Change Call"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Call"), UndoRedo::MERGE_ENDS); } else { - undo_redo->create_action(TTR("Anim Change Call")); + undo_redo->create_action(TTR("Animation Change Call")); } setting = true; @@ -304,7 +304,7 @@ public: const Variant &value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); float prev = animation->bezier_track_get_key_value(track, key); undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_value", track, key, value); undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_value", track, key, prev); @@ -320,7 +320,7 @@ public: const Variant &value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); Vector2 prev = animation->bezier_track_get_key_in_handle(track, key); undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, value); undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", track, key, prev); @@ -336,7 +336,7 @@ public: const Variant &value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); Vector2 prev = animation->bezier_track_get_key_out_handle(track, key); undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, value); undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", track, key, prev); @@ -352,7 +352,7 @@ public: const Variant &value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); int prev = animation->bezier_track_get_key_handle_mode(track, key); undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); undo_redo->add_undo_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, prev); @@ -369,7 +369,7 @@ public: Ref<AudioStream> stream = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); Ref<Resource> prev = animation->audio_track_get_key_stream(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_stream", track, key, stream); undo_redo->add_undo_method(animation.ptr(), "audio_track_set_key_stream", track, key, prev); @@ -385,7 +385,7 @@ public: float value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); float prev = animation->audio_track_get_key_start_offset(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_start_offset", track, key, value); undo_redo->add_undo_method(animation.ptr(), "audio_track_set_key_start_offset", track, key, prev); @@ -401,7 +401,7 @@ public: float value = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); float prev = animation->audio_track_get_key_end_offset(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_end_offset", track, key, value); undo_redo->add_undo_method(animation.ptr(), "audio_track_set_key_end_offset", track, key, prev); @@ -418,7 +418,7 @@ public: StringName anim_name = p_value; setting = true; - undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Change Keyframe Value"), UndoRedo::MERGE_ENDS); StringName prev = animation->animation_track_get_key_animation(track, key); undo_redo->add_do_method(animation.ptr(), "animation_track_set_key_animation", track, key, anim_name); undo_redo->add_undo_method(animation.ptr(), "animation_track_set_key_animation", track, key, prev); @@ -818,7 +818,7 @@ public: Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Time"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Time"), UndoRedo::MERGE_ENDS); } Variant val = animation->track_get_key_value(track, key); @@ -843,7 +843,7 @@ public: Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Transition"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Transition"), UndoRedo::MERGE_ENDS); } undo_redo->add_do_method(animation.ptr(), "track_set_key_transition", track, key, val); undo_redo->add_undo_method(animation.ptr(), "track_set_key_transition", track, key, prev_val); @@ -873,7 +873,7 @@ public: } setting = true; - undo_redo->create_action(vformat(TTR("Anim Multi Change %s"), chan)); + undo_redo->create_action(vformat(TTR("Animation Multi Change %s"), chan)); } undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, p_value); undo_redo->add_undo_method(animation.ptr(), "track_set_key_value", track, key, old); @@ -890,7 +890,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Variant prev = animation->track_get_key_value(track, key); undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, value); @@ -948,9 +948,9 @@ public: if (!setting) { if (mergeable) { - undo_redo->create_action(TTR("Anim Multi Change Call"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Call"), UndoRedo::MERGE_ENDS); } else { - undo_redo->create_action(TTR("Anim Multi Change Call")); + undo_redo->create_action(TTR("Animation Multi Change Call")); } setting = true; @@ -966,7 +966,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } float prev = animation->bezier_track_get_key_value(track, key); undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_value", track, key, value); @@ -977,7 +977,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Vector2 prev = animation->bezier_track_get_key_in_handle(track, key); undo_redo->add_do_method(this, "_bezier_track_set_key_in_handle", track, key, value); @@ -988,7 +988,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Vector2 prev = animation->bezier_track_get_key_out_handle(track, key); undo_redo->add_do_method(this, "_bezier_track_set_key_out_handle", track, key, value); @@ -999,7 +999,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } int prev = animation->bezier_track_get_key_handle_mode(track, key); undo_redo->add_do_method(this, "_bezier_track_set_key_handle_mode", animation.ptr(), track, key, value); @@ -1013,7 +1013,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } Ref<Resource> prev = animation->audio_track_get_key_stream(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_stream", track, key, stream); @@ -1024,7 +1024,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } float prev = animation->audio_track_get_key_start_offset(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_start_offset", track, key, value); @@ -1035,7 +1035,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } float prev = animation->audio_track_get_key_end_offset(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_end_offset", track, key, value); @@ -1049,7 +1049,7 @@ public: if (!setting) { setting = true; - undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); + undo_redo->create_action(TTR("Animation Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } StringName prev = animation->animation_track_get_key_animation(track, key); undo_redo->add_do_method(animation.ptr(), "animation_track_set_key_animation", track, key, anim_name); @@ -3814,7 +3814,7 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) { void AnimationTrackEditor::_insert_track(bool p_reset_wanted, bool p_create_beziers) { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Insert")); + undo_redo->create_action(TTR("Animation Insert Key")); Ref<Animation> reset_anim; if (p_reset_wanted) { @@ -4153,7 +4153,7 @@ Ref<Animation> AnimationTrackEditor::_create_and_get_reset_animation() { void AnimationTrackEditor::_confirm_insert_list() { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Create & Insert")); + undo_redo->create_action(TTR("Animation Insert Key")); bool create_reset = insert_confirm_reset->is_visible() && insert_confirm_reset->is_pressed(); Ref<Animation> reset_anim; @@ -4340,7 +4340,6 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD } } created = true; - undo_redo->create_action(TTR("Anim Insert Track & Key")); p_id.track_idx = p_next_tracks.normal; @@ -4349,9 +4348,6 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD if (p_id.type == Animation::TYPE_VALUE) { undo_redo->add_do_method(animation.ptr(), "value_track_set_update_mode", p_id.track_idx, update_mode); } - - } else { - undo_redo->create_action(TTR("Anim Insert Key")); } float time = timeline->get_play_position(); @@ -4422,8 +4418,6 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD } } - undo_redo->commit_action(); - return p_next_tracks; } @@ -5359,7 +5353,7 @@ void AnimationTrackEditor::_select_at_anim(const Ref<Animation> &p_anim, int p_t void AnimationTrackEditor::_move_selection_commit() { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Move Keys")); + undo_redo->create_action(TTR("Animation Move Keys")); List<_AnimMoveRestore> to_restore; @@ -5611,7 +5605,7 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) { int start_track = transpose ? _get_track_selected() : top_track; Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Duplicate Keys")); + undo_redo->create_action(TTR("Animation Duplicate Keys")); List<Pair<int, float>> new_selection_values; @@ -5911,7 +5905,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { ERR_FAIL_COND_MSG(s == 0, "Can't scale to 0."); Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Scale Keys")); + undo_redo->create_action(TTR("Animation Scale Keys")); List<_AnimMoveRestore> to_restore; @@ -6098,7 +6092,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { } break; case EDIT_ADD_RESET_KEY: { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Add RESET Keys")); + undo_redo->create_action(TTR("Animation Add RESET Keys")); Ref<Animation> reset = _create_and_get_reset_animation(); int reset_tracks = reset->get_track_count(); @@ -6159,7 +6153,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { if (selection.size()) { Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo(); - undo_redo->create_action(TTR("Anim Delete Keys")); + undo_redo->create_action(TTR("Animation Delete Keys")); for (RBMap<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) { undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key); diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 2bd77bf99c..1f0cc1dc77 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -788,23 +788,7 @@ bool ConnectionsDock::_is_item_signal(TreeItem &p_item) { } bool ConnectionsDock::_is_connection_inherited(Connection &p_connection) { - Node *scene_root = EditorNode::get_singleton()->get_edited_scene(); - Ref<PackedScene> scn = ResourceLoader::load(scene_root->get_scene_file_path()); - ERR_FAIL_NULL_V(scn, false); - - Ref<SceneState> state = scn->get_state(); - ERR_FAIL_NULL_V(state, false); - - Node *source = Object::cast_to<Node>(p_connection.signal.get_object()); - Node *target = Object::cast_to<Node>(p_connection.callable.get_object()); - - const NodePath source_path = scene_root->get_path_to(source); - const NodePath target_path = scene_root->get_path_to(target); - const StringName signal_name = p_connection.signal.get_name(); - const StringName method_name = p_connection.callable.get_method(); - - // If it cannot be found in PackedScene, this connection was inherited. - return !state->has_connection(source_path, signal_name, target_path, method_name, true); + return bool(p_connection.flags & CONNECT_INHERITED); } /* diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 2adab089e4..5292b51032 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -284,8 +284,9 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) || p_type_category == TypeCategory::OTHER_TYPE; + bool is_virtual = ClassDB::class_exists(p_type) && ClassDB::is_virtual(p_type); - if (can_instantiate && !ClassDB::is_virtual(p_type)) { + if (can_instantiate && !is_virtual) { r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback)); } else { r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, "NodeDisabled")); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 14a2640e63..65e73d8df4 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -701,7 +701,7 @@ void DocTools::generate(bool p_basic_types) { if (rt != Variant::NIL) { // Has operator. // Skip String % operator as it's registered separately for each Variant arg type, // we'll add it manually below. - if (i == Variant::STRING && Variant::Operator(j) == Variant::OP_MODULE) { + if ((i == Variant::STRING || i == Variant::STRING_NAME) && Variant::Operator(j) == Variant::OP_MODULE) { continue; } MethodInfo mi; @@ -718,7 +718,7 @@ void DocTools::generate(bool p_basic_types) { } } - if (i == Variant::STRING) { + if (i == Variant::STRING || i == Variant::STRING_NAME) { // We skipped % operator above, and we register it manually once for Variant arg type here. MethodInfo mi; mi.name = "operator %"; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 6bd67fbcb9..21119048cb 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -55,8 +55,6 @@ void EditorHelp::_update_theme() { qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp")); type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp")); - class_desc->add_theme_style_override("normal", get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"))); - class_desc->add_theme_style_override("focus", get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"))); class_desc->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp"))); class_desc->add_theme_constant_override("line_separation", get_theme_constant(SNAME("line_separation"), SNAME("EditorHelp"))); class_desc->add_theme_constant_override("table_h_separation", get_theme_constant(SNAME("table_h_separation"), SNAME("EditorHelp"))); @@ -196,10 +194,11 @@ void EditorHelp::_class_desc_resized(bool p_force_update_theme) { if (display_margin != new_display_margin || p_force_update_theme) { display_margin = new_display_margin; - Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox(SNAME("normal"), SNAME("RichTextLabel"))->duplicate(); + Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"))->duplicate(); class_desc_stylebox->set_default_margin(SIDE_LEFT, display_margin); class_desc_stylebox->set_default_margin(SIDE_RIGHT, display_margin); class_desc->add_theme_style_override("normal", class_desc_stylebox); + class_desc->add_theme_style_override("focused", class_desc_stylebox); } } diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 286dcf4b8e..b48fbb805a 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -443,6 +443,10 @@ bool EditorHelpSearch::Runner::_phase_member_items_init() { } bool EditorHelpSearch::Runner::_phase_member_items() { + if (!iterator_match) { + return true; + } + ClassMatch &match = iterator_match->value; if (!match.doc || match.doc->name.is_empty()) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 06e1e8b22e..463e8f6bdc 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6038,14 +6038,7 @@ EditorNode::EditorNode() { Input *id = Input::get_singleton(); if (id) { - bool found_touchscreen = false; - for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { - if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) { - found_touchscreen = true; - } - } - - if (!found_touchscreen && Input::get_singleton()) { + if (!DisplayServer::get_singleton()->is_touchscreen_available() && Input::get_singleton()) { // Only if no touchscreen ui hint, disable emulation just in case. id->set_emulate_touch_from_mouse(false); } diff --git a/editor/export/editor_export_platform_pc.cpp b/editor/export/editor_export_platform_pc.cpp index 5345346c48..9de2f94900 100644 --- a/editor/export/editor_export_platform_pc.cpp +++ b/editor/export/editor_export_platform_pc.cpp @@ -81,8 +81,8 @@ bool EditorExportPlatformPC::has_valid_export_configuration(const Ref<EditorExpo // Look for export templates (first official, and if defined custom templates). String arch = p_preset->get("binary_format/architecture"); - bool dvalid = exists_export_template(get_template_file_name("template_debug", arch), &err); - bool rvalid = exists_export_template(get_template_file_name("template_release", arch), &err); + bool dvalid = exists_export_template(get_template_file_name("debug", arch), &err); + bool rvalid = exists_export_template(get_template_file_name("release", arch), &err); if (p_preset->get("custom_template/debug") != "") { dvalid = FileAccess::exists(p_preset->get("custom_template/debug")); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 8df5808b11..6316a7f545 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1414,7 +1414,7 @@ void FileSystemDock::_update_dependencies_after_move(const HashMap<String, Strin Error err = ResourceLoader::rename_dependencies(file, p_renames); if (err == OK) { if (ResourceLoader::get_resource_type(file) == "PackedScene") { - EditorNode::get_singleton()->reload_scene(file); + callable_mp(EditorNode::get_singleton(), &EditorNode::reload_scene).bind(file).call_deferred(); } } else { EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n"); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index 666444eaf9..b7e7200b11 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -769,7 +769,7 @@ void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) { Rect2 match_rect = rect; match_rect.position.x += font->get_string_size(item_text.left(r.begin_trimmed), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x - 1; - match_rect.size.x = font->get_string_size(_search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 2; + match_rect.size.x = font->get_string_size(_search_text_label->get_text(), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x + 1; match_rect.position.y += 1 * EDSCALE; match_rect.size.y -= 2 * EDSCALE; diff --git a/editor/icons/OneWayTile.svg b/editor/icons/OneWayTile.svg new file mode 100644 index 0000000000..273b1a183b --- /dev/null +++ b/editor/icons/OneWayTile.svg @@ -0,0 +1 @@ +<svg clip-rule="evenodd" fill-rule="evenodd" height="16" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m10.958984 1.5-1.4785152 1.4667969-1.4785157 1.46875-1.4804687-1.4667969-1.4785156-1.4667969-.5214844.5136719-.5214844.5136719 2 1.9863281 2 1.984375 2-1.984375 2-1.9824219-.519531-.5175781zm0 8-1.4785152 1.466797-1.4785157 1.46875-1.4804687-1.466797-1.4785156-1.4667969-.5214844.5136719-.5214844.513672 2 1.986328 2 1.984375 2-1.984375 2-1.982422-.519531-.517578z" fill="#fff"/></svg> diff --git a/editor/icons/TileSelection.svg b/editor/icons/TileSelection.svg new file mode 100644 index 0000000000..418382aa1c --- /dev/null +++ b/editor/icons/TileSelection.svg @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + height="5" + viewBox="0 0 5 5" + width="5" + version="1.1" + id="svg10" + sodipodi:docname="TileSelection.svg" + inkscape:version="1.1 (c68e22c387, 2021-05-23)" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg"> + <defs + id="defs14"> + <linearGradient + id="linearGradient1060" + inkscape:swatch="solid"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop1058" /> + </linearGradient> + </defs> + <sodipodi:namedview + id="namedview12" + pagecolor="#505050" + bordercolor="#ffffff" + borderopacity="1" + inkscape:pageshadow="0" + inkscape:pageopacity="0" + inkscape:pagecheckerboard="1" + showgrid="false" + inkscape:zoom="64" + inkscape:cx="4.3125" + inkscape:cy="1.984375" + inkscape:window-width="3840" + inkscape:window-height="2066" + inkscape:window-x="-11" + inkscape:window-y="-11" + inkscape:window-maximized="1" + inkscape:current-layer="svg10" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:1.00038;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect940" + width="3.9996195" + height="3.999619" + x="0.50019002" + y="0.50019002" /> + <rect + style="fill:none;stroke:#000000;stroke-width:0.999543;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + id="rect3062" + width="2.000457" + height="2.000457" + x="1.4997715" + y="1.4997715" /> +</svg> diff --git a/editor/plugins/gdextension_export_plugin.h b/editor/plugins/gdextension_export_plugin.h index d62691c76d..586cd2bd59 100644 --- a/editor/plugins/gdextension_export_plugin.h +++ b/editor/plugins/gdextension_export_plugin.h @@ -85,7 +85,7 @@ void GDExtensionExportPlugin::_export_file(const String &p_path, const String &p for (const String &E : p_features) { features_vector.append(E); } - ERR_FAIL_MSG(vformat("No suitable library found. The libraries' tags referred to an invalid feature flag. Possible feature flags for your platform: %s", p_path, String(", ").join(tags))); + ERR_FAIL_MSG(vformat("No suitable library found for GDExtension: %s. Possible feature flags for your platform: %s", p_path, String(", ").join(features_vector))); } List<String> dependencies; diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index 0af2a13df2..c8b80db334 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -30,6 +30,7 @@ #include "node_3d_editor_gizmos.h" +#include "core/config/project_settings.h" #include "core/math/convex_hull.h" #include "core/math/geometry_2d.h" #include "core/math/geometry_3d.h" @@ -1732,6 +1733,24 @@ Camera3DGizmoPlugin::Camera3DGizmoPlugin() { create_handle_material("handles"); } +Size2i Camera3DGizmoPlugin::_get_viewport_size(Camera3D *p_camera) { + Viewport *viewport = p_camera->get_viewport(); + + Window *window = Object::cast_to<Window>(viewport); + if (window) { + return window->get_size(); + } + + SubViewport *sub_viewport = Object::cast_to<SubViewport>(viewport); + ERR_FAIL_NULL_V(sub_viewport, Size2i()); + + if (sub_viewport == EditorNode::get_singleton()->get_scene_root()) { + return Size2(GLOBAL_GET("display/window/size/viewport_width"), GLOBAL_GET("display/window/size/viewport_height")); + } + + return sub_viewport->get_size(); +} + bool Camera3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { return Object::cast_to<Camera3D>(p_spatial) != nullptr; } @@ -1830,6 +1849,10 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Ref<Material> material = get_material("camera_material", p_gizmo); + const Size2i viewport_size = _get_viewport_size(camera); + const real_t viewport_aspect = viewport_size.x > 0 && viewport_size.y > 0 ? viewport_size.aspect() : 1.0; + const Size2 size_factor = viewport_aspect > 1.0 ? Size2(1.0, 1.0 / viewport_aspect) : Size2(viewport_aspect, 1.0); + #define ADD_TRIANGLE(m_a, m_b, m_c) \ { \ lines.push_back(m_a); \ @@ -1857,10 +1880,11 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { // The real FOV is halved for accurate representation float fov = camera->get_fov() / 2.0; - Vector3 side = Vector3(Math::sin(Math::deg_to_rad(fov)), 0, -Math::cos(Math::deg_to_rad(fov))); - Vector3 nside = side; - nside.x = -nside.x; - Vector3 up = Vector3(0, side.x, 0); + const float hsize = Math::sin(Math::deg_to_rad(fov)); + const float depth = -Math::cos(Math::deg_to_rad(fov)); + Vector3 side = Vector3(hsize * size_factor.x, 0, depth); + Vector3 nside = Vector3(-side.x, side.y, side.z); + Vector3 up = Vector3(0, hsize * size_factor.y, 0); ADD_TRIANGLE(Vector3(), side + up, side - up); ADD_TRIANGLE(Vector3(), nside + up, nside - up); @@ -1868,18 +1892,18 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { ADD_TRIANGLE(Vector3(), side - up, nside - up); handles.push_back(side); - side.x *= 0.25; - nside.x *= 0.25; - Vector3 tup(0, up.y * 3 / 2, side.z); + side.x = MIN(side.x, hsize * 0.25); + nside.x = -side.x; + Vector3 tup(0, up.y + hsize / 2, side.z); ADD_TRIANGLE(tup, side + up, nside + up); - } break; + case Camera3D::PROJECTION_ORTHOGONAL: { float size = camera->get_size(); float hsize = size * 0.5; - Vector3 right(hsize, 0, 0); - Vector3 up(0, hsize, 0); + Vector3 right(hsize * size_factor.x, 0, 0); + Vector3 up(0, hsize * size_factor.y, 0); Vector3 back(0, 0, -1.0); Vector3 front(0, 0, 0); @@ -1890,18 +1914,19 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { handles.push_back(right + back); - right.x *= 0.25; - Vector3 tup(0, up.y * 3 / 2, back.z); + right.x = MIN(right.x, hsize * 0.25); + Vector3 tup(0, up.y + hsize / 2, back.z); ADD_TRIANGLE(tup, right + up + back, -right + up + back); } break; + case Camera3D::PROJECTION_FRUSTUM: { float hsize = camera->get_size() / 2.0; Vector3 side = Vector3(hsize, 0, -camera->get_near()).normalized(); - Vector3 nside = side; - nside.x = -nside.x; - Vector3 up = Vector3(0, side.x, 0); + side.x *= size_factor.x; + Vector3 nside = Vector3(-side.x, side.y, side.z); + Vector3 up = Vector3(0, hsize * size_factor.y, 0); Vector3 offset = Vector3(camera->get_frustum_offset().x, camera->get_frustum_offset().y, 0.0); ADD_TRIANGLE(Vector3(), side + up + offset, side - up + offset); @@ -1909,11 +1934,11 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { ADD_TRIANGLE(Vector3(), side + up + offset, nside + up + offset); ADD_TRIANGLE(Vector3(), side - up + offset, nside - up + offset); - side.x *= 0.25; - nside.x *= 0.25; - Vector3 tup(0, up.y * 3 / 2, side.z); + side.x = MIN(side.x, hsize * 0.25); + nside.x = -side.x; + Vector3 tup(0, up.y + hsize / 2, side.z); ADD_TRIANGLE(tup + offset, side + up + offset, nside + up + offset); - } + } break; } #undef ADD_TRIANGLE @@ -1921,7 +1946,10 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_lines(lines, material); p_gizmo->add_collision_segments(lines); - p_gizmo->add_handles(handles, get_material("handles")); + + if (!handles.is_empty()) { + p_gizmo->add_handles(handles, get_material("handles")); + } } ////// diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index d7e3e03f61..60d44ad787 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -264,6 +264,9 @@ public: class Camera3DGizmoPlugin : public EditorNode3DGizmoPlugin { GDCLASS(Camera3DGizmoPlugin, EditorNode3DGizmoPlugin); +private: + static Size2i _get_viewport_size(Camera3D *p_camera); + public: bool has_gizmo(Node3D *p_spatial) override; String get_gizmo_name() const override; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index c97de80a76..f5dd893377 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -7477,6 +7477,8 @@ void Node3DEditor::_notification(int p_what) { sun_state->set_custom_minimum_size(sun_vb->get_combined_minimum_size()); environ_state->set_custom_minimum_size(environ_vb->get_combined_minimum_size()); + + EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &Node3DEditor::update_all_gizmos).bind(Variant())); } break; case NOTIFICATION_ENTER_TREE: { @@ -7637,6 +7639,13 @@ void Node3DEditor::_request_gizmo(Object *p_obj) { } } +void Node3DEditor::_request_gizmo_for_id(ObjectID p_id) { + Node3D *node = Object::cast_to<Node3D>(ObjectDB::get_instance(p_id)); + if (node) { + _request_gizmo(node); + } +} + void Node3DEditor::_set_subgizmo_selection(Object *p_obj, Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform) { if (p_id == -1) { _clear_subgizmo_selection(p_obj); @@ -7817,6 +7826,7 @@ void Node3DEditor::_register_all_gizmos() { void Node3DEditor::_bind_methods() { ClassDB::bind_method("_get_editor_data", &Node3DEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &Node3DEditor::_request_gizmo); + ClassDB::bind_method("_request_gizmo_for_id", &Node3DEditor::_request_gizmo_for_id); ClassDB::bind_method("_set_subgizmo_selection", &Node3DEditor::_set_subgizmo_selection); ClassDB::bind_method("_clear_subgizmo_selection", &Node3DEditor::_clear_subgizmo_selection); ClassDB::bind_method("_refresh_menu_icons", &Node3DEditor::_refresh_menu_icons); @@ -8420,7 +8430,7 @@ Node3DEditor::Node3DEditor() { EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.9); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::FLOAT, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01")); EDITOR_DEF_RST("editors/3d/navigation/show_viewport_rotation_gizmo", true); - EDITOR_DEF_RST("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->screen_is_touchscreen()); + EDITOR_DEF_RST("editors/3d/navigation/show_viewport_navigation_gizmo", DisplayServer::get_singleton()->is_touchscreen_available()); current_hover_gizmo_handle = -1; current_hover_gizmo_handle_secondary = false; diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index ed555d86c3..fc252822c4 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -716,6 +716,7 @@ private: Node3D *selected = nullptr; void _request_gizmo(Object *p_obj); + void _request_gizmo_for_id(ObjectID p_id); void _set_subgizmo_selection(Object *p_obj, Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform = Transform3D()); void _clear_subgizmo_selection(Object *p_obj = nullptr); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 747fdfd041..38639ac811 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1223,7 +1223,9 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_foldable_line(tx->get_caret_line()); + for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) { + tx->toggle_foldable_line(tx->get_caret_line(caret_idx)); + } tx->queue_redraw(); } break; case EDIT_FOLD_ALL_LINES: { @@ -1291,28 +1293,28 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case EDIT_EVALUATE: { Expression expression; - Vector<String> lines = code_editor->get_text_editor()->get_selected_text().split("\n"); - PackedStringArray results; - - for (int i = 0; i < lines.size(); i++) { - String line = lines[i]; - String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning - - if (expression.parse(line) == OK) { - Variant result = expression.execute(Array(), Variant(), false, true); - if (expression.get_error_text().is_empty()) { - results.push_back(whitespace + result.get_construct_string()); + tx->begin_complex_operation(); + for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) { + Vector<String> lines = tx->get_selected_text(caret_idx).split("\n"); + PackedStringArray results; + + for (int i = 0; i < lines.size(); i++) { + String line = lines[i]; + String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); // Extract the whitespace at the beginning. + if (expression.parse(line) == OK) { + Variant result = expression.execute(Array(), Variant(), false, true); + if (expression.get_error_text().is_empty()) { + results.push_back(whitespace + result.get_construct_string()); + } else { + results.push_back(line); + } } else { results.push_back(line); } - } else { - results.push_back(line); } + tx->insert_text_at_caret(String("\n").join(results), caret_idx); } - - code_editor->get_text_editor()->begin_complex_operation(); //prevents creating a two-step undo - code_editor->get_text_editor()->insert_text_at_caret(String("\n").join(results)); - code_editor->get_text_editor()->end_complex_operation(); + tx->end_complex_operation(); } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); @@ -1327,14 +1329,14 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selected_text(); + String selected_text = tx->get_selected_text(); // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal(SNAME("search_in_files_requested"), selected_text); } break; case REPLACE_IN_FILES: { - String selected_text = code_editor->get_text_editor()->get_selected_text(); + String selected_text = tx->get_selected_text(); emit_signal(SNAME("replace_in_files_requested"), selected_text); } break; @@ -1358,10 +1360,12 @@ void ScriptTextEditor::_edit_option(int p_op) { code_editor->remove_all_bookmarks(); } break; case DEBUG_TOGGLE_BREAKPOINT: { - int line = tx->get_caret_line(); - bool dobreak = !tx->is_line_breakpointed(line); - tx->set_line_as_breakpoint(line, dobreak); - EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak); + for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) { + int line = tx->get_caret_line(caret_idx); + bool dobreak = !tx->is_line_breakpointed(line); + tx->set_line_as_breakpoint(line, dobreak); + EditorDebuggerNode::get_singleton()->set_breakpoint(script->get_path(), line + 1, dobreak); + } } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { PackedInt32Array bpoints = tx->get_breakpointed_lines(); @@ -1379,26 +1383,14 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - tx->remove_secondary_carets(); - int line = tx->get_caret_line(); - - // wrap around - if (line >= (int)bpoints[bpoints.size() - 1]) { - tx->unfold_line(bpoints[0]); - tx->set_caret_line(bpoints[0]); - tx->center_viewport_to_caret(); - } else { - for (int i = 0; i < bpoints.size(); i++) { - int bline = bpoints[i]; - if (bline > line) { - tx->unfold_line(bline); - tx->set_caret_line(bline); - tx->center_viewport_to_caret(); - return; - } + int current_line = tx->get_caret_line(); + int bpoint_idx = 0; + if (current_line < (int)bpoints[bpoints.size() - 1]) { + while (bpoint_idx < bpoints.size() && bpoints[bpoint_idx] <= current_line) { + bpoint_idx++; } } - + code_editor->goto_line_centered(bpoints[bpoint_idx]); } break; case DEBUG_GOTO_PREV_BREAKPOINT: { PackedInt32Array bpoints = tx->get_breakpointed_lines(); @@ -1406,25 +1398,14 @@ void ScriptTextEditor::_edit_option(int p_op) { return; } - tx->remove_secondary_carets(); - int line = tx->get_caret_line(); - // wrap around - if (line <= (int)bpoints[0]) { - tx->unfold_line(bpoints[bpoints.size() - 1]); - tx->set_caret_line(bpoints[bpoints.size() - 1]); - tx->center_viewport_to_caret(); - } else { - for (int i = bpoints.size() - 1; i >= 0; i--) { - int bline = bpoints[i]; - if (bline < line) { - tx->unfold_line(bline); - tx->set_caret_line(bline); - tx->center_viewport_to_caret(); - return; - } + int current_line = tx->get_caret_line(); + int bpoint_idx = bpoints.size() - 1; + if (current_line > (int)bpoints[0]) { + while (bpoint_idx >= 0 && bpoints[bpoint_idx] >= current_line) { + bpoint_idx--; } } - + code_editor->goto_line_centered(bpoints[bpoint_idx]); } break; case HELP_CONTEXTUAL: { String text = tx->get_selected_text(0); @@ -1835,7 +1816,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { base = _find_node_for_script(base, base, script); } ScriptLanguage::LookupResult result; - if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) { + if (script->get_language()->lookup_code(tx->get_text_for_symbol_lookup(), word_at_pos, script->get_path(), base, result) == OK) { open_docs = true; } } diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 1ae419053e..4f0894a1a9 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -96,6 +96,7 @@ protected: static void _bind_methods(); public: + virtual String get_name() const override { return "Shader"; } virtual void edit(Object *p_object) override; virtual bool handles(Object *p_object) const override; virtual void make_visible(bool p_visible) override; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index baf5e363f8..d6079d6285 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -353,7 +353,9 @@ void TextEditor::_edit_option(int p_op) { code_editor->duplicate_selection(); } break; case EDIT_TOGGLE_FOLD_LINE: { - tx->toggle_foldable_line(tx->get_caret_line()); + for (int caret_idx = 0; caret_idx < tx->get_caret_count(); caret_idx++) { + tx->toggle_foldable_line(tx->get_caret_line(caret_idx)); + } tx->queue_redraw(); } break; case EDIT_FOLD_ALL_LINES: { diff --git a/editor/plugins/tiles/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp index e266d26b73..f892f3637d 100644 --- a/editor/plugins/tiles/atlas_merging_dialog.cpp +++ b/editor/plugins/tiles/atlas_merging_dialog.cpp @@ -236,7 +236,7 @@ void AtlasMergingDialog::update_tile_set(Ref<TileSet> p_tile_set) { if (atlas_source.is_valid()) { Ref<Texture2D> texture = atlas_source->get_texture(); if (texture.is_valid()) { - String item_text = vformat("%s (id:%d)", texture->get_path().get_file(), source_id); + String item_text = vformat(TTR("%s (ID: %d)"), texture->get_path().get_file(), source_id); atlas_merging_atlases_list->add_item(item_text, texture); atlas_merging_atlases_list->set_item_metadata(-1, source_id); } diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 993f606f2f..147bb5f4e9 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -1603,12 +1603,31 @@ void TileDataCollisionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transfor } RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), p_transform); + + Ref<Texture2D> one_way_icon = get_theme_icon(SNAME("OneWayTile"), SNAME("EditorIcons")); for (int i = 0; i < tile_data->get_collision_polygons_count(physics_layer); i++) { Vector<Vector2> polygon = tile_data->get_collision_polygon_points(physics_layer, i); - if (polygon.size() >= 3) { - p_canvas_item->draw_polygon(polygon, color); + if (polygon.size() < 3) { + continue; + } + + p_canvas_item->draw_polygon(polygon, color); + + if (tile_data->is_collision_polygon_one_way(physics_layer, i)) { + PackedVector2Array uvs; + uvs.resize(polygon.size()); + Vector2 size_1 = Vector2(1, 1) / tile_set->get_tile_size(); + + for (int j = 0; j < polygon.size(); j++) { + uvs.write[j] = polygon[j] * size_1 + Vector2(0.5, 0.5); + } + + Vector<Color> color2; + color2.push_back(Color(1, 1, 1, 0.4)); + p_canvas_item->draw_polygon(polygon, color2, uvs, one_way_icon); } } + RenderingServer::get_singleton()->canvas_item_add_set_transform(p_canvas_item->get_canvas_item(), Transform2D()); } diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index e622a0817a..0331e3f69e 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -156,7 +156,7 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() { // Common to all type of sources. if (!source->get_name().is_empty()) { - item_text = vformat(TTR("%s (id:%d)"), source->get_name(), source_id); + item_text = vformat(TTR("%s (ID: %d)"), source->get_name(), source_id); } // Atlas source. @@ -165,7 +165,7 @@ void TileMapEditorTilesPlugin::_update_tile_set_sources_list() { texture = atlas_source->get_texture(); if (item_text.is_empty()) { if (texture.is_valid()) { - item_text = vformat("%s (ID: %d)", texture->get_path().get_file(), source_id); + item_text = vformat(TTR("%s (ID: %d)"), texture->get_path().get_file(), source_id); } else { item_text = vformat(TTR("No Texture Atlas Source (ID: %d)"), source_id); } @@ -472,6 +472,7 @@ void TileMapEditorTilesPlugin::_update_theme() { random_tile_toggle->set_icon(tiles_bottom_panel->get_theme_icon(SNAME("RandomNumberGenerator"), SNAME("EditorIcons"))); missing_atlas_texture_icon = tiles_bottom_panel->get_theme_icon(SNAME("TileSet"), SNAME("EditorIcons")); + _update_tile_set_sources_list(); } bool TileMapEditorTilesPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { @@ -1164,7 +1165,7 @@ HashMap<Vector2i, TileMapCell> TileMapEditorTilesPlugin::_draw_bucket_fill(Vecto } // Get surrounding tiles (handles different tile shapes). - TypedArray<Vector2i> around = tile_map->get_surrounding_tiles(coords); + TypedArray<Vector2i> around = tile_map->get_surrounding_cells(coords); for (int i = 0; i < around.size(); i++) { to_check.push_back(around[i]); } @@ -1697,7 +1698,7 @@ void TileMapEditorTilesPlugin::_tile_atlas_control_draw() { if (frame > 0) { color.a *= 0.3; } - tile_atlas_control->draw_rect(atlas->get_tile_texture_region(E.get_atlas_coords(), frame), color, false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, atlas->get_tile_texture_region(E.get_atlas_coords(), frame), color); } } } @@ -1705,11 +1706,8 @@ void TileMapEditorTilesPlugin::_tile_atlas_control_draw() { // Draw the hovered tile. if (hovered_tile.get_atlas_coords() != TileSetSource::INVALID_ATLAS_COORDS && hovered_tile.alternative_tile == 0 && !tile_set_dragging_selection) { for (int frame = 0; frame < atlas->get_tile_animation_frames_count(hovered_tile.get_atlas_coords()); frame++) { - Color color = Color(1.0, 1.0, 1.0); - if (frame > 0) { - color.a *= 0.3; - } - tile_atlas_control->draw_rect(atlas->get_tile_texture_region(hovered_tile.get_atlas_coords(), frame), color, false); + Color color = Color(1.0, 0.8, 0.0, frame == 0 ? 0.6 : 0.3); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, atlas->get_tile_texture_region(hovered_tile.get_atlas_coords(), frame), color); } } @@ -1730,9 +1728,8 @@ void TileMapEditorTilesPlugin::_tile_atlas_control_draw() { } } } - Color selection_rect_color = selection_color.lightened(0.2); for (const Vector2i &E : to_draw) { - tile_atlas_control->draw_rect(atlas->get_tile_texture_region(E), selection_rect_color, false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, atlas->get_tile_texture_region(E)); } } } @@ -1881,7 +1878,7 @@ void TileMapEditorTilesPlugin::_tile_alternatives_control_draw() { if (E.source_id == source_id && E.get_atlas_coords() != TileSetSource::INVALID_ATLAS_COORDS && E.alternative_tile > 0) { Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E.get_atlas_coords(), E.alternative_tile); if (rect != Rect2i()) { - alternative_tiles_control->draw_rect(rect, Color(0.2, 0.2, 1.0), false); + TilesEditorPlugin::draw_selection_rect(alternative_tiles_control, rect); } } } @@ -1890,7 +1887,7 @@ void TileMapEditorTilesPlugin::_tile_alternatives_control_draw() { if (hovered_tile.get_atlas_coords() != TileSetSource::INVALID_ATLAS_COORDS && hovered_tile.alternative_tile > 0) { Rect2i rect = tile_atlas_view->get_alternative_tile_rect(hovered_tile.get_atlas_coords(), hovered_tile.alternative_tile); if (rect != Rect2i()) { - alternative_tiles_control->draw_rect(rect, Color(1.0, 1.0, 1.0), false); + TilesEditorPlugin::draw_selection_rect(alternative_tiles_control, rect, Color(1.0, 0.8, 0.0, 0.5)); } } } @@ -2547,7 +2544,7 @@ RBSet<Vector2i> TileMapEditorTerrainsPlugin::_get_cells_for_bucket_fill(Vector2i output.insert(coords); // Get surrounding tiles (handles different tile shapes). - TypedArray<Vector2i> around = tile_map->get_surrounding_tiles(coords); + TypedArray<Vector2i> around = tile_map->get_surrounding_cells(coords); for (int i = 0; i < around.size(); i++) { to_check.push_back(around[i]); } diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp index 40557f9b8e..b31fb1aa58 100644 --- a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp @@ -77,7 +77,7 @@ void TileProxiesManagerDialog::_delete_selected_bindings() { Vector<int> alternative_level_selected = alternative_level_list->get_selected_items(); for (int i = 0; i < alternative_level_selected.size(); i++) { Array key = alternative_level_list->get_item_metadata(alternative_level_selected[i]); - Array val = tile_set->get_coords_level_tile_proxy(key[0], key[1]); + Array val = tile_set->get_alternative_level_tile_proxy(key[0], key[1], key[2]); undo_redo->add_do_method(*tile_set, "remove_alternative_level_tile_proxy", key[0], key[1], key[2]); undo_redo->add_undo_method(*tile_set, "set_alternative_level_tile_proxy", key[0], key[1], key[2], val[0], val[1], val[2]); } diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index 7ed84423bc..524a1fa38a 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -1684,10 +1684,6 @@ Array TileSetAtlasSourceEditor::_get_selection_as_array() { } void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { - // Colors. - Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color"); - Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); - // Draw the selected tile. if (tools_button_group->get_pressed_button() == tool_select_button) { for (const TileSelection &E : selection) { @@ -1695,12 +1691,9 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { if (selected.alternative == 0) { // Draw the rect. for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(selected.tile); frame++) { - Color color = selection_color; - if (frame > 0) { - color.a *= 0.3; - } + Color color = Color(0.0, 1.0, 0.0, frame == 0 ? 1.0 : 0.3); Rect2 region = tile_set_atlas_source->get_tile_texture_region(selected.tile, frame); - tile_atlas_control->draw_rect(region, color, false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, region, color); } } } @@ -1742,7 +1735,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { // Draw the tiles to be removed. for (const Vector2i &E : drag_modified_tiles) { for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(E); frame++) { - tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(E, frame), Color(0.0, 0.0, 0.0), false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, tile_set_atlas_source->get_tile_texture_region(E, frame), Color(0.0, 0.0, 0.0)); } } } else if (drag_type == DRAG_TYPE_RECT_SELECT || drag_type == DRAG_TYPE_REMOVE_TILES_USING_RECT) { @@ -1754,7 +1747,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { Color color = Color(0.0, 0.0, 0.0); if (drag_type == DRAG_TYPE_RECT_SELECT) { - color = selection_color.lightened(0.2); + color = Color(1.0, 1.0, 0.0); } RBSet<Vector2i> to_paint; @@ -1769,7 +1762,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { for (const Vector2i &E : to_paint) { Vector2i coords = E; - tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(coords), color, false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, tile_set_atlas_source->get_tile_texture_region(coords), color); } } else if (drag_type == DRAG_TYPE_CREATE_TILES_USING_RECT) { // Draw tiles to be created. @@ -1786,7 +1779,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { Vector2i coords = Vector2i(x, y); if (tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) { Vector2i origin = margins + (coords * (tile_size + separation)); - tile_atlas_control->draw_rect(Rect2i(origin, tile_size), Color(1.0, 1.0, 1.0), false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, Rect2i(origin, tile_size)); } } } @@ -1803,7 +1796,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { Vector2i separation = tile_set_atlas_source->get_separation(); Vector2i tile_size = tile_set_atlas_source->get_texture_region_size(); Vector2i origin = margins + (area.position * (tile_size + separation)); - tile_atlas_control->draw_rect(Rect2i(origin, area.size * tile_size), Color(1.0, 1.0, 1.0), false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, Rect2i(origin, area.size * tile_size)); } else { Vector2i grid_size = tile_set_atlas_source->get_atlas_grid_size(); if (hovered_base_tile_coords.x >= 0 && hovered_base_tile_coords.y >= 0 && hovered_base_tile_coords.x < grid_size.x && hovered_base_tile_coords.y < grid_size.y) { @@ -1811,11 +1804,8 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { if (hovered_tile != TileSetSource::INVALID_ATLAS_COORDS) { // Draw existing hovered tile. for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(hovered_tile); frame++) { - Color color = Color(1.0, 1.0, 1.0); - if (frame > 0) { - color.a *= 0.3; - } - tile_atlas_control->draw_rect(tile_set_atlas_source->get_tile_texture_region(hovered_tile, frame), color, false); + Color color = Color(1.0, 0.8, 0.0, frame == 0 ? 0.6 : 0.3); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, tile_set_atlas_source->get_tile_texture_region(hovered_tile, frame), color); } } else { // Draw empty tile, only in add/remove tiles mode. @@ -1824,7 +1814,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_draw() { Vector2i separation = tile_set_atlas_source->get_separation(); Vector2i tile_size = tile_set_atlas_source->get_texture_region_size(); Vector2i origin = margins + (hovered_base_tile_coords * (tile_size + separation)); - tile_atlas_control->draw_rect(Rect2i(origin, tile_size), Color(1.0, 1.0, 1.0), false); + TilesEditorPlugin::draw_selection_rect(tile_atlas_control, Rect2i(origin, tile_size)); } } } @@ -1976,9 +1966,6 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_mouse_exited() { } void TileSetAtlasSourceEditor::_tile_alternatives_control_draw() { - Color grid_color = EDITOR_GET("editors/tiles_editor/grid_color"); - Color selection_color = Color().from_hsv(Math::fposmod(grid_color.get_h() + 0.5, 1.0), grid_color.get_s(), grid_color.get_v(), 1.0); - // Update the hovered alternative tile. if (tools_button_group->get_pressed_button() == tool_select_button) { // Draw hovered tile. @@ -1986,7 +1973,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_draw() { if (coords != TileSetSource::INVALID_ATLAS_COORDS) { Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, hovered_alternative_tile_coords.z); if (rect != Rect2i()) { - alternative_tiles_control->draw_rect(rect, Color(1.0, 1.0, 1.0), false); + TilesEditorPlugin::draw_selection_rect(alternative_tiles_control, rect, Color(1.0, 0.8, 0.0, 0.5)); } } @@ -1996,7 +1983,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_draw() { if (selected.alternative >= 1) { Rect2i rect = tile_atlas_view->get_alternative_tile_rect(selected.tile, selected.alternative); if (rect != Rect2i()) { - alternative_tiles_control->draw_rect(rect, selection_color, false); + TilesEditorPlugin::draw_selection_rect(alternative_tiles_control, rect); } } } diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index b24c5059b0..e8ceacf8f8 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -120,7 +120,9 @@ bool TileSetEditor::_can_drop_data_fw(const Point2 &p_point, const Variant &p_da } void TileSetEditor::_update_sources_list(int force_selected_id) { - ERR_FAIL_COND(!tile_set.is_valid()); + if (tile_set.is_null()) { + return; + } // Get the previously selected id. int old_selected = TileSet::INVALID_SOURCE; @@ -151,7 +153,7 @@ void TileSetEditor::_update_sources_list(int force_selected_id) { // Common to all type of sources. if (!source->get_name().is_empty()) { - item_text = vformat(TTR("%s (id:%d)"), source->get_name(), source_id); + item_text = vformat(TTR("%s (ID: %d)"), source->get_name(), source_id); } // Atlas source. @@ -160,7 +162,7 @@ void TileSetEditor::_update_sources_list(int force_selected_id) { texture = atlas_source->get_texture(); if (item_text.is_empty()) { if (texture.is_valid()) { - item_text = vformat("%s (ID: %d)", texture->get_path().get_file(), source_id); + item_text = vformat(TTR("%s (ID: %d)"), texture->get_path().get_file(), source_id); } else { item_text = vformat(TTR("No Texture Atlas Source (ID: %d)"), source_id); } @@ -346,6 +348,7 @@ void TileSetEditor::_notification(int p_what) { source_sort_button->set_icon(get_theme_icon(SNAME("Sort"), SNAME("EditorIcons"))); sources_advanced_menu_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); missing_texture_texture = get_theme_icon(SNAME("TileSet"), SNAME("EditorIcons")); + _update_sources_list(); } break; case NOTIFICATION_INTERNAL_PROCESS: { diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 5d93f58f34..ee29913334 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -385,6 +385,15 @@ bool TilesEditorPlugin::handles(Object *p_object) const { return p_object->is_class("TileMap") || p_object->is_class("TileSet"); } +void TilesEditorPlugin::draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color) { + real_t scale = p_ci->get_global_transform().get_scale().x * 0.5; + p_ci->draw_set_transform(p_rect.position, 0, Vector2(1, 1) / scale); + RS::get_singleton()->canvas_item_add_nine_patch( + p_ci->get_canvas_item(), Rect2(Vector2(), p_rect.size * scale), Rect2(), EditorNode::get_singleton()->get_gui_base()->get_theme_icon(SNAME("TileSelection"), SNAME("EditorIcons"))->get_rid(), + Vector2(2, 2), Vector2(2, 2), RS::NINE_PATCH_STRETCH, RS::NINE_PATCH_STRETCH, false, p_color); + p_ci->draw_set_transform_matrix(Transform2D()); +} + TilesEditorPlugin::TilesEditorPlugin() { set_process_internal(true); diff --git a/editor/plugins/tiles/tiles_editor_plugin.h b/editor/plugins/tiles/tiles_editor_plugin.h index fe0d8179bc..825a10dac2 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.h +++ b/editor/plugins/tiles/tiles_editor_plugin.h @@ -128,6 +128,8 @@ public: virtual bool handles(Object *p_object) const override; virtual void make_visible(bool p_visible) override; + static void draw_selection_rect(CanvasItem *p_ci, const Rect2 &p_rect, const Color &p_color = Color(1.0, 1.0, 1.0)); + TilesEditorPlugin(); ~TilesEditorPlugin(); }; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 9990d5c06f..cf811067c9 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -269,6 +269,19 @@ void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_no links[p_node_id].expression_edit->set_text(p_expression); } +Ref<Script> VisualShaderGraphPlugin::get_node_script(int p_node_id) const { + if (!links.has(p_node_id)) { + return Ref<Script>(); + } + + Ref<VisualShaderNodeCustom> custom = Ref<VisualShaderNodeCustom>(links[p_node_id].visual_node); + if (custom.is_valid()) { + return custom->get_script(); + } + + return Ref<Script>(); +} + void VisualShaderGraphPlugin::update_node_size(int p_node_id) { if (!links.has(p_node_id)) { return; @@ -1137,10 +1150,6 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { } } -void VisualShaderEditor::update_nodes() { - _update_nodes(); -} - void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) { if (plugins.has(p_plugin)) { return; @@ -1202,6 +1211,228 @@ void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> add_options.push_back(ao); } +Dictionary VisualShaderEditor::get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node) { + Dictionary dict; + dict["script"] = p_custom_node->get_script(); + + String name; + if (p_custom_node->has_method("_get_name")) { + name = (String)p_custom_node->call("_get_name"); + } else { + name = "Unnamed"; + } + dict["name"] = name; + + String description = ""; + if (p_custom_node->has_method("_get_description")) { + description = (String)p_custom_node->call("_get_description"); + } + dict["description"] = description; + + int return_icon_type = -1; + if (p_custom_node->has_method("_get_return_icon_type")) { + return_icon_type = (int)p_custom_node->call("_get_return_icon_type"); + } + dict["return_icon_type"] = return_icon_type; + + String category = ""; + if (p_custom_node->has_method("_get_category")) { + category = (String)p_custom_node->call("_get_category"); + } + category = category.rstrip("/"); + category = category.lstrip("/"); + category = "Addons/" + category; + + String subcategory = ""; + if (p_custom_node->has_method("_get_subcategory")) { + subcategory = (String)p_custom_node->call("_get_subcategory"); + } + if (!subcategory.is_empty()) { + category += "/" + subcategory; + } + dict["category"] = category; + + bool highend = false; + if (p_custom_node->has_method("_is_highend")) { + highend = (bool)p_custom_node->call("_is_highend"); + } + dict["highend"] = highend; + + return dict; +} + +void VisualShaderEditor::update_custom_type(const Ref<Resource> &p_resource) { + Ref<Script> scr = Ref<Script>(p_resource.ptr()); + if (scr.is_null() || scr->get_instance_base_type() != String("VisualShaderNodeCustom")) { + return; + } + + Ref<VisualShaderNodeCustom> ref; + ref.instantiate(); + ref->set_script(scr); + if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) { + for (int i = 0; i < add_options.size(); i++) { + if (add_options[i].is_custom && add_options[i].script == scr) { + add_options.remove_at(i); + _update_options_menu(); + // TODO: Make indication for the existed custom nodes with that script on graph to be disabled. + break; + } + } + return; + } + Dictionary dict = get_custom_node_data(ref); + + bool found_type = false; + bool need_rebuild = false; + + for (int i = 0; i < add_options.size(); i++) { + if (add_options[i].is_custom && add_options[i].script == scr) { + found_type = true; + + add_options.write[i].name = dict["name"]; + add_options.write[i].return_type = dict["return_icon_type"]; + add_options.write[i].description = dict["description"]; + add_options.write[i].category = dict["category"]; + add_options.write[i].highend = dict["highend"]; + + int max_type = 0; + int type_offset = 0; + switch (visual_shader->get_mode()) { + case Shader::MODE_CANVAS_ITEM: + case Shader::MODE_SPATIAL: { + max_type = 3; + } break; + case Shader::MODE_PARTICLES: { + max_type = 5; + type_offset = 3; + } break; + case Shader::MODE_SKY: { + max_type = 1; + type_offset = 8; + } break; + case Shader::MODE_FOG: { + max_type = 1; + type_offset = 9; + } break; + default: { + } break; + } + max_type = type_offset + max_type; + + for (int t = type_offset; t < max_type; t++) { + VisualShader::Type type = (VisualShader::Type)t; + Vector<int> nodes = visual_shader->get_node_list(type); + + List<VisualShader::Connection> node_connections; + visual_shader->get_node_connections(type, &node_connections); + + List<VisualShader::Connection> custom_node_input_connections; + List<VisualShader::Connection> custom_node_output_connections; + for (const VisualShader::Connection &E : node_connections) { + int from = E.from_node; + int from_idx = E.from_port; + int to = E.to_node; + int to_idx = E.to_port; + + if (graph_plugin->get_node_script(from) == scr) { + custom_node_output_connections.push_back({ from, from_idx, to, to_idx }); + } else if (graph_plugin->get_node_script(to) == scr) { + custom_node_input_connections.push_back({ from, from_idx, to, to_idx }); + } + } + + for (int j = 0; j < nodes.size(); j++) { + int node_id = nodes[j]; + + Ref<VisualShaderNode> vsnode = visual_shader->get_node(type, node_id); + if (vsnode.is_null()) { + continue; + } + Ref<VisualShaderNodeCustom> custom_node = Ref<VisualShaderNodeCustom>(vsnode.ptr()); + if (custom_node.is_null() || custom_node->get_script() != scr) { + continue; + } + need_rebuild = true; + + // Removes invalid connections. + { + int prev_input_port_count = custom_node->get_input_port_count(); + int prev_output_port_count = custom_node->get_output_port_count(); + + custom_node->update_ports(); + + int input_port_count = custom_node->get_input_port_count(); + int output_port_count = custom_node->get_output_port_count(); + + if (output_port_count != prev_output_port_count) { + for (const VisualShader::Connection &E : custom_node_output_connections) { + int from = E.from_node; + int from_idx = E.from_port; + int to = E.to_node; + int to_idx = E.to_port; + + if (from_idx >= output_port_count) { + visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx); + graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx); + } + } + } + if (input_port_count != prev_input_port_count) { + for (const VisualShader::Connection &E : custom_node_input_connections) { + int from = E.from_node; + int from_idx = E.from_port; + int to = E.to_node; + int to_idx = E.to_port; + + if (to_idx >= input_port_count) { + visual_shader->disconnect_nodes(type, from, from_idx, to, to_idx); + graph_plugin->disconnect_nodes(type, from, from_idx, to, to_idx); + } + } + } + } + + graph_plugin->update_node(type, node_id); + } + } + break; + } + } + + if (!found_type) { + add_custom_type(dict["name"], dict["script"], dict["description"], dict["return_icon_type"], dict["category"], dict["highend"]); + } + + // To prevent updating options multiple times when multiple scripts are saved. + if (!_block_update_options_menu) { + _block_update_options_menu = true; + + call_deferred(SNAME("_update_options_menu_deferred")); + } + + // To prevent rebuilding the shader multiple times when multiple scripts are saved. + if (need_rebuild && !_block_rebuild_shader) { + _block_rebuild_shader = true; + + call_deferred(SNAME("_rebuild_shader_deferred")); + } +} + +void VisualShaderEditor::_update_options_menu_deferred() { + _update_options_menu(); + + _block_update_options_menu = false; +} + +void VisualShaderEditor::_rebuild_shader_deferred() { + if (visual_shader.is_valid()) { + visual_shader->rebuild(); + } + + _block_rebuild_shader = false; +} + bool VisualShaderEditor::_is_available(int p_mode) { int current_mode = edit_type->get_selected(); @@ -1243,57 +1474,10 @@ void VisualShaderEditor::_update_nodes() { if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) { continue; } - - String name; - if (ref->has_method("_get_name")) { - name = (String)ref->call("_get_name"); - } else { - name = "Unnamed"; - } - - String description = ""; - if (ref->has_method("_get_description")) { - description = (String)ref->call("_get_description"); - } - - int return_icon_type = -1; - if (ref->has_method("_get_return_icon_type")) { - return_icon_type = (int)ref->call("_get_return_icon_type"); - } - - String category = ""; - if (ref->has_method("_get_category")) { - category = (String)ref->call("_get_category"); - } - - String subcategory = ""; - if (ref->has_method("_get_subcategory")) { - subcategory = (String)ref->call("_get_subcategory"); - } - - bool highend = false; - if (ref->has_method("_is_highend")) { - highend = (bool)ref->call("_is_highend"); - } - - Dictionary dict; - dict["name"] = name; - dict["script"] = scr; - dict["description"] = description; - dict["return_icon_type"] = return_icon_type; - - category = category.rstrip("/"); - category = category.lstrip("/"); - category = "Addons/" + category; - if (!subcategory.is_empty()) { - category += "/" + subcategory; - } - - dict["category"] = category; - dict["highend"] = highend; + Dictionary dict = get_custom_node_data(ref); String key; - key = category + "/" + name; + key = String(dict["category"]) + "/" + String(dict["name"]); added[key] = dict; } @@ -4694,6 +4878,8 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_update_constant", &VisualShaderEditor::_update_constant); ClassDB::bind_method("_update_parameter", &VisualShaderEditor::_update_parameter); ClassDB::bind_method("_expand_output_port", &VisualShaderEditor::_expand_output_port); + ClassDB::bind_method("_update_options_menu_deferred", &VisualShaderEditor::_update_options_menu_deferred); + ClassDB::bind_method("_rebuild_shader_deferred", &VisualShaderEditor::_rebuild_shader_deferred); ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw); @@ -4704,6 +4890,7 @@ void VisualShaderEditor::_bind_methods() { VisualShaderEditor::VisualShaderEditor() { ShaderLanguage::get_keyword_list(&keyword_list); + EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &VisualShaderEditor::update_custom_type)); graph = memnew(GraphEdit); graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 8afad9f668..d559237569 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -133,6 +133,7 @@ public: void update_curve_xyz(int p_node_id); void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); int get_constant_index(float p_constant) const; + Ref<Script> get_node_script(int p_node_id) const; void update_node_size(int p_node_id); void update_theme(); VisualShader::Type get_shader_type() const; @@ -190,6 +191,9 @@ class VisualShaderEditor : public VBoxContainer { PanelContainer *error_panel = nullptr; Label *error_label = nullptr; + bool _block_update_options_menu = false; + bool _block_rebuild_shader = false; + Point2 saved_node_pos; bool saved_node_pos_dirty = false; @@ -497,6 +501,9 @@ class VisualShaderEditor : public VBoxContainer { void _update_parameter_refs(HashSet<String> &p_names); void _update_varyings(); + void _update_options_menu_deferred(); + void _rebuild_shader_deferred(); + void _visibility_changed(); protected: @@ -504,7 +511,6 @@ protected: static void _bind_methods(); public: - void update_nodes(); void add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); void remove_plugin(const Ref<VisualShaderNodePlugin> &p_plugin); @@ -513,6 +519,9 @@ public: void clear_custom_types(); void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, bool p_highend); + Dictionary get_custom_node_data(Ref<VisualShaderNodeCustom> &p_custom_node); + void update_custom_type(const Ref<Resource> &p_resource); + virtual Size2 get_minimum_size() const override; void edit(VisualShader *p_visual_shader); VisualShaderEditor(); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 1e917e6b3d..b406b2a1ce 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -280,6 +280,8 @@ void ProjectSettingsEditor::_add_feature_overrides() { presets.insert("debug"); presets.insert("release"); presets.insert("template"); + presets.insert("double"); + presets.insert("single"); presets.insert("32"); presets.insert("64"); presets.insert("movie"); diff --git a/main/main.cpp b/main/main.cpp index c2e2238482..09cec68ef9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1862,6 +1862,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph GLOBAL_DEF_BASIC("xr/openxr/reference_space", "1"); ProjectSettings::get_singleton()->set_custom_property_info("xr/openxr/reference_space", PropertyInfo(Variant::INT, "xr/openxr/reference_space", PROPERTY_HINT_ENUM, "Local,Stage")); + GLOBAL_DEF_BASIC("xr/openxr/submit_depth_buffer", false); + #ifdef TOOLS_ENABLED // Disabled for now, using XR inside of the editor we'll be working on during the coming months. @@ -2233,13 +2235,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { - bool found_touchscreen = false; - for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { - if (DisplayServer::get_singleton()->screen_is_touchscreen(i)) { - found_touchscreen = true; - } - } - if (!found_touchscreen) { + if (!DisplayServer::get_singleton()->is_touchscreen_available()) { //only if no touchscreen ui hint, set emulation id->set_emulate_touch_from_mouse(true); } @@ -3332,6 +3328,8 @@ void Main::cleanup(bool p_force) { ResourceLoader::clear_translation_remaps(); ResourceLoader::clear_path_remaps(); + ResourceLoader::clear_thread_load_tasks(); + ScriptServer::finish_languages(); // Sync pending commands that may have been queued from a different thread during ScriptServer finalization @@ -3365,6 +3363,7 @@ void Main::cleanup(bool p_force) { finalize_theme_db(); // Before deinitializing server extensions, finalize servers which may be loaded as extensions. + finalize_navigation_server(); finalize_physics(); NativeExtensionManager::get_singleton()->deinitialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SERVERS); @@ -3388,7 +3387,6 @@ void Main::cleanup(bool p_force) { OS::get_singleton()->finalize(); - finalize_navigation_server(); finalize_display(); if (input) { diff --git a/methods.py b/methods.py index f4afead9f4..99a59b49e3 100644 --- a/methods.py +++ b/methods.py @@ -774,7 +774,7 @@ def generate_vs_project(env, num_jobs): for platform in ModuleConfigs.PLATFORMS ] self.arg_dict["runfile"] += [ - f'bin\\godot.windows.{config}{ModuleConfigs.DEV_SUFFIX}{".double" if env["float"] == "64" else ""}.{plat_id}{f".{name}" if name else ""}.exe' + f'bin\\godot.windows.{config}{ModuleConfigs.DEV_SUFFIX}{".double" if env["precision"] == "double" else ""}.{plat_id}{f".{name}" if name else ""}.exe' for config in ModuleConfigs.CONFIGURATIONS for plat_id in ModuleConfigs.PLATFORM_IDS ] @@ -820,8 +820,8 @@ def generate_vs_project(env, num_jobs): if env["custom_modules"]: common_build_postfix.append("custom_modules=%s" % env["custom_modules"]) - if env["float"] == "64": - common_build_postfix.append("float=64") + if env["precision"] == "double": + common_build_postfix.append("precision=double") result = " ^& ".join(common_build_prefix + [" ".join([commands] + common_build_postfix)]) return result diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index c8195de640..91f31174dd 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -478,7 +478,7 @@ void GDScript::_clear_doc() { void GDScript::_update_doc() { _clear_doc(); - doc.script_path = "\"" + get_path().get_slice("://", 1) + "\""; + doc.script_path = vformat(R"("%s")", get_script_path().get_slice("://", 1)); if (!name.is_empty()) { doc.name = name; } else { @@ -701,6 +701,7 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderSc Variant default_value; if (member.variable->initializer && member.variable->initializer->is_constant) { default_value = member.variable->initializer->reduced_value; + GDScriptCompiler::convert_to_initializer_type(default_value, member.variable); } member_default_values_cache[member.variable->identifier->name] = default_value; } break; @@ -801,9 +802,9 @@ void GDScript::update_exports() { String GDScript::_get_debug_path() const { if (is_built_in() && !get_name().is_empty()) { - return get_name() + " (" + get_path() + ")"; + return vformat("%s(%s)", get_name(), get_script_path()); } else { - return get_path(); + return get_script_path(); } } @@ -904,7 +905,7 @@ Error GDScript::reload(bool p_keep_state) { for (const GDScriptWarning &warning : parser.get_warnings()) { if (EngineDebugger::is_active()) { Vector<ScriptLanguage::StackInfo> si; - EngineDebugger::get_script_debugger()->send_error("", get_path(), warning.start_line, warning.get_name(), warning.get_message(), false, ERR_HANDLER_WARNING, si); + EngineDebugger::get_script_debugger()->send_error("", get_script_path(), warning.start_line, warning.get_name(), warning.get_message(), false, ERR_HANDLER_WARNING, si); } } #endif @@ -1027,6 +1028,10 @@ void GDScript::set_path(const String &p_path, bool p_take_over) { } } +String GDScript::get_script_path() const { + return path; +} + Error GDScript::load_source_code(const String &p_path) { if (p_path.is_empty() || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") { return OK; @@ -1347,13 +1352,11 @@ void GDScript::_get_dependencies(RBSet<GDScript *> &p_dependencies, const GDScri GDScript::GDScript() : script_list(this) { -#ifdef DEBUG_ENABLED { MutexLock lock(GDScriptLanguage::get_singleton()->mutex); GDScriptLanguage::get_singleton()->script_list.add(&script_list); } -#endif } void GDScript::_save_orphaned_subclasses() { @@ -1487,13 +1490,11 @@ GDScript::~GDScript() { } } -#ifdef DEBUG_ENABLED { MutexLock lock(GDScriptLanguage::get_singleton()->mutex); GDScriptLanguage::get_singleton()->script_list.remove(&script_list); } -#endif if (GDScriptCache::singleton) { // Cache may have been already destroyed at engine shutdown. GDScriptCache::remove_script(get_path()); @@ -2164,7 +2165,8 @@ void GDScriptLanguage::reload_all_scripts() { SelfList<GDScript> *elem = script_list.first(); while (elem) { - if (elem->self()->get_path().is_resource_file()) { + // Scripts will reload all subclasses, so only reload root scripts. + if (elem->self()->is_root_script() && elem->self()->get_path().is_resource_file()) { print_verbose("GDScript: Found: " + elem->self()->get_path()); scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident } @@ -2193,7 +2195,8 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so SelfList<GDScript> *elem = script_list.first(); while (elem) { - if (elem->self()->get_path().is_resource_file()) { + // Scripts will reload all subclasses, so only reload root scripts. + if (elem->self()->is_root_script() && elem->self()->get_path().is_resource_file()) { scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident } elem = elem->next(); diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 2df89d812c..7911ea47ec 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -240,6 +240,7 @@ public: virtual Error reload(bool p_keep_state = false) override; virtual void set_path(const String &p_path, bool p_take_over = false) override; + String get_script_path() const; Error load_source_code(const String &p_path); Error load_byte_code(const String &p_path); @@ -432,7 +433,7 @@ public: csi.write[_debug_call_stack_pos - i - 1].line = _call_stack[i].line ? *_call_stack[i].line : 0; if (_call_stack[i].function) { csi.write[_debug_call_stack_pos - i - 1].func = _call_stack[i].function->get_name(); - csi.write[_debug_call_stack_pos - i - 1].file = _call_stack[i].function->get_script()->get_path(); + csi.write[_debug_call_stack_pos - i - 1].file = _call_stack[i].function->get_script()->get_script_path(); } } return csi; diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 663d72038d..81e50d6b79 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -219,6 +219,22 @@ Error GDScriptAnalyzer::check_class_member_name_conflict(const GDScriptParser::C return OK; } +void GDScriptAnalyzer::get_class_node_current_scope_classes(GDScriptParser::ClassNode *p_node, List<GDScriptParser::ClassNode *> *p_list) { + if (p_list->find(p_node) != nullptr) { + return; + } + p_list->push_back(p_node); + + // Prioritize node base type over its outer class + if (p_node->base_type.class_type != nullptr) { + get_class_node_current_scope_classes(p_node->base_type.class_type, p_list); + } + + if (p_node->outer != nullptr) { + get_class_node_current_scope_classes(p_node->outer, p_list); + } +} + Error GDScriptAnalyzer::resolve_inheritance(GDScriptParser::ClassNode *p_class, bool p_recursive) { if (p_class->base_type.is_set()) { // Already resolved @@ -327,9 +343,10 @@ Error GDScriptAnalyzer::resolve_inheritance(GDScriptParser::ClassNode *p_class, base.native_type = name; } else { // Look for other classes in script. - GDScriptParser::ClassNode *look_class = p_class; bool found = false; - while (look_class != nullptr) { + List<GDScriptParser::ClassNode *> script_classes; + get_class_node_current_scope_classes(p_class, &script_classes); + for (GDScriptParser::ClassNode *look_class : script_classes) { if (look_class->identifier && look_class->identifier->name == name) { if (!look_class->get_datatype().is_set()) { Error err = resolve_inheritance(look_class, false); @@ -353,7 +370,6 @@ Error GDScriptAnalyzer::resolve_inheritance(GDScriptParser::ClassNode *p_class, found = true; break; } - look_class = look_class->outer; } if (!found) { @@ -517,12 +533,11 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type result = make_native_enum_type(parser->current_class->base_type.native_type, first); } else { // Classes in current scope. - GDScriptParser::ClassNode *script_class = parser->current_class; - bool found = false; - while (!found && script_class != nullptr) { + List<GDScriptParser::ClassNode *> script_classes; + get_class_node_current_scope_classes(parser->current_class, &script_classes); + for (GDScriptParser::ClassNode *script_class : script_classes) { if (script_class->identifier && script_class->identifier->name == first) { result = script_class->get_datatype(); - found = true; break; } if (script_class->members_indices.has(first)) { @@ -530,24 +545,21 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type switch (member.type) { case GDScriptParser::ClassNode::Member::CLASS: result = member.m_class->get_datatype(); - found = true; break; case GDScriptParser::ClassNode::Member::ENUM: result = member.m_enum->get_datatype(); - found = true; break; case GDScriptParser::ClassNode::Member::CONSTANT: if (member.constant->get_datatype().is_meta_type) { result = member.constant->get_datatype(); result.is_meta_type = false; - found = true; break; } else if (Ref<Script>(member.constant->initializer->reduced_value).is_valid()) { Ref<GDScript> gdscript = member.constant->initializer->reduced_value; if (gdscript.is_valid()) { - Ref<GDScriptParserRef> ref = get_parser_for(gdscript->get_path()); + Ref<GDScriptParserRef> ref = get_parser_for(gdscript->get_script_path()); if (ref->raise_status(GDScriptParserRef::INTERFACE_SOLVED) != OK) { - push_error(vformat(R"(Could not parse script from "%s".)", gdscript->get_path()), p_type); + push_error(vformat(R"(Could not parse script from "%s".)", gdscript->get_script_path()), p_type); return GDScriptParser::DataType(); } result = ref->get_parser()->head->get_datatype(); @@ -569,7 +581,6 @@ GDScriptParser::DataType GDScriptAnalyzer::resolve_datatype(GDScriptParser::Type return GDScriptParser::DataType(); } } - script_class = script_class->outer; } } if (!result.is_set()) { @@ -2160,7 +2171,7 @@ void GDScriptAnalyzer::reduce_binary_op(GDScriptParser::BinaryOpNode *p_binary_o GDScriptParser::DataType test_type = right_type; test_type.is_meta_type = false; - if (!is_type_compatible(test_type, p_binary_op->left_operand->get_datatype(), false)) { + if (!is_type_compatible(test_type, left_type, false)) { push_error(vformat(R"(Expression is of type "%s" so it can't be of type "%s".)"), p_binary_op->left_operand); p_binary_op->reduced_value = false; } else { @@ -2194,11 +2205,11 @@ void GDScriptAnalyzer::reduce_binary_op(GDScriptParser::BinaryOpNode *p_binary_o GDScriptParser::DataType test_type = right_type; test_type.is_meta_type = false; - if (!is_type_compatible(test_type, p_binary_op->left_operand->get_datatype(), false)) { + if (!is_type_compatible(test_type, left_type, false)) { // Test reverse as well to consider for subtypes. - if (!is_type_compatible(p_binary_op->left_operand->get_datatype(), test_type, false)) { - if (p_binary_op->left_operand->get_datatype().is_hard_type()) { - push_error(vformat(R"(Expression is of type "%s" so it can't be of type "%s".)", p_binary_op->left_operand->get_datatype().to_string(), test_type.to_string()), p_binary_op->left_operand); + if (!is_type_compatible(left_type, test_type, false)) { + if (left_type.is_hard_type()) { + push_error(vformat(R"(Expression is of type "%s" so it can't be of type "%s".)", left_type.to_string(), test_type.to_string()), p_binary_op->left_operand); } else { // TODO: Warning. mark_node_unsafe(p_binary_op); @@ -2676,7 +2687,7 @@ void GDScriptAnalyzer::reduce_cast(GDScriptParser::CastNode *p_cast) { } void GDScriptAnalyzer::reduce_dictionary(GDScriptParser::DictionaryNode *p_dictionary) { - HashMap<Variant, GDScriptParser::ExpressionNode *, VariantHasher, VariantComparator> elements; + HashMap<Variant, GDScriptParser::ExpressionNode *, VariantHasher, StringLikeVariantComparator> elements; for (int i = 0; i < p_dictionary->elements.size(); i++) { const GDScriptParser::DictionaryNode::Pair &element = p_dictionary->elements[i]; @@ -2891,41 +2902,43 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod } // Check outer constants. // TODO: Allow outer static functions. - GDScriptParser::ClassNode *outer = base_class->outer; - while (outer != nullptr) { - if (outer->has_member(name)) { - const GDScriptParser::ClassNode::Member &member = outer->get_member(name); - switch (member.type) { - case GDScriptParser::ClassNode::Member::CONSTANT: { - // TODO: Make sure loops won't cause problem. And make special error message for those. - // For out-of-order resolution: - reduce_expression(member.constant->initializer); - p_identifier->set_datatype(member.get_datatype()); - p_identifier->is_constant = true; - p_identifier->reduced_value = member.constant->initializer->reduced_value; - return; - } break; - case GDScriptParser::ClassNode::Member::ENUM_VALUE: { - p_identifier->set_datatype(member.get_datatype()); - p_identifier->is_constant = true; - p_identifier->reduced_value = member.enum_value.value; - return; - } break; - case GDScriptParser::ClassNode::Member::ENUM: { - p_identifier->set_datatype(member.get_datatype()); - p_identifier->is_constant = false; - return; - } break; - case GDScriptParser::ClassNode::Member::CLASS: { - resolve_class_interface(member.m_class); - p_identifier->set_datatype(member.m_class->get_datatype()); - return; - } break; - default: - break; + if (base_class->outer != nullptr) { + List<GDScriptParser::ClassNode *> script_classes; + get_class_node_current_scope_classes(parser->current_class, &script_classes); + for (GDScriptParser::ClassNode *script_class : script_classes) { + if (script_class->has_member(name)) { + const GDScriptParser::ClassNode::Member &member = script_class->get_member(name); + switch (member.type) { + case GDScriptParser::ClassNode::Member::CONSTANT: { + // TODO: Make sure loops won't cause problem. And make special error message for those. + // For out-of-order resolution: + reduce_expression(member.constant->initializer); + p_identifier->set_datatype(member.get_datatype()); + p_identifier->is_constant = true; + p_identifier->reduced_value = member.constant->initializer->reduced_value; + return; + } break; + case GDScriptParser::ClassNode::Member::ENUM_VALUE: { + p_identifier->set_datatype(member.get_datatype()); + p_identifier->is_constant = true; + p_identifier->reduced_value = member.enum_value.value; + return; + } break; + case GDScriptParser::ClassNode::Member::ENUM: { + p_identifier->set_datatype(member.get_datatype()); + p_identifier->is_constant = false; + return; + } break; + case GDScriptParser::ClassNode::Member::CLASS: { + resolve_class_interface(member.m_class); + p_identifier->set_datatype(member.m_class->get_datatype()); + return; + } break; + default: + break; + } } } - outer = outer->outer; } base_class = base_class->base_type.class_type; @@ -3136,9 +3149,9 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident Variant constant = GDScriptLanguage::get_singleton()->get_named_globals_map()[name]; Node *node = Object::cast_to<Node>(constant); if (node != nullptr) { - Ref<Script> scr = node->get_script(); + Ref<GDScript> scr = node->get_script(); if (scr.is_valid()) { - Ref<GDScriptParserRef> singl_parser = get_parser_for(scr->get_path()); + Ref<GDScriptParserRef> singl_parser = get_parser_for(scr->get_script_path()); if (singl_parser.is_valid()) { Error err = singl_parser->raise_status(GDScriptParserRef::INTERFACE_SOLVED); if (err == OK) { @@ -3332,7 +3345,10 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri if (p_subscript->attribute == nullptr) { return; } - if (p_subscript->base->is_constant) { + + GDScriptParser::DataType base_type = p_subscript->base->get_datatype(); + // If base is a class metatype, use the analyzer instead. + if (p_subscript->base->is_constant && !(base_type.is_meta_type && base_type.kind == GDScriptParser::DataType::CLASS)) { // Just try to get it. bool valid = false; Variant value = p_subscript->base->reduced_value.get_named(p_subscript->attribute->name, valid); @@ -3341,7 +3357,7 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri Ref<GDScript> gdscr = Ref<GDScript>(p_subscript->base->reduced_value); if (!valid && gdscr.is_valid()) { Error err = OK; - GDScriptCache::get_full_script(gdscr->get_path(), err); + GDScriptCache::get_full_script(gdscr->get_script_path(), err); if (err == OK) { value = p_subscript->base->reduced_value.get_named(p_subscript->attribute->name, valid); } @@ -3356,8 +3372,6 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri result_type = type_from_variant(value, p_subscript); } } else { - GDScriptParser::DataType base_type = p_subscript->base->get_datatype(); - if (base_type.is_variant() || !base_type.is_hard_type()) { result_type.kind = GDScriptParser::DataType::VARIANT; mark_node_unsafe(p_subscript); @@ -3432,7 +3446,7 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri case Variant::QUATERNION: case Variant::AABB: case Variant::OBJECT: - error = index_type.builtin_type != Variant::STRING; + error = index_type.builtin_type != Variant::STRING && index_type.builtin_type != Variant::STRING_NAME; break; // Expect String or number. case Variant::BASIS: @@ -3446,11 +3460,11 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri case Variant::TRANSFORM3D: case Variant::PROJECTION: error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::FLOAT && - index_type.builtin_type != Variant::STRING; + index_type.builtin_type != Variant::STRING && index_type.builtin_type != Variant::STRING_NAME; break; // Expect String or int. case Variant::COLOR: - error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::STRING; + error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::STRING && index_type.builtin_type != Variant::STRING_NAME; break; // Don't support indexing, but we will check it later. case Variant::RID: @@ -3626,6 +3640,7 @@ void GDScriptAnalyzer::reduce_ternary_op(GDScriptParser::TernaryOpNode *p_ternar void GDScriptAnalyzer::reduce_unary_op(GDScriptParser::UnaryOpNode *p_unary_op) { reduce_expression(p_unary_op->operand); + GDScriptParser::DataType operand_type = p_unary_op->operand->get_datatype(); GDScriptParser::DataType result; if (p_unary_op->operand == nullptr) { @@ -3638,15 +3653,17 @@ void GDScriptAnalyzer::reduce_unary_op(GDScriptParser::UnaryOpNode *p_unary_op) p_unary_op->is_constant = true; p_unary_op->reduced_value = Variant::evaluate(p_unary_op->variant_op, p_unary_op->operand->reduced_value, Variant()); result = type_from_variant(p_unary_op->reduced_value, p_unary_op); - } else if (p_unary_op->operand->get_datatype().is_variant()) { + } + + if (operand_type.is_variant()) { result.kind = GDScriptParser::DataType::VARIANT; mark_node_unsafe(p_unary_op); } else { bool valid = false; - result = get_operation_type(p_unary_op->variant_op, p_unary_op->operand->get_datatype(), valid, p_unary_op); + result = get_operation_type(p_unary_op->variant_op, operand_type, valid, p_unary_op); if (!valid) { - push_error(vformat(R"(Invalid operand of type "%s" for unary operator "%s".)", p_unary_op->operand->get_datatype().to_string(), Variant::get_operator_name(p_unary_op->variant_op)), p_unary_op->operand); + push_error(vformat(R"(Invalid operand of type "%s" for unary operator "%s".)", operand_type.to_string(), Variant::get_operator_name(p_unary_op->variant_op)), p_unary_op); } } @@ -3714,7 +3731,13 @@ GDScriptParser::DataType GDScriptAnalyzer::type_from_variant(const Variant &p_va result.builtin_type = p_value.get_type(); result.type_source = GDScriptParser::DataType::ANNOTATED_EXPLICIT; // Constant has explicit type. - if (p_value.get_type() == Variant::OBJECT) { + if (p_value.get_type() == Variant::NIL) { + // A null value is a variant, not void. + result.kind = GDScriptParser::DataType::VARIANT; + } else if (p_value.get_type() == Variant::OBJECT) { + // Object is treated as a native type, not a builtin type. + result.kind = GDScriptParser::DataType::NATIVE; + Object *obj = p_value; if (!obj) { return GDScriptParser::DataType(); @@ -4164,6 +4187,8 @@ bool GDScriptAnalyzer::is_type_compatible(const GDScriptParser::DataType &p_targ if (p_target.kind == GDScriptParser::DataType::BUILTIN) { bool valid = p_source.kind == GDScriptParser::DataType::BUILTIN && p_target.builtin_type == p_source.builtin_type; + valid |= p_source.builtin_type == Variant::STRING && p_target.builtin_type == Variant::STRING_NAME; + valid |= p_source.builtin_type == Variant::STRING_NAME && p_target.builtin_type == Variant::STRING; if (!valid && p_allow_implicit_conversion) { valid = Variant::can_convert_strict(p_source.builtin_type, p_target.builtin_type); } diff --git a/modules/gdscript/gdscript_analyzer.h b/modules/gdscript/gdscript_analyzer.h index 23a3ad39a5..44ca1593ed 100644 --- a/modules/gdscript/gdscript_analyzer.h +++ b/modules/gdscript/gdscript_analyzer.h @@ -50,6 +50,8 @@ class GDScriptAnalyzer { Error check_native_member_name_conflict(const StringName &p_member_name, const GDScriptParser::Node *p_member_node, const StringName &p_native_type_string); Error check_class_member_name_conflict(const GDScriptParser::ClassNode *p_class_node, const StringName &p_member_name, const GDScriptParser::Node *p_member_node); + void get_class_node_current_scope_classes(GDScriptParser::ClassNode *p_node, List<GDScriptParser::ClassNode *> *p_list); + Error resolve_inheritance(GDScriptParser::ClassNode *p_class, bool p_recursive = true); GDScriptParser::DataType resolve_datatype(GDScriptParser::TypeNode *p_type); diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index fa158591fd..1bc83fbbb5 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -164,7 +164,7 @@ void GDScriptByteCodeGenerator::write_start(GDScript *p_script, const StringName function->name = p_function_name; function->_script = p_script; - function->source = p_script->get_path(); + function->source = p_script->get_script_path(); #ifdef DEBUG_ENABLED function->func_cname = (String(function->source) + " - " + String(p_function_name)).utf8(); diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index 699ce67933..d1467eea95 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -128,6 +128,10 @@ void GDScriptCache::move_script(const String &p_from, const String &p_to) { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { if (E.value.has(p_from)) { E.value.insert(p_to); @@ -158,6 +162,10 @@ void GDScriptCache::remove_script(const String &p_path) { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { if (!E.value.has(p_path)) { continue; @@ -371,6 +379,10 @@ void GDScriptCache::clear_unreferenced_packed_scenes() { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + for (KeyValue<String, HashSet<String>> &E : singleton->packed_scene_dependencies) { if (E.value.size() > 0 || !ResourceLoader::is_imported(E.key)) { continue; @@ -388,6 +400,11 @@ void GDScriptCache::clear() { MutexLock lock(singleton->mutex); + if (singleton->cleared) { + return; + } + singleton->cleared = true; + RBSet<Ref<GDScriptParserRef>> parser_map_refs; for (KeyValue<String, GDScriptParserRef *> &E : singleton->parser_map) { parser_map_refs.insert(E.value); @@ -398,6 +415,9 @@ void GDScriptCache::clear() { E->clear(); } + singleton->packed_scene_dependencies.clear(); + singleton->packed_scene_cache.clear(); + parser_map_refs.clear(); singleton->parser_map.clear(); singleton->shallow_gdscript_cache.clear(); @@ -412,7 +432,8 @@ GDScriptCache::GDScriptCache() { } GDScriptCache::~GDScriptCache() { - destructing = true; - clear(); + if (!cleared) { + clear(); + } singleton = nullptr; } diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h index e7e1901d5d..0ee269f96c 100644 --- a/modules/gdscript/gdscript_cache.h +++ b/modules/gdscript/gdscript_cache.h @@ -87,7 +87,7 @@ class GDScriptCache { static GDScriptCache *singleton; - bool destructing = false; + bool cleared = false; Mutex mutex; @@ -104,13 +104,6 @@ public: static Ref<PackedScene> get_packed_scene(const String &p_path, Error &r_error, const String &p_owner = ""); static void clear_unreferenced_packed_scenes(); - static bool is_destructing() { - if (singleton == nullptr) { - return true; - } - return singleton->destructing; - }; - static void clear(); GDScriptCache(); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index ea93e1ebfc..2a98b856ce 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1256,9 +1256,30 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &c equality_type.kind = GDScriptDataType::BUILTIN; equality_type.builtin_type = Variant::BOOL; + GDScriptCodeGenerator::Address type_string_addr = codegen.add_constant(Variant::STRING); + GDScriptCodeGenerator::Address type_string_name_addr = codegen.add_constant(Variant::STRING_NAME); + // Check type equality. GDScriptCodeGenerator::Address type_equality_addr = codegen.add_temporary(equality_type); codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_EQUAL, p_type_addr, literal_type_addr); + + // Check if StringName <-> String comparison is possible. + GDScriptCodeGenerator::Address type_comp_addr_1 = codegen.add_temporary(equality_type); + GDScriptCodeGenerator::Address type_comp_addr_2 = codegen.add_temporary(equality_type); + + codegen.generator->write_binary_operator(type_comp_addr_1, Variant::OP_EQUAL, p_type_addr, type_string_addr); + codegen.generator->write_binary_operator(type_comp_addr_2, Variant::OP_EQUAL, literal_type_addr, type_string_name_addr); + codegen.generator->write_binary_operator(type_comp_addr_1, Variant::OP_AND, type_comp_addr_1, type_comp_addr_2); + codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_OR, type_equality_addr, type_comp_addr_1); + + codegen.generator->write_binary_operator(type_comp_addr_1, Variant::OP_EQUAL, p_type_addr, type_string_name_addr); + codegen.generator->write_binary_operator(type_comp_addr_2, Variant::OP_EQUAL, literal_type_addr, type_string_addr); + codegen.generator->write_binary_operator(type_comp_addr_1, Variant::OP_AND, type_comp_addr_1, type_comp_addr_2); + codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_OR, type_equality_addr, type_comp_addr_1); + + codegen.generator->pop_temporary(); // Remove type_comp_addr_2 from stack. + codegen.generator->pop_temporary(); // Remove type_comp_addr_1 from stack. + codegen.generator->write_and_left_operand(type_equality_addr); // Get literal. @@ -2096,8 +2117,8 @@ GDScriptFunction *GDScriptCompiler::_parse_function(Error &r_error, GDScript *p_ if (EngineDebugger::is_active()) { String signature; // Path. - if (!p_script->get_path().is_empty()) { - signature += p_script->get_path(); + if (!p_script->get_script_path().is_empty()) { + signature += p_script->get_script_path(); } // Location. if (p_func) { @@ -2368,6 +2389,7 @@ Error GDScriptCompiler::_populate_class_members(GDScript *p_script, const GDScri #ifdef TOOLS_ENABLED if (variable->initializer != nullptr && variable->initializer->is_constant) { p_script->member_default_values[name] = variable->initializer->reduced_value; + GDScriptCompiler::convert_to_initializer_type(p_script->member_default_values[name], variable); } else { p_script->member_default_values.erase(name); } @@ -2625,6 +2647,20 @@ Error GDScriptCompiler::_compile_class(GDScript *p_script, const GDScriptParser: return OK; } +void GDScriptCompiler::convert_to_initializer_type(Variant &p_variant, const GDScriptParser::VariableNode *p_node) { + // Set p_variant to the value of p_node's initializer, with the type of p_node's variable. + GDScriptParser::DataType member_t = p_node->datatype; + GDScriptParser::DataType init_t = p_node->initializer->datatype; + if (member_t.is_hard_type() && init_t.is_hard_type() && + member_t.kind == GDScriptParser::DataType::BUILTIN && init_t.kind == GDScriptParser::DataType::BUILTIN) { + if (Variant::can_convert_strict(init_t.builtin_type, member_t.builtin_type)) { + Variant *v = &p_node->initializer->reduced_value; + Callable::CallError ce; + Variant::construct(member_t.builtin_type, p_variant, const_cast<const Variant **>(&v), 1, ce); + } + } +} + void GDScriptCompiler::make_scripts(GDScript *p_script, const GDScriptParser::ClassNode *p_class, bool p_keep_state) { p_script->fully_qualified_name = p_class->fqcn; p_script->name = p_class->identifier ? p_class->identifier->name : ""; diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h index cba585e5a5..fc5aa05190 100644 --- a/modules/gdscript/gdscript_compiler.h +++ b/modules/gdscript/gdscript_compiler.h @@ -140,6 +140,7 @@ class GDScriptCompiler { bool within_await = false; public: + static void convert_to_initializer_type(Variant &p_variant, const GDScriptParser::VariableNode *p_node); static void make_scripts(GDScript *p_script, const GDScriptParser::ClassNode *p_class, bool p_keep_state); Error compile(const GDScriptParser *p_parser, GDScript *p_script, bool p_keep_state = false); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 6d5936ad2e..79387d1bf6 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1612,7 +1612,7 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context, } } - if (!found) { + if (!found && base.value.get_type() != Variant::NIL) { found = _guess_method_return_type_from_base(c, base, call->function_name, r_type); } } @@ -2272,6 +2272,11 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex if (base_type.class_type->has_function(p_method)) { const GDScriptParser::FunctionNode *method = base_type.class_type->get_member(p_method).function; if (!is_static || method->is_static) { + if (method->get_datatype().is_set() && !method->get_datatype().is_variant()) { + r_type.type = method->get_datatype(); + return true; + } + int last_return_line = -1; const GDScriptParser::ExpressionNode *last_returned_value = nullptr; GDScriptParser::CompletionContext c = p_context; @@ -2285,10 +2290,6 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex if (_guess_expression_type(c, last_returned_value, r_type)) { return true; } - if (method->get_datatype().is_set() && !method->get_datatype().is_variant()) { - r_type.type = method->get_datatype(); - return true; - } } } } @@ -2624,7 +2625,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c } } - if (p_context.base != nullptr && subscript->is_attribute) { + if (subscript->is_attribute) { bool found_type = _get_subscript_type(p_context, subscript, base_type, &base); if (!found_type) { @@ -3288,6 +3289,7 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co parser.parse(p_code, p_path, true); GDScriptParser::CompletionContext context = parser.get_completion_context(); + context.base = p_owner; // Allows class functions with the names like built-ins to be handled properly. if (context.type != GDScriptParser::COMPLETION_ATTRIBUTE) { @@ -3460,7 +3462,9 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co break; } GDScriptCompletionIdentifier base; - if (!_guess_expression_type(context, subscript->base, base)) { + + bool found_type = _get_subscript_type(context, subscript, base.type); + if (!found_type && !_guess_expression_type(context, subscript->base, base)) { break; } diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp index bcbe8b8d2b..27b6792e84 100644 --- a/modules/gdscript/gdscript_utility_functions.cpp +++ b/modules/gdscript/gdscript_utility_functions.cpp @@ -294,6 +294,7 @@ struct GDScriptUtilityFunctionsDefinitions { } GDScript *p = base.ptr(); + String path = p->get_script_path(); Vector<StringName> sname; while (p->_owner) { @@ -302,7 +303,7 @@ struct GDScriptUtilityFunctionsDefinitions { } sname.reverse(); - if (!p->path.is_resource_file()) { + if (!path.is_resource_file()) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::DICTIONARY; @@ -317,7 +318,7 @@ struct GDScriptUtilityFunctionsDefinitions { Dictionary d; d["@subpath"] = cp; - d["@path"] = p->get_path(); + d["@path"] = path; for (const KeyValue<StringName, GDScript::MemberInfo> &E : base->member_indices) { if (!d.has(E.key)) { diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index c73ba798aa..fdcc0625d7 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -2227,7 +2227,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } #ifdef DEBUG_ENABLED gdfs->state.function_name = name; - gdfs->state.script_path = _script->get_path(); + gdfs->state.script_path = _script->get_script_path(); #endif gdfs->state.defarg = defarg; gdfs->function = this; diff --git a/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.gd new file mode 100644 index 0000000000..4dd2b556ee --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.gd @@ -0,0 +1,9 @@ +# https://github.com/godotengine/godot/issues/62957 + +func test(): + var dict = { + &"key": "StringName", + "key": "String" + } + + print("Invalid dictionary: %s" % dict) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.out new file mode 100644 index 0000000000..189d8a7955 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/dictionary_string_stringname_equivalent.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Key "key" was already used in this dictionary (at line 5). diff --git a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd new file mode 100644 index 0000000000..4511c3d10b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.gd @@ -0,0 +1,8 @@ +func test(): + # Converted to String when initialized + var string_array: Array[String] = [&"abc"] + print(string_array) + + # Converted to StringName when initialized + var stringname_array: Array[StringName] = ["abc"] + print(stringname_array) diff --git a/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out new file mode 100644 index 0000000000..70dd01d88e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/array_string_stringname_equivalent.out @@ -0,0 +1,3 @@ +GDTEST_OK +["abc"] +[&"abc"] diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd new file mode 100644 index 0000000000..7881a0feb6 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd @@ -0,0 +1,14 @@ +const A: = preload("base_outer_resolution_a.notest.gd") +const B: = preload("base_outer_resolution_b.notest.gd") +const C: = preload("base_outer_resolution_c.notest.gd") + +const Extend: = preload("base_outer_resolution_extend.notest.gd") + +func test() -> void: + Extend.test_a(A.new()) + Extend.test_b(B.new()) + Extend.InnerClass.test_c(C.new()) + Extend.InnerClass.InnerInnerClass.test_a_b_c(A.new(), B.new(), C.new()) + Extend.InnerClass.InnerInnerClass.test_enum(C.TestEnum.HELLO_WORLD) + Extend.InnerClass.InnerInnerClass.test_a_prime(A.APrime.new()) + diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.out b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.out new file mode 100644 index 0000000000..bd27bd31f6 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.out @@ -0,0 +1,7 @@ +GDTEST_OK +true +true +true +true +true +true diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_a.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_a.notest.gd new file mode 100644 index 0000000000..966c8bfc8f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_a.notest.gd @@ -0,0 +1,2 @@ +class APrime: + pass diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_b.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_b.notest.gd new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_b.notest.gd diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_base.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_base.notest.gd new file mode 100644 index 0000000000..666b147ced --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_base.notest.gd @@ -0,0 +1,4 @@ +const A: = preload("base_outer_resolution_a.notest.gd") + +class InnerClassInBase: + const C: = preload("base_outer_resolution_c.notest.gd") diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_c.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_c.notest.gd new file mode 100644 index 0000000000..814be35314 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_c.notest.gd @@ -0,0 +1,3 @@ +enum TestEnum { + HELLO_WORLD +} diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_extend.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_extend.notest.gd new file mode 100644 index 0000000000..fbd28779d4 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution_extend.notest.gd @@ -0,0 +1,23 @@ +extends "base_outer_resolution_base.notest.gd" + +const B: = preload("base_outer_resolution_b.notest.gd") + +static func test_a(a: A) -> void: + print(a is A) + +static func test_b(b: B) -> void: + print(b is B) + +class InnerClass extends InnerClassInBase: + static func test_c(c: C) -> void: + print(c is C) + + class InnerInnerClass: + static func test_a_b_c(a: A, b: B, c: C) -> void: + print(a is A and b is B and c is C) + + static func test_enum(test_enum: C.TestEnum) -> void: + print(test_enum == C.TestEnum.HELLO_WORLD) + + static func test_a_prime(a_prime: A.APrime) -> void: + print(a_prime is A.APrime) diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd new file mode 100644 index 0000000000..5303fb04e2 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd @@ -0,0 +1,35 @@ +# https://github.com/godotengine/godot/issues/63965 + +func test(): + var array_str: Array = [] + array_str.push_back("godot") + print("StringName in Array: ", &"godot" in array_str) + + var array_sname: Array = [] + array_sname.push_back(&"godot") + print("String in Array: ", "godot" in array_sname) + + # Not equal because the values are different types. + print("Arrays not equal: ", array_str != array_sname) + + var string_array: Array[String] = [] + var stringname_array: Array[StringName] = [] + + assert(!string_array.push_back(&"abc")) + print("Array[String] insert converted: ", typeof(string_array[0]) == TYPE_STRING) + + assert(!stringname_array.push_back("abc")) + print("Array[StringName] insert converted: ", typeof(stringname_array[0]) == TYPE_STRING_NAME) + + print("StringName in Array[String]: ", &"abc" in string_array) + print("String in Array[StringName]: ", "abc" in stringname_array) + + var packed_string_array: PackedStringArray = [] + assert(!packed_string_array.push_back("abc")) + print("StringName in PackedStringArray: ", &"abc" in packed_string_array) + + assert(!string_array.push_back("abc")) + print("StringName finds String in Array: ", string_array.find(&"abc")) + + assert(!stringname_array.push_back(&"abc")) + print("String finds StringName in Array: ", stringname_array.find("abc")) diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out new file mode 100644 index 0000000000..98ab78e8f1 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.out @@ -0,0 +1,11 @@ +GDTEST_OK +StringName in Array: true +String in Array: true +Arrays not equal: true +Array[String] insert converted: true +Array[StringName] insert converted: true +StringName in Array[String]: true +String in Array[StringName]: true +StringName in PackedStringArray: true +StringName finds String in Array: 0 +String finds StringName in Array: 0 diff --git a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd new file mode 100644 index 0000000000..1f15026f17 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd @@ -0,0 +1,17 @@ +# https://github.com/godotengine/godot/issues/62957 + +func test(): + var string_dict = {} + string_dict["abc"] = 42 + var stringname_dict = {} + stringname_dict[&"abc"] = 24 + + print("String key is TYPE_STRING: ", typeof(string_dict.keys()[0]) == TYPE_STRING) + print("StringName key is TYPE_STRING: ", typeof(stringname_dict.keys()[0]) == TYPE_STRING) + + print("StringName gets String: ", string_dict.get(&"abc")) + print("String gets StringName: ", stringname_dict.get("abc")) + + stringname_dict[&"abc"] = 42 + # They compare equal because StringName keys are converted to String. + print("String Dictionary == StringName Dictionary: ", string_dict == stringname_dict) diff --git a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out new file mode 100644 index 0000000000..ab5b89d55c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.out @@ -0,0 +1,6 @@ +GDTEST_OK +String key is TYPE_STRING: true +StringName key is TYPE_STRING: true +StringName gets String: 42 +String gets StringName: 24 +String Dictionary == StringName Dictionary: true diff --git a/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd new file mode 100644 index 0000000000..55be021a90 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.gd @@ -0,0 +1,14 @@ +# https://github.com/godotengine/godot/issues/60145 + +func test(): + match "abc": + &"abc": + print("String matched StringName") + _: + print("no match") + + match &"abc": + "abc": + print("StringName matched String") + _: + print("no match") diff --git a/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out new file mode 100644 index 0000000000..9d5a18da3d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/match_string_stringname_equivalent.out @@ -0,0 +1,3 @@ +GDTEST_OK +String matched StringName +StringName matched String diff --git a/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd new file mode 100644 index 0000000000..f8bd46523e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.gd @@ -0,0 +1,11 @@ +# https://github.com/godotengine/godot/issues/64171 + +func test(): + print("Compare ==: ", "abc" == &"abc") + print("Compare ==: ", &"abc" == "abc") + print("Compare !=: ", "abc" != &"abc") + print("Compare !=: ", &"abc" != "abc") + + print("Concat: ", "abc" + &"def") + print("Concat: ", &"abc" + "def") + print("Concat: ", &"abc" + &"def") diff --git a/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out new file mode 100644 index 0000000000..7e9c364b60 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/string_stringname_equivalent.out @@ -0,0 +1,8 @@ +GDTEST_OK +Compare ==: true +Compare ==: true +Compare !=: false +Compare !=: false +Concat: abcdef +Concat: abcdef +Concat: abcdef diff --git a/modules/gltf/doc_classes/GLTFDocumentExtension.xml b/modules/gltf/doc_classes/GLTFDocumentExtension.xml index 87d3d9bcb0..6004de32f1 100644 --- a/modules/gltf/doc_classes/GLTFDocumentExtension.xml +++ b/modules/gltf/doc_classes/GLTFDocumentExtension.xml @@ -42,10 +42,11 @@ </method> <method name="_export_preflight" qualifiers="virtual"> <return type="int" /> - <param index="0" name="root" type="Node" /> + <param index="0" name="state" type="GLTFState" /> + <param index="1" name="root" type="Node" /> <description> Part of the export process. This method is run first, before all other parts of the export process. - The return value is used to determine if this GLTFDocumentExtension class should be used for exporting a given GLTF file. If [constant OK], the export will use this GLTFDocumentExtension class. If not overridden, [constant OK] is returned. + The return value is used to determine if this [GLTFDocumentExtension] instance should be used for exporting a given GLTF file. If [constant OK], the export will use this [GLTFDocumentExtension] instance. If not overridden, [constant OK] is returned. </description> </method> <method name="_generate_scene_node" qualifiers="virtual"> @@ -99,7 +100,7 @@ <param index="1" name="extensions" type="PackedStringArray" /> <description> Part of the import process. This method is run first, before all other parts of the import process. - The return value is used to determine if this GLTFDocumentExtension class should be used for importing a given GLTF file. If [constant OK], the import will use this GLTFDocumentExtension class. If not overridden, [constant OK] is returned. + The return value is used to determine if this [GLTFDocumentExtension] instance should be used for importing a given GLTF file. If [constant OK], the import will use this [GLTFDocumentExtension] instance. If not overridden, [constant OK] is returned. </description> </method> <method name="_parse_node_extensions" qualifiers="virtual"> @@ -109,7 +110,7 @@ <param index="2" name="extensions" type="Dictionary" /> <description> Part of the import process. This method is run after [method _get_supported_extensions] and before [method _generate_scene_node]. - Runs when parsing the node extensions of a GLTFNode. This method can be used to process the extension JSON data into a format that can be used by [method _generate_scene_node]. + Runs when parsing the node extensions of a GLTFNode. This method can be used to process the extension JSON data into a format that can be used by [method _generate_scene_node]. The return value should be a member of the [enum Error] enum. </description> </method> </methods> diff --git a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp index 0c0b134bd1..fe63afcc56 100644 --- a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp +++ b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp @@ -33,18 +33,10 @@ #include "editor_scene_exporter_gltf_plugin.h" #include "../gltf_document.h" -#include "../gltf_state.h" -#include "core/config/project_settings.h" -#include "core/error/error_list.h" -#include "core/object/object.h" -#include "core/templates/vector.h" #include "editor/editor_file_dialog.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/gui/check_box.h" -#include "scene/main/node.h" String SceneExporterGLTFPlugin::get_name() const { return "ConvertGLTF2"; diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp index 7007ea5d13..4dafa746bc 100644 --- a/modules/gltf/editor/editor_scene_importer_blend.cpp +++ b/modules/gltf/editor/editor_scene_importer_blend.cpp @@ -33,7 +33,6 @@ #ifdef TOOLS_ENABLED #include "../gltf_document.h" -#include "../gltf_state.h" #include "core/config/project_settings.h" #include "editor/editor_file_dialog.h" @@ -42,8 +41,6 @@ #include "editor/editor_settings.h" #include "main/main.h" #include "scene/gui/line_edit.h" -#include "scene/main/node.h" -#include "scene/resources/animation.h" #ifdef WINDOWS_ENABLED // Code by Pedro Estebanez (https://github.com/godotengine/godot/pull/59766) diff --git a/modules/gltf/editor/editor_scene_importer_fbx.cpp b/modules/gltf/editor/editor_scene_importer_fbx.cpp index 14f2117413..fb5fb455b8 100644 --- a/modules/gltf/editor/editor_scene_importer_fbx.cpp +++ b/modules/gltf/editor/editor_scene_importer_fbx.cpp @@ -33,12 +33,9 @@ #ifdef TOOLS_ENABLED #include "../gltf_document.h" -#include "../gltf_state.h" #include "core/config/project_settings.h" #include "editor/editor_settings.h" -#include "scene/main/node.h" -#include "scene/resources/animation.h" uint32_t EditorSceneFormatImporterFBX::get_import_flags() const { return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION; diff --git a/modules/gltf/editor/editor_scene_importer_gltf.cpp b/modules/gltf/editor/editor_scene_importer_gltf.cpp index 3cf49a3046..bd1ba85abf 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor/editor_scene_importer_gltf.cpp @@ -33,9 +33,6 @@ #include "editor_scene_importer_gltf.h" #include "../gltf_document.h" -#include "../gltf_state.h" - -#include "scene/resources/animation.h" uint32_t EditorSceneFormatImporterGLTF::get_import_flags() const { return ImportFlags::IMPORT_SCENE | ImportFlags::IMPORT_ANIMATION; @@ -63,7 +60,12 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t if (p_options.has("animation/import")) { state->set_create_animations(bool(p_options["animation/import"])); } - return doc->generate_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"]); + + if (p_options.has("animation/trimming")) { + return doc->generate_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"]); + } else { + return doc->generate_scene(state, (float)p_options["animation/fps"], false); + } } #endif // TOOLS_ENABLED diff --git a/modules/gltf/extensions/gltf_document_extension.cpp b/modules/gltf/extensions/gltf_document_extension.cpp index f997fe8f66..630a62ba5c 100644 --- a/modules/gltf/extensions/gltf_document_extension.cpp +++ b/modules/gltf/extensions/gltf_document_extension.cpp @@ -40,7 +40,7 @@ void GLTFDocumentExtension::_bind_methods() { GDVIRTUAL_BIND(_import_node, "state", "gltf_node", "json", "node"); GDVIRTUAL_BIND(_import_post, "state", "root"); // Export process. - GDVIRTUAL_BIND(_export_preflight, "root"); + GDVIRTUAL_BIND(_export_preflight, "state", "root"); GDVIRTUAL_BIND(_convert_scene_node, "state", "gltf_node", "scene_node"); GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node"); GDVIRTUAL_BIND(_export_post, "state"); @@ -102,10 +102,10 @@ Error GLTFDocumentExtension::import_post(Ref<GLTFState> p_state, Node *p_root) { } // Export process. -Error GLTFDocumentExtension::export_preflight(Node *p_root) { +Error GLTFDocumentExtension::export_preflight(Ref<GLTFState> p_state, Node *p_root) { ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); int err = OK; - GDVIRTUAL_CALL(_export_preflight, p_root, err); + GDVIRTUAL_CALL(_export_preflight, p_state, p_root, err); return Error(err); } diff --git a/modules/gltf/extensions/gltf_document_extension.h b/modules/gltf/extensions/gltf_document_extension.h index 7cc9ca592f..66cb9a3c33 100644 --- a/modules/gltf/extensions/gltf_document_extension.h +++ b/modules/gltf/extensions/gltf_document_extension.h @@ -49,7 +49,7 @@ public: virtual Error import_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node); virtual Error import_post(Ref<GLTFState> p_state, Node *p_node); // Export process. - virtual Error export_preflight(Node *p_state); + virtual Error export_preflight(Ref<GLTFState> p_state, Node *p_root); virtual void convert_scene_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Node *p_scene_node); virtual Error export_node(Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node, Dictionary &r_json, Node *p_node); virtual Error export_post(Ref<GLTFState> p_state); @@ -63,7 +63,7 @@ public: GDVIRTUAL4R(int, _import_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *); GDVIRTUAL2R(int, _import_post, Ref<GLTFState>, Node *); // Export process. - GDVIRTUAL1R(int, _export_preflight, Node *); + GDVIRTUAL2R(int, _export_preflight, Ref<GLTFState>, Node *); GDVIRTUAL3(_convert_scene_node, Ref<GLTFState>, Ref<GLTFNode>, Node *); GDVIRTUAL4R(int, _export_node, Ref<GLTFState>, Ref<GLTFNode>, Dictionary, Node *); GDVIRTUAL1R(int, _export_post, Ref<GLTFState>); diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp index 49496afb62..cfa498af65 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.cpp @@ -30,9 +30,7 @@ #include "gltf_document_extension_convert_importer_mesh.h" -#include "../gltf_state.h" - -#include "core/error/error_macros.h" +#include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/resources/importer_mesh.h" diff --git a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h index 00e664e73f..4fbfa0e066 100644 --- a/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h +++ b/modules/gltf/extensions/gltf_document_extension_convert_importer_mesh.h @@ -33,10 +33,6 @@ #include "gltf_document_extension.h" -#include "scene/3d/importer_mesh_instance_3d.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/resources/importer_mesh.h" - class GLTFDocumentExtensionConvertImporterMesh : public GLTFDocumentExtension { GDCLASS(GLTFDocumentExtensionConvertImporterMesh, GLTFDocumentExtension); diff --git a/modules/gltf/extensions/gltf_light.cpp b/modules/gltf/extensions/gltf_light.cpp index d00bead61c..0379c62c9d 100644 --- a/modules/gltf/extensions/gltf_light.cpp +++ b/modules/gltf/extensions/gltf_light.cpp @@ -30,6 +30,8 @@ #include "gltf_light.h" +#include "scene/3d/light_3d.h" + void GLTFLight::_bind_methods() { ClassDB::bind_static_method("GLTFLight", D_METHOD("from_node", "light_node"), &GLTFLight::from_node); ClassDB::bind_method(D_METHOD("to_node"), &GLTFLight::to_node); diff --git a/modules/gltf/extensions/gltf_light.h b/modules/gltf/extensions/gltf_light.h index 04980e144c..85284f1d0e 100644 --- a/modules/gltf/extensions/gltf_light.h +++ b/modules/gltf/extensions/gltf_light.h @@ -31,9 +31,9 @@ #ifndef GLTF_LIGHT_H #define GLTF_LIGHT_H -#include "core/config/engine.h" #include "core/io/resource.h" -#include "scene/3d/light_3d.h" + +class Light3D; // https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_lights_punctual diff --git a/modules/gltf/extensions/gltf_spec_gloss.cpp b/modules/gltf/extensions/gltf_spec_gloss.cpp index 83af91bfcc..0645f31e01 100644 --- a/modules/gltf/extensions/gltf_spec_gloss.cpp +++ b/modules/gltf/extensions/gltf_spec_gloss.cpp @@ -30,6 +30,8 @@ #include "gltf_spec_gloss.h" +#include "core/io/image.h" + void GLTFSpecGloss::_bind_methods() { ClassDB::bind_method(D_METHOD("get_diffuse_img"), &GLTFSpecGloss::get_diffuse_img); ClassDB::bind_method(D_METHOD("set_diffuse_img", "diffuse_img"), &GLTFSpecGloss::set_diffuse_img); diff --git a/modules/gltf/extensions/gltf_spec_gloss.h b/modules/gltf/extensions/gltf_spec_gloss.h index 2b4d3ee609..56474acd03 100644 --- a/modules/gltf/extensions/gltf_spec_gloss.h +++ b/modules/gltf/extensions/gltf_spec_gloss.h @@ -31,9 +31,10 @@ #ifndef GLTF_SPEC_GLOSS_H #define GLTF_SPEC_GLOSS_H -#include "core/io/image.h" #include "core/io/resource.h" +class Image; + // KHR_materials_pbrSpecularGlossiness is an archived GLTF extension. // This means that it is deprecated and not recommended for new files. // However, it is still supported for loading old files. diff --git a/modules/gltf/gltf_defines.h b/modules/gltf/gltf_defines.h index 23bf33869e..7b990e6573 100644 --- a/modules/gltf/gltf_defines.h +++ b/modules/gltf/gltf_defines.h @@ -36,9 +36,10 @@ // Godot classes used by GLTF headers. class BoneAttachment3D; class CSGShape3D; -class DirectionalLight3D; class GridMap; +class ImporterMeshInstance3D; class Light3D; +class MeshInstance3D; class MultiMeshInstance3D; class Skeleton3D; class Skin; diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index a3685daf0e..f4db576b0c 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -31,31 +31,23 @@ #include "gltf_document.h" #include "extensions/gltf_spec_gloss.h" -#include "gltf_state.h" #include "core/crypto/crypto_core.h" -#include "core/error/error_macros.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/io/file_access_memory.h" #include "core/io/json.h" #include "core/io/stream_peer.h" #include "core/math/disjoint_set.h" -#include "core/math/vector2.h" -#include "core/variant/dictionary.h" -#include "core/variant/typed_array.h" -#include "core/variant/variant.h" #include "core/version.h" #include "drivers/png/png_driver_common.h" -#include "scene/2d/node_2d.h" +#include "scene/3d/bone_attachment_3d.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/importer_mesh_instance_3d.h" +#include "scene/3d/light_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/multimesh_instance_3d.h" -#include "scene/3d/node_3d.h" -#include "scene/animation/animation_player.h" -#include "scene/resources/importer_mesh.h" -#include "scene/resources/material.h" -#include "scene/resources/mesh.h" -#include "scene/resources/multimesh.h" +#include "scene/resources/skin.h" #include "scene/resources/surface_tool.h" #include "modules/modules_enabled.gen.h" // For csg, gridmap. @@ -111,147 +103,147 @@ static Ref<ImporterMesh> _mesh_to_importer_mesh(Ref<Mesh> p_mesh) { return importer_mesh; } -Error GLTFDocument::_serialize(Ref<GLTFState> state, const String &p_path) { - if (!state->buffers.size()) { - state->buffers.push_back(Vector<uint8_t>()); +Error GLTFDocument::_serialize(Ref<GLTFState> p_state, const String &p_path) { + if (!p_state->buffers.size()) { + p_state->buffers.push_back(Vector<uint8_t>()); } /* STEP CONVERT MESH INSTANCES */ - _convert_mesh_instances(state); + _convert_mesh_instances(p_state); /* STEP SERIALIZE CAMERAS */ - Error err = _serialize_cameras(state); + Error err = _serialize_cameras(p_state); if (err != OK) { return Error::FAILED; } /* STEP 3 CREATE SKINS */ - err = _serialize_skins(state); + err = _serialize_skins(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE MESHES (we have enough info now) */ - err = _serialize_meshes(state); + err = _serialize_meshes(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE TEXTURES */ - err = _serialize_materials(state); + err = _serialize_materials(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE TEXTURE SAMPLERS */ - err = _serialize_texture_samplers(state); + err = _serialize_texture_samplers(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE ANIMATIONS */ - err = _serialize_animations(state); + err = _serialize_animations(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE ACCESSORS */ - err = _encode_accessors(state); + err = _encode_accessors(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE IMAGES */ - err = _serialize_images(state, p_path); + err = _serialize_images(p_state, p_path); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE TEXTURES */ - err = _serialize_textures(state); + err = _serialize_textures(p_state); if (err != OK) { return Error::FAILED; } - for (GLTFBufferViewIndex i = 0; i < state->buffer_views.size(); i++) { - state->buffer_views.write[i]->buffer = 0; + for (GLTFBufferViewIndex i = 0; i < p_state->buffer_views.size(); i++) { + p_state->buffer_views.write[i]->buffer = 0; } /* STEP SERIALIZE BUFFER VIEWS */ - err = _encode_buffer_views(state); + err = _encode_buffer_views(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE NODES */ - err = _serialize_nodes(state); + err = _serialize_nodes(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE SCENE */ - err = _serialize_scenes(state); + err = _serialize_scenes(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE LIGHTS */ - err = _serialize_lights(state); + err = _serialize_lights(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE EXTENSIONS */ - err = _serialize_gltf_extensions(state); + err = _serialize_gltf_extensions(p_state); if (err != OK) { return Error::FAILED; } /* STEP SERIALIZE VERSION */ - err = _serialize_version(state); + err = _serialize_version(p_state); if (err != OK) { return Error::FAILED; } for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - err = ext->export_post(state); + err = ext->export_post(p_state); ERR_FAIL_COND_V(err != OK, err); } return OK; } -Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> state) const { - Vector<String> extensions_used = state->extensions_used; - Vector<String> extensions_required = state->extensions_required; - if (!state->lights.is_empty()) { +Error GLTFDocument::_serialize_gltf_extensions(Ref<GLTFState> p_state) const { + Vector<String> extensions_used = p_state->extensions_used; + Vector<String> extensions_required = p_state->extensions_required; + if (!p_state->lights.is_empty()) { extensions_used.push_back("KHR_lights_punctual"); } - if (state->use_khr_texture_transform) { + if (p_state->use_khr_texture_transform) { extensions_used.push_back("KHR_texture_transform"); extensions_required.push_back("KHR_texture_transform"); } if (!extensions_used.is_empty()) { extensions_used.sort(); - state->json["extensionsUsed"] = extensions_used; + p_state->json["extensionsUsed"] = extensions_used; } if (!extensions_required.is_empty()) { extensions_required.sort(); - state->json["extensionsRequired"] = extensions_required; + p_state->json["extensionsRequired"] = extensions_required; } return OK; } -Error GLTFDocument::_serialize_scenes(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_scenes(Ref<GLTFState> p_state) { Array scenes; const int loaded_scene = 0; - state->json["scene"] = loaded_scene; + p_state->json["scene"] = loaded_scene; - if (state->nodes.size()) { + if (p_state->nodes.size()) { Dictionary s; - if (!state->scene_name.is_empty()) { - s["name"] = state->scene_name; + if (!p_state->scene_name.is_empty()) { + s["name"] = p_state->scene_name; } Array nodes; @@ -259,21 +251,21 @@ Error GLTFDocument::_serialize_scenes(Ref<GLTFState> state) { s["nodes"] = nodes; scenes.push_back(s); } - state->json["scenes"] = scenes; + p_state->json["scenes"] = scenes; return OK; } -Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) { +Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> p_state) { Error err; - Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err); - if (f.is_null()) { + Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ, &err); + if (file.is_null()) { return err; } Vector<uint8_t> array; - array.resize(f->get_length()); - f->get_buffer(array.ptrw(), array.size()); + array.resize(file->get_length()); + file->get_buffer(array.ptrw(), array.size()); String text; text.parse_utf8((const char *)array.ptr(), array.size()); @@ -283,26 +275,26 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) { _err_print_error("", p_path.utf8().get_data(), json.get_error_line(), json.get_error_message().utf8().get_data(), false, ERR_HANDLER_SCRIPT); return err; } - state->json = json.get_data(); + p_state->json = json.get_data(); return OK; } -Error GLTFDocument::_parse_glb(Ref<FileAccess> f, Ref<GLTFState> state) { - ERR_FAIL_NULL_V(f, ERR_INVALID_PARAMETER); - ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(f->get_position() != 0, ERR_FILE_CANT_READ); - uint32_t magic = f->get_32(); +Error GLTFDocument::_parse_glb(Ref<FileAccess> p_file, Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_file, ERR_INVALID_PARAMETER); + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_file->get_position() != 0, ERR_FILE_CANT_READ); + uint32_t magic = p_file->get_32(); ERR_FAIL_COND_V(magic != 0x46546C67, ERR_FILE_UNRECOGNIZED); //glTF - f->get_32(); // version - f->get_32(); // length - uint32_t chunk_length = f->get_32(); - uint32_t chunk_type = f->get_32(); + p_file->get_32(); // version + p_file->get_32(); // length + uint32_t chunk_length = p_file->get_32(); + uint32_t chunk_type = p_file->get_32(); ERR_FAIL_COND_V(chunk_type != 0x4E4F534A, ERR_PARSE_ERROR); //JSON Vector<uint8_t> json_data; json_data.resize(chunk_length); - uint32_t len = f->get_buffer(json_data.ptrw(), chunk_length); + uint32_t len = p_file->get_buffer(json_data.ptrw(), chunk_length); ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT); String text; @@ -315,21 +307,21 @@ Error GLTFDocument::_parse_glb(Ref<FileAccess> f, Ref<GLTFState> state) { return err; } - state->json = json.get_data(); + p_state->json = json.get_data(); //data? - chunk_length = f->get_32(); - chunk_type = f->get_32(); + chunk_length = p_file->get_32(); + chunk_type = p_file->get_32(); - if (f->eof_reached()) { + if (p_file->eof_reached()) { return OK; //all good } ERR_FAIL_COND_V(chunk_type != 0x004E4942, ERR_PARSE_ERROR); //BIN - state->glb_data.resize(chunk_length); - len = f->get_buffer(state->glb_data.ptrw(), chunk_length); + p_state->glb_data.resize(chunk_length); + len = p_file->get_buffer(p_state->glb_data.ptrw(), chunk_length); ERR_FAIL_COND_V(len != chunk_length, ERR_FILE_CORRUPT); return OK; @@ -402,11 +394,11 @@ static Vector<real_t> _xform_to_array(const Transform3D p_transform) { return array; } -Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_nodes(Ref<GLTFState> p_state) { Array nodes; - for (int i = 0; i < state->nodes.size(); i++) { + for (int i = 0; i < p_state->nodes.size(); i++) { Dictionary node; - Ref<GLTFNode> gltf_node = state->nodes[i]; + Ref<GLTFNode> gltf_node = p_state->nodes[i]; Dictionary extensions; node["extensions"] = extensions; if (!gltf_node->get_name().is_empty()) { @@ -453,18 +445,18 @@ Error GLTFDocument::_serialize_nodes(Ref<GLTFState> state) { for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - ERR_CONTINUE(!state->scene_nodes.find(i)); - Error err = ext->export_node(state, gltf_node, node, state->scene_nodes[i]); + ERR_CONTINUE(!p_state->scene_nodes.find(i)); + Error err = ext->export_node(p_state, gltf_node, node, p_state->scene_nodes[i]); ERR_CONTINUE(err != OK); } nodes.push_back(node); } - state->json["nodes"] = nodes; + p_state->json["nodes"] = nodes; return OK; } -String GLTFDocument::_gen_unique_name(Ref<GLTFState> state, const String &p_name) { +String GLTFDocument::_gen_unique_name(Ref<GLTFState> p_state, const String &p_name) { const String s_name = p_name.validate_node_name(); String u_name; @@ -475,13 +467,13 @@ String GLTFDocument::_gen_unique_name(Ref<GLTFState> state, const String &p_name if (index > 1) { u_name += itos(index); } - if (!state->unique_names.has(u_name)) { + if (!p_state->unique_names.has(u_name)) { break; } index++; } - state->unique_names.insert(u_name); + p_state->unique_names.insert(u_name); return u_name; } @@ -497,7 +489,7 @@ String GLTFDocument::_sanitize_animation_name(const String &p_name) { return anim_name; } -String GLTFDocument::_gen_unique_animation_name(Ref<GLTFState> state, const String &p_name) { +String GLTFDocument::_gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name) { const String s_name = _sanitize_animation_name(p_name); String u_name; @@ -508,13 +500,13 @@ String GLTFDocument::_gen_unique_animation_name(Ref<GLTFState> state, const Stri if (index > 1) { u_name += itos(index); } - if (!state->unique_animation_names.has(u_name)) { + if (!p_state->unique_animation_names.has(u_name)) { break; } index++; } - state->unique_animation_names.insert(u_name); + p_state->unique_animation_names.insert(u_name); return u_name; } @@ -526,7 +518,7 @@ String GLTFDocument::_sanitize_bone_name(const String &p_name) { return bone_name; } -String GLTFDocument::_gen_unique_bone_name(Ref<GLTFState> state, const GLTFSkeletonIndex skel_i, const String &p_name) { +String GLTFDocument::_gen_unique_bone_name(Ref<GLTFState> p_state, const GLTFSkeletonIndex p_skel_i, const String &p_name) { String s_name = _sanitize_bone_name(p_name); if (s_name.is_empty()) { s_name = "bone"; @@ -539,23 +531,23 @@ String GLTFDocument::_gen_unique_bone_name(Ref<GLTFState> state, const GLTFSkele if (index > 1) { u_name += "_" + itos(index); } - if (!state->skeletons[skel_i]->unique_names.has(u_name)) { + if (!p_state->skeletons[p_skel_i]->unique_names.has(u_name)) { break; } index++; } - state->skeletons.write[skel_i]->unique_names.insert(u_name); + p_state->skeletons.write[p_skel_i]->unique_names.insert(u_name); return u_name; } -Error GLTFDocument::_parse_scenes(Ref<GLTFState> state) { - ERR_FAIL_COND_V(!state->json.has("scenes"), ERR_FILE_CORRUPT); - const Array &scenes = state->json["scenes"]; +Error GLTFDocument::_parse_scenes(Ref<GLTFState> p_state) { + ERR_FAIL_COND_V(!p_state->json.has("scenes"), ERR_FILE_CORRUPT); + const Array &scenes = p_state->json["scenes"]; int loaded_scene = 0; - if (state->json.has("scene")) { - loaded_scene = state->json["scene"]; + if (p_state->json.has("scene")) { + loaded_scene = p_state->json["scene"]; } else { WARN_PRINT("The load-time scene is not defined in the glTF2 file. Picking the first scene."); } @@ -566,22 +558,22 @@ Error GLTFDocument::_parse_scenes(Ref<GLTFState> state) { ERR_FAIL_COND_V(!s.has("nodes"), ERR_UNAVAILABLE); const Array &nodes = s["nodes"]; for (int j = 0; j < nodes.size(); j++) { - state->root_nodes.push_back(nodes[j]); + p_state->root_nodes.push_back(nodes[j]); } if (s.has("name") && !String(s["name"]).is_empty() && !((String)s["name"]).begins_with("Scene")) { - state->scene_name = _gen_unique_name(state, s["name"]); + p_state->scene_name = _gen_unique_name(p_state, s["name"]); } else { - state->scene_name = _gen_unique_name(state, state->filename); + p_state->scene_name = _gen_unique_name(p_state, p_state->filename); } } return OK; } -Error GLTFDocument::_parse_nodes(Ref<GLTFState> state) { - ERR_FAIL_COND_V(!state->json.has("nodes"), ERR_FILE_CORRUPT); - const Array &nodes = state->json["nodes"]; +Error GLTFDocument::_parse_nodes(Ref<GLTFState> p_state) { + ERR_FAIL_COND_V(!p_state->json.has("nodes"), ERR_FILE_CORRUPT); + const Array &nodes = p_state->json["nodes"]; for (int i = 0; i < nodes.size(); i++) { Ref<GLTFNode> node; node.instantiate(); @@ -627,8 +619,8 @@ Error GLTFDocument::_parse_nodes(Ref<GLTFState> state) { } for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - Error err = ext->parse_node_extensions(state, node, extensions); - ERR_CONTINUE_MSG(err != OK, "GLTF: Encountered error " + itos(err) + " when parsing node extensions for node " + node->get_name() + " in file " + state->filename + ". Continuing."); + Error err = ext->parse_node_extensions(p_state, node, extensions); + ERR_CONTINUE_MSG(err != OK, "GLTF: Encountered error " + itos(err) + " when parsing node extensions for node " + node->get_name() + " in file " + p_state->filename + ". Continuing."); } } @@ -639,35 +631,35 @@ Error GLTFDocument::_parse_nodes(Ref<GLTFState> state) { } } - state->nodes.push_back(node); + p_state->nodes.push_back(node); } // build the hierarchy - for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); node_i++) { - for (int j = 0; j < state->nodes[node_i]->children.size(); j++) { - GLTFNodeIndex child_i = state->nodes[node_i]->children[j]; + for (GLTFNodeIndex node_i = 0; node_i < p_state->nodes.size(); node_i++) { + for (int j = 0; j < p_state->nodes[node_i]->children.size(); j++) { + GLTFNodeIndex child_i = p_state->nodes[node_i]->children[j]; - ERR_FAIL_INDEX_V(child_i, state->nodes.size(), ERR_FILE_CORRUPT); - ERR_CONTINUE(state->nodes[child_i]->parent != -1); //node already has a parent, wtf. + ERR_FAIL_INDEX_V(child_i, p_state->nodes.size(), ERR_FILE_CORRUPT); + ERR_CONTINUE(p_state->nodes[child_i]->parent != -1); //node already has a parent, wtf. - state->nodes.write[child_i]->parent = node_i; + p_state->nodes.write[child_i]->parent = node_i; } } - _compute_node_heights(state); + _compute_node_heights(p_state); return OK; } -void GLTFDocument::_compute_node_heights(Ref<GLTFState> state) { - state->root_nodes.clear(); - for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); ++node_i) { - Ref<GLTFNode> node = state->nodes[node_i]; +void GLTFDocument::_compute_node_heights(Ref<GLTFState> p_state) { + p_state->root_nodes.clear(); + for (GLTFNodeIndex node_i = 0; node_i < p_state->nodes.size(); ++node_i) { + Ref<GLTFNode> node = p_state->nodes[node_i]; node->height = 0; GLTFNodeIndex current_i = node_i; while (current_i >= 0) { - const GLTFNodeIndex parent_i = state->nodes[current_i]->parent; + const GLTFNodeIndex parent_i = p_state->nodes[current_i]->parent; if (parent_i >= 0) { ++node->height; } @@ -675,7 +667,7 @@ void GLTFDocument::_compute_node_heights(Ref<GLTFState> state) { } if (node->height == 0) { - state->root_nodes.push_back(node_i); + p_state->root_nodes.push_back(node_i); } } } @@ -698,86 +690,86 @@ static Vector<uint8_t> _parse_base64_uri(const String &uri) { return buf; } -Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> state, const String &p_path) { - print_verbose("glTF: Total buffers: " + itos(state->buffers.size())); +Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path) { + print_verbose("glTF: Total buffers: " + itos(p_state->buffers.size())); - if (!state->buffers.size()) { + if (!p_state->buffers.size()) { return OK; } Array buffers; - if (state->buffers.size()) { - Vector<uint8_t> buffer_data = state->buffers[0]; + if (p_state->buffers.size()) { + Vector<uint8_t> buffer_data = p_state->buffers[0]; Dictionary gltf_buffer; gltf_buffer["byteLength"] = buffer_data.size(); buffers.push_back(gltf_buffer); } - for (GLTFBufferIndex i = 1; i < state->buffers.size() - 1; i++) { - Vector<uint8_t> buffer_data = state->buffers[i]; + for (GLTFBufferIndex i = 1; i < p_state->buffers.size() - 1; i++) { + Vector<uint8_t> buffer_data = p_state->buffers[i]; Dictionary gltf_buffer; String filename = p_path.get_basename().get_file() + itos(i) + ".bin"; String path = p_path.get_base_dir() + "/" + filename; Error err; - Ref<FileAccess> f = FileAccess::open(path, FileAccess::WRITE, &err); - if (f.is_null()) { + Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &err); + if (file.is_null()) { return err; } if (buffer_data.size() == 0) { return OK; } - f->create(FileAccess::ACCESS_RESOURCES); - f->store_buffer(buffer_data.ptr(), buffer_data.size()); + file->create(FileAccess::ACCESS_RESOURCES); + file->store_buffer(buffer_data.ptr(), buffer_data.size()); gltf_buffer["uri"] = filename; gltf_buffer["byteLength"] = buffer_data.size(); buffers.push_back(gltf_buffer); } - state->json["buffers"] = buffers; + p_state->json["buffers"] = buffers; return OK; } -Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> state, const String &p_path) { - print_verbose("glTF: Total buffers: " + itos(state->buffers.size())); +Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path) { + print_verbose("glTF: Total buffers: " + itos(p_state->buffers.size())); - if (!state->buffers.size()) { + if (!p_state->buffers.size()) { return OK; } Array buffers; - for (GLTFBufferIndex i = 0; i < state->buffers.size(); i++) { - Vector<uint8_t> buffer_data = state->buffers[i]; + for (GLTFBufferIndex i = 0; i < p_state->buffers.size(); i++) { + Vector<uint8_t> buffer_data = p_state->buffers[i]; Dictionary gltf_buffer; String filename = p_path.get_basename().get_file() + itos(i) + ".bin"; String path = p_path.get_base_dir() + "/" + filename; Error err; - Ref<FileAccess> f = FileAccess::open(path, FileAccess::WRITE, &err); - if (f.is_null()) { + Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &err); + if (file.is_null()) { return err; } if (buffer_data.size() == 0) { return OK; } - f->create(FileAccess::ACCESS_RESOURCES); - f->store_buffer(buffer_data.ptr(), buffer_data.size()); + file->create(FileAccess::ACCESS_RESOURCES); + file->store_buffer(buffer_data.ptr(), buffer_data.size()); gltf_buffer["uri"] = filename; gltf_buffer["byteLength"] = buffer_data.size(); buffers.push_back(gltf_buffer); } - state->json["buffers"] = buffers; + p_state->json["buffers"] = buffers; return OK; } -Error GLTFDocument::_parse_buffers(Ref<GLTFState> state, const String &p_base_path) { - if (!state->json.has("buffers")) { +Error GLTFDocument::_parse_buffers(Ref<GLTFState> p_state, const String &p_base_path) { + if (!p_state->json.has("buffers")) { return OK; } - const Array &buffers = state->json["buffers"]; + const Array &buffers = p_state->json["buffers"]; for (GLTFBufferIndex i = 0; i < buffers.size(); i++) { - if (i == 0 && state->glb_data.size()) { - state->buffers.push_back(state->glb_data); + if (i == 0 && p_state->glb_data.size()) { + p_state->buffers.push_back(p_state->glb_data); } else { const Dictionary &buffer = buffers[i]; @@ -803,22 +795,22 @@ Error GLTFDocument::_parse_buffers(Ref<GLTFState> state, const String &p_base_pa ERR_FAIL_COND_V(!buffer.has("byteLength"), ERR_PARSE_ERROR); int byteLength = buffer["byteLength"]; ERR_FAIL_COND_V(byteLength < buffer_data.size(), ERR_PARSE_ERROR); - state->buffers.push_back(buffer_data); + p_state->buffers.push_back(buffer_data); } } } - print_verbose("glTF: Total buffers: " + itos(state->buffers.size())); + print_verbose("glTF: Total buffers: " + itos(p_state->buffers.size())); return OK; } -Error GLTFDocument::_encode_buffer_views(Ref<GLTFState> state) { +Error GLTFDocument::_encode_buffer_views(Ref<GLTFState> p_state) { Array buffers; - for (GLTFBufferViewIndex i = 0; i < state->buffer_views.size(); i++) { + for (GLTFBufferViewIndex i = 0; i < p_state->buffer_views.size(); i++) { Dictionary d; - Ref<GLTFBufferView> buffer_view = state->buffer_views[i]; + Ref<GLTFBufferView> buffer_view = p_state->buffer_views[i]; d["buffer"] = buffer_view->buffer; d["byteLength"] = buffer_view->byte_length; @@ -836,19 +828,19 @@ Error GLTFDocument::_encode_buffer_views(Ref<GLTFState> state) { ERR_FAIL_COND_V(!d.has("byteLength"), ERR_INVALID_DATA); buffers.push_back(d); } - print_verbose("glTF: Total buffer views: " + itos(state->buffer_views.size())); + print_verbose("glTF: Total buffer views: " + itos(p_state->buffer_views.size())); if (!buffers.size()) { return OK; } - state->json["bufferViews"] = buffers; + p_state->json["bufferViews"] = buffers; return OK; } -Error GLTFDocument::_parse_buffer_views(Ref<GLTFState> state) { - if (!state->json.has("bufferViews")) { +Error GLTFDocument::_parse_buffer_views(Ref<GLTFState> p_state) { + if (!p_state->json.has("bufferViews")) { return OK; } - const Array &buffers = state->json["bufferViews"]; + const Array &buffers = p_state->json["bufferViews"]; for (GLTFBufferViewIndex i = 0; i < buffers.size(); i++) { const Dictionary &d = buffers[i]; @@ -873,20 +865,20 @@ Error GLTFDocument::_parse_buffer_views(Ref<GLTFState> state) { buffer_view->indices = target == GLTFDocument::ELEMENT_ARRAY_BUFFER; } - state->buffer_views.push_back(buffer_view); + p_state->buffer_views.push_back(buffer_view); } - print_verbose("glTF: Total buffer views: " + itos(state->buffer_views.size())); + print_verbose("glTF: Total buffer views: " + itos(p_state->buffer_views.size())); return OK; } -Error GLTFDocument::_encode_accessors(Ref<GLTFState> state) { +Error GLTFDocument::_encode_accessors(Ref<GLTFState> p_state) { Array accessors; - for (GLTFAccessorIndex i = 0; i < state->accessors.size(); i++) { + for (GLTFAccessorIndex i = 0; i < p_state->accessors.size(); i++) { Dictionary d; - Ref<GLTFAccessor> accessor = state->accessors[i]; + Ref<GLTFAccessor> accessor = p_state->accessors[i]; d["componentType"] = accessor->component_type; d["count"] = accessor->count; d["type"] = _get_accessor_type_name(accessor->type); @@ -932,9 +924,9 @@ Error GLTFDocument::_encode_accessors(Ref<GLTFState> state) { if (!accessors.size()) { return OK; } - state->json["accessors"] = accessors; - ERR_FAIL_COND_V(!state->json.has("accessors"), ERR_FILE_CORRUPT); - print_verbose("glTF: Total accessors: " + itos(state->accessors.size())); + p_state->json["accessors"] = accessors; + ERR_FAIL_COND_V(!p_state->json.has("accessors"), ERR_FILE_CORRUPT); + print_verbose("glTF: Total accessors: " + itos(p_state->accessors.size())); return OK; } @@ -993,11 +985,11 @@ GLTFType GLTFDocument::_get_type_from_str(const String &p_string) { ERR_FAIL_V(GLTFType::TYPE_SCALAR); } -Error GLTFDocument::_parse_accessors(Ref<GLTFState> state) { - if (!state->json.has("accessors")) { +Error GLTFDocument::_parse_accessors(Ref<GLTFState> p_state) { + if (!p_state->json.has("accessors")) { return OK; } - const Array &accessors = state->json["accessors"]; + const Array &accessors = p_state->json["accessors"]; for (GLTFAccessorIndex i = 0; i < accessors.size(); i++) { const Dictionary &d = accessors[i]; @@ -1060,10 +1052,10 @@ Error GLTFDocument::_parse_accessors(Ref<GLTFState> state) { } } - state->accessors.push_back(accessor); + p_state->accessors.push_back(accessor); } - print_verbose("glTF: Total accessors: " + itos(state->accessors.size())); + print_verbose("glTF: Total accessors: " + itos(p_state->accessors.size())); return OK; } @@ -1108,33 +1100,33 @@ String GLTFDocument::_get_type_name(const GLTFType p_component) { return names[p_component]; } -Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, const int count, const GLTFType type, const int component_type, const bool normalized, const int byte_offset, const bool for_vertex, GLTFBufferViewIndex &r_accessor) { +Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, const int p_count, const GLTFType p_type, const int p_component_type, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_accessor) { const int component_count_for_type[7] = { 1, 2, 3, 4, 4, 9, 16 }; - const int component_count = component_count_for_type[type]; - const int component_size = _get_component_type_size(component_type); + const int component_count = component_count_for_type[p_type]; + const int component_size = _get_component_type_size(p_component_type); ERR_FAIL_COND_V(component_size == 0, FAILED); int skip_every = 0; int skip_bytes = 0; //special case of alignments, as described in spec - switch (component_type) { + switch (p_component_type) { case COMPONENT_TYPE_BYTE: case COMPONENT_TYPE_UNSIGNED_BYTE: { - if (type == TYPE_MAT2) { + if (p_type == TYPE_MAT2) { skip_every = 2; skip_bytes = 2; } - if (type == TYPE_MAT3) { + if (p_type == TYPE_MAT3) { skip_every = 3; skip_bytes = 1; } } break; case COMPONENT_TYPE_SHORT: case COMPONENT_TYPE_UNSIGNED_SHORT: { - if (type == TYPE_MAT3) { + if (p_type == TYPE_MAT3) { skip_every = 6; skip_bytes = 4; } @@ -1145,39 +1137,39 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, Ref<GLTFBufferView> bv; bv.instantiate(); - const uint32_t offset = bv->byte_offset = byte_offset; - Vector<uint8_t> &gltf_buffer = state->buffers.write[0]; + const uint32_t offset = bv->byte_offset = p_byte_offset; + Vector<uint8_t> &gltf_buffer = p_state->buffers.write[0]; - int stride = _get_component_type_size(component_type); - if (for_vertex && stride % 4) { + int stride = _get_component_type_size(p_component_type); + if (p_for_vertex && stride % 4) { stride += 4 - (stride % 4); //according to spec must be multiple of 4 } //use to debug - print_verbose("glTF: encoding type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count)); + print_verbose("glTF: encoding type " + _get_type_name(p_type) + " component type: " + _get_component_type_name(p_component_type) + " stride: " + itos(stride) + " amount " + itos(p_count)); - print_verbose("glTF: encoding accessor offset " + itos(byte_offset) + " view offset: " + itos(bv->byte_offset) + " total buffer len: " + itos(gltf_buffer.size()) + " view len " + itos(bv->byte_length)); + print_verbose("glTF: encoding accessor offset " + itos(p_byte_offset) + " view offset: " + itos(bv->byte_offset) + " total buffer len: " + itos(gltf_buffer.size()) + " view len " + itos(bv->byte_length)); - const int buffer_end = (stride * (count - 1)) + _get_component_type_size(component_type); + const int buffer_end = (stride * (p_count - 1)) + _get_component_type_size(p_component_type); // TODO define bv->byte_stride bv->byte_offset = gltf_buffer.size(); - switch (component_type) { + switch (p_component_type) { case COMPONENT_TYPE_BYTE: { Vector<int8_t> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; - if (normalized) { + double d = *p_src; + if (p_normalized) { buffer.write[dst_i] = d * 128.0; } else { buffer.write[dst_i] = d; } - src++; + p_src++; dst_i++; } } @@ -1188,20 +1180,20 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } break; case COMPONENT_TYPE_UNSIGNED_BYTE: { Vector<uint8_t> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; - if (normalized) { + double d = *p_src; + if (p_normalized) { buffer.write[dst_i] = d * 255.0; } else { buffer.write[dst_i] = d; } - src++; + p_src++; dst_i++; } } @@ -1210,20 +1202,20 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } break; case COMPONENT_TYPE_SHORT: { Vector<int16_t> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; - if (normalized) { + double d = *p_src; + if (p_normalized) { buffer.write[dst_i] = d * 32768.0; } else { buffer.write[dst_i] = d; } - src++; + p_src++; dst_i++; } } @@ -1234,20 +1226,20 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } break; case COMPONENT_TYPE_UNSIGNED_SHORT: { Vector<uint16_t> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; - if (normalized) { + double d = *p_src; + if (p_normalized) { buffer.write[dst_i] = d * 65535.0; } else { buffer.write[dst_i] = d; } - src++; + p_src++; dst_i++; } } @@ -1258,16 +1250,16 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } break; case COMPONENT_TYPE_INT: { Vector<int> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; + double d = *p_src; buffer.write[dst_i] = d; - src++; + p_src++; dst_i++; } } @@ -1278,16 +1270,16 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, } break; case COMPONENT_TYPE_FLOAT: { Vector<float> buffer; - buffer.resize(count * component_count); + buffer.resize(p_count * component_count); int32_t dst_i = 0; - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { for (int j = 0; j < component_count; j++) { if (skip_every && j > 0 && (j % skip_every) == 0) { dst_i += skip_bytes; } - double d = *src; + double d = *p_src; buffer.write[dst_i] = d; - src++; + p_src++; dst_i++; } } @@ -1300,53 +1292,53 @@ Error GLTFDocument::_encode_buffer_view(Ref<GLTFState> state, const double *src, ERR_FAIL_COND_V(buffer_end > bv->byte_length, ERR_INVALID_DATA); ERR_FAIL_COND_V((int)(offset + buffer_end) > gltf_buffer.size(), ERR_INVALID_DATA); - r_accessor = bv->buffer = state->buffer_views.size(); - state->buffer_views.push_back(bv); + r_accessor = bv->buffer = p_state->buffer_views.size(); + p_state->buffer_views.push_back(bv); return OK; } -Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> state, double *dst, const GLTFBufferViewIndex p_buffer_view, const int skip_every, const int skip_bytes, const int element_size, const int count, const GLTFType type, const int component_count, const int component_type, const int component_size, const bool normalized, const int byte_offset, const bool for_vertex) { - const Ref<GLTFBufferView> bv = state->buffer_views[p_buffer_view]; +Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, const GLTFBufferViewIndex p_buffer_view, const int p_skip_every, const int p_skip_bytes, const int p_element_size, const int p_count, const GLTFType p_type, const int p_component_count, const int p_component_type, const int p_component_size, const bool p_normalized, const int p_byte_offset, const bool p_for_vertex) { + const Ref<GLTFBufferView> bv = p_state->buffer_views[p_buffer_view]; - int stride = element_size; + int stride = p_element_size; if (bv->byte_stride != -1) { stride = bv->byte_stride; } - if (for_vertex && stride % 4) { + if (p_for_vertex && stride % 4) { stride += 4 - (stride % 4); //according to spec must be multiple of 4 } - ERR_FAIL_INDEX_V(bv->buffer, state->buffers.size(), ERR_PARSE_ERROR); + ERR_FAIL_INDEX_V(bv->buffer, p_state->buffers.size(), ERR_PARSE_ERROR); - const uint32_t offset = bv->byte_offset + byte_offset; - Vector<uint8_t> buffer = state->buffers[bv->buffer]; //copy on write, so no performance hit + const uint32_t offset = bv->byte_offset + p_byte_offset; + Vector<uint8_t> buffer = p_state->buffers[bv->buffer]; //copy on write, so no performance hit const uint8_t *bufptr = buffer.ptr(); //use to debug - print_verbose("glTF: type " + _get_type_name(type) + " component type: " + _get_component_type_name(component_type) + " stride: " + itos(stride) + " amount " + itos(count)); - print_verbose("glTF: accessor offset " + itos(byte_offset) + " view offset: " + itos(bv->byte_offset) + " total buffer len: " + itos(buffer.size()) + " view len " + itos(bv->byte_length)); + print_verbose("glTF: type " + _get_type_name(p_type) + " component type: " + _get_component_type_name(p_component_type) + " stride: " + itos(stride) + " amount " + itos(p_count)); + print_verbose("glTF: accessor offset " + itos(p_byte_offset) + " view offset: " + itos(bv->byte_offset) + " total buffer len: " + itos(buffer.size()) + " view len " + itos(bv->byte_length)); - const int buffer_end = (stride * (count - 1)) + element_size; + const int buffer_end = (stride * (p_count - 1)) + p_element_size; ERR_FAIL_COND_V(buffer_end > bv->byte_length, ERR_PARSE_ERROR); ERR_FAIL_COND_V((int)(offset + buffer_end) > buffer.size(), ERR_PARSE_ERROR); //fill everything as doubles - for (int i = 0; i < count; i++) { + for (int i = 0; i < p_count; i++) { const uint8_t *src = &bufptr[offset + i * stride]; - for (int j = 0; j < component_count; j++) { - if (skip_every && j > 0 && (j % skip_every) == 0) { - src += skip_bytes; + for (int j = 0; j < p_component_count; j++) { + if (p_skip_every && j > 0 && (j % p_skip_every) == 0) { + src += p_skip_bytes; } double d = 0; - switch (component_type) { + switch (p_component_type) { case COMPONENT_TYPE_BYTE: { int8_t b = int8_t(*src); - if (normalized) { + if (p_normalized) { d = (double(b) / 128.0); } else { d = double(b); @@ -1354,7 +1346,7 @@ Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> state, double *dst, const } break; case COMPONENT_TYPE_UNSIGNED_BYTE: { uint8_t b = *src; - if (normalized) { + if (p_normalized) { d = (double(b) / 255.0); } else { d = double(b); @@ -1362,7 +1354,7 @@ Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> state, double *dst, const } break; case COMPONENT_TYPE_SHORT: { int16_t s = *(int16_t *)src; - if (normalized) { + if (p_normalized) { d = (double(s) / 32768.0); } else { d = double(s); @@ -1370,7 +1362,7 @@ Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> state, double *dst, const } break; case COMPONENT_TYPE_UNSIGNED_SHORT: { uint16_t s = *(uint16_t *)src; - if (normalized) { + if (p_normalized) { d = (double(s) / 65535.0); } else { d = double(s); @@ -1384,16 +1376,16 @@ Error GLTFDocument::_decode_buffer_view(Ref<GLTFState> state, double *dst, const } break; } - *dst++ = d; - src += component_size; + *p_dst++ = d; + src += p_component_size; } } return OK; } -int GLTFDocument::_get_component_type_size(const int component_type) { - switch (component_type) { +int GLTFDocument::_get_component_type_size(const int p_component_type) { + switch (p_component_type) { case COMPONENT_TYPE_BYTE: case COMPONENT_TYPE_UNSIGNED_BYTE: return 1; @@ -1413,13 +1405,13 @@ int GLTFDocument::_get_component_type_size(const int component_type) { return 0; } -Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { +Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { //spec, for reference: //https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment - ERR_FAIL_INDEX_V(p_accessor, state->accessors.size(), Vector<double>()); + ERR_FAIL_INDEX_V(p_accessor, p_state->accessors.size(), Vector<double>()); - const Ref<GLTFAccessor> a = state->accessors[p_accessor]; + const Ref<GLTFAccessor> a = p_state->accessors[p_accessor]; const int component_count_for_type[7] = { 1, 2, 3, 4, 4, 9, 16 @@ -1464,9 +1456,9 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> state, const GLTFAc double *dst = dst_buffer.ptrw(); if (a->buffer_view >= 0) { - ERR_FAIL_INDEX_V(a->buffer_view, state->buffer_views.size(), Vector<double>()); + ERR_FAIL_INDEX_V(a->buffer_view, p_state->buffer_views.size(), Vector<double>()); - const Error err = _decode_buffer_view(state, dst, a->buffer_view, skip_every, skip_bytes, element_size, a->count, a->type, component_count, a->component_type, component_size, a->normalized, a->byte_offset, p_for_vertex); + const Error err = _decode_buffer_view(p_state, dst, a->buffer_view, skip_every, skip_bytes, element_size, a->count, a->type, component_count, a->component_type, component_size, a->normalized, a->byte_offset, p_for_vertex); if (err != OK) { return Vector<double>(); } @@ -1483,14 +1475,14 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> state, const GLTFAc indices.resize(a->sparse_count); const int indices_component_size = _get_component_type_size(a->sparse_indices_component_type); - Error err = _decode_buffer_view(state, indices.ptrw(), a->sparse_indices_buffer_view, 0, 0, indices_component_size, a->sparse_count, TYPE_SCALAR, 1, a->sparse_indices_component_type, indices_component_size, false, a->sparse_indices_byte_offset, false); + Error err = _decode_buffer_view(p_state, indices.ptrw(), a->sparse_indices_buffer_view, 0, 0, indices_component_size, a->sparse_count, TYPE_SCALAR, 1, a->sparse_indices_component_type, indices_component_size, false, a->sparse_indices_byte_offset, false); if (err != OK) { return Vector<double>(); } Vector<double> data; data.resize(component_count * a->sparse_count); - err = _decode_buffer_view(state, data.ptrw(), a->sparse_values_buffer_view, skip_every, skip_bytes, element_size, a->sparse_count, a->type, component_count, a->component_type, component_size, a->normalized, a->sparse_values_byte_offset, p_for_vertex); + err = _decode_buffer_view(p_state, data.ptrw(), a->sparse_values_buffer_view, skip_every, skip_bytes, element_size, a->sparse_count, a->type, component_count, a->component_type, component_size, a->normalized, a->sparse_values_byte_offset, p_for_vertex); if (err != OK) { return Vector<double>(); } @@ -1507,7 +1499,7 @@ Vector<double> GLTFDocument::_decode_accessor(Ref<GLTFState> state, const GLTFAc return dst_buffer; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> state, const Vector<int32_t> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> p_state, const Vector<int32_t> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1540,7 +1532,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> state, c Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_SCALAR; const int component_type = GLTFDocument::COMPONENT_TYPE_INT; @@ -1551,17 +1543,17 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_ints(Ref<GLTFState> state, c accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -Vector<int> GLTFDocument::_decode_accessor_as_ints(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<int> GLTFDocument::_decode_accessor_as_ints(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<int> ret; if (attribs.size() == 0) { @@ -1579,8 +1571,8 @@ Vector<int> GLTFDocument::_decode_accessor_as_ints(Ref<GLTFState> state, const G return ret; } -Vector<float> GLTFDocument::_decode_accessor_as_floats(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<float> GLTFDocument::_decode_accessor_as_floats(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<float> ret; if (attribs.size() == 0) { @@ -1598,7 +1590,7 @@ Vector<float> GLTFDocument::_decode_accessor_as_floats(Ref<GLTFState> state, con return ret; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> state, const Vector<Vector2> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> p_state, const Vector<Vector2> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1624,7 +1616,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> state, c Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC2; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1635,16 +1627,16 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec2(Ref<GLTFState> state, c accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> state, const Vector<Color> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1673,7 +1665,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> state, Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1684,31 +1676,31 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_color(Ref<GLTFState> state, accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -void GLTFDocument::_calc_accessor_min_max(int i, const int element_count, Vector<double> &type_max, Vector<double> attribs, Vector<double> &type_min) { - if (i == 0) { - for (int32_t type_i = 0; type_i < element_count; type_i++) { - type_max.write[type_i] = attribs[(i * element_count) + type_i]; - type_min.write[type_i] = attribs[(i * element_count) + type_i]; +void GLTFDocument::_calc_accessor_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min) { + if (p_i == 0) { + for (int32_t type_i = 0; type_i < p_element_count; type_i++) { + p_type_max.write[type_i] = p_attribs[(p_i * p_element_count) + type_i]; + p_type_min.write[type_i] = p_attribs[(p_i * p_element_count) + type_i]; } } - for (int32_t type_i = 0; type_i < element_count; type_i++) { - type_max.write[type_i] = MAX(attribs[(i * element_count) + type_i], type_max[type_i]); - type_min.write[type_i] = MIN(attribs[(i * element_count) + type_i], type_min[type_i]); - type_max.write[type_i] = _filter_number(type_max.write[type_i]); - type_min.write[type_i] = _filter_number(type_min.write[type_i]); + for (int32_t type_i = 0; type_i < p_element_count; type_i++) { + p_type_max.write[type_i] = MAX(p_attribs[(p_i * p_element_count) + type_i], p_type_max[type_i]); + p_type_min.write[type_i] = MIN(p_attribs[(p_i * p_element_count) + type_i], p_type_min[type_i]); + p_type_max.write[type_i] = _filter_number(p_type_max.write[type_i]); + p_type_min.write[type_i] = _filter_number(p_type_min.write[type_i]); } } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> state, const Vector<Color> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1738,7 +1730,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> state Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1749,16 +1741,16 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_weights(Ref<GLTFState> state accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state, const Vector<Color> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1785,7 +1777,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state, Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_UNSIGNED_SHORT; @@ -1796,16 +1788,16 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_joints(Ref<GLTFState> state, accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> state, const Vector<Quaternion> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> p_state, const Vector<Quaternion> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1834,7 +1826,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> s Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1845,17 +1837,17 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_quaternions(Ref<GLTFState> s accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Vector2> ret; if (attribs.size() == 0) { @@ -1874,7 +1866,7 @@ Vector<Vector2> GLTFDocument::_decode_accessor_as_vec2(Ref<GLTFState> state, con return ret; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> state, const Vector<real_t> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> p_state, const Vector<real_t> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1899,7 +1891,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> state, Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_SCALAR; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1910,16 +1902,16 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_floats(Ref<GLTFState> state, accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, const Vector<Vector3> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -1945,7 +1937,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, c Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_VEC3; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -1956,16 +1948,16 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_vec3(Ref<GLTFState> state, c accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, const Vector<Transform3D> p_attribs, const bool p_for_vertex) { +GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> p_state, const Vector<Transform3D> p_attribs, const bool p_for_vertex) { if (p_attribs.size() == 0) { return -1; } @@ -2013,7 +2005,7 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, Ref<GLTFAccessor> accessor; accessor.instantiate(); GLTFBufferIndex buffer_view_i; - int64_t size = state->buffers[0].size(); + int64_t size = p_state->buffers[0].size(); const GLTFType type = GLTFType::TYPE_MAT4; const int component_type = GLTFDocument::COMPONENT_TYPE_FLOAT; @@ -2024,17 +2016,17 @@ GLTFAccessorIndex GLTFDocument::_encode_accessor_as_xform(Ref<GLTFState> state, accessor->type = type; accessor->component_type = component_type; accessor->byte_offset = 0; - Error err = _encode_buffer_view(state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); + Error err = _encode_buffer_view(p_state, attribs.ptr(), p_attribs.size(), type, component_type, accessor->normalized, size, p_for_vertex, buffer_view_i); if (err != OK) { return -1; } accessor->buffer_view = buffer_view_i; - state->accessors.push_back(accessor); - return state->accessors.size() - 1; + p_state->accessors.push_back(accessor); + return p_state->accessors.size() - 1; } -Vector<Vector3> GLTFDocument::_decode_accessor_as_vec3(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Vector3> GLTFDocument::_decode_accessor_as_vec3(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Vector3> ret; if (attribs.size() == 0) { @@ -2053,15 +2045,15 @@ Vector<Vector3> GLTFDocument::_decode_accessor_as_vec3(Ref<GLTFState> state, con return ret; } -Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Color> ret; if (attribs.size() == 0) { return ret; } - const int type = state->accessors[p_accessor]->type; + const int type = p_state->accessors[p_accessor]->type; ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret); int vec_len = 3; if (type == TYPE_VEC4) { @@ -2079,8 +2071,8 @@ Vector<Color> GLTFDocument::_decode_accessor_as_color(Ref<GLTFState> state, cons } return ret; } -Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Quaternion> ret; if (attribs.size() == 0) { @@ -2098,8 +2090,8 @@ Vector<Quaternion> GLTFDocument::_decode_accessor_as_quaternion(Ref<GLTFState> s } return ret; } -Vector<Transform2D> GLTFDocument::_decode_accessor_as_xform2d(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Transform2D> GLTFDocument::_decode_accessor_as_xform2d(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Transform2D> ret; if (attribs.size() == 0) { @@ -2115,8 +2107,8 @@ Vector<Transform2D> GLTFDocument::_decode_accessor_as_xform2d(Ref<GLTFState> sta return ret; } -Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Basis> ret; if (attribs.size() == 0) { @@ -2133,8 +2125,8 @@ Vector<Basis> GLTFDocument::_decode_accessor_as_basis(Ref<GLTFState> state, cons return ret; } -Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { - const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex); +Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex) { + const Vector<double> attribs = _decode_accessor(p_state, p_accessor, p_for_vertex); Vector<Transform3D> ret; if (attribs.size() == 0) { @@ -2152,15 +2144,15 @@ Vector<Transform3D> GLTFDocument::_decode_accessor_as_xform(Ref<GLTFState> state return ret; } -Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_meshes(Ref<GLTFState> p_state) { Array meshes; - for (GLTFMeshIndex gltf_mesh_i = 0; gltf_mesh_i < state->meshes.size(); gltf_mesh_i++) { + for (GLTFMeshIndex gltf_mesh_i = 0; gltf_mesh_i < p_state->meshes.size(); gltf_mesh_i++) { print_verbose("glTF: Serializing mesh: " + itos(gltf_mesh_i)); - Ref<ImporterMesh> import_mesh = state->meshes.write[gltf_mesh_i]->get_mesh(); + Ref<ImporterMesh> import_mesh = p_state->meshes.write[gltf_mesh_i]->get_mesh(); if (import_mesh.is_null()) { continue; } - Array instance_materials = state->meshes.write[gltf_mesh_i]->get_instance_materials(); + Array instance_materials = p_state->meshes.write[gltf_mesh_i]->get_instance_materials(); Array primitives; Dictionary gltf_mesh; Array target_names; @@ -2213,7 +2205,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { { Vector<Vector3> a = array[Mesh::ARRAY_VERTEX]; ERR_FAIL_COND_V(!a.size(), ERR_INVALID_DATA); - attributes["POSITION"] = _encode_accessor_as_vec3(state, a, true); + attributes["POSITION"] = _encode_accessor_as_vec3(p_state, a, true); vertex_num = a.size(); } { @@ -2230,7 +2222,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { out.a = a[(i * 4) + 3]; attribs.write[i] = out; } - attributes["TANGENT"] = _encode_accessor_as_color(state, attribs, true); + attributes["TANGENT"] = _encode_accessor_as_color(p_state, attribs, true); } } { @@ -2242,19 +2234,19 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { for (int i = 0; i < ret_size; i++) { attribs.write[i] = Vector3(a[i]).normalized(); } - attributes["NORMAL"] = _encode_accessor_as_vec3(state, attribs, true); + attributes["NORMAL"] = _encode_accessor_as_vec3(p_state, attribs, true); } } { Vector<Vector2> a = array[Mesh::ARRAY_TEX_UV]; if (a.size()) { - attributes["TEXCOORD_0"] = _encode_accessor_as_vec2(state, a, true); + attributes["TEXCOORD_0"] = _encode_accessor_as_vec2(p_state, a, true); } } { Vector<Vector2> a = array[Mesh::ARRAY_TEX_UV2]; if (a.size()) { - attributes["TEXCOORD_1"] = _encode_accessor_as_vec2(state, a, true); + attributes["TEXCOORD_1"] = _encode_accessor_as_vec2(p_state, a, true); } } for (int custom_i = 0; custom_i < 3; custom_i++) { @@ -2283,7 +2275,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { if (!attributes.has(gltf_texcoord_key)) { Vector<Vector2> empty; empty.resize(vertex_num); - attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(state, empty, true); + attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(p_state, empty, true); } } @@ -2304,25 +2296,25 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { } } gltf_texcoord_key = vformat("TEXCOORD_%d", texcoord_i); - attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(state, first_channel, true); + attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(p_state, first_channel, true); gltf_texcoord_key = vformat("TEXCOORD_%d", texcoord_i + 1); - attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(state, second_channel, true); + attributes[gltf_texcoord_key] = _encode_accessor_as_vec2(p_state, second_channel, true); } } { Vector<Color> a = array[Mesh::ARRAY_COLOR]; if (a.size()) { - attributes["COLOR_0"] = _encode_accessor_as_color(state, a, true); + attributes["COLOR_0"] = _encode_accessor_as_color(p_state, a, true); } } HashMap<int, int> joint_i_to_bone_i; - for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); node_i++) { + for (GLTFNodeIndex node_i = 0; node_i < p_state->nodes.size(); node_i++) { GLTFSkinIndex skin_i = -1; - if (state->nodes[node_i]->mesh == gltf_mesh_i) { - skin_i = state->nodes[node_i]->skin; + if (p_state->nodes[node_i]->mesh == gltf_mesh_i) { + skin_i = p_state->nodes[node_i]->skin; } if (skin_i != -1) { - joint_i_to_bone_i = state->skins[skin_i]->joint_i_to_bone_i; + joint_i_to_bone_i = p_state->skins[skin_i]->joint_i_to_bone_i; break; } } @@ -2342,7 +2334,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { attribs.write[array_i] = Color(joint_0, joint_1, joint_2, joint_3); } } - attributes["JOINTS_0"] = _encode_accessor_as_joints(state, attribs, true); + attributes["JOINTS_0"] = _encode_accessor_as_joints(p_state, attribs, true); } else if ((a.size() / (JOINT_GROUP_SIZE * 2)) >= vertex_array.size()) { Vector<Color> joints_0; joints_0.resize(vertex_num); @@ -2363,8 +2355,8 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { joint_1.a = a[vertex_i * weights_8_count + 7]; joints_1.write[vertex_i] = joint_1; } - attributes["JOINTS_0"] = _encode_accessor_as_joints(state, joints_0, true); - attributes["JOINTS_1"] = _encode_accessor_as_joints(state, joints_1, true); + attributes["JOINTS_0"] = _encode_accessor_as_joints(p_state, joints_0, true); + attributes["JOINTS_1"] = _encode_accessor_as_joints(p_state, joints_1, true); } } { @@ -2377,7 +2369,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { for (int i = 0; i < vertex_count; i++) { attribs.write[i] = Color(a[(i * JOINT_GROUP_SIZE) + 0], a[(i * JOINT_GROUP_SIZE) + 1], a[(i * JOINT_GROUP_SIZE) + 2], a[(i * JOINT_GROUP_SIZE) + 3]); } - attributes["WEIGHTS_0"] = _encode_accessor_as_weights(state, attribs, true); + attributes["WEIGHTS_0"] = _encode_accessor_as_weights(p_state, attribs, true); } else if ((a.size() / (JOINT_GROUP_SIZE * 2)) >= vertex_array.size()) { Vector<Color> weights_0; weights_0.resize(vertex_num); @@ -2398,8 +2390,8 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { weight_1.a = a[vertex_i * weights_8_count + 7]; weights_1.write[vertex_i] = weight_1; } - attributes["WEIGHTS_0"] = _encode_accessor_as_weights(state, weights_0, true); - attributes["WEIGHTS_1"] = _encode_accessor_as_weights(state, weights_1, true); + attributes["WEIGHTS_0"] = _encode_accessor_as_weights(p_state, weights_0, true); + attributes["WEIGHTS_1"] = _encode_accessor_as_weights(p_state, weights_1, true); } } { @@ -2412,7 +2404,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { SWAP(mesh_indices.write[k + 0], mesh_indices.write[k + 2]); } } - primitive["indices"] = _encode_accessor_as_ints(state, mesh_indices, true); + primitive["indices"] = _encode_accessor_as_ints(p_state, mesh_indices, true); } else { if (primitive_type == Mesh::PRIMITIVE_TRIANGLES) { //generate indices because they need to be swapped for CW/CCW @@ -2431,7 +2423,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { generated_indices.write[k + 2] = k + 1; } } - primitive["indices"] = _encode_accessor_as_ints(state, generated_indices, true); + primitive["indices"] = _encode_accessor_as_ints(p_state, generated_indices, true); } } } @@ -2456,12 +2448,12 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { } } - t["POSITION"] = _encode_accessor_as_vec3(state, varr, true); + t["POSITION"] = _encode_accessor_as_vec3(p_state, varr, true); } Vector<Vector3> narr = array_morph[Mesh::ARRAY_NORMAL]; if (narr.size()) { - t["NORMAL"] = _encode_accessor_as_vec3(state, narr, true); + t["NORMAL"] = _encode_accessor_as_vec3(p_state, narr, true); } Vector<real_t> tarr = array_morph[Mesh::ARRAY_TANGENT]; if (tarr.size()) { @@ -2474,7 +2466,7 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { vec3.y = tarr[(i * 4) + 1]; vec3.z = tarr[(i * 4) + 2]; } - t["TANGENT"] = _encode_accessor_as_vec3(state, attribs, true); + t["TANGENT"] = _encode_accessor_as_vec3(p_state, attribs, true); } targets.push_back(t); } @@ -2489,14 +2481,14 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { mat = import_mesh->get_surface_material(surface_i); } if (mat.is_valid()) { - HashMap<Ref<Material>, GLTFMaterialIndex>::Iterator material_cache_i = state->material_cache.find(mat); + HashMap<Ref<Material>, GLTFMaterialIndex>::Iterator material_cache_i = p_state->material_cache.find(mat); if (material_cache_i && material_cache_i->value != -1) { primitive["material"] = material_cache_i->value; } else { - GLTFMaterialIndex mat_i = state->materials.size(); - state->materials.push_back(mat); + GLTFMaterialIndex mat_i = p_state->materials.size(); + p_state->materials.push_back(mat); primitive["material"] = mat_i; - state->material_cache.insert(mat, mat_i); + p_state->material_cache.insert(mat, mat_i); } } @@ -2513,8 +2505,8 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { weights.resize(target_names.size()); for (int name_i = 0; name_i < target_names.size(); name_i++) { real_t weight = 0.0; - if (name_i < state->meshes.write[gltf_mesh_i]->get_blend_weights().size()) { - weight = state->meshes.write[gltf_mesh_i]->get_blend_weights()[name_i]; + if (name_i < p_state->meshes.write[gltf_mesh_i]->get_blend_weights().size()) { + weight = p_state->meshes.write[gltf_mesh_i]->get_blend_weights()[name_i]; } weights[name_i] = weight; } @@ -2534,18 +2526,18 @@ Error GLTFDocument::_serialize_meshes(Ref<GLTFState> state) { if (!meshes.size()) { return OK; } - state->json["meshes"] = meshes; + p_state->json["meshes"] = meshes; print_verbose("glTF: Total meshes: " + itos(meshes.size())); return OK; } -Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { - if (!state->json.has("meshes")) { +Error GLTFDocument::_parse_meshes(Ref<GLTFState> p_state) { + if (!p_state->json.has("meshes")) { return OK; } - Array meshes = state->json["meshes"]; + Array meshes = p_state->json["meshes"]; for (GLTFMeshIndex i = 0; i < meshes.size(); i++) { print_verbose("glTF: Parsing mesh: " + itos(i)); Dictionary d = meshes[i]; @@ -2564,7 +2556,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { if (d.has("name") && !String(d["name"]).is_empty()) { mesh_name = d["name"]; } - import_mesh->set_name(_gen_unique_name(state, vformat("%s_%s", state->scene_name, mesh_name))); + import_mesh->set_name(_gen_unique_name(p_state, vformat("%s_%s", p_state->scene_name, mesh_name))); for (int j = 0; j < primitives.size(); j++) { uint32_t flags = 0; @@ -2600,21 +2592,21 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { ERR_FAIL_COND_V(!a.has("POSITION"), ERR_PARSE_ERROR); int32_t vertex_num = 0; if (a.has("POSITION")) { - PackedVector3Array vertices = _decode_accessor_as_vec3(state, a["POSITION"], true); + PackedVector3Array vertices = _decode_accessor_as_vec3(p_state, a["POSITION"], true); array[Mesh::ARRAY_VERTEX] = vertices; vertex_num = vertices.size(); } if (a.has("NORMAL")) { - array[Mesh::ARRAY_NORMAL] = _decode_accessor_as_vec3(state, a["NORMAL"], true); + array[Mesh::ARRAY_NORMAL] = _decode_accessor_as_vec3(p_state, a["NORMAL"], true); } if (a.has("TANGENT")) { - array[Mesh::ARRAY_TANGENT] = _decode_accessor_as_floats(state, a["TANGENT"], true); + array[Mesh::ARRAY_TANGENT] = _decode_accessor_as_floats(p_state, a["TANGENT"], true); } if (a.has("TEXCOORD_0")) { - array[Mesh::ARRAY_TEX_UV] = _decode_accessor_as_vec2(state, a["TEXCOORD_0"], true); + array[Mesh::ARRAY_TEX_UV] = _decode_accessor_as_vec2(p_state, a["TEXCOORD_0"], true); } if (a.has("TEXCOORD_1")) { - array[Mesh::ARRAY_TEX_UV2] = _decode_accessor_as_vec2(state, a["TEXCOORD_1"], true); + array[Mesh::ARRAY_TEX_UV2] = _decode_accessor_as_vec2(p_state, a["TEXCOORD_1"], true); } for (int custom_i = 0; custom_i < 3; custom_i++) { Vector<float> cur_custom; @@ -2625,12 +2617,12 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { String gltf_texcoord_key = vformat("TEXCOORD_%d", texcoord_i); int num_channels = 0; if (a.has(gltf_texcoord_key)) { - texcoord_first = _decode_accessor_as_vec2(state, a[gltf_texcoord_key], true); + texcoord_first = _decode_accessor_as_vec2(p_state, a[gltf_texcoord_key], true); num_channels = 2; } gltf_texcoord_key = vformat("TEXCOORD_%d", texcoord_i + 1); if (a.has(gltf_texcoord_key)) { - texcoord_second = _decode_accessor_as_vec2(state, a[gltf_texcoord_key], true); + texcoord_second = _decode_accessor_as_vec2(p_state, a[gltf_texcoord_key], true); num_channels = 4; } if (!num_channels) { @@ -2671,14 +2663,14 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { } } if (a.has("COLOR_0")) { - array[Mesh::ARRAY_COLOR] = _decode_accessor_as_color(state, a["COLOR_0"], true); + array[Mesh::ARRAY_COLOR] = _decode_accessor_as_color(p_state, a["COLOR_0"], true); has_vertex_color = true; } if (a.has("JOINTS_0") && !a.has("JOINTS_1")) { - array[Mesh::ARRAY_BONES] = _decode_accessor_as_ints(state, a["JOINTS_0"], true); + array[Mesh::ARRAY_BONES] = _decode_accessor_as_ints(p_state, a["JOINTS_0"], true); } else if (a.has("JOINTS_0") && a.has("JOINTS_1")) { - PackedInt32Array joints_0 = _decode_accessor_as_ints(state, a["JOINTS_0"], true); - PackedInt32Array joints_1 = _decode_accessor_as_ints(state, a["JOINTS_1"], true); + PackedInt32Array joints_0 = _decode_accessor_as_ints(p_state, a["JOINTS_0"], true); + PackedInt32Array joints_1 = _decode_accessor_as_ints(p_state, a["JOINTS_1"], true); ERR_FAIL_COND_V(joints_0.size() != joints_1.size(), ERR_INVALID_DATA); int32_t weight_8_count = JOINT_GROUP_SIZE * 2; Vector<int> joints; @@ -2696,7 +2688,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { array[Mesh::ARRAY_BONES] = joints; } if (a.has("WEIGHTS_0") && !a.has("WEIGHTS_1")) { - Vector<float> weights = _decode_accessor_as_floats(state, a["WEIGHTS_0"], true); + Vector<float> weights = _decode_accessor_as_floats(p_state, a["WEIGHTS_0"], true); { //gltf does not seem to normalize the weights for some reason.. int wc = weights.size(); float *w = weights.ptrw(); @@ -2717,8 +2709,8 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { } array[Mesh::ARRAY_WEIGHTS] = weights; } else if (a.has("WEIGHTS_0") && a.has("WEIGHTS_1")) { - Vector<float> weights_0 = _decode_accessor_as_floats(state, a["WEIGHTS_0"], true); - Vector<float> weights_1 = _decode_accessor_as_floats(state, a["WEIGHTS_1"], true); + Vector<float> weights_0 = _decode_accessor_as_floats(p_state, a["WEIGHTS_0"], true); + Vector<float> weights_1 = _decode_accessor_as_floats(p_state, a["WEIGHTS_1"], true); Vector<float> weights; ERR_FAIL_COND_V(weights_0.size() != weights_1.size(), ERR_INVALID_DATA); int32_t weight_8_count = JOINT_GROUP_SIZE * 2; @@ -2763,7 +2755,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { } if (p.has("indices")) { - Vector<int> indices = _decode_accessor_as_ints(state, p["indices"], false); + Vector<int> indices = _decode_accessor_as_ints(p_state, p["indices"], false); if (primitive == Mesh::PRIMITIVE_TRIANGLES) { //swap around indices, convert ccw to cw for front face @@ -2837,7 +2829,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { } if (t.has("POSITION")) { - Vector<Vector3> varr = _decode_accessor_as_vec3(state, t["POSITION"], true); + Vector<Vector3> varr = _decode_accessor_as_vec3(p_state, t["POSITION"], true); const Vector<Vector3> src_varr = array[Mesh::ARRAY_VERTEX]; const int size = src_varr.size(); ERR_FAIL_COND_V(size == 0, ERR_PARSE_ERROR); @@ -2859,7 +2851,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { array_copy[Mesh::ARRAY_VERTEX] = varr; } if (t.has("NORMAL")) { - Vector<Vector3> narr = _decode_accessor_as_vec3(state, t["NORMAL"], true); + Vector<Vector3> narr = _decode_accessor_as_vec3(p_state, t["NORMAL"], true); const Vector<Vector3> src_narr = array[Mesh::ARRAY_NORMAL]; int size = src_narr.size(); ERR_FAIL_COND_V(size == 0, ERR_PARSE_ERROR); @@ -2881,7 +2873,7 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { array_copy[Mesh::ARRAY_NORMAL] = narr; } if (t.has("TANGENT")) { - const Vector<Vector3> tangents_v3 = _decode_accessor_as_vec3(state, t["TANGENT"], true); + const Vector<Vector3> tangents_v3 = _decode_accessor_as_vec3(p_state, t["TANGENT"], true); const Vector<float> src_tangents = array[Mesh::ARRAY_TANGENT]; ERR_FAIL_COND_V(src_tangents.size() == 0, ERR_PARSE_ERROR); @@ -2939,11 +2931,11 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { Ref<Material> mat; String mat_name; - if (!state->discard_meshes_and_materials) { + if (!p_state->discard_meshes_and_materials) { if (p.has("material")) { const int material = p["material"]; - ERR_FAIL_INDEX_V(material, state->materials.size(), ERR_FILE_CORRUPT); - Ref<Material> mat3d = state->materials[material]; + ERR_FAIL_INDEX_V(material, p_state->materials.size(), ERR_FILE_CORRUPT); + Ref<Material> mat3d = p_state->materials[material]; ERR_FAIL_NULL_V(mat3d, ERR_FILE_CORRUPT); Ref<BaseMaterial3D> base_material = mat3d; @@ -2985,22 +2977,22 @@ Error GLTFDocument::_parse_meshes(Ref<GLTFState> state) { mesh->set_blend_weights(blend_weights); mesh->set_mesh(import_mesh); - state->meshes.push_back(mesh); + p_state->meshes.push_back(mesh); } - print_verbose("glTF: Total meshes: " + itos(state->meshes.size())); + print_verbose("glTF: Total meshes: " + itos(p_state->meshes.size())); return OK; } -Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path) { +Error GLTFDocument::_serialize_images(Ref<GLTFState> p_state, const String &p_path) { Array images; - for (int i = 0; i < state->images.size(); i++) { + for (int i = 0; i < p_state->images.size(); i++) { Dictionary d; - ERR_CONTINUE(state->images[i].is_null()); + ERR_CONTINUE(p_state->images[i].is_null()); - Ref<Image> image = state->images[i]->get_image(); + Ref<Image> image = p_state->images[i]->get_image(); ERR_CONTINUE(image.is_null()); if (p_path.to_lower().ends_with("glb") || p_path.is_empty()) { @@ -3011,8 +3003,8 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path const GLTFBufferIndex bi = 0; bv->buffer = bi; - bv->byte_offset = state->buffers[bi].size(); - ERR_FAIL_INDEX_V(bi, state->buffers.size(), ERR_PARAMETER_RANGE_ERROR); + bv->byte_offset = p_state->buffers[bi].size(); + ERR_FAIL_INDEX_V(bi, p_state->buffers.size(), ERR_PARAMETER_RANGE_ERROR); Vector<uint8_t> buffer; Ref<ImageTexture> img_tex = image; @@ -3023,21 +3015,21 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG."); bv->byte_length = buffer.size(); - state->buffers.write[bi].resize(state->buffers[bi].size() + bv->byte_length); - memcpy(&state->buffers.write[bi].write[bv->byte_offset], buffer.ptr(), buffer.size()); - ERR_FAIL_COND_V(bv->byte_offset + bv->byte_length > state->buffers[bi].size(), ERR_FILE_CORRUPT); + p_state->buffers.write[bi].resize(p_state->buffers[bi].size() + bv->byte_length); + memcpy(&p_state->buffers.write[bi].write[bv->byte_offset], buffer.ptr(), buffer.size()); + ERR_FAIL_COND_V(bv->byte_offset + bv->byte_length > p_state->buffers[bi].size(), ERR_FILE_CORRUPT); - state->buffer_views.push_back(bv); - bvi = state->buffer_views.size() - 1; + p_state->buffer_views.push_back(bv); + bvi = p_state->buffer_views.size() - 1; d["bufferView"] = bvi; d["mimeType"] = "image/png"; } else { ERR_FAIL_COND_V(p_path.is_empty(), ERR_INVALID_PARAMETER); - String img_name = state->images[i]->get_name(); + String img_name = p_state->images[i]->get_name(); if (img_name.is_empty()) { img_name = itos(i); } - img_name = _gen_unique_name(state, img_name); + img_name = _gen_unique_name(p_state, img_name); img_name = img_name.pad_zeros(3) + ".png"; String texture_dir = "textures"; String path = p_path.get_base_dir(); @@ -3052,25 +3044,25 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path images.push_back(d); } - print_verbose("Total images: " + itos(state->images.size())); + print_verbose("Total images: " + itos(p_state->images.size())); if (!images.size()) { return OK; } - state->json["images"] = images; + p_state->json["images"] = images; return OK; } -Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_path) { - ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER); - if (!state->json.has("images")) { +Error GLTFDocument::_parse_images(Ref<GLTFState> p_state, const String &p_base_path) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + if (!p_state->json.has("images")) { return OK; } // Ref: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#images - const Array &images = state->json["images"]; + const Array &images = p_state->json["images"]; for (int i = 0; i < images.size(); i++) { const Dictionary &d = images[i]; @@ -3108,7 +3100,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat !uri.begins_with("data:image/png;base64") && !uri.begins_with("data:image/jpeg;base64")) { WARN_PRINT(vformat("glTF: Image index '%d' uses an unsupported URI data type: %s. Skipping it.", i, uri)); - state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. + p_state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. continue; } data = _parse_base64_uri(uri); @@ -3133,7 +3125,7 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat // the material), so we do this only as fallback. Ref<Texture2D> texture = ResourceLoader::load(uri); if (texture.is_valid()) { - state->images.push_back(texture); + p_state->images.push_back(texture); continue; } else if (mimetype == "image/png" || mimetype == "image/jpeg") { // Fallback to loading as byte array. @@ -3142,14 +3134,14 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat data = FileAccess::get_file_as_bytes(uri); if (data.size() == 0) { WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded as a buffer of MIME type '%s' from URI: %s. Skipping it.", i, mimetype, uri)); - state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. + p_state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. continue; } data_ptr = data.ptr(); data_size = data.size(); } else { WARN_PRINT(vformat("glTF: Image index '%d' couldn't be loaded from URI: %s. Skipping it.", i, uri)); - state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. + p_state->images.push_back(Ref<Texture2D>()); // Placeholder to keep count. continue; } } @@ -3160,16 +3152,16 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat const GLTFBufferViewIndex bvi = d["bufferView"]; - ERR_FAIL_INDEX_V(bvi, state->buffer_views.size(), ERR_PARAMETER_RANGE_ERROR); + ERR_FAIL_INDEX_V(bvi, p_state->buffer_views.size(), ERR_PARAMETER_RANGE_ERROR); - Ref<GLTFBufferView> bv = state->buffer_views[bvi]; + Ref<GLTFBufferView> bv = p_state->buffer_views[bvi]; const GLTFBufferIndex bi = bv->buffer; - ERR_FAIL_INDEX_V(bi, state->buffers.size(), ERR_PARAMETER_RANGE_ERROR); + ERR_FAIL_INDEX_V(bi, p_state->buffers.size(), ERR_PARAMETER_RANGE_ERROR); - ERR_FAIL_COND_V(bv->byte_offset + bv->byte_length > state->buffers[bi].size(), ERR_FILE_CORRUPT); + ERR_FAIL_COND_V(bv->byte_offset + bv->byte_length > p_state->buffers[bi].size(), ERR_FILE_CORRUPT); - data_ptr = &state->buffers[bi][bv->byte_offset]; + data_ptr = &p_state->buffers[bi][bv->byte_offset]; data_size = bv->byte_length; } @@ -3202,26 +3194,26 @@ Error GLTFDocument::_parse_images(Ref<GLTFState> state, const String &p_base_pat // Now we've done our best, fix your scenes. if (img.is_null()) { ERR_PRINT(vformat("glTF: Couldn't load image index '%d' with its given mimetype: %s.", i, mimetype)); - state->images.push_back(Ref<Texture2D>()); + p_state->images.push_back(Ref<Texture2D>()); continue; } - state->images.push_back(ImageTexture::create_from_image(img)); + p_state->images.push_back(ImageTexture::create_from_image(img)); } - print_verbose("glTF: Total images: " + itos(state->images.size())); + print_verbose("glTF: Total images: " + itos(p_state->images.size())); return OK; } -Error GLTFDocument::_serialize_textures(Ref<GLTFState> state) { - if (!state->textures.size()) { +Error GLTFDocument::_serialize_textures(Ref<GLTFState> p_state) { + if (!p_state->textures.size()) { return OK; } Array textures; - for (int32_t i = 0; i < state->textures.size(); i++) { + for (int32_t i = 0; i < p_state->textures.size(); i++) { Dictionary d; - Ref<GLTFTexture> t = state->textures[i]; + Ref<GLTFTexture> t = p_state->textures[i]; ERR_CONTINUE(t->get_src_image() == -1); d["source"] = t->get_src_image(); @@ -3231,17 +3223,17 @@ Error GLTFDocument::_serialize_textures(Ref<GLTFState> state) { } textures.push_back(d); } - state->json["textures"] = textures; + p_state->json["textures"] = textures; return OK; } -Error GLTFDocument::_parse_textures(Ref<GLTFState> state) { - if (!state->json.has("textures")) { +Error GLTFDocument::_parse_textures(Ref<GLTFState> p_state) { + if (!p_state->json.has("textures")) { return OK; } - const Array &textures = state->json["textures"]; + const Array &textures = p_state->json["textures"]; for (GLTFTextureIndex i = 0; i < textures.size(); i++) { const Dictionary &d = textures[i]; @@ -3255,96 +3247,96 @@ Error GLTFDocument::_parse_textures(Ref<GLTFState> state) { } else { t->set_sampler(-1); } - state->textures.push_back(t); + p_state->textures.push_back(t); } return OK; } -GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { +GLTFTextureIndex GLTFDocument::_set_texture(Ref<GLTFState> p_state, Ref<Texture2D> p_texture, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { ERR_FAIL_COND_V(p_texture.is_null(), -1); Ref<GLTFTexture> gltf_texture; gltf_texture.instantiate(); ERR_FAIL_COND_V(p_texture->get_image().is_null(), -1); - GLTFImageIndex gltf_src_image_i = state->images.size(); - state->images.push_back(p_texture); + GLTFImageIndex gltf_src_image_i = p_state->images.size(); + p_state->images.push_back(p_texture); gltf_texture->set_src_image(gltf_src_image_i); - gltf_texture->set_sampler(_set_sampler_for_mode(state, p_filter_mode, p_repeats)); - GLTFTextureIndex gltf_texture_i = state->textures.size(); - state->textures.push_back(gltf_texture); + gltf_texture->set_sampler(_set_sampler_for_mode(p_state, p_filter_mode, p_repeats)); + GLTFTextureIndex gltf_texture_i = p_state->textures.size(); + p_state->textures.push_back(gltf_texture); return gltf_texture_i; } -Ref<Texture2D> GLTFDocument::_get_texture(Ref<GLTFState> state, const GLTFTextureIndex p_texture) { - ERR_FAIL_INDEX_V(p_texture, state->textures.size(), Ref<Texture2D>()); - const GLTFImageIndex image = state->textures[p_texture]->get_src_image(); +Ref<Texture2D> GLTFDocument::_get_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture) { + ERR_FAIL_INDEX_V(p_texture, p_state->textures.size(), Ref<Texture2D>()); + const GLTFImageIndex image = p_state->textures[p_texture]->get_src_image(); - ERR_FAIL_INDEX_V(image, state->images.size(), Ref<Texture2D>()); + ERR_FAIL_INDEX_V(image, p_state->images.size(), Ref<Texture2D>()); - return state->images[image]; + return p_state->images[image]; } -GLTFTextureSamplerIndex GLTFDocument::_set_sampler_for_mode(Ref<GLTFState> state, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { - for (int i = 0; i < state->texture_samplers.size(); ++i) { - if (state->texture_samplers[i]->get_filter_mode() == p_filter_mode) { +GLTFTextureSamplerIndex GLTFDocument::_set_sampler_for_mode(Ref<GLTFState> p_state, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats) { + for (int i = 0; i < p_state->texture_samplers.size(); ++i) { + if (p_state->texture_samplers[i]->get_filter_mode() == p_filter_mode) { return i; } } - GLTFTextureSamplerIndex gltf_sampler_i = state->texture_samplers.size(); + GLTFTextureSamplerIndex gltf_sampler_i = p_state->texture_samplers.size(); Ref<GLTFTextureSampler> gltf_sampler; gltf_sampler.instantiate(); gltf_sampler->set_filter_mode(p_filter_mode); gltf_sampler->set_wrap_mode(p_repeats); - state->texture_samplers.push_back(gltf_sampler); + p_state->texture_samplers.push_back(gltf_sampler); return gltf_sampler_i; } -Ref<GLTFTextureSampler> GLTFDocument::_get_sampler_for_texture(Ref<GLTFState> state, const GLTFTextureIndex p_texture) { - ERR_FAIL_INDEX_V(p_texture, state->textures.size(), Ref<Texture2D>()); - const GLTFTextureSamplerIndex sampler = state->textures[p_texture]->get_sampler(); +Ref<GLTFTextureSampler> GLTFDocument::_get_sampler_for_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture) { + ERR_FAIL_INDEX_V(p_texture, p_state->textures.size(), Ref<Texture2D>()); + const GLTFTextureSamplerIndex sampler = p_state->textures[p_texture]->get_sampler(); if (sampler == -1) { - return state->default_texture_sampler; + return p_state->default_texture_sampler; } else { - ERR_FAIL_INDEX_V(sampler, state->texture_samplers.size(), Ref<GLTFTextureSampler>()); + ERR_FAIL_INDEX_V(sampler, p_state->texture_samplers.size(), Ref<GLTFTextureSampler>()); - return state->texture_samplers[sampler]; + return p_state->texture_samplers[sampler]; } } -Error GLTFDocument::_serialize_texture_samplers(Ref<GLTFState> state) { - if (!state->texture_samplers.size()) { +Error GLTFDocument::_serialize_texture_samplers(Ref<GLTFState> p_state) { + if (!p_state->texture_samplers.size()) { return OK; } Array samplers; - for (int32_t i = 0; i < state->texture_samplers.size(); ++i) { + for (int32_t i = 0; i < p_state->texture_samplers.size(); ++i) { Dictionary d; - Ref<GLTFTextureSampler> s = state->texture_samplers[i]; + Ref<GLTFTextureSampler> s = p_state->texture_samplers[i]; d["magFilter"] = s->get_mag_filter(); d["minFilter"] = s->get_min_filter(); d["wrapS"] = s->get_wrap_s(); d["wrapT"] = s->get_wrap_t(); samplers.push_back(d); } - state->json["samplers"] = samplers; + p_state->json["samplers"] = samplers; return OK; } -Error GLTFDocument::_parse_texture_samplers(Ref<GLTFState> state) { - state->default_texture_sampler.instantiate(); - state->default_texture_sampler->set_min_filter(GLTFTextureSampler::FilterMode::LINEAR_MIPMAP_LINEAR); - state->default_texture_sampler->set_mag_filter(GLTFTextureSampler::FilterMode::LINEAR); - state->default_texture_sampler->set_wrap_s(GLTFTextureSampler::WrapMode::REPEAT); - state->default_texture_sampler->set_wrap_t(GLTFTextureSampler::WrapMode::REPEAT); +Error GLTFDocument::_parse_texture_samplers(Ref<GLTFState> p_state) { + p_state->default_texture_sampler.instantiate(); + p_state->default_texture_sampler->set_min_filter(GLTFTextureSampler::FilterMode::LINEAR_MIPMAP_LINEAR); + p_state->default_texture_sampler->set_mag_filter(GLTFTextureSampler::FilterMode::LINEAR); + p_state->default_texture_sampler->set_wrap_s(GLTFTextureSampler::WrapMode::REPEAT); + p_state->default_texture_sampler->set_wrap_t(GLTFTextureSampler::WrapMode::REPEAT); - if (!state->json.has("samplers")) { + if (!p_state->json.has("samplers")) { return OK; } - const Array &samplers = state->json["samplers"]; + const Array &samplers = p_state->json["samplers"]; for (int i = 0; i < samplers.size(); ++i) { const Dictionary &d = samplers[i]; @@ -3374,23 +3366,23 @@ Error GLTFDocument::_parse_texture_samplers(Ref<GLTFState> state) { sampler->set_wrap_t(GLTFTextureSampler::WrapMode::DEFAULT); } - state->texture_samplers.push_back(sampler); + p_state->texture_samplers.push_back(sampler); } return OK; } -Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_materials(Ref<GLTFState> p_state) { Array materials; - for (int32_t i = 0; i < state->materials.size(); i++) { + for (int32_t i = 0; i < p_state->materials.size(); i++) { Dictionary d; - Ref<Material> material = state->materials[i]; + Ref<Material> material = p_state->materials[i]; if (material.is_null()) { materials.push_back(d); continue; } if (!material->get_name().is_empty()) { - d["name"] = _gen_unique_name(state, material->get_name()); + d["name"] = _gen_unique_name(p_state, material->get_name()); } Ref<BaseMaterial3D> base_material = material; if (base_material.is_valid()) { @@ -3412,14 +3404,14 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { if (albedo_texture.is_valid() && albedo_texture->get_image().is_valid()) { albedo_texture->set_name(material->get_name() + "_albedo"); - gltf_texture_index = _set_texture(state, albedo_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); + gltf_texture_index = _set_texture(p_state, albedo_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); } if (gltf_texture_index != -1) { bct["index"] = gltf_texture_index; Dictionary extensions = _serialize_texture_transform_uv1(material); if (!extensions.is_empty()) { bct["extensions"] = extensions; - state->use_khr_texture_transform = true; + p_state->use_khr_texture_transform = true; } mr["baseColorTexture"] = bct; } @@ -3543,7 +3535,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { GLTFTextureIndex orm_texture_index = -1; if (has_ao || has_roughness || has_metalness) { orm_texture->set_name(material->get_name() + "_orm"); - orm_texture_index = _set_texture(state, orm_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); + orm_texture_index = _set_texture(p_state, orm_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); } if (has_ao) { Dictionary occt; @@ -3555,7 +3547,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { Dictionary extensions = _serialize_texture_transform_uv1(material); if (!extensions.is_empty()) { mrt["extensions"] = extensions; - state->use_khr_texture_transform = true; + p_state->use_khr_texture_transform = true; } mr["metallicRoughnessTexture"] = mrt; } @@ -3598,7 +3590,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { GLTFTextureIndex gltf_texture_index = -1; if (tex.is_valid() && tex->get_image().is_valid()) { tex->set_name(material->get_name() + "_normal"); - gltf_texture_index = _set_texture(state, tex, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); + gltf_texture_index = _set_texture(p_state, tex, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); } nt["scale"] = base_material->get_normal_scale(); if (gltf_texture_index != -1) { @@ -3621,7 +3613,7 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { GLTFTextureIndex gltf_texture_index = -1; if (emission_texture.is_valid() && emission_texture->get_image().is_valid()) { emission_texture->set_name(material->get_name() + "_emission"); - gltf_texture_index = _set_texture(state, emission_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); + gltf_texture_index = _set_texture(p_state, emission_texture, base_material->get_texture_filter(), base_material->get_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT)); } if (gltf_texture_index != -1) { @@ -3644,18 +3636,18 @@ Error GLTFDocument::_serialize_materials(Ref<GLTFState> state) { if (!materials.size()) { return OK; } - state->json["materials"] = materials; - print_verbose("Total materials: " + itos(state->materials.size())); + p_state->json["materials"] = materials; + print_verbose("Total materials: " + itos(p_state->materials.size())); return OK; } -Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { - if (!state->json.has("materials")) { +Error GLTFDocument::_parse_materials(Ref<GLTFState> p_state) { + if (!p_state->json.has("materials")) { return OK; } - const Array &materials = state->json["materials"]; + const Array &materials = p_state->json["materials"]; for (GLTFMaterialIndex i = 0; i < materials.size(); i++) { const Dictionary &d = materials[i]; @@ -3680,12 +3672,12 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (sgm.has("diffuseTexture")) { const Dictionary &diffuse_texture_dict = sgm["diffuseTexture"]; if (diffuse_texture_dict.has("index")) { - Ref<GLTFTextureSampler> diffuse_sampler = _get_sampler_for_texture(state, diffuse_texture_dict["index"]); + Ref<GLTFTextureSampler> diffuse_sampler = _get_sampler_for_texture(p_state, diffuse_texture_dict["index"]); if (diffuse_sampler.is_valid()) { material->set_texture_filter(diffuse_sampler->get_filter_mode()); material->set_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT, diffuse_sampler->get_wrap_mode()); } - Ref<Texture2D> diffuse_texture = _get_texture(state, diffuse_texture_dict["index"]); + Ref<Texture2D> diffuse_texture = _get_texture(p_state, diffuse_texture_dict["index"]); if (diffuse_texture.is_valid()) { spec_gloss->diffuse_img = diffuse_texture->get_image(); material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, diffuse_texture); @@ -3713,7 +3705,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (sgm.has("specularGlossinessTexture")) { const Dictionary &spec_gloss_texture = sgm["specularGlossinessTexture"]; if (spec_gloss_texture.has("index")) { - const Ref<Texture2D> orig_texture = _get_texture(state, spec_gloss_texture["index"]); + const Ref<Texture2D> orig_texture = _get_texture(p_state, spec_gloss_texture["index"]); if (orig_texture.is_valid()) { spec_gloss->spec_gloss_img = orig_texture->get_image(); } @@ -3733,10 +3725,10 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (mr.has("baseColorTexture")) { const Dictionary &bct = mr["baseColorTexture"]; if (bct.has("index")) { - Ref<GLTFTextureSampler> bct_sampler = _get_sampler_for_texture(state, bct["index"]); + Ref<GLTFTextureSampler> bct_sampler = _get_sampler_for_texture(p_state, bct["index"]); material->set_texture_filter(bct_sampler->get_filter_mode()); material->set_flag(BaseMaterial3D::FLAG_USE_TEXTURE_REPEAT, bct_sampler->get_wrap_mode()); - material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, _get_texture(state, bct["index"])); + material->set_texture(BaseMaterial3D::TEXTURE_ALBEDO, _get_texture(p_state, bct["index"])); } if (!mr.has("baseColorFactor")) { material->set_albedo(Color(1, 1, 1)); @@ -3759,7 +3751,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (mr.has("metallicRoughnessTexture")) { const Dictionary &bct = mr["metallicRoughnessTexture"]; if (bct.has("index")) { - const Ref<Texture2D> t = _get_texture(state, bct["index"]); + const Ref<Texture2D> t = _get_texture(p_state, bct["index"]); material->set_texture(BaseMaterial3D::TEXTURE_METALLIC, t); material->set_metallic_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_BLUE); material->set_texture(BaseMaterial3D::TEXTURE_ROUGHNESS, t); @@ -3777,7 +3769,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (d.has("normalTexture")) { const Dictionary &bct = d["normalTexture"]; if (bct.has("index")) { - material->set_texture(BaseMaterial3D::TEXTURE_NORMAL, _get_texture(state, bct["index"])); + material->set_texture(BaseMaterial3D::TEXTURE_NORMAL, _get_texture(p_state, bct["index"])); material->set_feature(BaseMaterial3D::FEATURE_NORMAL_MAPPING, true); } if (bct.has("scale")) { @@ -3787,7 +3779,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (d.has("occlusionTexture")) { const Dictionary &bct = d["occlusionTexture"]; if (bct.has("index")) { - material->set_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION, _get_texture(state, bct["index"])); + material->set_texture(BaseMaterial3D::TEXTURE_AMBIENT_OCCLUSION, _get_texture(p_state, bct["index"])); material->set_ao_texture_channel(BaseMaterial3D::TEXTURE_CHANNEL_RED); material->set_feature(BaseMaterial3D::FEATURE_AMBIENT_OCCLUSION, true); } @@ -3805,7 +3797,7 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { if (d.has("emissiveTexture")) { const Dictionary &bct = d["emissiveTexture"]; if (bct.has("index")) { - material->set_texture(BaseMaterial3D::TEXTURE_EMISSION, _get_texture(state, bct["index"])); + material->set_texture(BaseMaterial3D::TEXTURE_EMISSION, _get_texture(p_state, bct["index"])); material->set_feature(BaseMaterial3D::FEATURE_EMISSION, true); material->set_emission(Color(0, 0, 0)); } @@ -3830,30 +3822,30 @@ Error GLTFDocument::_parse_materials(Ref<GLTFState> state) { } } } - state->materials.push_back(material); + p_state->materials.push_back(material); } - print_verbose("Total materials: " + itos(state->materials.size())); + print_verbose("Total materials: " + itos(p_state->materials.size())); return OK; } -void GLTFDocument::_set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material) { - if (d.has("extensions")) { - const Dictionary &extensions = d["extensions"]; +void GLTFDocument::_set_texture_transform_uv1(const Dictionary &p_dict, Ref<BaseMaterial3D> p_material) { + if (p_dict.has("extensions")) { + const Dictionary &extensions = p_dict["extensions"]; if (extensions.has("KHR_texture_transform")) { - if (material.is_valid()) { + if (p_material.is_valid()) { const Dictionary &texture_transform = extensions["KHR_texture_transform"]; const Array &offset_arr = texture_transform["offset"]; if (offset_arr.size() == 2) { const Vector3 offset_vector3 = Vector3(offset_arr[0], offset_arr[1], 0.0f); - material->set_uv1_offset(offset_vector3); + p_material->set_uv1_offset(offset_vector3); } const Array &scale_arr = texture_transform["scale"]; if (scale_arr.size() == 2) { const Vector3 scale_vector3 = Vector3(scale_arr[0], scale_arr[1], 1.0f); - material->set_uv1_scale(scale_vector3); + p_material->set_uv1_scale(scale_vector3); } } } @@ -3944,13 +3936,13 @@ void GLTFDocument::spec_gloss_to_metal_base_color(const Color &p_specular_factor r_base_color = r_base_color.clamp(); } -GLTFNodeIndex GLTFDocument::_find_highest_node(Ref<GLTFState> state, const Vector<GLTFNodeIndex> &subset) { +GLTFNodeIndex GLTFDocument::_find_highest_node(Ref<GLTFState> p_state, const Vector<GLTFNodeIndex> &p_subset) { int highest = -1; GLTFNodeIndex best_node = -1; - for (int i = 0; i < subset.size(); ++i) { - const GLTFNodeIndex node_i = subset[i]; - const Ref<GLTFNode> node = state->nodes[node_i]; + for (int i = 0; i < p_subset.size(); ++i) { + const GLTFNodeIndex node_i = p_subset[i]; + const Ref<GLTFNode> node = p_state->nodes[node_i]; if (highest == -1 || node->height < highest) { highest = node->height; @@ -3961,38 +3953,38 @@ GLTFNodeIndex GLTFDocument::_find_highest_node(Ref<GLTFState> state, const Vecto return best_node; } -bool GLTFDocument::_capture_nodes_in_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin, const GLTFNodeIndex node_index) { +bool GLTFDocument::_capture_nodes_in_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin, const GLTFNodeIndex p_node_index) { bool found_joint = false; - for (int i = 0; i < state->nodes[node_index]->children.size(); ++i) { - found_joint |= _capture_nodes_in_skin(state, skin, state->nodes[node_index]->children[i]); + for (int i = 0; i < p_state->nodes[p_node_index]->children.size(); ++i) { + found_joint |= _capture_nodes_in_skin(p_state, p_skin, p_state->nodes[p_node_index]->children[i]); } if (found_joint) { // Mark it if we happen to find another skins joint... - if (state->nodes[node_index]->joint && skin->joints.find(node_index) < 0) { - skin->joints.push_back(node_index); - } else if (skin->non_joints.find(node_index) < 0) { - skin->non_joints.push_back(node_index); + if (p_state->nodes[p_node_index]->joint && p_skin->joints.find(p_node_index) < 0) { + p_skin->joints.push_back(p_node_index); + } else if (p_skin->non_joints.find(p_node_index) < 0) { + p_skin->non_joints.push_back(p_node_index); } } - if (skin->joints.find(node_index) > 0) { + if (p_skin->joints.find(p_node_index) > 0) { return true; } return false; } -void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { +void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin) { DisjointSet<GLTFNodeIndex> disjoint_set; - for (int i = 0; i < skin->joints.size(); ++i) { - const GLTFNodeIndex node_index = skin->joints[i]; - const GLTFNodeIndex parent = state->nodes[node_index]->parent; + for (int i = 0; i < p_skin->joints.size(); ++i) { + const GLTFNodeIndex node_index = p_skin->joints[i]; + const GLTFNodeIndex parent = p_state->nodes[node_index]->parent; disjoint_set.insert(node_index); - if (skin->joints.find(parent) >= 0) { + if (p_skin->joints.find(parent) >= 0) { disjoint_set.create_union(parent, node_index); } } @@ -4010,8 +4002,8 @@ void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref for (int i = 0; i < roots.size(); ++i) { const GLTFNodeIndex root = roots[i]; - if (maxHeight == -1 || state->nodes[root]->height < maxHeight) { - maxHeight = state->nodes[root]->height; + if (maxHeight == -1 || p_state->nodes[root]->height < maxHeight) { + maxHeight = p_state->nodes[root]->height; } } @@ -4019,13 +4011,13 @@ void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref // This sucks, but 99% of all game engines (not just Godot) would have this same issue. for (int i = 0; i < roots.size(); ++i) { GLTFNodeIndex current_node = roots[i]; - while (state->nodes[current_node]->height > maxHeight) { - GLTFNodeIndex parent = state->nodes[current_node]->parent; + while (p_state->nodes[current_node]->height > maxHeight) { + GLTFNodeIndex parent = p_state->nodes[current_node]->parent; - if (state->nodes[parent]->joint && skin->joints.find(parent) < 0) { - skin->joints.push_back(parent); - } else if (skin->non_joints.find(parent) < 0) { - skin->non_joints.push_back(parent); + if (p_state->nodes[parent]->joint && p_skin->joints.find(parent) < 0) { + p_skin->joints.push_back(parent); + } else if (p_skin->non_joints.find(parent) < 0) { + p_skin->non_joints.push_back(parent); } current_node = parent; @@ -4040,21 +4032,21 @@ void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref do { all_same = true; - const GLTFNodeIndex first_parent = state->nodes[roots[0]]->parent; + const GLTFNodeIndex first_parent = p_state->nodes[roots[0]]->parent; for (int i = 1; i < roots.size(); ++i) { - all_same &= (first_parent == state->nodes[roots[i]]->parent); + all_same &= (first_parent == p_state->nodes[roots[i]]->parent); } if (!all_same) { for (int i = 0; i < roots.size(); ++i) { const GLTFNodeIndex current_node = roots[i]; - const GLTFNodeIndex parent = state->nodes[current_node]->parent; + const GLTFNodeIndex parent = p_state->nodes[current_node]->parent; - if (state->nodes[parent]->joint && skin->joints.find(parent) < 0) { - skin->joints.push_back(parent); - } else if (skin->non_joints.find(parent) < 0) { - skin->non_joints.push_back(parent); + if (p_state->nodes[parent]->joint && p_skin->joints.find(parent) < 0) { + p_skin->joints.push_back(parent); + } else if (p_skin->non_joints.find(parent) < 0) { + p_skin->non_joints.push_back(parent); } roots.write[i] = parent; @@ -4064,19 +4056,19 @@ void GLTFDocument::_capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref } while (!all_same); } -Error GLTFDocument::_expand_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { - _capture_nodes_for_multirooted_skin(state, skin); +Error GLTFDocument::_expand_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin) { + _capture_nodes_for_multirooted_skin(p_state, p_skin); // Grab all nodes that lay in between skin joints/nodes DisjointSet<GLTFNodeIndex> disjoint_set; Vector<GLTFNodeIndex> all_skin_nodes; - all_skin_nodes.append_array(skin->joints); - all_skin_nodes.append_array(skin->non_joints); + all_skin_nodes.append_array(p_skin->joints); + all_skin_nodes.append_array(p_skin->non_joints); for (int i = 0; i < all_skin_nodes.size(); ++i) { const GLTFNodeIndex node_index = all_skin_nodes[i]; - const GLTFNodeIndex parent = state->nodes[node_index]->parent; + const GLTFNodeIndex parent = p_state->nodes[node_index]->parent; disjoint_set.insert(node_index); if (all_skin_nodes.find(parent) >= 0) { @@ -4093,7 +4085,7 @@ Error GLTFDocument::_expand_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { Vector<GLTFNodeIndex> set; disjoint_set.get_members(set, out_owners[i]); - const GLTFNodeIndex root = _find_highest_node(state, set); + const GLTFNodeIndex root = _find_highest_node(p_state, set); ERR_FAIL_COND_V(root < 0, FAILED); out_roots.push_back(root); } @@ -4101,15 +4093,15 @@ Error GLTFDocument::_expand_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { out_roots.sort(); for (int i = 0; i < out_roots.size(); ++i) { - _capture_nodes_in_skin(state, skin, out_roots[i]); + _capture_nodes_in_skin(p_state, p_skin, out_roots[i]); } - skin->roots = out_roots; + p_skin->roots = out_roots; return OK; } -Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { +Error GLTFDocument::_verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin) { // This may seem duplicated from expand_skins, but this is really a sanity check! (so it kinda is) // In case additional interpolating logic is added to the skins, this will help ensure that you // do not cause it to self implode into a fiery blaze @@ -4121,12 +4113,12 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { DisjointSet<GLTFNodeIndex> disjoint_set; Vector<GLTFNodeIndex> all_skin_nodes; - all_skin_nodes.append_array(skin->joints); - all_skin_nodes.append_array(skin->non_joints); + all_skin_nodes.append_array(p_skin->joints); + all_skin_nodes.append_array(p_skin->non_joints); for (int i = 0; i < all_skin_nodes.size(); ++i) { const GLTFNodeIndex node_index = all_skin_nodes[i]; - const GLTFNodeIndex parent = state->nodes[node_index]->parent; + const GLTFNodeIndex parent = p_state->nodes[node_index]->parent; disjoint_set.insert(node_index); if (all_skin_nodes.find(parent) >= 0) { @@ -4143,7 +4135,7 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { Vector<GLTFNodeIndex> set; disjoint_set.get_members(set, out_owners[i]); - const GLTFNodeIndex root = _find_highest_node(state, set); + const GLTFNodeIndex root = _find_highest_node(p_state, set); ERR_FAIL_COND_V(root < 0, FAILED); out_roots.push_back(root); } @@ -4153,9 +4145,9 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { ERR_FAIL_COND_V(out_roots.size() == 0, FAILED); // Make sure the roots are the exact same (they better be) - ERR_FAIL_COND_V(out_roots.size() != skin->roots.size(), FAILED); + ERR_FAIL_COND_V(out_roots.size() != p_skin->roots.size(), FAILED); for (int i = 0; i < out_roots.size(); ++i) { - ERR_FAIL_COND_V(out_roots[i] != skin->roots[i], FAILED); + ERR_FAIL_COND_V(out_roots[i] != p_skin->roots[i], FAILED); } // Single rooted skin? Perfectly ok! @@ -4164,9 +4156,9 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { } // Make sure all parents of a multi-rooted skin are the SAME - const GLTFNodeIndex parent = state->nodes[out_roots[0]]->parent; + const GLTFNodeIndex parent = p_state->nodes[out_roots[0]]->parent; for (int i = 1; i < out_roots.size(); ++i) { - if (state->nodes[out_roots[i]]->parent != parent) { + if (p_state->nodes[out_roots[i]]->parent != parent) { return FAILED; } } @@ -4174,12 +4166,12 @@ Error GLTFDocument::_verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin) { return OK; } -Error GLTFDocument::_parse_skins(Ref<GLTFState> state) { - if (!state->json.has("skins")) { +Error GLTFDocument::_parse_skins(Ref<GLTFState> p_state) { + if (!p_state->json.has("skins")) { return OK; } - const Array &skins = state->json["skins"]; + const Array &skins = p_state->json["skins"]; // Create the base skins, and mark nodes that are joints for (int i = 0; i < skins.size(); i++) { @@ -4193,18 +4185,18 @@ Error GLTFDocument::_parse_skins(Ref<GLTFState> state) { const Array &joints = d["joints"]; if (d.has("inverseBindMatrices")) { - skin->inverse_binds = _decode_accessor_as_xform(state, d["inverseBindMatrices"], false); + skin->inverse_binds = _decode_accessor_as_xform(p_state, d["inverseBindMatrices"], false); ERR_FAIL_COND_V(skin->inverse_binds.size() != joints.size(), ERR_PARSE_ERROR); } for (int j = 0; j < joints.size(); j++) { const GLTFNodeIndex node = joints[j]; - ERR_FAIL_INDEX_V(node, state->nodes.size(), ERR_PARSE_ERROR); + ERR_FAIL_INDEX_V(node, p_state->nodes.size(), ERR_PARSE_ERROR); skin->joints.push_back(node); skin->joints_original.push_back(node); - state->nodes.write[node]->joint = true; + p_state->nodes.write[node]->joint = true; } if (d.has("name") && !String(d["name"]).is_empty()) { @@ -4217,32 +4209,32 @@ Error GLTFDocument::_parse_skins(Ref<GLTFState> state) { skin->skin_root = d["skeleton"]; } - state->skins.push_back(skin); + p_state->skins.push_back(skin); } - for (GLTFSkinIndex i = 0; i < state->skins.size(); ++i) { - Ref<GLTFSkin> skin = state->skins.write[i]; + for (GLTFSkinIndex i = 0; i < p_state->skins.size(); ++i) { + Ref<GLTFSkin> skin = p_state->skins.write[i]; // Expand the skin to capture all the extra non-joints that lie in between the actual joints, // and expand the hierarchy to ensure multi-rooted trees lie on the same height level - ERR_FAIL_COND_V(_expand_skin(state, skin), ERR_PARSE_ERROR); - ERR_FAIL_COND_V(_verify_skin(state, skin), ERR_PARSE_ERROR); + ERR_FAIL_COND_V(_expand_skin(p_state, skin), ERR_PARSE_ERROR); + ERR_FAIL_COND_V(_verify_skin(p_state, skin), ERR_PARSE_ERROR); } - print_verbose("glTF: Total skins: " + itos(state->skins.size())); + print_verbose("glTF: Total skins: " + itos(p_state->skins.size())); return OK; } -Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { +Error GLTFDocument::_determine_skeletons(Ref<GLTFState> p_state) { // Using a disjoint set, we are going to potentially combine all skins that are actually branches // of a main skeleton, or treat skins defining the same set of nodes as ONE skeleton. // This is another unclear issue caused by the current glTF specification. DisjointSet<GLTFNodeIndex> skeleton_sets; - for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) { - const Ref<GLTFSkin> skin = state->skins[skin_i]; + for (GLTFSkinIndex skin_i = 0; skin_i < p_state->skins.size(); ++skin_i) { + const Ref<GLTFSkin> skin = p_state->skins[skin_i]; Vector<GLTFNodeIndex> all_skin_nodes; all_skin_nodes.append_array(skin->joints); @@ -4250,7 +4242,7 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { for (int i = 0; i < all_skin_nodes.size(); ++i) { const GLTFNodeIndex node_index = all_skin_nodes[i]; - const GLTFNodeIndex parent = state->nodes[node_index]->parent; + const GLTFNodeIndex parent = p_state->nodes[node_index]->parent; skeleton_sets.insert(node_index); if (all_skin_nodes.find(parent) >= 0) { @@ -4274,7 +4266,7 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { for (int i = 0; i < groups_representatives.size(); ++i) { Vector<GLTFNodeIndex> group; skeleton_sets.get_members(group, groups_representatives[i]); - highest_group_members.push_back(_find_highest_node(state, group)); + highest_group_members.push_back(_find_highest_node(p_state, group)); groups.push_back(group); } @@ -4286,13 +4278,13 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { const GLTFNodeIndex node_j = highest_group_members[j]; // Even if they are siblings under the root! :) - if (state->nodes[node_i]->parent == state->nodes[node_j]->parent) { + if (p_state->nodes[node_i]->parent == p_state->nodes[node_j]->parent) { skeleton_sets.create_union(node_i, node_j); } } // Attach any parenting going on together (we need to do this n^2 times) - const GLTFNodeIndex node_i_parent = state->nodes[node_i]->parent; + const GLTFNodeIndex node_i_parent = p_state->nodes[node_i]->parent; if (node_i_parent >= 0) { for (int j = 0; j < groups.size() && i != j; ++j) { const Vector<GLTFNodeIndex> &group = groups[j]; @@ -4319,8 +4311,8 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { Vector<GLTFNodeIndex> skeleton_nodes; skeleton_sets.get_members(skeleton_nodes, skeleton_owner); - for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) { - Ref<GLTFSkin> skin = state->skins.write[skin_i]; + for (GLTFSkinIndex skin_i = 0; skin_i < p_state->skins.size(); ++skin_i) { + Ref<GLTFSkin> skin = p_state->skins.write[skin_i]; // If any of the the skeletons nodes exist in a skin, that skin now maps to the skeleton for (int i = 0; i < skeleton_nodes.size(); ++i) { @@ -4336,37 +4328,37 @@ Error GLTFDocument::_determine_skeletons(Ref<GLTFState> state) { for (int i = 0; i < skeleton_nodes.size(); ++i) { const GLTFNodeIndex node_i = skeleton_nodes[i]; - if (state->nodes[node_i]->joint) { + if (p_state->nodes[node_i]->joint) { skeleton->joints.push_back(node_i); } else { non_joints.push_back(node_i); } } - state->skeletons.push_back(skeleton); + p_state->skeletons.push_back(skeleton); - _reparent_non_joint_skeleton_subtrees(state, state->skeletons.write[skel_i], non_joints); + _reparent_non_joint_skeleton_subtrees(p_state, p_state->skeletons.write[skel_i], non_joints); } - for (GLTFSkeletonIndex skel_i = 0; skel_i < state->skeletons.size(); ++skel_i) { - Ref<GLTFSkeleton> skeleton = state->skeletons.write[skel_i]; + for (GLTFSkeletonIndex skel_i = 0; skel_i < p_state->skeletons.size(); ++skel_i) { + Ref<GLTFSkeleton> skeleton = p_state->skeletons.write[skel_i]; for (int i = 0; i < skeleton->joints.size(); ++i) { const GLTFNodeIndex node_i = skeleton->joints[i]; - Ref<GLTFNode> node = state->nodes[node_i]; + Ref<GLTFNode> node = p_state->nodes[node_i]; ERR_FAIL_COND_V(!node->joint, ERR_PARSE_ERROR); ERR_FAIL_COND_V(node->skeleton >= 0, ERR_PARSE_ERROR); node->skeleton = skel_i; } - ERR_FAIL_COND_V(_determine_skeleton_roots(state, skel_i), ERR_PARSE_ERROR); + ERR_FAIL_COND_V(_determine_skeleton_roots(p_state, skel_i), ERR_PARSE_ERROR); } return OK; } -Error GLTFDocument::_reparent_non_joint_skeleton_subtrees(Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton, const Vector<GLTFNodeIndex> &non_joints) { +Error GLTFDocument::_reparent_non_joint_skeleton_subtrees(Ref<GLTFState> p_state, Ref<GLTFSkeleton> p_skeleton, const Vector<GLTFNodeIndex> &p_non_joints) { DisjointSet<GLTFNodeIndex> subtree_set; // Populate the disjoint set with ONLY non joints that are in the skeleton hierarchy (non_joints vector) @@ -4377,13 +4369,13 @@ Error GLTFDocument::_reparent_non_joint_skeleton_subtrees(Ref<GLTFState> state, // skinD depicted here explains this issue: // https://github.com/KhronosGroup/glTF-Asset-Generator/blob/master/Output/Positive/Animation_Skin - for (int i = 0; i < non_joints.size(); ++i) { - const GLTFNodeIndex node_i = non_joints[i]; + for (int i = 0; i < p_non_joints.size(); ++i) { + const GLTFNodeIndex node_i = p_non_joints[i]; subtree_set.insert(node_i); - const GLTFNodeIndex parent_i = state->nodes[node_i]->parent; - if (parent_i >= 0 && non_joints.find(parent_i) >= 0 && !state->nodes[parent_i]->joint) { + const GLTFNodeIndex parent_i = p_state->nodes[node_i]->parent; + if (parent_i >= 0 && p_non_joints.find(parent_i) >= 0 && !p_state->nodes[parent_i]->joint) { subtree_set.create_union(parent_i, node_i); } } @@ -4400,34 +4392,34 @@ Error GLTFDocument::_reparent_non_joint_skeleton_subtrees(Ref<GLTFState> state, subtree_set.get_members(subtree_nodes, subtree_root); for (int subtree_i = 0; subtree_i < subtree_nodes.size(); ++subtree_i) { - Ref<GLTFNode> node = state->nodes[subtree_nodes[subtree_i]]; + Ref<GLTFNode> node = p_state->nodes[subtree_nodes[subtree_i]]; node->joint = true; // Add the joint to the skeletons joints - skeleton->joints.push_back(subtree_nodes[subtree_i]); + p_skeleton->joints.push_back(subtree_nodes[subtree_i]); } } return OK; } -Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> state, const GLTFSkeletonIndex skel_i) { +Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> p_state, const GLTFSkeletonIndex p_skel_i) { DisjointSet<GLTFNodeIndex> disjoint_set; - for (GLTFNodeIndex i = 0; i < state->nodes.size(); ++i) { - const Ref<GLTFNode> node = state->nodes[i]; + for (GLTFNodeIndex i = 0; i < p_state->nodes.size(); ++i) { + const Ref<GLTFNode> node = p_state->nodes[i]; - if (node->skeleton != skel_i) { + if (node->skeleton != p_skel_i) { continue; } disjoint_set.insert(i); - if (node->parent >= 0 && state->nodes[node->parent]->skeleton == skel_i) { + if (node->parent >= 0 && p_state->nodes[node->parent]->skeleton == p_skel_i) { disjoint_set.create_union(node->parent, i); } } - Ref<GLTFSkeleton> skeleton = state->skeletons.write[skel_i]; + Ref<GLTFSkeleton> skeleton = p_state->skeletons.write[p_skel_i]; Vector<GLTFNodeIndex> representatives; disjoint_set.get_representatives(representatives); @@ -4437,7 +4429,7 @@ Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> state, const GLTFSk for (int i = 0; i < representatives.size(); ++i) { Vector<GLTFNodeIndex> set; disjoint_set.get_members(set, representatives[i]); - const GLTFNodeIndex root = _find_highest_node(state, set); + const GLTFNodeIndex root = _find_highest_node(p_state, set); ERR_FAIL_COND_V(root < 0, FAILED); roots.push_back(root); } @@ -4453,9 +4445,9 @@ Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> state, const GLTFSk } // Check that the subtrees have the same parent root - const GLTFNodeIndex parent = state->nodes[roots[0]]->parent; + const GLTFNodeIndex parent = p_state->nodes[roots[0]]->parent; for (int i = 1; i < roots.size(); ++i) { - if (state->nodes[roots[i]]->parent != parent) { + if (p_state->nodes[roots[i]]->parent != parent) { return FAILED; } } @@ -4463,16 +4455,16 @@ Error GLTFDocument::_determine_skeleton_roots(Ref<GLTFState> state, const GLTFSk return OK; } -Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) { - for (GLTFSkeletonIndex skel_i = 0; skel_i < state->skeletons.size(); ++skel_i) { - Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skel_i]; +Error GLTFDocument::_create_skeletons(Ref<GLTFState> p_state) { + for (GLTFSkeletonIndex skel_i = 0; skel_i < p_state->skeletons.size(); ++skel_i) { + Ref<GLTFSkeleton> gltf_skeleton = p_state->skeletons.write[skel_i]; Skeleton3D *skeleton = memnew(Skeleton3D); gltf_skeleton->godot_skeleton = skeleton; - state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skel_i; + p_state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skel_i; // Make a unique name, no gltf node represents this skeleton - skeleton->set_name(_gen_unique_name(state, "Skeleton3D")); + skeleton->set_name(_gen_unique_name(p_state, "Skeleton3D")); List<GLTFNodeIndex> bones; @@ -4488,14 +4480,14 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) { const GLTFNodeIndex node_i = bones.front()->get(); bones.pop_front(); - Ref<GLTFNode> node = state->nodes[node_i]; + Ref<GLTFNode> node = p_state->nodes[node_i]; ERR_FAIL_COND_V(node->skeleton != skel_i, FAILED); { // Add all child nodes to the stack (deterministically) Vector<GLTFNodeIndex> child_nodes; for (int i = 0; i < node->children.size(); ++i) { const GLTFNodeIndex child_i = node->children[i]; - if (state->nodes[child_i]->skeleton == skel_i) { + if (p_state->nodes[child_i]->skeleton == skel_i) { child_nodes.push_back(child_i); } } @@ -4513,7 +4505,7 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) { node->set_name("bone"); } - node->set_name(_gen_unique_bone_name(state, skel_i, node->get_name())); + node->set_name(_gen_unique_bone_name(p_state, skel_i, node->get_name())); skeleton->add_bone(node->get_name()); skeleton->set_bone_rest(bone_index, node->xform); @@ -4521,30 +4513,30 @@ Error GLTFDocument::_create_skeletons(Ref<GLTFState> state) { skeleton->set_bone_pose_rotation(bone_index, node->rotation.normalized()); skeleton->set_bone_pose_scale(bone_index, node->scale); - if (node->parent >= 0 && state->nodes[node->parent]->skeleton == skel_i) { - const int bone_parent = skeleton->find_bone(state->nodes[node->parent]->get_name()); + if (node->parent >= 0 && p_state->nodes[node->parent]->skeleton == skel_i) { + const int bone_parent = skeleton->find_bone(p_state->nodes[node->parent]->get_name()); ERR_FAIL_COND_V(bone_parent < 0, FAILED); - skeleton->set_bone_parent(bone_index, skeleton->find_bone(state->nodes[node->parent]->get_name())); + skeleton->set_bone_parent(bone_index, skeleton->find_bone(p_state->nodes[node->parent]->get_name())); } - state->scene_nodes.insert(node_i, skeleton); + p_state->scene_nodes.insert(node_i, skeleton); } } - ERR_FAIL_COND_V(_map_skin_joints_indices_to_skeleton_bone_indices(state), ERR_PARSE_ERROR); + ERR_FAIL_COND_V(_map_skin_joints_indices_to_skeleton_bone_indices(p_state), ERR_PARSE_ERROR); return OK; } -Error GLTFDocument::_map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> state) { - for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) { - Ref<GLTFSkin> skin = state->skins.write[skin_i]; +Error GLTFDocument::_map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> p_state) { + for (GLTFSkinIndex skin_i = 0; skin_i < p_state->skins.size(); ++skin_i) { + Ref<GLTFSkin> skin = p_state->skins.write[skin_i]; - Ref<GLTFSkeleton> skeleton = state->skeletons[skin->skeleton]; + Ref<GLTFSkeleton> skeleton = p_state->skeletons[skin->skeleton]; for (int joint_index = 0; joint_index < skin->joints_original.size(); ++joint_index) { const GLTFNodeIndex node_i = skin->joints_original[joint_index]; - const Ref<GLTFNode> node = state->nodes[node_i]; + const Ref<GLTFNode> node = p_state->nodes[node_i]; const int bone_index = skeleton->godot_skeleton->find_bone(node->get_name()); ERR_FAIL_COND_V(bone_index < 0, FAILED); @@ -4556,28 +4548,28 @@ Error GLTFDocument::_map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFSt return OK; } -Error GLTFDocument::_serialize_skins(Ref<GLTFState> state) { - _remove_duplicate_skins(state); +Error GLTFDocument::_serialize_skins(Ref<GLTFState> p_state) { + _remove_duplicate_skins(p_state); Array json_skins; - for (int skin_i = 0; skin_i < state->skins.size(); skin_i++) { - Ref<GLTFSkin> gltf_skin = state->skins[skin_i]; + for (int skin_i = 0; skin_i < p_state->skins.size(); skin_i++) { + Ref<GLTFSkin> gltf_skin = p_state->skins[skin_i]; Dictionary json_skin; - json_skin["inverseBindMatrices"] = _encode_accessor_as_xform(state, gltf_skin->inverse_binds, false); + json_skin["inverseBindMatrices"] = _encode_accessor_as_xform(p_state, gltf_skin->inverse_binds, false); json_skin["joints"] = gltf_skin->get_joints(); json_skin["name"] = gltf_skin->get_name(); json_skins.push_back(json_skin); } - if (!state->skins.size()) { + if (!p_state->skins.size()) { return OK; } - state->json["skins"] = json_skins; + p_state->json["skins"] = json_skins; return OK; } -Error GLTFDocument::_create_skins(Ref<GLTFState> state) { - for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) { - Ref<GLTFSkin> gltf_skin = state->skins.write[skin_i]; +Error GLTFDocument::_create_skins(Ref<GLTFState> p_state) { + for (GLTFSkinIndex skin_i = 0; skin_i < p_state->skins.size(); ++skin_i) { + Ref<GLTFSkin> gltf_skin = p_state->skins.write[skin_i]; Ref<Skin> skin; skin.instantiate(); @@ -4587,14 +4579,14 @@ Error GLTFDocument::_create_skins(Ref<GLTFState> state) { for (int joint_i = 0; joint_i < gltf_skin->joints_original.size(); ++joint_i) { GLTFNodeIndex node = gltf_skin->joints_original[joint_i]; - String bone_name = state->nodes[node]->get_name(); + String bone_name = p_state->nodes[node]->get_name(); Transform3D xform; if (has_ibms) { xform = gltf_skin->inverse_binds[joint_i]; } - if (state->use_named_skin_binds) { + if (p_state->use_named_skin_binds) { skin->add_named_bind(bone_name, xform); } else { int32_t bone_i = gltf_skin->joint_i_to_bone_i[joint_i]; @@ -4606,35 +4598,35 @@ Error GLTFDocument::_create_skins(Ref<GLTFState> state) { } // Purge the duplicates! - _remove_duplicate_skins(state); + _remove_duplicate_skins(p_state); // Create unique names now, after removing duplicates - for (GLTFSkinIndex skin_i = 0; skin_i < state->skins.size(); ++skin_i) { - Ref<Skin> skin = state->skins.write[skin_i]->godot_skin; + for (GLTFSkinIndex skin_i = 0; skin_i < p_state->skins.size(); ++skin_i) { + Ref<Skin> skin = p_state->skins.write[skin_i]->godot_skin; if (skin->get_name().is_empty()) { // Make a unique name, no gltf node represents this skin - skin->set_name(_gen_unique_name(state, "Skin")); + skin->set_name(_gen_unique_name(p_state, "Skin")); } } return OK; } -bool GLTFDocument::_skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_b) { - if (skin_a->get_bind_count() != skin_b->get_bind_count()) { +bool GLTFDocument::_skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b) { + if (p_skin_a->get_bind_count() != p_skin_b->get_bind_count()) { return false; } - for (int i = 0; i < skin_a->get_bind_count(); ++i) { - if (skin_a->get_bind_bone(i) != skin_b->get_bind_bone(i)) { + for (int i = 0; i < p_skin_a->get_bind_count(); ++i) { + if (p_skin_a->get_bind_bone(i) != p_skin_b->get_bind_bone(i)) { return false; } - if (skin_a->get_bind_name(i) != skin_b->get_bind_name(i)) { + if (p_skin_a->get_bind_name(i) != p_skin_b->get_bind_name(i)) { return false; } - Transform3D a_xform = skin_a->get_bind_pose(i); - Transform3D b_xform = skin_b->get_bind_pose(i); + Transform3D a_xform = p_skin_a->get_bind_pose(i); + Transform3D b_xform = p_skin_b->get_bind_pose(i); if (a_xform != b_xform) { return false; @@ -4644,67 +4636,67 @@ bool GLTFDocument::_skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_ return true; } -void GLTFDocument::_remove_duplicate_skins(Ref<GLTFState> state) { - for (int i = 0; i < state->skins.size(); ++i) { - for (int j = i + 1; j < state->skins.size(); ++j) { - const Ref<Skin> skin_i = state->skins[i]->godot_skin; - const Ref<Skin> skin_j = state->skins[j]->godot_skin; +void GLTFDocument::_remove_duplicate_skins(Ref<GLTFState> p_state) { + for (int i = 0; i < p_state->skins.size(); ++i) { + for (int j = i + 1; j < p_state->skins.size(); ++j) { + const Ref<Skin> skin_i = p_state->skins[i]->godot_skin; + const Ref<Skin> skin_j = p_state->skins[j]->godot_skin; if (_skins_are_same(skin_i, skin_j)) { // replace it and delete the old - state->skins.write[j]->godot_skin = skin_i; + p_state->skins.write[j]->godot_skin = skin_i; } } } } -Error GLTFDocument::_serialize_lights(Ref<GLTFState> state) { - if (state->lights.is_empty()) { +Error GLTFDocument::_serialize_lights(Ref<GLTFState> p_state) { + if (p_state->lights.is_empty()) { return OK; } Array lights; - for (GLTFLightIndex i = 0; i < state->lights.size(); i++) { - lights.push_back(state->lights[i]->to_dictionary()); + for (GLTFLightIndex i = 0; i < p_state->lights.size(); i++) { + lights.push_back(p_state->lights[i]->to_dictionary()); } Dictionary extensions; - if (state->json.has("extensions")) { - extensions = state->json["extensions"]; + if (p_state->json.has("extensions")) { + extensions = p_state->json["extensions"]; } else { - state->json["extensions"] = extensions; + p_state->json["extensions"] = extensions; } Dictionary lights_punctual; extensions["KHR_lights_punctual"] = lights_punctual; lights_punctual["lights"] = lights; - print_verbose("glTF: Total lights: " + itos(state->lights.size())); + print_verbose("glTF: Total lights: " + itos(p_state->lights.size())); return OK; } -Error GLTFDocument::_serialize_cameras(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_cameras(Ref<GLTFState> p_state) { Array cameras; - cameras.resize(state->cameras.size()); - for (GLTFCameraIndex i = 0; i < state->cameras.size(); i++) { - cameras[i] = state->cameras[i]->to_dictionary(); + cameras.resize(p_state->cameras.size()); + for (GLTFCameraIndex i = 0; i < p_state->cameras.size(); i++) { + cameras[i] = p_state->cameras[i]->to_dictionary(); } - if (!state->cameras.size()) { + if (!p_state->cameras.size()) { return OK; } - state->json["cameras"] = cameras; + p_state->json["cameras"] = cameras; - print_verbose("glTF: Total cameras: " + itos(state->cameras.size())); + print_verbose("glTF: Total cameras: " + itos(p_state->cameras.size())); return OK; } -Error GLTFDocument::_parse_lights(Ref<GLTFState> state) { - if (!state->json.has("extensions")) { +Error GLTFDocument::_parse_lights(Ref<GLTFState> p_state) { + if (!p_state->json.has("extensions")) { return OK; } - Dictionary extensions = state->json["extensions"]; + Dictionary extensions = p_state->json["extensions"]; if (!extensions.has("KHR_lights_punctual")) { return OK; } @@ -4720,26 +4712,26 @@ Error GLTFDocument::_parse_lights(Ref<GLTFState> state) { if (light.is_null()) { return Error::ERR_PARSE_ERROR; } - state->lights.push_back(light); + p_state->lights.push_back(light); } - print_verbose("glTF: Total lights: " + itos(state->lights.size())); + print_verbose("glTF: Total lights: " + itos(p_state->lights.size())); return OK; } -Error GLTFDocument::_parse_cameras(Ref<GLTFState> state) { - if (!state->json.has("cameras")) { +Error GLTFDocument::_parse_cameras(Ref<GLTFState> p_state) { + if (!p_state->json.has("cameras")) { return OK; } - const Array cameras = state->json["cameras"]; + const Array cameras = p_state->json["cameras"]; for (GLTFCameraIndex i = 0; i < cameras.size(); i++) { - state->cameras.push_back(GLTFCamera::from_dictionary(cameras[i])); + p_state->cameras.push_back(GLTFCamera::from_dictionary(cameras[i])); } - print_verbose("glTF: Total cameras: " + itos(state->cameras.size())); + print_verbose("glTF: Total cameras: " + itos(p_state->cameras.size())); return OK; } @@ -4759,24 +4751,24 @@ String GLTFDocument::interpolation_to_string(const GLTFAnimation::Interpolation return interp; } -Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { - if (!state->animation_players.size()) { +Error GLTFDocument::_serialize_animations(Ref<GLTFState> p_state) { + if (!p_state->animation_players.size()) { return OK; } - for (int32_t player_i = 0; player_i < state->animation_players.size(); player_i++) { + for (int32_t player_i = 0; player_i < p_state->animation_players.size(); player_i++) { List<StringName> animation_names; - AnimationPlayer *animation_player = state->animation_players[player_i]; + AnimationPlayer *animation_player = p_state->animation_players[player_i]; animation_player->get_animation_list(&animation_names); if (animation_names.size()) { for (int animation_name_i = 0; animation_name_i < animation_names.size(); animation_name_i++) { - _convert_animation(state, animation_player, animation_names[animation_name_i]); + _convert_animation(p_state, animation_player, animation_names[animation_name_i]); } } } Array animations; - for (GLTFAnimationIndex animation_i = 0; animation_i < state->animations.size(); animation_i++) { + for (GLTFAnimationIndex animation_i = 0; animation_i < p_state->animations.size(); animation_i++) { Dictionary d; - Ref<GLTFAnimation> gltf_animation = state->animations[animation_i]; + Ref<GLTFAnimation> gltf_animation = p_state->animations[animation_i]; if (!gltf_animation->get_tracks().size()) { continue; } @@ -4796,9 +4788,9 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { s["interpolation"] = interpolation_to_string(track.position_track.interpolation); Vector<real_t> times = Variant(track.position_track.times); - s["input"] = _encode_accessor_as_floats(state, times, false); + s["input"] = _encode_accessor_as_floats(p_state, times, false); Vector<Vector3> values = Variant(track.position_track.values); - s["output"] = _encode_accessor_as_vec3(state, values, false); + s["output"] = _encode_accessor_as_vec3(p_state, values, false); samplers.push_back(s); @@ -4816,9 +4808,9 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { s["interpolation"] = interpolation_to_string(track.rotation_track.interpolation); Vector<real_t> times = Variant(track.rotation_track.times); - s["input"] = _encode_accessor_as_floats(state, times, false); + s["input"] = _encode_accessor_as_floats(p_state, times, false); Vector<Quaternion> values = track.rotation_track.values; - s["output"] = _encode_accessor_as_quaternions(state, values, false); + s["output"] = _encode_accessor_as_quaternions(p_state, values, false); samplers.push_back(s); @@ -4836,9 +4828,9 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { s["interpolation"] = interpolation_to_string(track.scale_track.interpolation); Vector<real_t> times = Variant(track.scale_track.times); - s["input"] = _encode_accessor_as_floats(state, times, false); + s["input"] = _encode_accessor_as_floats(p_state, times, false); Vector<Vector3> values = Variant(track.scale_track.values); - s["output"] = _encode_accessor_as_vec3(state, values, false); + s["output"] = _encode_accessor_as_vec3(p_state, values, false); samplers.push_back(s); @@ -4916,8 +4908,8 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { } s["interpolation"] = interpolation_to_string(track.weight_tracks[track.weight_tracks.size() - 1].interpolation); - s["input"] = _encode_accessor_as_floats(state, all_track_times, false); - s["output"] = _encode_accessor_as_floats(state, all_track_values, false); + s["input"] = _encode_accessor_as_floats(p_state, all_track_times, false); + s["output"] = _encode_accessor_as_floats(p_state, all_track_values, false); samplers.push_back(s); @@ -4939,19 +4931,19 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> state) { if (!animations.size()) { return OK; } - state->json["animations"] = animations; + p_state->json["animations"] = animations; - print_verbose("glTF: Total animations '" + itos(state->animations.size()) + "'."); + print_verbose("glTF: Total animations '" + itos(p_state->animations.size()) + "'."); return OK; } -Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { - if (!state->json.has("animations")) { +Error GLTFDocument::_parse_animations(Ref<GLTFState> p_state) { + if (!p_state->json.has("animations")) { return OK; } - const Array &animations = state->json["animations"]; + const Array &animations = p_state->json["animations"]; for (GLTFAnimationIndex i = 0; i < animations.size(); i++) { const Dictionary &d = animations[i]; @@ -4972,7 +4964,7 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { if (anim_name_lower.begins_with("loop") || anim_name_lower.ends_with("loop") || anim_name_lower.begins_with("cycle") || anim_name_lower.ends_with("cycle")) { animation->set_loop(true); } - animation->set_name(_gen_unique_animation_name(state, anim_name)); + animation->set_name(_gen_unique_animation_name(p_state, anim_name)); } for (int j = 0; j < channels.size(); j++) { @@ -4993,7 +4985,7 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { GLTFNodeIndex node = t["node"]; String path = t["path"]; - ERR_FAIL_INDEX_V(node, state->nodes.size(), ERR_PARSE_ERROR); + ERR_FAIL_INDEX_V(node, p_state->nodes.size(), ERR_PARSE_ERROR); GLTFAnimation::Track *track = nullptr; @@ -5028,27 +5020,27 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { } } - const Vector<float> times = _decode_accessor_as_floats(state, input, false); + const Vector<float> times = _decode_accessor_as_floats(p_state, input, false); if (path == "translation") { - const Vector<Vector3> positions = _decode_accessor_as_vec3(state, output, false); + const Vector<Vector3> positions = _decode_accessor_as_vec3(p_state, output, false); track->position_track.interpolation = interp; track->position_track.times = Variant(times); //convert via variant track->position_track.values = Variant(positions); //convert via variant } else if (path == "rotation") { - const Vector<Quaternion> rotations = _decode_accessor_as_quaternion(state, output, false); + const Vector<Quaternion> rotations = _decode_accessor_as_quaternion(p_state, output, false); track->rotation_track.interpolation = interp; track->rotation_track.times = Variant(times); //convert via variant track->rotation_track.values = rotations; } else if (path == "scale") { - const Vector<Vector3> scales = _decode_accessor_as_vec3(state, output, false); + const Vector<Vector3> scales = _decode_accessor_as_vec3(p_state, output, false); track->scale_track.interpolation = interp; track->scale_track.times = Variant(times); //convert via variant track->scale_track.values = Variant(scales); //convert via variant } else if (path == "weights") { - const Vector<float> weights = _decode_accessor_as_floats(state, output, false); + const Vector<float> weights = _decode_accessor_as_floats(p_state, output, false); - ERR_FAIL_INDEX_V(state->nodes[node]->mesh, state->meshes.size(), ERR_PARSE_ERROR); - Ref<GLTFMesh> mesh = state->meshes[state->nodes[node]->mesh]; + ERR_FAIL_INDEX_V(p_state->nodes[node]->mesh, p_state->meshes.size(), ERR_PARSE_ERROR); + Ref<GLTFMesh> mesh = p_state->meshes[p_state->nodes[node]->mesh]; ERR_CONTINUE(!mesh->get_blend_weights().size()); const int wc = mesh->get_blend_weights().size(); @@ -5076,17 +5068,17 @@ Error GLTFDocument::_parse_animations(Ref<GLTFState> state) { } } - state->animations.push_back(animation); + p_state->animations.push_back(animation); } - print_verbose("glTF: Total animations '" + itos(state->animations.size()) + "'."); + print_verbose("glTF: Total animations '" + itos(p_state->animations.size()) + "'."); return OK; } -void GLTFDocument::_assign_scene_names(Ref<GLTFState> state) { - for (int i = 0; i < state->nodes.size(); i++) { - Ref<GLTFNode> n = state->nodes[i]; +void GLTFDocument::_assign_scene_names(Ref<GLTFState> p_state) { + for (int i = 0; i < p_state->nodes.size(); i++) { + Ref<GLTFNode> n = p_state->nodes[i]; // Any joints get unique names generated when the skeleton is made, unique to the skeleton if (n->skeleton >= 0) { @@ -5095,21 +5087,21 @@ void GLTFDocument::_assign_scene_names(Ref<GLTFState> state) { if (n->get_name().is_empty()) { if (n->mesh >= 0) { - n->set_name(_gen_unique_name(state, "Mesh")); + n->set_name(_gen_unique_name(p_state, "Mesh")); } else if (n->camera >= 0) { - n->set_name(_gen_unique_name(state, "Camera3D")); + n->set_name(_gen_unique_name(p_state, "Camera3D")); } else { - n->set_name(_gen_unique_name(state, "Node")); + n->set_name(_gen_unique_name(p_state, "Node")); } } - n->set_name(_gen_unique_name(state, n->get_name())); + n->set_name(_gen_unique_name(p_state, n->get_name())); } } -BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> state, Skeleton3D *skeleton, const GLTFNodeIndex node_index, const GLTFNodeIndex bone_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; - Ref<GLTFNode> bone_node = state->nodes[bone_index]; +BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> p_state, Skeleton3D *p_skeleton, const GLTFNodeIndex p_node_index, const GLTFNodeIndex p_bone_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; + Ref<GLTFNode> bone_node = p_state->nodes[p_bone_index]; BoneAttachment3D *bone_attachment = memnew(BoneAttachment3D); print_verbose("glTF: Creating bone attachment for: " + gltf_node->get_name()); @@ -5120,7 +5112,7 @@ BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> state, return bone_attachment; } -GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> state, MeshInstance3D *p_mesh_instance) { +GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> p_state, MeshInstance3D *p_mesh_instance) { ERR_FAIL_NULL_V(p_mesh_instance, -1); if (p_mesh_instance->get_mesh().is_null()) { return -1; @@ -5151,20 +5143,20 @@ GLTFMeshIndex GLTFDocument::_convert_mesh_to_gltf(Ref<GLTFState> state, MeshInst gltf_mesh->set_instance_materials(instance_materials); gltf_mesh->set_mesh(current_mesh); gltf_mesh->set_blend_weights(blend_weights); - GLTFMeshIndex mesh_i = state->meshes.size(); - state->meshes.push_back(gltf_mesh); + GLTFMeshIndex mesh_i = p_state->meshes.size(); + p_state->meshes.push_back(gltf_mesh); return mesh_i; } -ImporterMeshInstance3D *GLTFDocument::_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +ImporterMeshInstance3D *GLTFDocument::_generate_mesh_instance(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; - ERR_FAIL_INDEX_V(gltf_node->mesh, state->meshes.size(), nullptr); + ERR_FAIL_INDEX_V(gltf_node->mesh, p_state->meshes.size(), nullptr); ImporterMeshInstance3D *mi = memnew(ImporterMeshInstance3D); print_verbose("glTF: Creating mesh for: " + gltf_node->get_name()); - Ref<GLTFMesh> mesh = state->meshes.write[gltf_node->mesh]; + Ref<GLTFMesh> mesh = p_state->meshes.write[gltf_node->mesh]; if (mesh.is_null()) { return mi; } @@ -5176,56 +5168,56 @@ ImporterMeshInstance3D *GLTFDocument::_generate_mesh_instance(Ref<GLTFState> sta return mi; } -Light3D *GLTFDocument::_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +Light3D *GLTFDocument::_generate_light(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; - ERR_FAIL_INDEX_V(gltf_node->light, state->lights.size(), nullptr); + ERR_FAIL_INDEX_V(gltf_node->light, p_state->lights.size(), nullptr); print_verbose("glTF: Creating light for: " + gltf_node->get_name()); - Ref<GLTFLight> l = state->lights[gltf_node->light]; + Ref<GLTFLight> l = p_state->lights[gltf_node->light]; return l->to_node(); } -Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +Camera3D *GLTFDocument::_generate_camera(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; - ERR_FAIL_INDEX_V(gltf_node->camera, state->cameras.size(), nullptr); + ERR_FAIL_INDEX_V(gltf_node->camera, p_state->cameras.size(), nullptr); print_verbose("glTF: Creating camera for: " + gltf_node->get_name()); - Ref<GLTFCamera> c = state->cameras[gltf_node->camera]; + Ref<GLTFCamera> c = p_state->cameras[gltf_node->camera]; return c->to_node(); } -GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> state, Camera3D *p_camera) { +GLTFCameraIndex GLTFDocument::_convert_camera(Ref<GLTFState> p_state, Camera3D *p_camera) { print_verbose("glTF: Converting camera: " + p_camera->get_name()); Ref<GLTFCamera> c = GLTFCamera::from_node(p_camera); - GLTFCameraIndex camera_index = state->cameras.size(); - state->cameras.push_back(c); + GLTFCameraIndex camera_index = p_state->cameras.size(); + p_state->cameras.push_back(c); return camera_index; } -GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_light) { +GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> p_state, Light3D *p_light) { print_verbose("glTF: Converting light: " + p_light->get_name()); Ref<GLTFLight> l = GLTFLight::from_node(p_light); - GLTFLightIndex light_index = state->lights.size(); - state->lights.push_back(l); + GLTFLightIndex light_index = p_state->lights.size(); + p_state->lights.push_back(l); return light_index; } -void GLTFDocument::_convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node) { +void GLTFDocument::_convert_spatial(Ref<GLTFState> p_state, Node3D *p_spatial, Ref<GLTFNode> p_node) { Transform3D xform = p_spatial->get_transform(); p_node->scale = xform.basis.get_scale(); p_node->rotation = xform.basis.get_rotation_quaternion(); p_node->position = xform.origin; } -Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; Node3D *spatial = memnew(Node3D); print_verbose("glTF: Converting spatial: " + gltf_node->get_name()); @@ -5233,7 +5225,7 @@ Node3D *GLTFDocument::_generate_spatial(Ref<GLTFState> state, const GLTFNodeInde return spatial; } -void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { +void GLTFDocument::_convert_scene_node(Ref<GLTFState> p_state, Node *p_current, const GLTFNodeIndex p_gltf_parent, const GLTFNodeIndex p_gltf_root) { bool retflag = true; _check_visibility(p_current, retflag); if (retflag) { @@ -5241,68 +5233,68 @@ void GLTFDocument::_convert_scene_node(Ref<GLTFState> state, Node *p_current, co } Ref<GLTFNode> gltf_node; gltf_node.instantiate(); - gltf_node->set_name(_gen_unique_name(state, p_current->get_name())); + gltf_node->set_name(_gen_unique_name(p_state, p_current->get_name())); if (cast_to<Node3D>(p_current)) { Node3D *spatial = cast_to<Node3D>(p_current); - _convert_spatial(state, spatial, gltf_node); + _convert_spatial(p_state, spatial, gltf_node); } if (cast_to<MeshInstance3D>(p_current)) { MeshInstance3D *mi = cast_to<MeshInstance3D>(p_current); - _convert_mesh_instance_to_gltf(mi, state, gltf_node); + _convert_mesh_instance_to_gltf(mi, p_state, gltf_node); } else if (cast_to<BoneAttachment3D>(p_current)) { BoneAttachment3D *bone = cast_to<BoneAttachment3D>(p_current); - _convert_bone_attachment_to_gltf(bone, state, p_gltf_parent, p_gltf_root, gltf_node); + _convert_bone_attachment_to_gltf(bone, p_state, p_gltf_parent, p_gltf_root, gltf_node); return; } else if (cast_to<Skeleton3D>(p_current)) { Skeleton3D *skel = cast_to<Skeleton3D>(p_current); - _convert_skeleton_to_gltf(skel, state, p_gltf_parent, p_gltf_root, gltf_node); + _convert_skeleton_to_gltf(skel, p_state, p_gltf_parent, p_gltf_root, gltf_node); // We ignore the Godot Engine node that is the skeleton. return; } else if (cast_to<MultiMeshInstance3D>(p_current)) { MultiMeshInstance3D *multi = cast_to<MultiMeshInstance3D>(p_current); - _convert_multi_mesh_instance_to_gltf(multi, p_gltf_parent, p_gltf_root, gltf_node, state); + _convert_multi_mesh_instance_to_gltf(multi, p_gltf_parent, p_gltf_root, gltf_node, p_state); #ifdef MODULE_CSG_ENABLED } else if (cast_to<CSGShape3D>(p_current)) { CSGShape3D *shape = cast_to<CSGShape3D>(p_current); if (shape->get_parent() && shape->is_root_shape()) { - _convert_csg_shape_to_gltf(shape, p_gltf_parent, gltf_node, state); + _convert_csg_shape_to_gltf(shape, p_gltf_parent, gltf_node, p_state); } #endif // MODULE_CSG_ENABLED #ifdef MODULE_GRIDMAP_ENABLED } else if (cast_to<GridMap>(p_current)) { GridMap *gridmap = Object::cast_to<GridMap>(p_current); - _convert_grid_map_to_gltf(gridmap, p_gltf_parent, p_gltf_root, gltf_node, state); + _convert_grid_map_to_gltf(gridmap, p_gltf_parent, p_gltf_root, gltf_node, p_state); #endif // MODULE_GRIDMAP_ENABLED } else if (cast_to<Camera3D>(p_current)) { Camera3D *camera = Object::cast_to<Camera3D>(p_current); - _convert_camera_to_gltf(camera, state, gltf_node); + _convert_camera_to_gltf(camera, p_state, gltf_node); } else if (cast_to<Light3D>(p_current)) { Light3D *light = Object::cast_to<Light3D>(p_current); - _convert_light_to_gltf(light, state, gltf_node); + _convert_light_to_gltf(light, p_state, gltf_node); } else if (cast_to<AnimationPlayer>(p_current)) { AnimationPlayer *animation_player = Object::cast_to<AnimationPlayer>(p_current); - _convert_animation_player_to_gltf(animation_player, state, p_gltf_parent, p_gltf_root, gltf_node, p_current); + _convert_animation_player_to_gltf(animation_player, p_state, p_gltf_parent, p_gltf_root, gltf_node, p_current); } for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - ext->convert_scene_node(state, gltf_node, p_current); + ext->convert_scene_node(p_state, gltf_node, p_current); } - GLTFNodeIndex current_node_i = state->nodes.size(); + GLTFNodeIndex current_node_i = p_state->nodes.size(); GLTFNodeIndex gltf_root = p_gltf_root; if (gltf_root == -1) { gltf_root = current_node_i; Array scenes; scenes.push_back(gltf_root); - state->json["scene"] = scenes; + p_state->json["scene"] = scenes; } - _create_gltf_node(state, p_current, current_node_i, p_gltf_parent, gltf_root, gltf_node); + _create_gltf_node(p_state, p_current, current_node_i, p_gltf_parent, gltf_root, gltf_node); for (int node_i = 0; node_i < p_current->get_child_count(); node_i++) { - _convert_scene_node(state, p_current->get_child(node_i), current_node_i, gltf_root); + _convert_scene_node(p_state, p_current->get_child(node_i), current_node_i, gltf_root); } } #ifdef MODULE_CSG_ENABLED -void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { +void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { CSGShape3D *csg = p_current; csg->call("_update_shape"); Array meshes = csg->get_meshes(); @@ -5334,34 +5326,34 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd Ref<GLTFMesh> gltf_mesh; gltf_mesh.instantiate(); gltf_mesh->set_mesh(mesh); - GLTFMeshIndex mesh_i = state->meshes.size(); - state->meshes.push_back(gltf_mesh); - gltf_node->mesh = mesh_i; - gltf_node->xform = csg->get_meshes()[0]; - gltf_node->set_name(_gen_unique_name(state, csg->get_name())); + GLTFMeshIndex mesh_i = p_state->meshes.size(); + p_state->meshes.push_back(gltf_mesh); + p_gltf_node->mesh = mesh_i; + p_gltf_node->xform = csg->get_meshes()[0]; + p_gltf_node->set_name(_gen_unique_name(p_state, csg->get_name())); } #endif // MODULE_CSG_ENABLED -void GLTFDocument::_create_gltf_node(Ref<GLTFState> state, Node *p_scene_parent, GLTFNodeIndex current_node_i, - GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, Ref<GLTFNode> gltf_node) { - state->scene_nodes.insert(current_node_i, p_scene_parent); - state->nodes.push_back(gltf_node); - ERR_FAIL_COND(current_node_i == p_parent_node_index); - state->nodes.write[current_node_i]->parent = p_parent_node_index; +void GLTFDocument::_create_gltf_node(Ref<GLTFState> p_state, Node *p_scene_parent, GLTFNodeIndex p_current_node_i, + GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, Ref<GLTFNode> p_gltf_node) { + p_state->scene_nodes.insert(p_current_node_i, p_scene_parent); + p_state->nodes.push_back(p_gltf_node); + ERR_FAIL_COND(p_current_node_i == p_parent_node_index); + p_state->nodes.write[p_current_node_i]->parent = p_parent_node_index; if (p_parent_node_index == -1) { return; } - state->nodes.write[p_parent_node_index]->children.push_back(current_node_i); + p_state->nodes.write[p_parent_node_index]->children.push_back(p_current_node_i); } -void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *animation_player, Ref<GLTFState> state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) { - ERR_FAIL_COND(!animation_player); - state->animation_players.push_back(animation_player); - print_verbose(String("glTF: Converting animation player: ") + animation_player->get_name()); +void GLTFDocument::_convert_animation_player_to_gltf(AnimationPlayer *p_animation_player, Ref<GLTFState> p_state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent) { + ERR_FAIL_COND(!p_animation_player); + p_state->animation_players.push_back(p_animation_player); + print_verbose(String("glTF: Converting animation player: ") + p_animation_player->get_name()); } -void GLTFDocument::_check_visibility(Node *p_node, bool &retflag) { - retflag = true; +void GLTFDocument::_check_visibility(Node *p_node, bool &r_retflag) { + r_retflag = true; Node3D *spatial = Object::cast_to<Node3D>(p_node); Node2D *node_2d = Object::cast_to<Node2D>(p_node); if (node_2d && !node_2d->is_visible()) { @@ -5370,32 +5362,32 @@ void GLTFDocument::_check_visibility(Node *p_node, bool &retflag) { if (spatial && !spatial->is_visible()) { return; } - retflag = false; + r_retflag = false; } -void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { ERR_FAIL_COND(!camera); - GLTFCameraIndex camera_index = _convert_camera(state, camera); + GLTFCameraIndex camera_index = _convert_camera(p_state, camera); if (camera_index != -1) { - gltf_node->camera = camera_index; + p_gltf_node->camera = camera_index; } } -void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_light_to_gltf(Light3D *light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { ERR_FAIL_COND(!light); - GLTFLightIndex light_index = _convert_light(state, light); + GLTFLightIndex light_index = _convert_light(p_state, light); if (light_index != -1) { - gltf_node->light = light_index; + p_gltf_node->light = light_index; } } #ifdef MODULE_GRIDMAP_ENABLED -void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { +void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { Array cells = p_grid_map->get_used_cells(); for (int32_t k = 0; k < cells.size(); k++) { GLTFNode *new_gltf_node = memnew(GLTFNode); - gltf_node->children.push_back(state->nodes.size()); - state->nodes.push_back(new_gltf_node); + p_gltf_node->children.push_back(p_state->nodes.size()); + p_state->nodes.push_back(new_gltf_node); Vector3 cell_location = cells[k]; int32_t cell = p_grid_map->get_cell_item( Vector3(cell_location.x, cell_location.y, cell_location.z)); @@ -5411,10 +5403,10 @@ void GLTFDocument::_convert_grid_map_to_gltf(GridMap *p_grid_map, GLTFNodeIndex Ref<GLTFMesh> gltf_mesh; gltf_mesh.instantiate(); gltf_mesh->set_mesh(_mesh_to_importer_mesh(p_grid_map->get_mesh_library()->get_item_mesh(cell))); - new_gltf_node->mesh = state->meshes.size(); - state->meshes.push_back(gltf_mesh); + new_gltf_node->mesh = p_state->meshes.size(); + p_state->meshes.push_back(gltf_mesh); new_gltf_node->xform = cell_xform * p_grid_map->get_transform(); - new_gltf_node->set_name(_gen_unique_name(state, p_grid_map->get_mesh_library()->get_item_name(cell))); + new_gltf_node->set_name(_gen_unique_name(p_state, p_grid_map->get_mesh_library()->get_item_name(cell))); } } #endif // MODULE_GRIDMAP_ENABLED @@ -5423,7 +5415,7 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf( MultiMeshInstance3D *p_multi_mesh_instance, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, - Ref<GLTFNode> gltf_node, Ref<GLTFState> state) { + Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state) { ERR_FAIL_COND(!p_multi_mesh_instance); Ref<MultiMesh> multi_mesh = p_multi_mesh_instance->get_multimesh(); if (multi_mesh.is_null()) { @@ -5459,8 +5451,8 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf( blend_arrays, mesh->surface_get_lods(surface_i), mat, material_name, mesh->surface_get_format(surface_i)); } gltf_mesh->set_mesh(importer_mesh); - GLTFMeshIndex mesh_index = state->meshes.size(); - state->meshes.push_back(gltf_mesh); + GLTFMeshIndex mesh_index = p_state->meshes.size(); + p_state->meshes.push_back(gltf_mesh); for (int32_t instance_i = 0; instance_i < multi_mesh->get_instance_count(); instance_i++) { Transform3D transform; @@ -5482,22 +5474,22 @@ void GLTFDocument::_convert_multi_mesh_instance_to_gltf( new_gltf_node.instantiate(); new_gltf_node->mesh = mesh_index; new_gltf_node->xform = transform; - new_gltf_node->set_name(_gen_unique_name(state, p_multi_mesh_instance->get_name())); - gltf_node->children.push_back(state->nodes.size()); - state->nodes.push_back(new_gltf_node); + new_gltf_node->set_name(_gen_unique_name(p_state, p_multi_mesh_instance->get_name())); + p_gltf_node->children.push_back(p_state->nodes.size()); + p_state->nodes.push_back(new_gltf_node); } } -void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node) { Skeleton3D *skeleton = p_skeleton3d; Ref<GLTFSkeleton> gltf_skeleton; gltf_skeleton.instantiate(); - // GLTFSkeleton is only used to hold internal state data. It will not be written to the document. + // GLTFSkeleton is only used to hold internal p_state data. It will not be written to the document. // gltf_skeleton->godot_skeleton = skeleton; - GLTFSkeletonIndex skeleton_i = state->skeletons.size(); - state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skeleton_i; - state->skeletons.push_back(gltf_skeleton); + GLTFSkeletonIndex skeleton_i = p_state->skeletons.size(); + p_state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()] = skeleton_i; + p_state->skeletons.push_back(gltf_skeleton); BoneId bone_count = skeleton->get_bone_count(); for (BoneId bone_i = 0; bone_i < bone_count; bone_i++) { @@ -5505,15 +5497,15 @@ void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFS joint_node.instantiate(); // Note that we cannot use _gen_unique_bone_name here, because glTF spec requires all node // names to be unique regardless of whether or not they are used as joints. - joint_node->set_name(_gen_unique_name(state, skeleton->get_bone_name(bone_i))); + joint_node->set_name(_gen_unique_name(p_state, skeleton->get_bone_name(bone_i))); Transform3D xform = skeleton->get_bone_pose(bone_i); joint_node->scale = xform.basis.get_scale(); joint_node->rotation = xform.basis.get_rotation_quaternion(); joint_node->position = xform.origin; joint_node->joint = true; - GLTFNodeIndex current_node_i = state->nodes.size(); - state->scene_nodes.insert(current_node_i, skeleton); - state->nodes.push_back(joint_node); + GLTFNodeIndex current_node_i = p_state->nodes.size(); + p_state->scene_nodes.insert(current_node_i, skeleton); + p_state->nodes.push_back(joint_node); gltf_skeleton->joints.push_back(current_node_i); if (skeleton->get_bone_parent(bone_i) == -1) { @@ -5526,23 +5518,23 @@ void GLTFDocument::_convert_skeleton_to_gltf(Skeleton3D *p_skeleton3d, Ref<GLTFS BoneId parent_bone_id = skeleton->get_bone_parent(bone_i); if (parent_bone_id == -1) { if (p_parent_node_index != -1) { - state->nodes.write[current_node_i]->parent = p_parent_node_index; - state->nodes.write[p_parent_node_index]->children.push_back(current_node_i); + p_state->nodes.write[current_node_i]->parent = p_parent_node_index; + p_state->nodes.write[p_parent_node_index]->children.push_back(current_node_i); } } else { GLTFNodeIndex parent_node_i = gltf_skeleton->godot_bone_node[parent_bone_id]; - state->nodes.write[current_node_i]->parent = parent_node_i; - state->nodes.write[parent_node_i]->children.push_back(current_node_i); + p_state->nodes.write[current_node_i]->parent = parent_node_i; + p_state->nodes.write[parent_node_i]->children.push_back(current_node_i); } } // Remove placeholder skeleton3d node by not creating the gltf node // Skins are per mesh for (int node_i = 0; node_i < skeleton->get_child_count(); node_i++) { - _convert_scene_node(state, skeleton->get_child(node_i), p_parent_node_index, p_root_node_index); + _convert_scene_node(p_state, skeleton->get_child(node_i), p_parent_node_index, p_root_node_index); } } -void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, Ref<GLTFState> state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> gltf_node) { +void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, Ref<GLTFNode> p_gltf_node) { Skeleton3D *skeleton; // Note that relative transforms to external skeletons and pose overrides are not supported. if (p_bone_attachment->get_use_external_skeleton()) { @@ -5551,8 +5543,8 @@ void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_att skeleton = cast_to<Skeleton3D>(p_bone_attachment->get_parent()); } GLTFSkeletonIndex skel_gltf_i = -1; - if (skeleton != nullptr && state->skeleton3d_to_gltf_skeleton.has(skeleton->get_instance_id())) { - skel_gltf_i = state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()]; + if (skeleton != nullptr && p_state->skeleton3d_to_gltf_skeleton.has(skeleton->get_instance_id())) { + skel_gltf_i = p_state->skeleton3d_to_gltf_skeleton[skeleton->get_instance_id()]; } int bone_idx = -1; if (skeleton != nullptr) { @@ -5563,28 +5555,28 @@ void GLTFDocument::_convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_att } GLTFNodeIndex par_node_index = p_parent_node_index; if (skeleton != nullptr && bone_idx != -1 && skel_gltf_i != -1) { - Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skel_gltf_i]; + Ref<GLTFSkeleton> gltf_skeleton = p_state->skeletons.write[skel_gltf_i]; gltf_skeleton->bone_attachments.push_back(p_bone_attachment); par_node_index = gltf_skeleton->joints[bone_idx]; } for (int node_i = 0; node_i < p_bone_attachment->get_child_count(); node_i++) { - _convert_scene_node(state, p_bone_attachment->get_child(node_i), par_node_index, p_root_node_index); + _convert_scene_node(p_state, p_bone_attachment->get_child(node_i), par_node_index, p_root_node_index); } } -void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance3D *p_scene_parent, Ref<GLTFState> state, Ref<GLTFNode> gltf_node) { - GLTFMeshIndex gltf_mesh_index = _convert_mesh_to_gltf(state, p_scene_parent); +void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance3D *p_scene_parent, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node) { + GLTFMeshIndex gltf_mesh_index = _convert_mesh_to_gltf(p_state, p_scene_parent); if (gltf_mesh_index != -1) { - gltf_node->mesh = gltf_mesh_index; + p_gltf_node->mesh = gltf_mesh_index; } } -void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[node_index]; if (gltf_node->skeleton >= 0) { - _generate_skeleton_bone_node(state, scene_parent, scene_root, node_index); + _generate_skeleton_bone_node(p_state, scene_parent, scene_root, node_index); return; } @@ -5598,13 +5590,13 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent // skinned meshes must not be placed in a bone attachment. if (non_bone_parented_to_skeleton && gltf_node->skin < 0) { // Bone Attachment - Parent Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, gltf_node->parent); + BoneAttachment3D *bone_attachment = _generate_bone_attachment(p_state, active_skeleton, node_index, gltf_node->parent); scene_parent->add_child(bone_attachment, true); bone_attachment->set_owner(scene_root); // There is no gltf_node that represent this, so just directly create a unique name - bone_attachment->set_name(_gen_unique_name(state, "BoneAttachment3D")); + bone_attachment->set_name(_gen_unique_name(p_state, "BoneAttachment3D")); // We change the scene_parent to our bone attachment now. We do not set current_node because we want to make the node // and attach it to the bone_attachment @@ -5613,7 +5605,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent // Check if any GLTFDocumentExtension classes want to generate a node for us. for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - current_node = ext->generate_scene_node(state, gltf_node, scene_parent); + current_node = ext->generate_scene_node(p_state, gltf_node, scene_parent); if (current_node) { break; } @@ -5621,13 +5613,13 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent // If none of our GLTFDocumentExtension classes generated us a node, we generate one. if (!current_node) { if (gltf_node->mesh >= 0) { - current_node = _generate_mesh_instance(state, node_index); + current_node = _generate_mesh_instance(p_state, node_index); } else if (gltf_node->camera >= 0) { - current_node = _generate_camera(state, node_index); + current_node = _generate_camera(p_state, node_index); } else if (gltf_node->light >= 0) { - current_node = _generate_light(state, node_index); + current_node = _generate_light(p_state, node_index); } else { - current_node = _generate_spatial(state, node_index); + current_node = _generate_spatial(p_state, node_index); } } // Add the node we generated and set the owner to the scene root. @@ -5640,45 +5632,45 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> state, Node *scene_parent current_node->set_transform(gltf_node->xform); current_node->set_name(gltf_node->get_name()); - state->scene_nodes.insert(node_index, current_node); + p_state->scene_nodes.insert(node_index, current_node); for (int i = 0; i < gltf_node->children.size(); ++i) { - _generate_scene_node(state, current_node, scene_root, gltf_node->children[i]); + _generate_scene_node(p_state, current_node, scene_root, gltf_node->children[i]); } } -void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index) { - Ref<GLTFNode> gltf_node = state->nodes[node_index]; +void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> p_state, Node *p_scene_parent, Node3D *p_scene_root, const GLTFNodeIndex p_node_index) { + Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index]; Node3D *current_node = nullptr; - Skeleton3D *skeleton = state->skeletons[gltf_node->skeleton]->godot_skeleton; + Skeleton3D *skeleton = p_state->skeletons[gltf_node->skeleton]->godot_skeleton; // In this case, this node is already a bone in skeleton. const bool is_skinned_mesh = (gltf_node->skin >= 0 && gltf_node->mesh >= 0); const bool requires_extra_node = (gltf_node->mesh >= 0 || gltf_node->camera >= 0 || gltf_node->light >= 0); - Skeleton3D *active_skeleton = Object::cast_to<Skeleton3D>(scene_parent); + Skeleton3D *active_skeleton = Object::cast_to<Skeleton3D>(p_scene_parent); if (active_skeleton != skeleton) { if (active_skeleton) { // Bone Attachment - Direct Parented Skeleton Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, gltf_node->parent); + BoneAttachment3D *bone_attachment = _generate_bone_attachment(p_state, active_skeleton, p_node_index, gltf_node->parent); - scene_parent->add_child(bone_attachment, true); - bone_attachment->set_owner(scene_root); + p_scene_parent->add_child(bone_attachment, true); + bone_attachment->set_owner(p_scene_root); // There is no gltf_node that represent this, so just directly create a unique name - bone_attachment->set_name(_gen_unique_name(state, "BoneAttachment3D")); + bone_attachment->set_name(_gen_unique_name(p_state, "BoneAttachment3D")); // We change the scene_parent to our bone attachment now. We do not set current_node because we want to make the node // and attach it to the bone_attachment - scene_parent = bone_attachment; - WARN_PRINT(vformat("glTF: Generating scene detected direct parented Skeletons at node %d", node_index)); + p_scene_parent = bone_attachment; + WARN_PRINT(vformat("glTF: Generating scene detected direct parented Skeletons at node %d", p_node_index)); } // Add it to the scene if it has not already been added if (skeleton->get_parent() == nullptr) { - scene_parent->add_child(skeleton, true); - skeleton->set_owner(scene_root); + p_scene_parent->add_child(skeleton, true); + skeleton->set_owner(p_scene_root); } } @@ -5689,22 +5681,22 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> state, Node *scen // skinned meshes must not be placed in a bone attachment. if (!is_skinned_mesh) { // Bone Attachment - Same Node Case - BoneAttachment3D *bone_attachment = _generate_bone_attachment(state, active_skeleton, node_index, node_index); + BoneAttachment3D *bone_attachment = _generate_bone_attachment(p_state, active_skeleton, p_node_index, p_node_index); - scene_parent->add_child(bone_attachment, true); - bone_attachment->set_owner(scene_root); + p_scene_parent->add_child(bone_attachment, true); + bone_attachment->set_owner(p_scene_root); // There is no gltf_node that represent this, so just directly create a unique name - bone_attachment->set_name(_gen_unique_name(state, "BoneAttachment3D")); + bone_attachment->set_name(_gen_unique_name(p_state, "BoneAttachment3D")); // We change the scene_parent to our bone attachment now. We do not set current_node because we want to make the node // and attach it to the bone_attachment - scene_parent = bone_attachment; + p_scene_parent = bone_attachment; } // Check if any GLTFDocumentExtension classes want to generate a node for us. for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - current_node = ext->generate_scene_node(state, gltf_node, scene_parent); + current_node = ext->generate_scene_node(p_state, gltf_node, p_scene_parent); if (current_node) { break; } @@ -5712,30 +5704,30 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> state, Node *scen // If none of our GLTFDocumentExtension classes generated us a node, we generate one. if (!current_node) { if (gltf_node->mesh >= 0) { - current_node = _generate_mesh_instance(state, node_index); + current_node = _generate_mesh_instance(p_state, p_node_index); } else if (gltf_node->camera >= 0) { - current_node = _generate_camera(state, node_index); + current_node = _generate_camera(p_state, p_node_index); } else if (gltf_node->light >= 0) { - current_node = _generate_light(state, node_index); + current_node = _generate_light(p_state, p_node_index); } else { - current_node = _generate_spatial(state, node_index); + current_node = _generate_spatial(p_state, p_node_index); } } // Add the node we generated and set the owner to the scene root. - scene_parent->add_child(current_node, true); - if (current_node != scene_root) { + p_scene_parent->add_child(current_node, true); + if (current_node != p_scene_root) { Array args; - args.append(scene_root); + args.append(p_scene_root); current_node->propagate_call(StringName("set_owner"), args); } // Do not set transform here. Transform is already applied to our bone. current_node->set_name(gltf_node->get_name()); } - state->scene_nodes.insert(node_index, current_node); + p_state->scene_nodes.insert(p_node_index, current_node); for (int i = 0; i < gltf_node->children.size(); ++i) { - _generate_scene_node(state, active_skeleton, scene_root, gltf_node->children[i]); + _generate_scene_node(p_state, active_skeleton, p_scene_root, gltf_node->children[i]); } } @@ -5860,13 +5852,13 @@ T GLTFDocument::_interpolate_track(const Vector<real_t> &p_times, const Vector<T ERR_FAIL_V(p_values[0]); } -void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, const GLTFAnimationIndex index, const float bake_fps, const bool trimming) { - Ref<GLTFAnimation> anim = state->animations[index]; +void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, const GLTFAnimationIndex p_index, const float p_bake_fps, const bool p_trimming) { + Ref<GLTFAnimation> anim = p_state->animations[p_index]; String anim_name = anim->get_name(); if (anim_name.is_empty()) { // No node represent these, and they are not in the hierarchy, so just make a unique name - anim_name = _gen_unique_name(state, "Animation"); + anim_name = _gen_unique_name(p_state, "Animation"); } Ref<Animation> animation; @@ -5877,7 +5869,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, animation->set_loop_mode(Animation::LOOP_LINEAR); } - double anim_start = trimming ? INFINITY : 0.0; + double anim_start = p_trimming ? INFINITY : 0.0; double anim_end = 0.0; for (const KeyValue<int, GLTFAnimation::Track> &track_i : anim->get_tracks()) { @@ -5889,26 +5881,26 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, GLTFNodeIndex node_index = track_i.key; - const Ref<GLTFNode> gltf_node = state->nodes[track_i.key]; + const Ref<GLTFNode> gltf_node = p_state->nodes[track_i.key]; - Node *root = ap->get_parent(); + Node *root = p_animation_player->get_parent(); ERR_FAIL_COND(root == nullptr); - HashMap<GLTFNodeIndex, Node *>::Iterator node_element = state->scene_nodes.find(node_index); + HashMap<GLTFNodeIndex, Node *>::Iterator node_element = p_state->scene_nodes.find(node_index); ERR_CONTINUE_MSG(!node_element, vformat("Unable to find node %d for animation", node_index)); node_path = root->get_path_to(node_element->value); if (gltf_node->skeleton >= 0) { - const Skeleton3D *sk = state->skeletons[gltf_node->skeleton]->godot_skeleton; + const Skeleton3D *sk = p_state->skeletons[gltf_node->skeleton]->godot_skeleton; ERR_FAIL_COND(sk == nullptr); - const String path = ap->get_parent()->get_path_to(sk); + const String path = p_animation_player->get_parent()->get_path_to(sk); const String bone = gltf_node->get_name(); transform_node_path = path + ":" + bone; } else { transform_node_path = node_path; } - if (trimming) { + if (p_trimming) { for (int i = 0; i < track.rotation_track.times.size(); i++) { anim_start = MIN(anim_start, track.rotation_track.times[i]); anim_end = MAX(anim_end, track.rotation_track.times[i]); @@ -5955,7 +5947,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, int scale_idx = -1; if (track.position_track.values.size()) { - Vector3 base_pos = state->nodes[track_i.key]->position; + Vector3 base_pos = p_state->nodes[track_i.key]->position; bool not_default = false; //discard the track if all it contains is default values for (int i = 0; i < track.position_track.times.size(); i++) { Vector3 value = track.position_track.values[track.position_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i]; @@ -5974,7 +5966,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } } if (track.rotation_track.values.size()) { - Quaternion base_rot = state->nodes[track_i.key]->rotation.normalized(); + Quaternion base_rot = p_state->nodes[track_i.key]->rotation.normalized(); bool not_default = false; //discard the track if all it contains is default values for (int i = 0; i < track.rotation_track.times.size(); i++) { Quaternion value = track.rotation_track.values[track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i].normalized(); @@ -5992,7 +5984,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } } if (track.scale_track.values.size()) { - Vector3 base_scale = state->nodes[track_i.key]->scale; + Vector3 base_scale = p_state->nodes[track_i.key]->scale; bool not_default = false; //discard the track if all it contains is default values for (int i = 0; i < track.scale_track.times.size(); i++) { Vector3 value = track.scale_track.values[track.scale_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i]; @@ -6010,7 +6002,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } } - const double increment = 1.0 / bake_fps; + const double increment = 1.0 / p_bake_fps; double time = anim_start; Vector3 base_pos; @@ -6018,15 +6010,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, Vector3 base_scale = Vector3(1, 1, 1); if (rotation_idx == -1) { - base_rot = state->nodes[track_i.key]->rotation.normalized(); + base_rot = p_state->nodes[track_i.key]->rotation.normalized(); } if (position_idx == -1) { - base_pos = state->nodes[track_i.key]->position; + base_pos = p_state->nodes[track_i.key]->position; } if (scale_idx == -1) { - base_scale = state->nodes[track_i.key]->scale; + base_scale = p_state->nodes[track_i.key]->scale; } bool last = false; @@ -6062,8 +6054,8 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } for (int i = 0; i < track.weight_tracks.size(); i++) { - ERR_CONTINUE(gltf_node->mesh < 0 || gltf_node->mesh >= state->meshes.size()); - Ref<GLTFMesh> mesh = state->meshes[gltf_node->mesh]; + ERR_CONTINUE(gltf_node->mesh < 0 || gltf_node->mesh >= p_state->meshes.size()); + Ref<GLTFMesh> mesh = p_state->meshes[gltf_node->mesh]; ERR_CONTINUE(mesh.is_null()); ERR_CONTINUE(mesh->get_mesh().is_null()); ERR_CONTINUE(mesh->get_mesh()->get_mesh().is_null()); @@ -6086,7 +6078,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, } } else { // CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies. - const double increment = 1.0 / bake_fps; + const double increment = 1.0 / p_bake_fps; double time = 0.0; bool last = false; while (true) { @@ -6108,23 +6100,23 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap, animation->set_length(anim_end - anim_start); Ref<AnimationLibrary> library; - if (!ap->has_animation_library("")) { + if (!p_animation_player->has_animation_library("")) { library.instantiate(); - ap->add_animation_library("", library); + p_animation_player->add_animation_library("", library); } else { - library = ap->get_animation_library(""); + library = p_animation_player->get_animation_library(""); } library->add_animation(anim_name, animation); } -void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { - for (GLTFNodeIndex mi_node_i = 0; mi_node_i < state->nodes.size(); ++mi_node_i) { - Ref<GLTFNode> node = state->nodes[mi_node_i]; +void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> p_state) { + for (GLTFNodeIndex mi_node_i = 0; mi_node_i < p_state->nodes.size(); ++mi_node_i) { + Ref<GLTFNode> node = p_state->nodes[mi_node_i]; if (node->mesh < 0) { continue; } - HashMap<GLTFNodeIndex, Node *>::Iterator mi_element = state->scene_nodes.find(mi_node_i); + HashMap<GLTFNodeIndex, Node *>::Iterator mi_element = p_state->scene_nodes.find(mi_node_i); if (!mi_element) { continue; } @@ -6155,10 +6147,10 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { if (skel_node != nullptr) { godot_skeleton = cast_to<Skeleton3D>(skel_node); } - if (godot_skeleton != nullptr && state->skeleton3d_to_gltf_skeleton.has(godot_skeleton->get_instance_id())) { + if (godot_skeleton != nullptr && p_state->skeleton3d_to_gltf_skeleton.has(godot_skeleton->get_instance_id())) { // This is a skinned mesh. If the mesh has no ARRAY_WEIGHTS or ARRAY_BONES, it will be invisible. - const GLTFSkeletonIndex skeleton_gltf_i = state->skeleton3d_to_gltf_skeleton[godot_skeleton->get_instance_id()]; - Ref<GLTFSkeleton> gltf_skeleton = state->skeletons[skeleton_gltf_i]; + const GLTFSkeletonIndex skeleton_gltf_i = p_state->skeleton3d_to_gltf_skeleton[godot_skeleton->get_instance_id()]; + Ref<GLTFSkeleton> gltf_skeleton = p_state->skeletons[skeleton_gltf_i]; int bone_cnt = skeleton->get_bone_count(); ERR_FAIL_COND(bone_cnt != gltf_skeleton->joints.size()); @@ -6172,8 +6164,8 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { if (!gltf_skeleton->roots.is_empty()) { root_gltf_i = gltf_skeleton->roots[0]; } - if (state->skin_and_skeleton3d_to_gltf_skin.has(gltf_skin_key) && state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key].has(gltf_skel_key)) { - skin_gltf_i = state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key]; + if (p_state->skin_and_skeleton3d_to_gltf_skin.has(gltf_skin_key) && p_state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key].has(gltf_skel_key)) { + skin_gltf_i = p_state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key]; } else { if (skin.is_null()) { // Note that gltf_skin_key should remain null, so these can share a reference. @@ -6210,9 +6202,9 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { gltf_skin->joint_i_to_bone_i[bind_i] = bone_i; gltf_skin->joint_i_to_name[bind_i] = bind_name; } - skin_gltf_i = state->skins.size(); - state->skins.push_back(gltf_skin); - state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key] = skin_gltf_i; + skin_gltf_i = p_state->skins.size(); + p_state->skins.push_back(gltf_skin); + p_state->skin_and_skeleton3d_to_gltf_skin[gltf_skin_key][gltf_skel_key] = skin_gltf_i; } node->skin = skin_gltf_i; node->skeleton = skeleton_gltf_i; @@ -6220,14 +6212,14 @@ void GLTFDocument::_convert_mesh_instances(Ref<GLTFState> state) { } } -float GLTFDocument::solve_metallic(float p_dielectric_specular, float diffuse, float specular, float p_one_minus_specular_strength) { - if (specular <= p_dielectric_specular) { +float GLTFDocument::solve_metallic(float p_dielectric_specular, float p_diffuse, float p_specular, float p_one_minus_specular_strength) { + if (p_specular <= p_dielectric_specular) { return 0.0f; } const float a = p_dielectric_specular; - const float b = diffuse * p_one_minus_specular_strength / (1.0f - p_dielectric_specular) + specular - 2.0f * p_dielectric_specular; - const float c = p_dielectric_specular - specular; + const float b = p_diffuse * p_one_minus_specular_strength / (1.0f - p_dielectric_specular) + p_specular - 2.0f * p_dielectric_specular; + const float c = p_dielectric_specular - p_specular; const float D = b * b - 4.0f * a * c; return CLAMP((-b + Math::sqrt(D)) / (2.0f * a), 0.0f, 1.0f); } @@ -6251,21 +6243,21 @@ float GLTFDocument::get_max_component(const Color &p_color) { return MAX(MAX(r, g), b); } -void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_root) { - for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); ++node_i) { - Ref<GLTFNode> node = state->nodes[node_i]; +void GLTFDocument::_process_mesh_instances(Ref<GLTFState> p_state, Node *p_scene_root) { + for (GLTFNodeIndex node_i = 0; node_i < p_state->nodes.size(); ++node_i) { + Ref<GLTFNode> node = p_state->nodes[node_i]; if (node->skin >= 0 && node->mesh >= 0) { const GLTFSkinIndex skin_i = node->skin; - HashMap<GLTFNodeIndex, Node *>::Iterator mi_element = state->scene_nodes.find(node_i); + HashMap<GLTFNodeIndex, Node *>::Iterator mi_element = p_state->scene_nodes.find(node_i); ERR_CONTINUE_MSG(!mi_element, vformat("Unable to find node %d", node_i)); ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(mi_element->value); ERR_CONTINUE_MSG(mi == nullptr, vformat("Unable to cast node %d of type %s to ImporterMeshInstance3D", node_i, mi_element->value->get_class_name())); - const GLTFSkeletonIndex skel_i = state->skins.write[node->skin]->skeleton; - Ref<GLTFSkeleton> gltf_skeleton = state->skeletons.write[skel_i]; + const GLTFSkeletonIndex skel_i = p_state->skins.write[node->skin]->skeleton; + Ref<GLTFSkeleton> gltf_skeleton = p_state->skeletons.write[skel_i]; Skeleton3D *skeleton = gltf_skeleton->godot_skeleton; ERR_CONTINUE_MSG(skeleton == nullptr, vformat("Unable to find Skeleton for node %d skin %d", node_i, skin_i)); @@ -6273,14 +6265,14 @@ void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_roo skeleton->add_child(mi, true); mi->set_owner(skeleton->get_owner()); - mi->set_skin(state->skins.write[skin_i]->godot_skin); + mi->set_skin(p_state->skins.write[skin_i]->godot_skin); mi->set_skeleton_path(mi->get_path_to(skeleton)); mi->set_transform(Transform3D()); } } } -GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i) { +GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i) { Animation::InterpolationType interpolation = p_animation->track_get_interpolation_type(p_track_i); GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR; @@ -6426,11 +6418,11 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state return p_track; } -void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, String p_animation_track_name) { - Ref<Animation> animation = ap->get_animation(p_animation_track_name); +void GLTFDocument::_convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, String p_animation_track_name) { + Ref<Animation> animation = p_animation_player->get_animation(p_animation_track_name); Ref<GLTFAnimation> gltf_animation; gltf_animation.instantiate(); - gltf_animation->set_name(_gen_unique_name(state, p_animation_track_name)); + gltf_animation->set_name(_gen_unique_name(p_state, p_animation_track_name)); for (int32_t track_i = 0; track_i < animation->get_track_count(); track_i++) { if (!animation->track_is_enabled(track_i)) { @@ -6440,8 +6432,8 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (String(orig_track_path).contains(":position")) { const Vector<String> node_suffix = String(orig_track_path).split(":position"); const NodePath path = node_suffix[0]; - const Node *node = ap->get_parent()->get_node_or_null(path); - for (const KeyValue<GLTFNodeIndex, Node *> &position_scene_node_i : state->scene_nodes) { + const Node *node = p_animation_player->get_parent()->get_node_or_null(path); + for (const KeyValue<GLTFNodeIndex, Node *> &position_scene_node_i : p_state->scene_nodes) { if (position_scene_node_i.value == node) { GLTFNodeIndex node_index = position_scene_node_i.key; HashMap<int, GLTFAnimation::Track>::Iterator position_track_i = gltf_animation->get_tracks().find(node_index); @@ -6449,15 +6441,15 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (position_track_i) { track = position_track_i->value; } - track = _convert_animation_track(state, track, animation, track_i, node_index); + track = _convert_animation_track(p_state, track, animation, track_i, node_index); gltf_animation->get_tracks().insert(node_index, track); } } } else if (String(orig_track_path).contains(":rotation_degrees")) { const Vector<String> node_suffix = String(orig_track_path).split(":rotation_degrees"); const NodePath path = node_suffix[0]; - const Node *node = ap->get_parent()->get_node_or_null(path); - for (const KeyValue<GLTFNodeIndex, Node *> &rotation_degree_scene_node_i : state->scene_nodes) { + const Node *node = p_animation_player->get_parent()->get_node_or_null(path); + for (const KeyValue<GLTFNodeIndex, Node *> &rotation_degree_scene_node_i : p_state->scene_nodes) { if (rotation_degree_scene_node_i.value == node) { GLTFNodeIndex node_index = rotation_degree_scene_node_i.key; HashMap<int, GLTFAnimation::Track>::Iterator rotation_degree_track_i = gltf_animation->get_tracks().find(node_index); @@ -6465,15 +6457,15 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (rotation_degree_track_i) { track = rotation_degree_track_i->value; } - track = _convert_animation_track(state, track, animation, track_i, node_index); + track = _convert_animation_track(p_state, track, animation, track_i, node_index); gltf_animation->get_tracks().insert(node_index, track); } } } else if (String(orig_track_path).contains(":scale")) { const Vector<String> node_suffix = String(orig_track_path).split(":scale"); const NodePath path = node_suffix[0]; - const Node *node = ap->get_parent()->get_node_or_null(path); - for (const KeyValue<GLTFNodeIndex, Node *> &scale_scene_node_i : state->scene_nodes) { + const Node *node = p_animation_player->get_parent()->get_node_or_null(path); + for (const KeyValue<GLTFNodeIndex, Node *> &scale_scene_node_i : p_state->scene_nodes) { if (scale_scene_node_i.value == node) { GLTFNodeIndex node_index = scale_scene_node_i.key; HashMap<int, GLTFAnimation::Track>::Iterator scale_track_i = gltf_animation->get_tracks().find(node_index); @@ -6481,18 +6473,18 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (scale_track_i) { track = scale_track_i->value; } - track = _convert_animation_track(state, track, animation, track_i, node_index); + track = _convert_animation_track(p_state, track, animation, track_i, node_index); gltf_animation->get_tracks().insert(node_index, track); } } } else if (String(orig_track_path).contains(":transform")) { const Vector<String> node_suffix = String(orig_track_path).split(":transform"); const NodePath path = node_suffix[0]; - const Node *node = ap->get_parent()->get_node_or_null(path); - for (const KeyValue<GLTFNodeIndex, Node *> &transform_track_i : state->scene_nodes) { + const Node *node = p_animation_player->get_parent()->get_node_or_null(path); + for (const KeyValue<GLTFNodeIndex, Node *> &transform_track_i : p_state->scene_nodes) { if (transform_track_i.value == node) { GLTFAnimation::Track track; - track = _convert_animation_track(state, track, animation, track_i, transform_track_i.key); + track = _convert_animation_track(p_state, track, animation, track_i, transform_track_i.key); gltf_animation->get_tracks().insert(transform_track_i.key, track); } } @@ -6500,12 +6492,12 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const Vector<String> node_suffix = String(orig_track_path).split(":"); const NodePath path = node_suffix[0]; const String suffix = node_suffix[1]; - Node *node = ap->get_parent()->get_node_or_null(path); + Node *node = p_animation_player->get_parent()->get_node_or_null(path); MeshInstance3D *mi = cast_to<MeshInstance3D>(node); Ref<Mesh> mesh = mi->get_mesh(); ERR_CONTINUE(mesh.is_null()); int32_t mesh_index = -1; - for (const KeyValue<GLTFNodeIndex, Node *> &mesh_track_i : state->scene_nodes) { + for (const KeyValue<GLTFNodeIndex, Node *> &mesh_track_i : p_state->scene_nodes) { if (mesh_track_i.value == node) { mesh_index = mesh_track_i.key; } @@ -6558,15 +6550,15 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, const String node = node_suffix[0]; const NodePath node_path = node; const String suffix = node_suffix[1]; - Node *godot_node = ap->get_parent()->get_node_or_null(node_path); + Node *godot_node = p_animation_player->get_parent()->get_node_or_null(node_path); Skeleton3D *skeleton = nullptr; GLTFSkeletonIndex skeleton_gltf_i = -1; - for (GLTFSkeletonIndex skeleton_i = 0; skeleton_i < state->skeletons.size(); skeleton_i++) { - if (state->skeletons[skeleton_i]->godot_skeleton == cast_to<Skeleton3D>(godot_node)) { - skeleton = state->skeletons[skeleton_i]->godot_skeleton; + for (GLTFSkeletonIndex skeleton_i = 0; skeleton_i < p_state->skeletons.size(); skeleton_i++) { + if (p_state->skeletons[skeleton_i]->godot_skeleton == cast_to<Skeleton3D>(godot_node)) { + skeleton = p_state->skeletons[skeleton_i]->godot_skeleton; skeleton_gltf_i = skeleton_i; ERR_CONTINUE(!skeleton); - Ref<GLTFSkeleton> skeleton_gltf = state->skeletons[skeleton_gltf_i]; + Ref<GLTFSkeleton> skeleton_gltf = p_state->skeletons[skeleton_gltf_i]; int32_t bone = skeleton->find_bone(suffix); ERR_CONTINUE(bone == -1); if (!skeleton_gltf->godot_bone_node.has(bone)) { @@ -6578,14 +6570,14 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (property_track_i) { track = property_track_i->value; } - track = _convert_animation_track(state, track, animation, track_i, node_i); + track = _convert_animation_track(p_state, track, animation, track_i, node_i); gltf_animation->get_tracks()[node_i] = track; } } } else if (!String(orig_track_path).contains(":")) { - ERR_CONTINUE(!ap->get_parent()); - Node *godot_node = ap->get_parent()->get_node_or_null(orig_track_path); - for (const KeyValue<GLTFNodeIndex, Node *> &scene_node_i : state->scene_nodes) { + ERR_CONTINUE(!p_animation_player->get_parent()); + Node *godot_node = p_animation_player->get_parent()->get_node_or_null(orig_track_path); + for (const KeyValue<GLTFNodeIndex, Node *> &scene_node_i : p_state->scene_nodes) { if (scene_node_i.value == godot_node) { GLTFNodeIndex node_i = scene_node_i.key; HashMap<int, GLTFAnimation::Track>::Iterator node_track_i = gltf_animation->get_tracks().find(node_i); @@ -6593,7 +6585,7 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, if (node_track_i) { track = node_track_i->value; } - track = _convert_animation_track(state, track, animation, track_i, node_i); + track = _convert_animation_track(p_state, track, animation, track_i, node_i); gltf_animation->get_tracks()[node_i] = track; break; } @@ -6601,42 +6593,42 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, } } if (gltf_animation->get_tracks().size()) { - state->animations.push_back(gltf_animation); + p_state->animations.push_back(gltf_animation); } } -Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> f) { +Error GLTFDocument::_parse(Ref<GLTFState> p_state, String p_path, Ref<FileAccess> p_file) { Error err; - if (f.is_null()) { + if (p_file.is_null()) { return FAILED; } - f->seek(0); - uint32_t magic = f->get_32(); + p_file->seek(0); + uint32_t magic = p_file->get_32(); if (magic == 0x46546C67) { //binary file //text file - f->seek(0); - err = _parse_glb(f, state); + p_file->seek(0); + err = _parse_glb(p_file, p_state); if (err != OK) { return err; } } else { - f->seek(0); - String text = f->get_as_utf8_string(); + p_file->seek(0); + String text = p_file->get_as_utf8_string(); JSON json; err = json.parse(text); if (err != OK) { _err_print_error("", "", json.get_error_line(), json.get_error_message().utf8().get_data(), false, ERR_HANDLER_SCRIPT); } ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); - state->json = json.get_data(); + p_state->json = json.get_data(); } - if (!state->json.has("asset")) { + if (!p_state->json.has("asset")) { return ERR_PARSE_ERROR; } - Dictionary asset = state->json["asset"]; + Dictionary asset = p_state->json["asset"]; if (!asset.has("version")) { return ERR_PARSE_ERROR; @@ -6644,19 +6636,19 @@ Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> String version = asset["version"]; - state->major_version = version.get_slice(".", 0).to_int(); - state->minor_version = version.get_slice(".", 1).to_int(); + p_state->major_version = version.get_slice(".", 0).to_int(); + p_state->minor_version = version.get_slice(".", 1).to_int(); document_extensions.clear(); for (Ref<GLTFDocumentExtension> ext : all_document_extensions) { ERR_CONTINUE(ext.is_null()); - err = ext->import_preflight(state, state->json["extensionsUsed"]); + err = ext->import_preflight(p_state, p_state->json["extensionsUsed"]); if (err == OK) { document_extensions.push_back(ext); } } - err = _parse_gltf_state(state, p_path); + err = _parse_gltf_state(p_state, p_path); ERR_FAIL_COND_V(err != OK, err); return OK; @@ -6702,30 +6694,30 @@ Dictionary GLTFDocument::_serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_ return _serialize_texture_transform_uv(Vector2(offset.x, offset.y), Vector2(scale.x, scale.y)); } -Error GLTFDocument::_serialize_version(Ref<GLTFState> state) { +Error GLTFDocument::_serialize_version(Ref<GLTFState> p_state) { const String version = "2.0"; - state->major_version = version.get_slice(".", 0).to_int(); - state->minor_version = version.get_slice(".", 1).to_int(); + p_state->major_version = version.get_slice(".", 0).to_int(); + p_state->minor_version = version.get_slice(".", 1).to_int(); Dictionary asset; asset["version"] = version; String hash = String(VERSION_HASH); asset["generator"] = String(VERSION_FULL_NAME) + String("@") + (hash.is_empty() ? String("unknown") : hash); - state->json["asset"] = asset; + p_state->json["asset"] = asset; ERR_FAIL_COND_V(!asset.has("version"), Error::FAILED); - ERR_FAIL_COND_V(!state->json.has("asset"), Error::FAILED); + ERR_FAIL_COND_V(!p_state->json.has("asset"), Error::FAILED); return OK; } -Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) { +Error GLTFDocument::_serialize_file(Ref<GLTFState> p_state, const String p_path) { Error err = FAILED; if (p_path.to_lower().ends_with("glb")) { - err = _encode_buffer_glb(state, p_path); + err = _encode_buffer_glb(p_state, p_path); ERR_FAIL_COND_V(err != OK, err); - Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(f.is_null(), FAILED); + Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err); + ERR_FAIL_COND_V(file.is_null(), FAILED); - String json = Variant(state->json).to_json_string(); + String json = Variant(p_state->json).to_json_string(); const uint32_t magic = 0x46546C67; // GLTF const int32_t header_size = 12; @@ -6736,39 +6728,39 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) { const uint32_t text_chunk_type = 0x4E4F534A; //JSON uint32_t binary_data_length = 0; - if (state->buffers.size()) { - binary_data_length = state->buffers[0].size(); + if (p_state->buffers.size()) { + binary_data_length = p_state->buffers[0].size(); } const uint32_t binary_chunk_length = ((binary_data_length + 3) & (~3)); const uint32_t binary_chunk_type = 0x004E4942; //BIN - f->create(FileAccess::ACCESS_RESOURCES); - f->store_32(magic); - f->store_32(state->major_version); // version - f->store_32(header_size + chunk_header_size + text_chunk_length + chunk_header_size + binary_chunk_length); // length - f->store_32(text_chunk_length); - f->store_32(text_chunk_type); - f->store_buffer((uint8_t *)&cs[0], cs.length()); + file->create(FileAccess::ACCESS_RESOURCES); + file->store_32(magic); + file->store_32(p_state->major_version); // version + file->store_32(header_size + chunk_header_size + text_chunk_length + chunk_header_size + binary_chunk_length); // length + file->store_32(text_chunk_length); + file->store_32(text_chunk_type); + file->store_buffer((uint8_t *)&cs[0], cs.length()); for (uint32_t pad_i = text_data_length; pad_i < text_chunk_length; pad_i++) { - f->store_8(' '); + file->store_8(' '); } if (binary_chunk_length) { - f->store_32(binary_chunk_length); - f->store_32(binary_chunk_type); - f->store_buffer(state->buffers[0].ptr(), binary_data_length); + file->store_32(binary_chunk_length); + file->store_32(binary_chunk_type); + file->store_buffer(p_state->buffers[0].ptr(), binary_data_length); } for (uint32_t pad_i = binary_data_length; pad_i < binary_chunk_length; pad_i++) { - f->store_8(0); + file->store_8(0); } } else { - err = _encode_buffer_bins(state, p_path); + err = _encode_buffer_bins(p_state, p_path); ERR_FAIL_COND_V(err != OK, err); - Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(f.is_null(), FAILED); + Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err); + ERR_FAIL_COND_V(file.is_null(), FAILED); - f->create(FileAccess::ACCESS_RESOURCES); - String json = Variant(state->json).to_json_string(); - f->store_string(json); + file->create(FileAccess::ACCESS_RESOURCES); + String json = Variant(p_state->json).to_json_string(); + file->store_string(json); } return err; } @@ -6793,16 +6785,16 @@ void GLTFDocument::_bind_methods() { &GLTFDocument::unregister_gltf_document_extension); } -void GLTFDocument::_build_parent_hierachy(Ref<GLTFState> state) { +void GLTFDocument::_build_parent_hierachy(Ref<GLTFState> p_state) { // build the hierarchy - for (GLTFNodeIndex node_i = 0; node_i < state->nodes.size(); node_i++) { - for (int j = 0; j < state->nodes[node_i]->children.size(); j++) { - GLTFNodeIndex child_i = state->nodes[node_i]->children[j]; - ERR_FAIL_INDEX(child_i, state->nodes.size()); - if (state->nodes.write[child_i]->parent != -1) { + for (GLTFNodeIndex node_i = 0; node_i < p_state->nodes.size(); node_i++) { + for (int j = 0; j < p_state->nodes[node_i]->children.size(); j++) { + GLTFNodeIndex child_i = p_state->nodes[node_i]->children[j]; + ERR_FAIL_INDEX(child_i, p_state->nodes.size()); + if (p_state->nodes.write[child_i]->parent != -1) { continue; } - state->nodes.write[child_i]->parent = node_i; + p_state->nodes.write[child_i]->parent = node_i; } } } @@ -6827,13 +6819,13 @@ void GLTFDocument::unregister_all_gltf_document_extensions() { all_document_extensions.clear(); } -PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error *r_err) { - Error err = _encode_buffer_glb(state, ""); +PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> p_state, Error *r_err) { + Error err = _encode_buffer_glb(p_state, ""); if (r_err) { *r_err = err; } ERR_FAIL_COND_V(err != OK, PackedByteArray()); - String json = Variant(state->json).to_json_string(); + String json = Variant(p_state->json).to_json_string(); const uint32_t magic = 0x46546C67; // GLTF const int32_t header_size = 12; @@ -6847,8 +6839,8 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error const uint32_t text_chunk_type = 0x4E4F534A; //JSON int32_t binary_data_length = 0; - if (state->buffers.size()) { - binary_data_length = state->buffers[0].size(); + if (p_state->buffers.size()) { + binary_data_length = p_state->buffers[0].size(); } const int32_t binary_chunk_length = binary_data_length; const int32_t binary_chunk_type = 0x004E4942; //BIN @@ -6856,7 +6848,7 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error Ref<StreamPeerBuffer> buffer; buffer.instantiate(); buffer->put_32(magic); - buffer->put_32(state->major_version); // version + buffer->put_32(p_state->major_version); // version buffer->put_32(header_size + chunk_header_size + text_chunk_length + chunk_header_size + binary_data_length); // length buffer->put_32(text_chunk_length); buffer->put_32(text_chunk_type); @@ -6864,204 +6856,204 @@ PackedByteArray GLTFDocument::_serialize_glb_buffer(Ref<GLTFState> state, Error if (binary_chunk_length) { buffer->put_32(binary_chunk_length); buffer->put_32(binary_chunk_type); - buffer->put_data(state->buffers[0].ptr(), binary_data_length); + buffer->put_data(p_state->buffers[0].ptr(), binary_data_length); } return buffer->get_data_array(); } -PackedByteArray GLTFDocument::generate_buffer(Ref<GLTFState> state) { - ERR_FAIL_NULL_V(state, PackedByteArray()); - Error err = _serialize(state, ""); +PackedByteArray GLTFDocument::generate_buffer(Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_state, PackedByteArray()); + Error err = _serialize(p_state, ""); ERR_FAIL_COND_V(err != OK, PackedByteArray()); - PackedByteArray bytes = _serialize_glb_buffer(state, &err); + PackedByteArray bytes = _serialize_glb_buffer(p_state, &err); return bytes; } -Error GLTFDocument::write_to_filesystem(Ref<GLTFState> state, const String &p_path) { - ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER); - Error err = _serialize(state, p_path); +Error GLTFDocument::write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) { + ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); + Error err = _serialize(p_state, p_path); if (err != OK) { return err; } - err = _serialize_file(state, p_path); + err = _serialize_file(p_state, p_path); if (err != OK) { return Error::FAILED; } return OK; } -Node *GLTFDocument::generate_scene(Ref<GLTFState> state, float p_bake_fps, bool p_trimming) { - ERR_FAIL_NULL_V(state, nullptr); - ERR_FAIL_INDEX_V(0, state->root_nodes.size(), nullptr); +Node *GLTFDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool p_trimming) { + ERR_FAIL_NULL_V(p_state, nullptr); + ERR_FAIL_INDEX_V(0, p_state->root_nodes.size(), nullptr); Error err = OK; - GLTFNodeIndex gltf_root = state->root_nodes.write[0]; - Node *gltf_root_node = state->get_scene_node(gltf_root); + GLTFNodeIndex gltf_root = p_state->root_nodes.write[0]; + Node *gltf_root_node = p_state->get_scene_node(gltf_root); Node *root = gltf_root_node->get_parent(); ERR_FAIL_NULL_V(root, nullptr); - _process_mesh_instances(state, root); - if (state->get_create_animations() && state->animations.size()) { + _process_mesh_instances(p_state, root); + if (p_state->get_create_animations() && p_state->animations.size()) { AnimationPlayer *ap = memnew(AnimationPlayer); root->add_child(ap, true); ap->set_owner(root); - for (int i = 0; i < state->animations.size(); i++) { - _import_animation(state, ap, i, p_bake_fps, p_trimming); + for (int i = 0; i < p_state->animations.size(); i++) { + _import_animation(p_state, ap, i, p_bake_fps, p_trimming); } } - for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) { + for (KeyValue<GLTFNodeIndex, Node *> E : p_state->scene_nodes) { ERR_CONTINUE(!E.value); for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - ERR_CONTINUE(!state->json.has("nodes")); - Array nodes = state->json["nodes"]; + ERR_CONTINUE(!p_state->json.has("nodes")); + Array nodes = p_state->json["nodes"]; ERR_CONTINUE(E.key >= nodes.size()); ERR_CONTINUE(E.key < 0); Dictionary node_json = nodes[E.key]; - Ref<GLTFNode> gltf_node = state->nodes[E.key]; - err = ext->import_node(state, gltf_node, node_json, E.value); + Ref<GLTFNode> gltf_node = p_state->nodes[E.key]; + err = ext->import_node(p_state, gltf_node, node_json, E.value); ERR_CONTINUE(err != OK); } } for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - err = ext->import_post(state, root); + err = ext->import_post(p_state, root); ERR_CONTINUE(err != OK); } ERR_FAIL_NULL_V(root, nullptr); return root; } -Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> state, uint32_t p_flags) { - ERR_FAIL_COND_V(state.is_null(), FAILED); - state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; - state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; +Error GLTFDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags) { + ERR_FAIL_COND_V(p_state.is_null(), FAILED); + p_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; + p_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; document_extensions.clear(); for (Ref<GLTFDocumentExtension> ext : all_document_extensions) { ERR_CONTINUE(ext.is_null()); - Error err = ext->export_preflight(p_node); + Error err = ext->export_preflight(p_state, p_node); if (err == OK) { document_extensions.push_back(ext); } } - _convert_scene_node(state, p_node, -1, -1); - if (!state->buffers.size()) { - state->buffers.push_back(Vector<uint8_t>()); + _convert_scene_node(p_state, p_node, -1, -1); + if (!p_state->buffers.size()) { + p_state->buffers.push_back(Vector<uint8_t>()); } return OK; } -Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> state, uint32_t p_flags) { - ERR_FAIL_COND_V(state.is_null(), FAILED); +Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags) { + ERR_FAIL_COND_V(p_state.is_null(), FAILED); // TODO Add missing texture and missing .bin file paths to r_missing_deps 2021-09-10 fire Error err = FAILED; - state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; - state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; + p_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; + p_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; Ref<FileAccessMemory> file_access; file_access.instantiate(); file_access->open_custom(p_bytes.ptr(), p_bytes.size()); - state->base_path = p_base_path.get_base_dir(); - err = _parse(state, state->base_path, file_access); + p_state->base_path = p_base_path.get_base_dir(); + err = _parse(p_state, p_state->base_path, file_access); ERR_FAIL_COND_V(err != OK, err); for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); - err = ext->import_post_parse(state); + err = ext->import_post_parse(p_state); ERR_FAIL_COND_V(err != OK, err); } return OK; } -Error GLTFDocument::_parse_gltf_state(Ref<GLTFState> state, const String &p_search_path) { +Error GLTFDocument::_parse_gltf_state(Ref<GLTFState> p_state, const String &p_search_path) { Error err; /* PARSE EXTENSIONS */ - err = _parse_gltf_extensions(state); + err = _parse_gltf_extensions(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE SCENE */ - err = _parse_scenes(state); + err = _parse_scenes(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE NODES */ - err = _parse_nodes(state); + err = _parse_nodes(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE BUFFERS */ - err = _parse_buffers(state, p_search_path); + err = _parse_buffers(p_state, p_search_path); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE BUFFER VIEWS */ - err = _parse_buffer_views(state); + err = _parse_buffer_views(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE ACCESSORS */ - err = _parse_accessors(state); + err = _parse_accessors(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); - if (!state->discard_meshes_and_materials) { + if (!p_state->discard_meshes_and_materials) { /* PARSE IMAGES */ - err = _parse_images(state, p_search_path); + err = _parse_images(p_state, p_search_path); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE TEXTURE SAMPLERS */ - err = _parse_texture_samplers(state); + err = _parse_texture_samplers(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE TEXTURES */ - err = _parse_textures(state); + err = _parse_textures(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE TEXTURES */ - err = _parse_materials(state); + err = _parse_materials(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); } /* PARSE SKINS */ - err = _parse_skins(state); + err = _parse_skins(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* DETERMINE SKELETONS */ - err = _determine_skeletons(state); + err = _determine_skeletons(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* CREATE SKELETONS */ - err = _create_skeletons(state); + err = _create_skeletons(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* CREATE SKINS */ - err = _create_skins(state); + err = _create_skins(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE MESHES (we have enough info now) */ - err = _parse_meshes(state); + err = _parse_meshes(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE LIGHTS */ - err = _parse_lights(state); + err = _parse_lights(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE CAMERAS */ - err = _parse_cameras(state); + err = _parse_cameras(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* PARSE ANIMATIONS */ - err = _parse_animations(state); + err = _parse_animations(p_state); ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR); /* ASSIGN SCENE NAMES */ - _assign_scene_names(state); + _assign_scene_names(p_state); Node3D *root = memnew(Node3D); - for (int32_t root_i = 0; root_i < state->root_nodes.size(); root_i++) { - _generate_scene_node(state, root, root, state->root_nodes[root_i]); + for (int32_t root_i = 0; root_i < p_state->root_nodes.size(); root_i++) { + _generate_scene_node(p_state, root, root, p_state->root_nodes[root_i]); } return OK; @@ -7076,15 +7068,15 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> r_state, uint r_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; r_state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; Error err; - Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err); + Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ, &err); ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN); - ERR_FAIL_NULL_V(f, ERR_FILE_CANT_OPEN); + ERR_FAIL_NULL_V(file, ERR_FILE_CANT_OPEN); String base_path = p_base_path; if (base_path.is_empty()) { base_path = p_path.get_base_dir(); } r_state->base_path = base_path; - err = _parse(r_state, base_path, f); + err = _parse(r_state, base_path, file); ERR_FAIL_COND_V(err != OK, err); for (Ref<GLTFDocumentExtension> ext : document_extensions) { ERR_CONTINUE(ext.is_null()); @@ -7094,15 +7086,15 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> r_state, uint return OK; } -Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> state) { - ERR_FAIL_NULL_V(state, ERR_PARSE_ERROR); - if (state->json.has("extensionsUsed")) { - Vector<String> ext_array = state->json["extensionsUsed"]; - state->extensions_used = ext_array; +Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> p_state) { + ERR_FAIL_NULL_V(p_state, ERR_PARSE_ERROR); + if (p_state->json.has("extensionsUsed")) { + Vector<String> ext_array = p_state->json["extensionsUsed"]; + p_state->extensions_used = ext_array; } - if (state->json.has("extensionsRequired")) { - Vector<String> ext_array = state->json["extensionsRequired"]; - state->extensions_required = ext_array; + if (p_state->json.has("extensionsRequired")) { + Vector<String> ext_array = p_state->json["extensionsRequired"]; + p_state->extensions_required = ext_array; } HashSet<String> supported_extensions; supported_extensions.insert("KHR_lights_punctual"); @@ -7116,9 +7108,9 @@ Error GLTFDocument::_parse_gltf_extensions(Ref<GLTFState> state) { } } Error ret = Error::OK; - for (int i = 0; i < state->extensions_required.size(); i++) { - if (!supported_extensions.has(state->extensions_required[i])) { - ERR_PRINT("GLTF: Can't import file '" + state->filename + "', required extension '" + String(state->extensions_required[i]) + "' is not supported. Are you missing a GLTFDocumentExtension plugin?"); + for (int i = 0; i < p_state->extensions_required.size(); i++) { + if (!supported_extensions.has(p_state->extensions_required[i])) { + ERR_PRINT("GLTF: Can't import file '" + p_state->filename + "', required extension '" + String(p_state->extensions_required[i]) + "' is not supported. Are you missing a GLTFDocumentExtension plugin?"); ret = ERR_UNAVAILABLE; } } diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 6eb38354a2..6e2d0e2fd4 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -32,13 +32,6 @@ #define GLTF_DOCUMENT_H #include "extensions/gltf_document_extension.h" -#include "structures/gltf_animation.h" - -#include "scene/3d/bone_attachment_3d.h" -#include "scene/3d/importer_mesh_instance_3d.h" -#include "scene/3d/mesh_instance_3d.h" -#include "scene/animation/animation_player.h" -#include "scene/resources/material.h" #include "modules/modules_enabled.gen.h" // For csg, gridmap. @@ -81,199 +74,199 @@ public: static void unregister_all_gltf_document_extensions(); private: - void _build_parent_hierachy(Ref<GLTFState> state); + void _build_parent_hierachy(Ref<GLTFState> p_state); double _filter_number(double p_float); String _get_component_type_name(const uint32_t p_component); - int _get_component_type_size(const int component_type); - Error _parse_scenes(Ref<GLTFState> state); - Error _parse_nodes(Ref<GLTFState> state); + int _get_component_type_size(const int p_component_type); + Error _parse_scenes(Ref<GLTFState> p_state); + Error _parse_nodes(Ref<GLTFState> p_state); String _get_type_name(const GLTFType p_component); String _get_accessor_type_name(const GLTFType p_type); - String _gen_unique_name(Ref<GLTFState> state, const String &p_name); - String _sanitize_animation_name(const String &name); - String _gen_unique_animation_name(Ref<GLTFState> state, const String &p_name); - String _sanitize_bone_name(const String &name); - String _gen_unique_bone_name(Ref<GLTFState> state, - const GLTFSkeletonIndex skel_i, + String _gen_unique_name(Ref<GLTFState> p_state, const String &p_name); + String _sanitize_animation_name(const String &p_name); + String _gen_unique_animation_name(Ref<GLTFState> p_state, const String &p_name); + String _sanitize_bone_name(const String &p_name); + String _gen_unique_bone_name(Ref<GLTFState> p_state, + const GLTFSkeletonIndex p_skel_i, const String &p_name); - GLTFTextureIndex _set_texture(Ref<GLTFState> state, Ref<Texture2D> p_texture, + GLTFTextureIndex _set_texture(Ref<GLTFState> p_state, Ref<Texture2D> p_texture, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats); - Ref<Texture2D> _get_texture(Ref<GLTFState> state, + Ref<Texture2D> _get_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture); - GLTFTextureSamplerIndex _set_sampler_for_mode(Ref<GLTFState> state, + GLTFTextureSamplerIndex _set_sampler_for_mode(Ref<GLTFState> p_state, StandardMaterial3D::TextureFilter p_filter_mode, bool p_repeats); - Ref<GLTFTextureSampler> _get_sampler_for_texture(Ref<GLTFState> state, + Ref<GLTFTextureSampler> _get_sampler_for_texture(Ref<GLTFState> p_state, const GLTFTextureIndex p_texture); - Error _parse_json(const String &p_path, Ref<GLTFState> state); - Error _parse_glb(Ref<FileAccess> f, Ref<GLTFState> state); - void _compute_node_heights(Ref<GLTFState> state); - Error _parse_buffers(Ref<GLTFState> state, const String &p_base_path); - Error _parse_buffer_views(Ref<GLTFState> state); + Error _parse_json(const String &p_path, Ref<GLTFState> p_state); + Error _parse_glb(Ref<FileAccess> p_file, Ref<GLTFState> p_state); + void _compute_node_heights(Ref<GLTFState> p_state); + Error _parse_buffers(Ref<GLTFState> p_state, const String &p_base_path); + Error _parse_buffer_views(Ref<GLTFState> p_state); GLTFType _get_type_from_str(const String &p_string); - Error _parse_accessors(Ref<GLTFState> state); - Error _decode_buffer_view(Ref<GLTFState> state, double *dst, + Error _parse_accessors(Ref<GLTFState> p_state); + Error _decode_buffer_view(Ref<GLTFState> p_state, double *p_dst, const GLTFBufferViewIndex p_buffer_view, - const int skip_every, const int skip_bytes, - const int element_size, const int count, - const GLTFType type, const int component_count, - const int component_type, const int component_size, - const bool normalized, const int byte_offset, - const bool for_vertex); - Vector<double> _decode_accessor(Ref<GLTFState> state, + const int p_skip_every, const int p_skip_bytes, + const int p_element_size, const int p_count, + const GLTFType p_type, const int p_component_count, + const int p_component_type, const int p_component_size, + const bool p_normalized, const int p_byte_offset, + const bool p_for_vertex); + Vector<double> _decode_accessor(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<float> _decode_accessor_as_floats(Ref<GLTFState> state, + Vector<float> _decode_accessor_as_floats(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<int> _decode_accessor_as_ints(Ref<GLTFState> state, + Vector<int> _decode_accessor_as_ints(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> state, + Vector<Vector2> _decode_accessor_as_vec2(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> state, + Vector<Vector3> _decode_accessor_as_vec3(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Color> _decode_accessor_as_color(Ref<GLTFState> state, + Vector<Color> _decode_accessor_as_color(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Quaternion> _decode_accessor_as_quaternion(Ref<GLTFState> state, + Vector<Quaternion> _decode_accessor_as_quaternion(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> state, + Vector<Transform2D> _decode_accessor_as_xform2d(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> state, + Vector<Basis> _decode_accessor_as_basis(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Vector<Transform3D> _decode_accessor_as_xform(Ref<GLTFState> state, + Vector<Transform3D> _decode_accessor_as_xform(Ref<GLTFState> p_state, const GLTFAccessorIndex p_accessor, const bool p_for_vertex); - Error _parse_meshes(Ref<GLTFState> state); - Error _serialize_textures(Ref<GLTFState> state); - Error _serialize_texture_samplers(Ref<GLTFState> state); - Error _serialize_images(Ref<GLTFState> state, const String &p_path); - Error _serialize_lights(Ref<GLTFState> state); - Error _parse_images(Ref<GLTFState> state, const String &p_base_path); - Error _parse_textures(Ref<GLTFState> state); - Error _parse_texture_samplers(Ref<GLTFState> state); - Error _parse_materials(Ref<GLTFState> state); - void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> material); + Error _parse_meshes(Ref<GLTFState> p_state); + Error _serialize_textures(Ref<GLTFState> p_state); + Error _serialize_texture_samplers(Ref<GLTFState> p_state); + Error _serialize_images(Ref<GLTFState> p_state, const String &p_path); + Error _serialize_lights(Ref<GLTFState> p_state); + Error _parse_images(Ref<GLTFState> p_state, const String &p_base_path); + Error _parse_textures(Ref<GLTFState> p_state); + Error _parse_texture_samplers(Ref<GLTFState> p_state); + Error _parse_materials(Ref<GLTFState> p_state); + void _set_texture_transform_uv1(const Dictionary &d, Ref<BaseMaterial3D> p_material); void spec_gloss_to_rough_metal(Ref<GLTFSpecGloss> r_spec_gloss, Ref<BaseMaterial3D> p_material); static void spec_gloss_to_metal_base_color(const Color &p_specular_factor, const Color &p_diffuse, Color &r_base_color, float &r_metallic); - GLTFNodeIndex _find_highest_node(Ref<GLTFState> state, - const Vector<GLTFNodeIndex> &subset); - bool _capture_nodes_in_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin, - const GLTFNodeIndex node_index); - void _capture_nodes_for_multirooted_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin); - Error _expand_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin); - Error _verify_skin(Ref<GLTFState> state, Ref<GLTFSkin> skin); - Error _parse_skins(Ref<GLTFState> state); - Error _determine_skeletons(Ref<GLTFState> state); + GLTFNodeIndex _find_highest_node(Ref<GLTFState> p_state, + const Vector<GLTFNodeIndex> &p_subset); + bool _capture_nodes_in_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin, + const GLTFNodeIndex p_node_index); + void _capture_nodes_for_multirooted_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin); + Error _expand_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin); + Error _verify_skin(Ref<GLTFState> p_state, Ref<GLTFSkin> p_skin); + Error _parse_skins(Ref<GLTFState> p_state); + Error _determine_skeletons(Ref<GLTFState> p_state); Error _reparent_non_joint_skeleton_subtrees( - Ref<GLTFState> state, Ref<GLTFSkeleton> skeleton, - const Vector<GLTFNodeIndex> &non_joints); - Error _determine_skeleton_roots(Ref<GLTFState> state, - const GLTFSkeletonIndex skel_i); - Error _create_skeletons(Ref<GLTFState> state); - Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> state); - Error _serialize_skins(Ref<GLTFState> state); - Error _create_skins(Ref<GLTFState> state); - bool _skins_are_same(const Ref<Skin> skin_a, const Ref<Skin> skin_b); - void _remove_duplicate_skins(Ref<GLTFState> state); - Error _serialize_cameras(Ref<GLTFState> state); - Error _parse_cameras(Ref<GLTFState> state); - Error _parse_lights(Ref<GLTFState> state); - Error _parse_animations(Ref<GLTFState> state); - Error _serialize_animations(Ref<GLTFState> state); - BoneAttachment3D *_generate_bone_attachment(Ref<GLTFState> state, - Skeleton3D *skeleton, - const GLTFNodeIndex node_index, - const GLTFNodeIndex bone_index); - ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> state, const GLTFNodeIndex node_index); - Camera3D *_generate_camera(Ref<GLTFState> state, const GLTFNodeIndex node_index); - Light3D *_generate_light(Ref<GLTFState> state, const GLTFNodeIndex node_index); - Node3D *_generate_spatial(Ref<GLTFState> state, const GLTFNodeIndex node_index); - void _assign_scene_names(Ref<GLTFState> state); + Ref<GLTFState> p_state, Ref<GLTFSkeleton> p_skeleton, + const Vector<GLTFNodeIndex> &p_non_joints); + Error _determine_skeleton_roots(Ref<GLTFState> p_state, + const GLTFSkeletonIndex p_skel_i); + Error _create_skeletons(Ref<GLTFState> p_state); + Error _map_skin_joints_indices_to_skeleton_bone_indices(Ref<GLTFState> p_state); + Error _serialize_skins(Ref<GLTFState> p_state); + Error _create_skins(Ref<GLTFState> p_state); + bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b); + void _remove_duplicate_skins(Ref<GLTFState> p_state); + Error _serialize_cameras(Ref<GLTFState> p_state); + Error _parse_cameras(Ref<GLTFState> p_state); + Error _parse_lights(Ref<GLTFState> p_state); + Error _parse_animations(Ref<GLTFState> p_state); + Error _serialize_animations(Ref<GLTFState> p_state); + BoneAttachment3D *_generate_bone_attachment(Ref<GLTFState> p_state, + Skeleton3D *p_skeleton, + const GLTFNodeIndex p_node_index, + const GLTFNodeIndex p_bone_index); + ImporterMeshInstance3D *_generate_mesh_instance(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index); + Camera3D *_generate_camera(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index); + Light3D *_generate_light(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index); + Node3D *_generate_spatial(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index); + void _assign_scene_names(Ref<GLTFState> p_state); template <class T> T _interpolate_track(const Vector<real_t> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp); - GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_quaternions(Ref<GLTFState> p_state, const Vector<Quaternion> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_weights(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_joints(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_floats(Ref<GLTFState> p_state, const Vector<real_t> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_vec2(Ref<GLTFState> p_state, const Vector<Vector2> p_attribs, const bool p_for_vertex); - void _calc_accessor_vec2_min_max(int i, const int element_count, Vector<double> &type_max, Vector2 attribs, Vector<double> &type_min) { - if (i == 0) { - for (int32_t type_i = 0; type_i < element_count; type_i++) { - type_max.write[type_i] = attribs[(i * element_count) + type_i]; - type_min.write[type_i] = attribs[(i * element_count) + type_i]; + void _calc_accessor_vec2_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector2 p_attribs, Vector<double> &p_type_min) { + if (p_i == 0) { + for (int32_t type_i = 0; type_i < p_element_count; type_i++) { + p_type_max.write[type_i] = p_attribs[(p_i * p_element_count) + type_i]; + p_type_min.write[type_i] = p_attribs[(p_i * p_element_count) + type_i]; } } - for (int32_t type_i = 0; type_i < element_count; type_i++) { - type_max.write[type_i] = MAX(attribs[(i * element_count) + type_i], type_max[type_i]); - type_min.write[type_i] = MIN(attribs[(i * element_count) + type_i], type_min[type_i]); - type_max.write[type_i] = _filter_number(type_max.write[type_i]); - type_min.write[type_i] = _filter_number(type_min.write[type_i]); + for (int32_t type_i = 0; type_i < p_element_count; type_i++) { + p_type_max.write[type_i] = MAX(p_attribs[(p_i * p_element_count) + type_i], p_type_max[type_i]); + p_type_min.write[type_i] = MIN(p_attribs[(p_i * p_element_count) + type_i], p_type_min[type_i]); + p_type_max.write[type_i] = _filter_number(p_type_max.write[type_i]); + p_type_min.write[type_i] = _filter_number(p_type_min.write[type_i]); } } - GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_vec3(Ref<GLTFState> p_state, const Vector<Vector3> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_color(Ref<GLTFState> p_state, const Vector<Color> p_attribs, const bool p_for_vertex); void _calc_accessor_min_max(int p_i, const int p_element_count, Vector<double> &p_type_max, Vector<double> p_attribs, Vector<double> &p_type_min); - GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_ints(Ref<GLTFState> p_state, const Vector<int32_t> p_attribs, const bool p_for_vertex); - GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> state, + GLTFAccessorIndex _encode_accessor_as_xform(Ref<GLTFState> p_state, const Vector<Transform3D> p_attribs, const bool p_for_vertex); - Error _encode_buffer_view(Ref<GLTFState> state, const double *src, - const int count, const GLTFType type, - const int component_type, const bool normalized, - const int byte_offset, const bool for_vertex, + Error _encode_buffer_view(Ref<GLTFState> p_state, const double *p_src, + const int p_count, const GLTFType p_type, + const int p_component_type, const bool p_normalized, + const int p_byte_offset, const bool p_for_vertex, GLTFBufferViewIndex &r_accessor); - Error _encode_accessors(Ref<GLTFState> state); - Error _encode_buffer_views(Ref<GLTFState> state); - Error _serialize_materials(Ref<GLTFState> state); - Error _serialize_meshes(Ref<GLTFState> state); - Error _serialize_nodes(Ref<GLTFState> state); - Error _serialize_scenes(Ref<GLTFState> state); + Error _encode_accessors(Ref<GLTFState> p_state); + Error _encode_buffer_views(Ref<GLTFState> p_state); + Error _serialize_materials(Ref<GLTFState> p_state); + Error _serialize_meshes(Ref<GLTFState> p_state); + Error _serialize_nodes(Ref<GLTFState> p_state); + Error _serialize_scenes(Ref<GLTFState> p_state); String interpolation_to_string(const GLTFAnimation::Interpolation p_interp); - GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> state, + GLTFAnimation::Track _convert_animation_track(Ref<GLTFState> p_state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, int32_t p_track_i, GLTFNodeIndex p_node_i); - Error _encode_buffer_bins(Ref<GLTFState> state, const String &p_path); - Error _encode_buffer_glb(Ref<GLTFState> state, const String &p_path); - PackedByteArray _serialize_glb_buffer(Ref<GLTFState> state, Error *r_err); + Error _encode_buffer_bins(Ref<GLTFState> p_state, const String &p_path); + Error _encode_buffer_glb(Ref<GLTFState> p_state, const String &p_path); + PackedByteArray _serialize_glb_buffer(Ref<GLTFState> p_state, Error *r_err); Dictionary _serialize_texture_transform_uv1(Ref<BaseMaterial3D> p_material); Dictionary _serialize_texture_transform_uv2(Ref<BaseMaterial3D> p_material); - Error _serialize_version(Ref<GLTFState> state); - Error _serialize_file(Ref<GLTFState> state, const String p_path); - Error _serialize_gltf_extensions(Ref<GLTFState> state) const; + Error _serialize_version(Ref<GLTFState> p_state); + Error _serialize_file(Ref<GLTFState> p_state, const String p_path); + Error _serialize_gltf_extensions(Ref<GLTFState> p_state) const; public: // https://www.itu.int/rec/R-REC-BT.601 @@ -285,8 +278,8 @@ public: private: // https://github.com/microsoft/glTF-SDK/blob/master/GLTFSDK/Source/PBRUtils.cpp#L9 // https://bghgary.github.io/glTF/convert-between-workflows-bjs/js/babylon.pbrUtilities.js - static float solve_metallic(float p_dielectric_specular, float diffuse, - float specular, + static float solve_metallic(float p_dielectric_specular, float p_diffuse, + float p_specular, float p_one_minus_specular_strength); static float get_perceived_brightness(const Color p_color); static float get_max_component(const Color &p_color); @@ -297,78 +290,78 @@ public: Error append_from_scene(Node *p_node, Ref<GLTFState> r_state, uint32_t p_flags = 0); public: - Node *generate_scene(Ref<GLTFState> state, float p_bake_fps = 30.0f, bool p_trimming = false); - PackedByteArray generate_buffer(Ref<GLTFState> state); - Error write_to_filesystem(Ref<GLTFState> state, const String &p_path); + Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false); + PackedByteArray generate_buffer(Ref<GLTFState> p_state); + Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path); public: - Error _parse_gltf_state(Ref<GLTFState> state, const String &p_search_path); - Error _parse_gltf_extensions(Ref<GLTFState> state); - void _process_mesh_instances(Ref<GLTFState> state, Node *scene_root); - void _generate_scene_node(Ref<GLTFState> state, Node *scene_parent, - Node3D *scene_root, - const GLTFNodeIndex node_index); - void _generate_skeleton_bone_node(Ref<GLTFState> state, Node *scene_parent, Node3D *scene_root, const GLTFNodeIndex node_index); - void _import_animation(Ref<GLTFState> state, AnimationPlayer *ap, - const GLTFAnimationIndex index, const float bake_fps, const bool trimming); - void _convert_mesh_instances(Ref<GLTFState> state); - GLTFCameraIndex _convert_camera(Ref<GLTFState> state, Camera3D *p_camera); - void _convert_light_to_gltf(Light3D *light, Ref<GLTFState> state, Ref<GLTFNode> gltf_node); - GLTFLightIndex _convert_light(Ref<GLTFState> state, Light3D *p_light); - void _convert_spatial(Ref<GLTFState> state, Node3D *p_spatial, Ref<GLTFNode> p_node); - void _convert_scene_node(Ref<GLTFState> state, Node *p_current, + Error _parse_gltf_state(Ref<GLTFState> p_state, const String &p_search_path); + Error _parse_gltf_extensions(Ref<GLTFState> p_state); + void _process_mesh_instances(Ref<GLTFState> p_state, Node *p_scene_root); + void _generate_scene_node(Ref<GLTFState> p_state, Node *p_scene_parent, + Node3D *p_scene_root, + const GLTFNodeIndex p_node_index); + void _generate_skeleton_bone_node(Ref<GLTFState> p_state, Node *p_scene_parent, Node3D *p_scene_root, const GLTFNodeIndex p_node_index); + void _import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, + const GLTFAnimationIndex p_index, const float p_bake_fps, const bool p_trimming); + void _convert_mesh_instances(Ref<GLTFState> p_state); + GLTFCameraIndex _convert_camera(Ref<GLTFState> p_state, Camera3D *p_camera); + void _convert_light_to_gltf(Light3D *p_light, Ref<GLTFState> p_state, Ref<GLTFNode> p_gltf_node); + GLTFLightIndex _convert_light(Ref<GLTFState> p_state, Light3D *p_light); + void _convert_spatial(Ref<GLTFState> p_state, Node3D *p_spatial, Ref<GLTFNode> p_node); + void _convert_scene_node(Ref<GLTFState> p_state, Node *p_current, const GLTFNodeIndex p_gltf_current, const GLTFNodeIndex p_gltf_root); #ifdef MODULE_CSG_ENABLED - void _convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> gltf_node, Ref<GLTFState> state); + void _convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeIndex p_gltf_parent, Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state); #endif // MODULE_CSG_ENABLED - void _create_gltf_node(Ref<GLTFState> state, + void _create_gltf_node(Ref<GLTFState> p_state, Node *p_scene_parent, - GLTFNodeIndex current_node_i, + GLTFNodeIndex p_current_node_i, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_gltf_node, - Ref<GLTFNode> gltf_node); + Ref<GLTFNode> p_gltf_node); void _convert_animation_player_to_gltf( - AnimationPlayer *animation_player, Ref<GLTFState> state, + AnimationPlayer *p_animation_player, Ref<GLTFState> p_state, GLTFNodeIndex p_gltf_current, GLTFNodeIndex p_gltf_root_index, Ref<GLTFNode> p_gltf_node, Node *p_scene_parent); - void _check_visibility(Node *p_node, bool &retflag); - void _convert_camera_to_gltf(Camera3D *camera, Ref<GLTFState> state, - Ref<GLTFNode> gltf_node); + void _check_visibility(Node *p_node, bool &r_retflag); + void _convert_camera_to_gltf(Camera3D *p_camera, Ref<GLTFState> p_state, + Ref<GLTFNode> p_gltf_node); #ifdef MODULE_GRIDMAP_ENABLED void _convert_grid_map_to_gltf( GridMap *p_grid_map, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, - Ref<GLTFNode> gltf_node, Ref<GLTFState> state); + Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state); #endif // MODULE_GRIDMAP_ENABLED void _convert_multi_mesh_instance_to_gltf( MultiMeshInstance3D *p_multi_mesh_instance, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, - Ref<GLTFNode> gltf_node, Ref<GLTFState> state); + Ref<GLTFNode> p_gltf_node, Ref<GLTFState> p_state); void _convert_skeleton_to_gltf( - Skeleton3D *p_scene_parent, Ref<GLTFState> state, + Skeleton3D *p_scene_parent, Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, - Ref<GLTFNode> gltf_node); + Ref<GLTFNode> p_gltf_node); void _convert_bone_attachment_to_gltf(BoneAttachment3D *p_bone_attachment, - Ref<GLTFState> state, + Ref<GLTFState> p_state, GLTFNodeIndex p_parent_node_index, GLTFNodeIndex p_root_node_index, - Ref<GLTFNode> gltf_node); + Ref<GLTFNode> p_gltf_node); void _convert_mesh_instance_to_gltf(MeshInstance3D *p_mesh_instance, - Ref<GLTFState> state, - Ref<GLTFNode> gltf_node); - GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> state, + Ref<GLTFState> p_state, + Ref<GLTFNode> p_gltf_node); + GLTFMeshIndex _convert_mesh_to_gltf(Ref<GLTFState> p_state, MeshInstance3D *p_mesh_instance); - void _convert_animation(Ref<GLTFState> state, AnimationPlayer *ap, + void _convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, String p_animation_track_name); - Error _serialize(Ref<GLTFState> state, const String &p_path); - Error _parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> f); + Error _serialize(Ref<GLTFState> p_state, const String &p_path); + Error _parse(Ref<GLTFState> p_state, String p_path, Ref<FileAccess> p_file); }; #endif // GLTF_DOCUMENT_H diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp index 6654c9e5d2..9f6cb20935 100644 --- a/modules/gltf/gltf_state.cpp +++ b/modules/gltf/gltf_state.cpp @@ -30,6 +30,8 @@ #include "gltf_state.h" +#include "gltf_template_convert.h" + void GLTFState::_bind_methods() { ClassDB::bind_method(D_METHOD("add_used_extension", "extension_name", "required"), &GLTFState::add_used_extension); ClassDB::bind_method(D_METHOD("get_json"), &GLTFState::get_json); diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index 1c20520b22..e264da69e0 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -32,7 +32,6 @@ #define GLTF_STATE_H #include "extensions/gltf_light.h" -#include "gltf_template_convert.h" #include "structures/gltf_accessor.h" #include "structures/gltf_animation.h" #include "structures/gltf_buffer_view.h" @@ -44,10 +43,6 @@ #include "structures/gltf_texture.h" #include "structures/gltf_texture_sampler.h" -#include "core/templates/rb_map.h" -#include "scene/animation/animation_player.h" -#include "scene/resources/texture.h" - class GLTFState : public Resource { GDCLASS(GLTFState, Resource); friend class GLTFDocument; @@ -194,21 +189,6 @@ public: Variant get_additional_data(const StringName &p_extension_name); void set_additional_data(const StringName &p_extension_name, Variant p_additional_data); - - //void set_scene_nodes(RBMap<GLTFNodeIndex, Node *> p_scene_nodes) { - // this->scene_nodes = p_scene_nodes; - //} - - //void set_animation_players(Vector<AnimationPlayer *> p_animation_players) { - // this->animation_players = p_animation_players; - //} - - //RBMap<Ref<Material>, GLTFMaterialIndex> get_material_cache() { - // return this->material_cache; - //} - //void set_material_cache(RBMap<Ref<Material>, GLTFMaterialIndex> p_material_cache) { - // this->material_cache = p_material_cache; - //} }; #endif // GLTF_STATE_H diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index a7abf256ce..cd7a23fbb2 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -30,23 +30,9 @@ #include "register_types.h" -#ifndef _3D_DISABLED - #include "extensions/gltf_document_extension_convert_importer_mesh.h" -#include "extensions/gltf_light.h" #include "extensions/gltf_spec_gloss.h" #include "gltf_document.h" -#include "gltf_state.h" -#include "structures/gltf_accessor.h" -#include "structures/gltf_animation.h" -#include "structures/gltf_buffer_view.h" -#include "structures/gltf_camera.h" -#include "structures/gltf_mesh.h" -#include "structures/gltf_node.h" -#include "structures/gltf_skeleton.h" -#include "structures/gltf_skin.h" -#include "structures/gltf_texture.h" -#include "structures/gltf_texture_sampler.h" #ifdef TOOLS_ENABLED #include "core/config/project_settings.h" @@ -172,5 +158,3 @@ void uninitialize_gltf_module(ModuleInitializationLevel p_level) { } GLTFDocument::unregister_all_gltf_document_extensions(); } - -#endif // _3D_DISABLED diff --git a/modules/gltf/structures/gltf_accessor.h b/modules/gltf/structures/gltf_accessor.h index bfb71d57fe..8e4bb2d3f9 100644 --- a/modules/gltf/structures/gltf_accessor.h +++ b/modules/gltf/structures/gltf_accessor.h @@ -31,9 +31,8 @@ #ifndef GLTF_ACCESSOR_H #define GLTF_ACCESSOR_H -#include "core/io/resource.h" - #include "../gltf_defines.h" +#include "core/io/resource.h" struct GLTFAccessor : public Resource { GDCLASS(GLTFAccessor, Resource); diff --git a/modules/gltf/structures/gltf_animation.h b/modules/gltf/structures/gltf_animation.h index 3777f579f6..fc535631bb 100644 --- a/modules/gltf/structures/gltf_animation.h +++ b/modules/gltf/structures/gltf_animation.h @@ -31,7 +31,7 @@ #ifndef GLTF_ANIMATION_H #define GLTF_ANIMATION_H -#include "core/io/resource.h" +#include "scene/animation/animation_player.h" class GLTFAnimation : public Resource { GDCLASS(GLTFAnimation, Resource); diff --git a/modules/gltf/structures/gltf_camera.cpp b/modules/gltf/structures/gltf_camera.cpp index 212b9b80c8..7a5ab2763c 100644 --- a/modules/gltf/structures/gltf_camera.cpp +++ b/modules/gltf/structures/gltf_camera.cpp @@ -30,6 +30,8 @@ #include "gltf_camera.h" +#include "scene/3d/camera_3d.h" + void GLTFCamera::_bind_methods() { ClassDB::bind_static_method("GLTFCamera", D_METHOD("from_node", "camera_node"), &GLTFCamera::from_node); ClassDB::bind_method(D_METHOD("to_node"), &GLTFCamera::to_node); diff --git a/modules/gltf/structures/gltf_camera.h b/modules/gltf/structures/gltf_camera.h index 50ae10e17a..5e8a1da5f7 100644 --- a/modules/gltf/structures/gltf_camera.h +++ b/modules/gltf/structures/gltf_camera.h @@ -32,7 +32,8 @@ #define GLTF_CAMERA_H #include "core/io/resource.h" -#include "scene/3d/camera_3d.h" + +class Camera3D; // Reference and test file: // https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_015_SimpleCameras.md @@ -64,7 +65,7 @@ public: real_t get_depth_near() const { return depth_near; } void set_depth_near(real_t p_val) { depth_near = p_val; } - static Ref<GLTFCamera> from_node(const Camera3D *p_light); + static Ref<GLTFCamera> from_node(const Camera3D *p_camera); Camera3D *to_node() const; static Ref<GLTFCamera> from_dictionary(const Dictionary p_dictionary); diff --git a/modules/gltf/structures/gltf_mesh.h b/modules/gltf/structures/gltf_mesh.h index 2fa37fd727..92722ce75c 100644 --- a/modules/gltf/structures/gltf_mesh.h +++ b/modules/gltf/structures/gltf_mesh.h @@ -31,10 +31,8 @@ #ifndef GLTF_MESH_H #define GLTF_MESH_H -#include "core/io/resource.h" -#include "scene/3d/importer_mesh_instance_3d.h" +#include "../gltf_defines.h" #include "scene/resources/importer_mesh.h" -#include "scene/resources/mesh.h" class GLTFMesh : public Resource { GDCLASS(GLTFMesh, Resource); diff --git a/modules/gltf/structures/gltf_texture_sampler.h b/modules/gltf/structures/gltf_texture_sampler.h index 3fad31bbee..7bb7cd62e3 100644 --- a/modules/gltf/structures/gltf_texture_sampler.h +++ b/modules/gltf/structures/gltf_texture_sampler.h @@ -31,7 +31,6 @@ #ifndef GLTF_TEXTURE_SAMPLER_H #define GLTF_TEXTURE_SAMPLER_H -#include "core/io/resource.h" #include "scene/resources/material.h" class GLTFTextureSampler : public Resource { diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index de50e9ea1e..06ad806afc 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -656,6 +656,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) { if (bake_navigation) { RID region = NavigationServer3D::get_singleton()->region_create(); + NavigationServer3D::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers); NavigationServer3D::get_singleton()->region_set_navmesh(region, navmesh); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * nm.xform); @@ -779,6 +780,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F.key].item); if (nm.is_valid()) { RID region = NavigationServer3D::get_singleton()->region_create(); + NavigationServer3D::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer3D::get_singleton()->region_set_navigation_layers(region, navigation_layers); NavigationServer3D::get_singleton()->region_set_navmesh(region, nm); NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F.value.xform); diff --git a/modules/mono/README.md b/modules/mono/README.md index 366777cfc1..74b4531dfb 100644 --- a/modules/mono/README.md +++ b/modules/mono/README.md @@ -46,10 +46,10 @@ C# solutions during development to avoid mistakes. # Double Precision Support (REAL_T_IS_DOUBLE) -Follow the above instructions but build Godot with the float=64 argument to scons +Follow the above instructions but build Godot with the precision=double argument to scons -When building the NuGet packages, specify `--float=64` - for example: +When building the NuGet packages, specify `--precision=double` - for example: ```sh ./modules/mono/build_scripts/build_assemblies.py --godot-output-dir ./bin \ - --push-nupkgs-local ~/MyLocalNugetSource --float=64 + --push-nupkgs-local ~/MyLocalNugetSource --precision=double ``` diff --git a/modules/mono/build_scripts/build_assemblies.py b/modules/mono/build_scripts/build_assemblies.py index 7343af0b39..0b91cda9b8 100755 --- a/modules/mono/build_scripts/build_assemblies.py +++ b/modules/mono/build_scripts/build_assemblies.py @@ -193,7 +193,7 @@ def run_msbuild(tools: ToolsLocation, sln: str, msbuild_args: Optional[List[str] return subprocess.call(args, env=msbuild_env) -def build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, float_size): +def build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, precision): target_filenames = [ "GodotSharp.dll", "GodotSharp.pdb", @@ -214,7 +214,7 @@ def build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, flo args = ["/restore", "/t:Build", "/p:Configuration=" + build_config, "/p:NoWarn=1591"] if push_nupkgs_local: args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] - if float_size == "64": + if precision == "double": args += ["/p:GodotFloat64=true"] sln = os.path.join(module_dir, "glue/GodotSharp/GodotSharp.sln") @@ -303,12 +303,12 @@ def generate_sdk_package_versions(): f.close() -def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, push_nupkgs_local, float_size): +def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, push_nupkgs_local, precision): # Generate SdkPackageVersions.props generate_sdk_package_versions() # Godot API - exit_code = build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, float_size) + exit_code = build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local, precision) if exit_code != 0: return exit_code @@ -319,7 +319,7 @@ def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, p ) if push_nupkgs_local: args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] - if float_size == "64": + if precision == "double": args += ["/p:GodotFloat64=true"] exit_code = run_msbuild(msbuild_tool, sln=sln, msbuild_args=args) if exit_code != 0: @@ -329,7 +329,7 @@ def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, p args = ["/restore", "/t:Build", "/p:Configuration=Release"] if push_nupkgs_local: args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] - if float_size == "64": + if precision == "double": args += ["/p:GodotFloat64=true"] sln = os.path.join(module_dir, "editor/Godot.NET.Sdk/Godot.NET.Sdk.sln") exit_code = run_msbuild(msbuild_tool, sln=sln, msbuild_args=args) @@ -354,7 +354,9 @@ def main(): parser.add_argument("--godot-platform", type=str, default="") parser.add_argument("--mono-prefix", type=str, default="") parser.add_argument("--push-nupkgs-local", type=str, default="") - parser.add_argument("--float", type=str, default="32", choices=["32", "64"], help="Floating-point precision") + parser.add_argument( + "--precision", type=str, default="single", choices=["single", "double"], help="Floating-point precision level" + ) args = parser.parse_args() @@ -378,7 +380,7 @@ def main(): args.godot_platform, args.dev_debug, push_nupkgs_local, - args.float, + args.precision, ) sys.exit(exit_code) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs index 5b3f677f87..6dac120d15 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs @@ -304,7 +304,12 @@ namespace Godot.SourceGenerators { return marshalType switch { - // For generic Godot collections, VariantUtils.ConvertTo<T> is slower, so we need this special case + // We need a special case for GodotObjectOrDerived[], because it's not supported by VariantUtils.ConvertTo<T> + MarshalType.GodotObjectOrDerivedArray => + source.Append(VariantUtils, ".ConvertToSystemArrayOfGodotObject<", + ((IArrayTypeSymbol)typeSymbol).ElementType.FullQualifiedNameIncludeGlobal(), ">(", + inputExpr, ")"), + // We need a special case for generic Godot collections and GodotObjectOrDerived[], because VariantUtils.ConvertTo<T> is slower MarshalType.GodotGenericDictionary => source.Append(VariantUtils, ".ConvertToDictionaryObject<", ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedNameIncludeGlobal(), ", ", @@ -324,7 +329,10 @@ namespace Godot.SourceGenerators { return marshalType switch { - // For generic Godot collections, VariantUtils.CreateFrom<T> is slower, so we need this special case + // We need a special case for GodotObjectOrDerived[], because it's not supported by VariantUtils.CreateFrom<T> + MarshalType.GodotObjectOrDerivedArray => + source.Append(VariantUtils, ".CreateFromSystemArrayOfGodotObject(", inputExpr, ")"), + // We need a special case for generic Godot collections and GodotObjectOrDerived[], because VariantUtils.CreateFrom<T> is slower MarshalType.GodotGenericDictionary => source.Append(VariantUtils, ".CreateFromDictionary(", inputExpr, ")"), MarshalType.GodotGenericArray => @@ -339,7 +347,11 @@ namespace Godot.SourceGenerators { return marshalType switch { - // For generic Godot collections, Variant.As<T> is slower, so we need this special case + // We need a special case for GodotObjectOrDerived[], because it's not supported by Variant.As<T> + MarshalType.GodotObjectOrDerivedArray => + source.Append(inputExpr, ".AsGodotObjectArray<", + ((IArrayTypeSymbol)typeSymbol).ElementType.FullQualifiedNameIncludeGlobal(), ">()"), + // We need a special case for generic Godot collections and GodotObjectOrDerived[], because Variant.As<T> is slower MarshalType.GodotGenericDictionary => source.Append(inputExpr, ".AsGodotDictionary<", ((INamedTypeSymbol)typeSymbol).TypeArguments[0].FullQualifiedNameIncludeGlobal(), ", ", @@ -357,7 +369,10 @@ namespace Godot.SourceGenerators { return marshalType switch { - // For generic Godot collections, Variant.From<T> is slower, so we need this special case + // We need a special case for GodotObjectOrDerived[], because it's not supported by Variant.From<T> + MarshalType.GodotObjectOrDerivedArray => + source.Append("global::Godot.Variant.CreateFrom(", inputExpr, ")"), + // We need a special case for generic Godot collections, because Variant.From<T> is slower MarshalType.GodotGenericDictionary or MarshalType.GodotGenericArray => source.Append("global::Godot.Variant.CreateFrom(", inputExpr, ")"), _ => source.Append("global::Godot.Variant.From<", diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs index b7d633517a..acdae83d2e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/AssemblyHasScriptsAttribute.cs @@ -1,20 +1,32 @@ using System; +using System.Diagnostics.CodeAnalysis; #nullable enable namespace Godot { /// <summary> - /// An attribute that determines if an assembly has scripts. If so, what types of scripts the assembly has. + /// Attribute that determines that the assembly contains Godot scripts and, optionally, the + /// collection of types that implement scripts; otherwise, retrieving the types requires lookup. /// </summary> [AttributeUsage(AttributeTargets.Assembly)] public class AssemblyHasScriptsAttribute : Attribute { + /// <summary> + /// If the Godot scripts contained in the assembly require lookup + /// and can't rely on <see cref="ScriptTypes"/>. + /// </summary> + [MemberNotNullWhen(false, nameof(ScriptTypes))] public bool RequiresLookup { get; } + + /// <summary> + /// The collection of types that implement a Godot script. + /// </summary> public Type[]? ScriptTypes { get; } /// <summary> - /// Constructs a new AssemblyHasScriptsAttribute instance. + /// Constructs a new AssemblyHasScriptsAttribute instance + /// that requires lookup to get the Godot scripts. /// </summary> public AssemblyHasScriptsAttribute() { @@ -23,9 +35,10 @@ namespace Godot } /// <summary> - /// Constructs a new AssemblyHasScriptsAttribute instance. + /// Constructs a new AssemblyHasScriptsAttribute instance + /// that includes the Godot script types and requires no lookup. /// </summary> - /// <param name="scriptTypes">The specified type(s) of scripts.</param> + /// <param name="scriptTypes">The collection of types that implement a Godot script.</param> public AssemblyHasScriptsAttribute(Type[] scriptTypes) { RequiresLookup = false; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs index 3d204bdf9f..a48d79091f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportAttribute.cs @@ -3,23 +3,30 @@ using System; namespace Godot { /// <summary> - /// An attribute used to export objects. + /// Exports the annotated member as a property of the Godot Object. /// </summary> [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportAttribute : Attribute { - private PropertyHint hint; - private string hintString; + /// <summary> + /// Optional hint that determines how the property should be handled by the editor. + /// </summary> + public PropertyHint Hint { get; } + + /// <summary> + /// Optional string that can contain additional metadata for the <see cref="Hint"/>. + /// </summary> + public string HintString { get; } /// <summary> /// Constructs a new ExportAttribute Instance. /// </summary> - /// <param name="hint">A hint to the exported object.</param> - /// <param name="hintString">A string representing the exported object.</param> + /// <param name="hint">The hint for the exported property.</param> + /// <param name="hintString">A string that may contain additional metadata for the hint.</param> public ExportAttribute(PropertyHint hint = PropertyHint.None, string hintString = "") { - this.hint = hint; - this.hintString = hintString; + Hint = hint; + HintString = hintString; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs index 101e56f8d3..2ae55acd3e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportCategoryAttribute.cs @@ -8,7 +8,10 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportCategoryAttribute : Attribute { - private string name; + /// <summary> + /// Name of the category. + /// </summary> + public string Name { get; } /// <summary> /// Define a new category for the following exported properties. @@ -16,7 +19,7 @@ namespace Godot /// <param name="name">The name of the category.</param> public ExportCategoryAttribute(string name) { - this.name = name; + Name = name; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs index 3bd532cec1..82bd446640 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportGroupAttribute.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Godot { /// <summary> @@ -8,8 +10,15 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportGroupAttribute : Attribute { - private string name; - private string prefix; + /// <summary> + /// Name of the group. + /// </summary> + public string Name { get; } + + /// <summary> + /// If provided, the prefix that all properties must have to be considered part of the group. + /// </summary> + public string? Prefix { get; } /// <summary> /// Define a new group for the following exported properties. @@ -18,8 +27,8 @@ namespace Godot /// <param name="prefix">If provided, the group would make group to only consider properties that have this prefix.</param> public ExportGroupAttribute(string name, string prefix = "") { - this.name = name; - this.prefix = prefix; + Name = name; + Prefix = prefix; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs index 2ae6eb0b68..3282b466f6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ExportSubgroupAttribute.cs @@ -1,5 +1,7 @@ using System; +#nullable enable + namespace Godot { /// <summary> @@ -8,8 +10,15 @@ namespace Godot [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public sealed class ExportSubgroupAttribute : Attribute { - private string name; - private string prefix; + /// <summary> + /// Name of the subgroup. + /// </summary> + public string Name { get; } + + /// <summary> + /// If provided, the prefix that all properties must have to be considered part of the subgroup. + /// </summary> + public string? Prefix { get; } /// <summary> /// Define a new subgroup for the following exported properties. This helps to organize properties in the Inspector dock. @@ -18,8 +27,8 @@ namespace Godot /// <param name="prefix">If provided, the subgroup would make group to only consider properties that have this prefix.</param> public ExportSubgroupAttribute(string name, string prefix = "") { - this.name = name; - this.prefix = prefix; + Name = name; + Prefix = prefix; } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs index fb37838ffa..afee926464 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/RPCAttribute.cs @@ -19,17 +19,17 @@ namespace Godot /// <summary> /// If the method will also be called locally; otherwise, it is only called remotely. /// </summary> - public bool CallLocal { get; set; } = false; + public bool CallLocal { get; init; } = false; /// <summary> /// Transfer mode for the annotated method. /// </summary> - public MultiplayerPeer.TransferModeEnum TransferMode { get; set; } = MultiplayerPeer.TransferModeEnum.Reliable; + public MultiplayerPeer.TransferModeEnum TransferMode { get; init; } = MultiplayerPeer.TransferModeEnum.Reliable; /// <summary> /// Transfer channel for the annotated mode. /// </summary> - public int TransferChannel { get; set; } = 0; + public int TransferChannel { get; init; } = 0; /// <summary> /// Constructs a <see cref="RPCAttribute"/> instance. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs index 2c8a53ae1c..f05bcdac38 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Attributes/ScriptPathAttribute.cs @@ -8,6 +8,9 @@ namespace Godot [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class ScriptPathAttribute : Attribute { + /// <summary> + /// File path to the script. + /// </summary> public string Path { get; } /// <summary> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs index a3cfecfaa6..2a7a9e2026 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs @@ -739,6 +739,26 @@ namespace Godot if (typeof(Godot.Object).IsAssignableFrom(type)) return Convert.ChangeType(VariantUtils.ConvertTo<Godot.Object>(variant), type); + if (typeof(Godot.Object[]).IsAssignableFrom(type)) + { + static Godot.Object[] ConvertToSystemArrayOfGodotObject(in godot_array nativeArray, Type type) + { + var array = Collections.Array.CreateTakingOwnershipOfDisposableValue( + NativeFuncs.godotsharp_array_new_copy(nativeArray)); + + int length = array.Count; + var ret = (Godot.Object[])Activator.CreateInstance(type, length)!; + + for (int i = 0; i < length; i++) + ret[i] = array[i].AsGodotObject(); + + return ret; + } + + using var godotArray = NativeFuncs.godotsharp_variant_as_array(variant); + return Convert.ChangeType(ConvertToSystemArrayOfGodotObject(godotArray, type), type); + } + if (type.IsEnum) { var enumUnderlyingType = type.GetEnumUnderlyingType(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs index 6176093bc1..ab3d3ef60f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs @@ -333,22 +333,6 @@ namespace Godot.NativeInterop return ret; } - // TODO: This needs reflection. Look for an alternative. - internal static Godot.Object[] ConvertNativeGodotArrayToSystemArrayOfGodotObjectType(in godot_array p_array, - Type type) - { - var array = Collections.Array.CreateTakingOwnershipOfDisposableValue( - NativeFuncs.godotsharp_array_new_copy(p_array)); - - int length = array.Count; - var ret = (Godot.Object[])Activator.CreateInstance(type, length)!; - - for (int i = 0; i < length; i++) - ret[i] = array[i].AsGodotObject(); - - return ret; - } - internal static StringName[] ConvertNativeGodotArrayToSystemArrayOfStringName(in godot_array p_array) { var array = Collections.Array.CreateTakingOwnershipOfDisposableValue( diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index ba8e7a6c65..11f1e31384 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -594,12 +594,5 @@ namespace Godot.NativeInterop using var godotArray = NativeFuncs.godotsharp_variant_as_array(p_var); return Marshaling.ConvertNativeGodotArrayToSystemArrayOfGodotObjectType<T>(godotArray); } - - // ReSharper disable once RedundantNameQualifier - public static Godot.Object[] ConvertToSystemArrayOfGodotObject(in godot_variant p_var, Type type) - { - using var godotArray = NativeFuncs.godotsharp_variant_as_array(p_var); - return Marshaling.ConvertNativeGodotArrayToSystemArrayOfGodotObjectType(godotArray, type); - } } } diff --git a/modules/multiplayer/doc_classes/MultiplayerSynchronizer.xml b/modules/multiplayer/doc_classes/MultiplayerSynchronizer.xml index 7ed6255a62..af7c345f15 100644 --- a/modules/multiplayer/doc_classes/MultiplayerSynchronizer.xml +++ b/modules/multiplayer/doc_classes/MultiplayerSynchronizer.xml @@ -17,7 +17,7 @@ <param index="0" name="filter" type="Callable" /> <description> Adds a peer visibility filter for this synchronizer. - [code]filter[/code] should take a peer id [int] and return a [bool]. + [code]filter[/code] should take a peer ID [int] and return a [bool]. </description> </method> <method name="get_visibility_for" qualifiers="const"> diff --git a/modules/multiplayer/scene_rpc_interface.cpp b/modules/multiplayer/scene_rpc_interface.cpp index dbf2b3751e..a7e29dfcc7 100644 --- a/modules/multiplayer/scene_rpc_interface.cpp +++ b/modules/multiplayer/scene_rpc_interface.cpp @@ -82,7 +82,7 @@ void SceneRPCInterface::_parse_rpc_config(const Variant &p_config, bool p_for_no Array names = config.keys(); names.sort(); // Ensure ID order for (int i = 0; i < names.size(); i++) { - ERR_CONTINUE(names[i].get_type() != Variant::STRING); + ERR_CONTINUE(names[i].get_type() != Variant::STRING && names[i].get_type() != Variant::STRING_NAME); String name = names[i].operator String(); ERR_CONTINUE(config[name].get_type() != Variant::DICTIONARY); ERR_CONTINUE(!config[name].operator Dictionary().has("rpc_mode")); diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp index 8ca73a3adb..0e40e5a4af 100644 --- a/modules/navigation/godot_navigation_server.cpp +++ b/modules/navigation/godot_navigation_server.cpp @@ -383,6 +383,20 @@ real_t GodotNavigationServer::region_get_travel_cost(RID p_region) const { return region->get_travel_cost(); } +COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id) { + NavRegion *region = region_owner.get_or_null(p_region); + ERR_FAIL_COND(region == nullptr); + + region->set_owner_id(p_owner_id); +} + +ObjectID GodotNavigationServer::region_get_owner_id(RID p_region) const { + const NavRegion *region = region_owner.get_or_null(p_region); + ERR_FAIL_COND_V(region == nullptr, ObjectID()); + + return region->get_owner_id(); +} + bool GodotNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const { const NavRegion *region = region_owner.get_or_null(p_region); ERR_FAIL_COND_V(region == nullptr, false); @@ -570,6 +584,20 @@ real_t GodotNavigationServer::link_get_travel_cost(const RID p_link) const { return link->get_travel_cost(); } +COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id) { + NavLink *link = link_owner.get_or_null(p_link); + ERR_FAIL_COND(link == nullptr); + + link->set_owner_id(p_owner_id); +} + +ObjectID GodotNavigationServer::link_get_owner_id(RID p_link) const { + const NavLink *link = link_owner.get_or_null(p_link); + ERR_FAIL_COND_V(link == nullptr, ObjectID()); + + return link->get_owner_id(); +} + RID GodotNavigationServer::agent_create() const { GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this); MutexLock lock(mut_this->operations_mutex); diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h index ab5e722d35..08ad545b37 100644 --- a/modules/navigation/godot_navigation_server.h +++ b/modules/navigation/godot_navigation_server.h @@ -125,6 +125,9 @@ public: COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost); virtual real_t region_get_travel_cost(RID p_region) const override; + COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id); + virtual ObjectID region_get_owner_id(RID p_region) const override; + virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const override; COMMAND_2(region_set_map, RID, p_region, RID, p_map); @@ -153,6 +156,8 @@ public: virtual real_t link_get_enter_cost(RID p_link) const override; COMMAND_2(link_set_travel_cost, RID, p_link, real_t, p_travel_cost); virtual real_t link_get_travel_cost(RID p_link) const override; + COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id); + virtual ObjectID link_get_owner_id(RID p_link) const override; virtual RID agent_create() const override; COMMAND_2(agent_set_map, RID, p_agent, RID, p_map); diff --git a/modules/navigation/nav_base.h b/modules/navigation/nav_base.h index 6dfaaf9af4..f5d2880d36 100644 --- a/modules/navigation/nav_base.h +++ b/modules/navigation/nav_base.h @@ -41,6 +41,7 @@ protected: uint32_t navigation_layers = 1; float enter_cost = 0.0; float travel_cost = 1.0; + ObjectID owner_id; public: void set_navigation_layers(uint32_t p_navigation_layers) { navigation_layers = p_navigation_layers; } @@ -51,6 +52,9 @@ public: void set_travel_cost(float p_travel_cost) { travel_cost = MAX(p_travel_cost, 0.0); } float get_travel_cost() const { return travel_cost; } + + void set_owner_id(ObjectID p_owner_id) { owner_id = p_owner_id; } + ObjectID get_owner_id() const { return owner_id; } }; #endif // NAV_BASE_H diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index 71e1d9c351..b652ca4617 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -740,9 +740,10 @@ bool OpenXRAPI::create_swapchains() { ERR_FAIL_NULL_V_MSG(projection_views, false, "OpenXR Couldn't allocate memory for projection views"); // We create our depth swapchain if: + // - we've enabled submitting depth buffer // - we support our depth layer extension // - we have our spacewarp extension (not yet implemented) - if (OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) { + if (submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available()) { // Build a vector with swapchain formats we want to use, from best fit to worst Vector<int64_t> usable_swapchain_formats; int64_t swapchain_format_to_use = 0; @@ -790,7 +791,7 @@ bool OpenXRAPI::create_swapchains() { projection_views[i].subImage.imageRect.extent.width = recommended_size.width; projection_views[i].subImage.imageRect.extent.height = recommended_size.height; - if (OpenXRCompositionLayerDepthExtension::get_singleton()->is_available() && depth_views) { + if (submit_depth_buffer && OpenXRCompositionLayerDepthExtension::get_singleton()->is_available() && depth_views) { projection_views[i].next = &depth_views[i]; depth_views[i].type = XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR; @@ -1066,6 +1067,30 @@ bool OpenXRAPI::on_state_exiting() { return true; } +void OpenXRAPI::set_form_factor(XrFormFactor p_form_factor) { + ERR_FAIL_COND(is_initialized()); + + form_factor = p_form_factor; +} + +void OpenXRAPI::set_view_configuration(XrViewConfigurationType p_view_configuration) { + ERR_FAIL_COND(is_initialized()); + + view_configuration = p_view_configuration; +} + +void OpenXRAPI::set_reference_space(XrReferenceSpaceType p_reference_space) { + ERR_FAIL_COND(is_initialized()); + + reference_space = p_reference_space; +} + +void OpenXRAPI::set_submit_depth_buffer(bool p_submit_depth_buffer) { + ERR_FAIL_COND(is_initialized()); + + submit_depth_buffer = p_submit_depth_buffer; +} + bool OpenXRAPI::is_initialized() { return (instance != XR_NULL_HANDLE); } @@ -1684,7 +1709,7 @@ RID OpenXRAPI::get_color_texture() { } RID OpenXRAPI::get_depth_texture() { - if (swapchains[OPENXR_SWAPCHAIN_DEPTH].image_acquired) { + if (submit_depth_buffer && swapchains[OPENXR_SWAPCHAIN_DEPTH].image_acquired) { return graphics_extension->get_texture(swapchains[OPENXR_SWAPCHAIN_DEPTH].swapchain_graphics_data, swapchains[OPENXR_SWAPCHAIN_DEPTH].image_index); } else { return RID(); @@ -1862,6 +1887,8 @@ OpenXRAPI::OpenXRAPI() { default: break; } + + submit_depth_buffer = GLOBAL_GET("xr/openxr/submit_depth_buffer"); } // reset a few things that can't be done in our class definition diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index 5dce749351..ac4bbff94c 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -104,6 +104,7 @@ private: XrViewConfigurationType view_configuration = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO; XrReferenceSpaceType reference_space = XR_REFERENCE_SPACE_TYPE_STAGE; // XrEnvironmentBlendMode environment_blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE; + bool submit_depth_buffer = false; // if set to true we submit depth buffers to OpenXR if a suitable extension is enabled. // state XrInstance instance = XR_NULL_HANDLE; @@ -312,6 +313,18 @@ public: void set_xr_interface(OpenXRInterface *p_xr_interface); void register_extension_wrapper(OpenXRExtensionWrapper *p_extension_wrapper); + void set_form_factor(XrFormFactor p_form_factor); + XrFormFactor get_form_factor() const { return form_factor; } + + void set_view_configuration(XrViewConfigurationType p_view_configuration); + XrViewConfigurationType get_view_configuration() const { return view_configuration; } + + void set_reference_space(XrReferenceSpaceType p_reference_space); + XrReferenceSpaceType get_reference_space() const { return reference_space; } + + void set_submit_depth_buffer(bool p_submit_depth_buffer); + bool get_submit_depth_buffer() const { return submit_depth_buffer; } + bool is_initialized(); bool is_running(); bool initialize(const String &p_rendering_driver); diff --git a/modules/openxr/openxr_interface.cpp b/modules/openxr/openxr_interface.cpp index 77660eb6f0..40190ab2f3 100644 --- a/modules/openxr/openxr_interface.cpp +++ b/modules/openxr/openxr_interface.cpp @@ -45,7 +45,7 @@ void OpenXRInterface::_bind_methods() { // Display refresh rate ClassDB::bind_method(D_METHOD("get_display_refresh_rate"), &OpenXRInterface::get_display_refresh_rate); ClassDB::bind_method(D_METHOD("set_display_refresh_rate", "refresh_rate"), &OpenXRInterface::set_display_refresh_rate); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "display_refresh_rate"), "set_display_refresh_rate", "get_display_refresh_rate"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_refresh_rate"), "set_display_refresh_rate", "get_display_refresh_rate"); ClassDB::bind_method(D_METHOD("get_available_display_refresh_rates"), &OpenXRInterface::get_available_display_refresh_rates); } diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index c808211d68..6f02d20c25 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -50,8 +50,7 @@ int RegExMatch::_find(const Variant &p_name) const { return -1; } return i; - - } else if (p_name.get_type() == Variant::STRING) { + } else if (p_name.get_type() == Variant::STRING || p_name.get_type() == Variant::STRING_NAME) { HashMap<String, int>::ConstIterator found = names.find((String)p_name); if (found) { return found->value; diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 27fab88956..512643867b 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -2151,10 +2151,7 @@ void TextServerAdvanced::_font_set_allow_system_fallback(const RID &p_font_rid, ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - if (fd->allow_system_fallback != p_allow_system_fallback) { - _font_clear_cache(fd); - fd->allow_system_fallback = p_allow_system_fallback; - } + fd->allow_system_fallback = p_allow_system_fallback; } bool TextServerAdvanced::_font_is_allow_system_fallback(const RID &p_font_rid) const { @@ -6199,6 +6196,9 @@ String TextServerAdvanced::_strip_diacritics(const String &p_string) const { } String TextServerAdvanced::_string_to_upper(const String &p_string, const String &p_language) const { + if (p_string.is_empty()) { + return p_string; + } const String lang = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language; // Convert to UTF-16. @@ -6218,6 +6218,9 @@ String TextServerAdvanced::_string_to_upper(const String &p_string, const String } String TextServerAdvanced::_string_to_lower(const String &p_string, const String &p_language) const { + if (p_string.is_empty()) { + return p_string; + } const String lang = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language; // Convert to UTF-16. Char16String utf16 = p_string.utf16(); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 9133c277bb..353d370f14 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -1246,10 +1246,7 @@ void TextServerFallback::_font_set_allow_system_fallback(const RID &p_font_rid, ERR_FAIL_COND(!fd); MutexLock lock(fd->mutex); - if (fd->allow_system_fallback != p_allow_system_fallback) { - _font_clear_cache(fd); - fd->allow_system_fallback = p_allow_system_fallback; - } + fd->allow_system_fallback = p_allow_system_fallback; } bool TextServerFallback::_font_is_allow_system_fallback(const RID &p_font_rid) const { diff --git a/modules/webrtc/doc_classes/WebRTCDataChannel.xml b/modules/webrtc/doc_classes/WebRTCDataChannel.xml index a9ba8a23de..a186631ca8 100644 --- a/modules/webrtc/doc_classes/WebRTCDataChannel.xml +++ b/modules/webrtc/doc_classes/WebRTCDataChannel.xml @@ -22,8 +22,8 @@ <method name="get_id" qualifiers="const"> <return type="int" /> <description> - Returns the id assigned to this channel during creation (or auto-assigned during negotiation). - If the channel is not negotiated out-of-band the id will only be available after the connection is established (will return [code]65535[/code] until then). + Returns the ID assigned to this channel during creation (or auto-assigned during negotiation). + If the channel is not negotiated out-of-band the ID will only be available after the connection is established (will return [code]65535[/code] until then). </description> </method> <method name="get_label" qualifiers="const"> diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 937b929d62..9c796a8c07 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -221,7 +221,7 @@ float DisplayServerAndroid::screen_get_refresh_rate(int p_screen) const { return godot_io_java->get_screen_refresh_rate(SCREEN_REFRESH_RATE_FALLBACK); } -bool DisplayServerAndroid::screen_is_touchscreen(int p_screen) const { +bool DisplayServerAndroid::is_touchscreen_available() const { return true; } @@ -366,6 +366,10 @@ Point2i DisplayServerAndroid::window_get_position(DisplayServer::WindowID p_wind return Point2i(); } +Point2i DisplayServerAndroid::window_get_position_with_decorations(DisplayServer::WindowID p_window) const { + return Point2i(); +} + void DisplayServerAndroid::window_set_position(const Point2i &p_position, DisplayServer::WindowID p_window) { // Not supported on Android. } @@ -398,7 +402,7 @@ Size2i DisplayServerAndroid::window_get_size(DisplayServer::WindowID p_window) c return OS_Android::get_singleton()->get_display_size(); } -Size2i DisplayServerAndroid::window_get_real_size(DisplayServer::WindowID p_window) const { +Size2i DisplayServerAndroid::window_get_size_with_decorations(DisplayServer::WindowID p_window) const { return OS_Android::get_singleton()->get_display_size(); } diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h index c7f4d8046f..9ed07ca971 100644 --- a/platform/android/display_server_android.h +++ b/platform/android/display_server_android.h @@ -121,7 +121,7 @@ public: virtual int screen_get_dpi(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; virtual float screen_get_scale(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; - virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; + virtual bool is_touchscreen_available() const override; virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override; virtual void virtual_keyboard_hide() override; @@ -150,6 +150,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; @@ -162,7 +163,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h index 447f919139..4901eeefaf 100644 --- a/platform/ios/display_server_ios.h +++ b/platform/ios/display_server_ios.h @@ -162,6 +162,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; @@ -174,7 +175,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; @@ -199,7 +200,7 @@ public: virtual void window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override; - virtual bool screen_is_touchscreen(int p_screen) const override; + virtual bool is_touchscreen_available() const override; virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_length, int p_cursor_start, int p_cursor_end) override; virtual void virtual_keyboard_hide() override; diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index 6793b40dd4..ed1bc499ed 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -496,6 +496,10 @@ Point2i DisplayServerIOS::window_get_position(WindowID p_window) const { return Point2i(); } +Point2i DisplayServerIOS::window_get_position_with_decorations(WindowID p_window) const { + return Point2i(); +} + void DisplayServerIOS::window_set_position(const Point2i &p_position, WindowID p_window) { // Probably not supported for single window iOS app } @@ -529,7 +533,7 @@ Size2i DisplayServerIOS::window_get_size(WindowID p_window) const { return Size2i(screenBounds.size.width, screenBounds.size.height) * screen_get_max_scale(); } -Size2i DisplayServerIOS::window_get_real_size(WindowID p_window) const { +Size2i DisplayServerIOS::window_get_size_with_decorations(WindowID p_window) const { return window_get_size(p_window); } @@ -581,7 +585,7 @@ bool DisplayServerIOS::can_any_window_draw() const { return true; } -bool DisplayServerIOS::screen_is_touchscreen(int p_screen) const { +bool DisplayServerIOS::is_touchscreen_available() const { return true; } diff --git a/platform/linuxbsd/dbus-so_wrap.c b/platform/linuxbsd/dbus-so_wrap.c index 0876bc88b0..48d0d9b907 100644 --- a/platform/linuxbsd/dbus-so_wrap.c +++ b/platform/linuxbsd/dbus-so_wrap.c @@ -1,7 +1,7 @@ // This file is generated. Do not edit! // see https://github.com/hpvb/dynload-wrapper for details // generated by ./generate-wrapper.py 0.3 on 2022-07-29 07:23:21 -// flags: ./generate-wrapper.py --include /usr/include/dbus-1.0/dbus/dbus.h --sys-include <dbus/dbus.h> --soname libdbus-1.so --init-name dbus --output-header dbus-so_wrap.h --output-implementation dbus-so_wrap.c +// flags: ./generate-wrapper.py --include /usr/include/dbus-1.0/dbus/dbus.h --sys-include <dbus/dbus.h> --soname libdbus-1.so.3 --init-name dbus --output-header dbus-so_wrap.h --output-implementation dbus-so_wrap.c // #include <stdint.h> @@ -725,7 +725,7 @@ dbus_bool_t (*dbus_threads_init_default_dylibloader_wrapper_dbus)( void); int initialize_dbus(int verbose) { void *handle; char *error; - handle = dlopen("libdbus-1.so", RTLD_LAZY); + handle = dlopen("libdbus-1.so.3", RTLD_LAZY); if (!handle) { if (verbose) { fprintf(stderr, "%s\n", dlerror()); diff --git a/platform/linuxbsd/fontconfig-so_wrap.c b/platform/linuxbsd/fontconfig-so_wrap.c index a428cf1fb4..62901b14a9 100644 --- a/platform/linuxbsd/fontconfig-so_wrap.c +++ b/platform/linuxbsd/fontconfig-so_wrap.c @@ -1,7 +1,7 @@ // This file is generated. Do not edit! // see https://github.com/hpvb/dynload-wrapper for details // generated by ./generate-wrapper.py 0.3 on 2022-11-22 10:28:00 -// flags: ./generate-wrapper.py --include /usr/include/fontconfig/fontconfig.h --sys-include <fontconfig/fontconfig.h> --soname libfontconfig.so --init-name fontconfig --output-header fontconfig-so_wrap.h --output-implementation fontconfig-so_wrap.c --omit-prefix FcCharSetFirst --omit-prefix FcCharSetNext +// flags: ./generate-wrapper.py --include /usr/include/fontconfig/fontconfig.h --sys-include <fontconfig/fontconfig.h> --soname libfontconfig.so.1 --init-name fontconfig --output-header fontconfig-so_wrap.h --output-implementation fontconfig-so_wrap.c --omit-prefix FcCharSetFirst --omit-prefix FcCharSetNext // #include <stdint.h> @@ -677,7 +677,7 @@ FcBool (*FcConfigParseAndLoadFromMemory_dylibloader_wrapper_fontconfig)( FcConfi int initialize_fontconfig(int verbose) { void *handle; char *error; - handle = dlopen("libfontconfig.so", RTLD_LAZY); + handle = dlopen("libfontconfig.so.1", RTLD_LAZY); if (!handle) { if (verbose) { fprintf(stderr, "%s\n", dlerror()); diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index ec6947e180..1c5c8b2d19 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -1397,8 +1397,8 @@ void DisplayServerX11::window_set_mouse_passthrough(const Vector<Vector2> &p_reg XRectangle rect; rect.x = 0; rect.y = 0; - rect.width = window_get_real_size(p_window).x; - rect.height = window_get_real_size(p_window).y; + rect.width = window_get_size_with_decorations(p_window).x; + rect.height = window_get_size_with_decorations(p_window).y; XUnionRectWithRegion(&rect, region, region); } else { XPoint *points = (XPoint *)memalloc(sizeof(XPoint) * p_region.size()); @@ -1582,7 +1582,7 @@ void DisplayServerX11::_update_size_hints(WindowID p_window) { xsh->width = wd.size.width; xsh->height = wd.size.height; - if (window_mode == WINDOW_MODE_FULLSCREEN) { + if (window_mode == WINDOW_MODE_FULLSCREEN || window_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) { // Do not set any other hints to prevent the window manager from ignoring the fullscreen flags } else if (window_get_flag(WINDOW_FLAG_RESIZE_DISABLED, p_window)) { // If resizing is disabled, use the forced size @@ -1618,6 +1618,40 @@ Point2i DisplayServerX11::window_get_position(WindowID p_window) const { return wd.position; } +Point2i DisplayServerX11::window_get_position_with_decorations(WindowID p_window) const { + _THREAD_SAFE_METHOD_ + + ERR_FAIL_COND_V(!windows.has(p_window), Size2i()); + const WindowData &wd = windows[p_window]; + + if (wd.fullscreen) { + return wd.position; + } + + XWindowAttributes xwa; + XSync(x11_display, False); + XGetWindowAttributes(x11_display, wd.x11_window, &xwa); + int x = wd.position.x; + int y = wd.position.y; + Atom prop = XInternAtom(x11_display, "_NET_FRAME_EXTENTS", True); + if (prop != None) { + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = nullptr; + if (XGetWindowProperty(x11_display, wd.x11_window, prop, 0, 4, False, AnyPropertyType, &type, &format, &len, &remaining, &data) == Success) { + if (format == 32 && len == 4 && data) { + long *extents = (long *)data; + x -= extents[0]; // left + y -= extents[2]; // top + } + XFree(data); + } + } + return Size2i(x, y); +} + void DisplayServerX11::window_set_position(const Point2i &p_position, WindowID p_window) { _THREAD_SAFE_METHOD_ @@ -1762,12 +1796,16 @@ Size2i DisplayServerX11::window_get_size(WindowID p_window) const { return wd.size; } -Size2i DisplayServerX11::window_get_real_size(WindowID p_window) const { +Size2i DisplayServerX11::window_get_size_with_decorations(WindowID p_window) const { _THREAD_SAFE_METHOD_ ERR_FAIL_COND_V(!windows.has(p_window), Size2i()); const WindowData &wd = windows[p_window]; + if (wd.fullscreen) { + return wd.size; + } + XWindowAttributes xwa; XSync(x11_display, False); XGetWindowAttributes(x11_display, wd.x11_window, &xwa); @@ -1949,7 +1987,7 @@ void DisplayServerX11::_validate_mode_on_map(WindowID p_window) { // Check if we applied any window modes that didn't take effect while unmapped const WindowData &wd = windows[p_window]; if (wd.fullscreen && !_window_fullscreen_check(p_window)) { - _set_wm_fullscreen(p_window, true); + _set_wm_fullscreen(p_window, true, wd.exclusive_fullscreen); } else if (wd.maximized && !_window_maximize_check(p_window, "_NET_WM_STATE")) { _set_wm_maximized(p_window, true); } else if (wd.minimized && !_window_minimize_check(p_window)) { @@ -2024,7 +2062,7 @@ void DisplayServerX11::_set_wm_minimized(WindowID p_window, bool p_enabled) { wd.minimized = p_enabled; } -void DisplayServerX11::_set_wm_fullscreen(WindowID p_window, bool p_enabled) { +void DisplayServerX11::_set_wm_fullscreen(WindowID p_window, bool p_enabled, bool p_exclusive) { ERR_FAIL_COND(!windows.has(p_window)); WindowData &wd = windows[p_window]; @@ -2063,7 +2101,14 @@ void DisplayServerX11::_set_wm_fullscreen(WindowID p_window, bool p_enabled) { // set bypass compositor hint Atom bypass_compositor = XInternAtom(x11_display, "_NET_WM_BYPASS_COMPOSITOR", False); - unsigned long compositing_disable_on = p_enabled ? 1 : 0; + unsigned long compositing_disable_on = 0; // Use default. + if (p_enabled) { + if (p_exclusive) { + compositing_disable_on = 1; // Force composition OFF to reduce overhead. + } else { + compositing_disable_on = 2; // Force composition ON to allow popup windows. + } + } if (bypass_compositor != None) { XChangeProperty(x11_display, wd.x11_window, bypass_compositor, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&compositing_disable_on, 1); } @@ -2109,8 +2154,9 @@ void DisplayServerX11::window_set_mode(WindowMode p_mode, WindowID p_window) { case WINDOW_MODE_FULLSCREEN: { //Remove full-screen wd.fullscreen = false; + wd.exclusive_fullscreen = false; - _set_wm_fullscreen(p_window, false); + _set_wm_fullscreen(p_window, false, false); //un-maximize required for always on top bool on_top = window_get_flag(WINDOW_FLAG_ALWAYS_ON_TOP, p_window); @@ -2143,7 +2189,13 @@ void DisplayServerX11::window_set_mode(WindowMode p_mode, WindowID p_window) { } wd.fullscreen = true; - _set_wm_fullscreen(p_window, true); + if (p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN) { + wd.exclusive_fullscreen = true; + _set_wm_fullscreen(p_window, true, true); + } else { + wd.exclusive_fullscreen = false; + _set_wm_fullscreen(p_window, true, false); + } } break; case WINDOW_MODE_MAXIMIZED: { _set_wm_maximized(p_window, true); @@ -2158,7 +2210,11 @@ DisplayServer::WindowMode DisplayServerX11::window_get_mode(WindowID p_window) c const WindowData &wd = windows[p_window]; if (wd.fullscreen) { //if fullscreen, it's not in another mode - return WINDOW_MODE_FULLSCREEN; + if (wd.exclusive_fullscreen) { + return WINDOW_MODE_EXCLUSIVE_FULLSCREEN; + } else { + return WINDOW_MODE_FULLSCREEN; + } } // Test maximized. diff --git a/platform/linuxbsd/x11/display_server_x11.h b/platform/linuxbsd/x11/display_server_x11.h index c88a6b466a..2578ca06fd 100644 --- a/platform/linuxbsd/x11/display_server_x11.h +++ b/platform/linuxbsd/x11/display_server_x11.h @@ -159,6 +159,7 @@ class DisplayServerX11 : public DisplayServer { //better to guess on the fly, given WM can change it //WindowMode mode; bool fullscreen = false; //OS can't exit from this mode + bool exclusive_fullscreen = false; bool on_top = false; bool borderless = false; bool resize_disabled = false; @@ -283,7 +284,7 @@ class DisplayServerX11 : public DisplayServer { bool _window_minimize_check(WindowID p_window) const; void _validate_mode_on_map(WindowID p_window); void _update_size_hints(WindowID p_window); - void _set_wm_fullscreen(WindowID p_window, bool p_enabled); + void _set_wm_fullscreen(WindowID p_window, bool p_enabled, bool p_exclusive); void _set_wm_maximized(WindowID p_window, bool p_enabled); void _set_wm_minimized(WindowID p_window, bool p_enabled); @@ -392,6 +393,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_max_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; @@ -405,7 +407,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index 8f315f736b..bd26f6e417 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -355,6 +355,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; @@ -368,7 +369,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index ad6143e16e..5c979dbf22 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -2414,6 +2414,27 @@ Point2i DisplayServerMacOS::window_get_position(WindowID p_window) const { return pos; } +Point2i DisplayServerMacOS::window_get_position_with_decorations(WindowID p_window) const { + _THREAD_SAFE_METHOD_ + + ERR_FAIL_COND_V(!windows.has(p_window), Point2i()); + const WindowData &wd = windows[p_window]; + + const NSRect nsrect = [wd.window_object frame]; + Point2i pos; + + // Return the position of the top-left corner, for OS X the y starts at the bottom. + const float scale = screen_get_max_scale(); + pos.x = nsrect.origin.x; + pos.y = (nsrect.origin.y + nsrect.size.height); + pos *= scale; + pos -= _get_screens_origin(); + // OS X native y-coordinate relative to _get_screens_origin() is negative, + // Godot expects a positive value. + pos.y *= -1; + return pos; +} + void DisplayServerMacOS::window_set_position(const Point2i &p_position, WindowID p_window) { _THREAD_SAFE_METHOD_ @@ -2573,7 +2594,7 @@ Size2i DisplayServerMacOS::window_get_size(WindowID p_window) const { return wd.size; } -Size2i DisplayServerMacOS::window_get_real_size(WindowID p_window) const { +Size2i DisplayServerMacOS::window_get_size_with_decorations(WindowID p_window) const { _THREAD_SAFE_METHOD_ ERR_FAIL_COND_V(!windows.has(p_window), Size2i()); diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 5e71d10a3f..49c8c7758d 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -91,11 +91,14 @@ bool EditorExportPlatformMacOS::get_export_option_visibility(const EditorExportP return false; } } break; - case 2: { // "altool" + case 2: { // "notarytool" + // All options are visible. + } break; + case 3: { // "altool" // All options are visible. } break; default: { // disabled - if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key") { + if (p_option == "notarization/apple_id_name" || p_option == "notarization/apple_id_password" || p_option == "notarization/apple_team_id" || p_option == "notarization/api_uuid" || p_option == "notarization/api_key" || p_option == "notarization/api_key_id") { return false; } } break; @@ -129,9 +132,9 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "display/high_res"), false)); #ifdef MACOS_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign,Xcode codesign"), 3, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign,Xcode codesign"), 3, true)); #else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),PyOxidizer rcodesign"), 1, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/codesign", PROPERTY_HINT_ENUM, "Disabled,Built-in (ad-hoc only),rcodesign"), 1, true)); #endif // "codesign" only options: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/identity", PROPERTY_HINT_PLACEHOLDER_TEXT, "Type: Name (ID)"), "")); @@ -165,17 +168,18 @@ void EditorExportPlatformMacOS::get_export_options(List<ExportOption> *r_options r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray())); #ifdef MACOS_ENABLED - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign,Xcode altool"), 0, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign,Xcode notarytool,Xcode altool (deprecated)"), 0, true)); #else - r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,PyOxidizer rcodesign"), 0, true)); + r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "notarization/notarization", PROPERTY_HINT_ENUM, "Disabled,rcodesign"), 0, true)); #endif - // "altool" only options: + // "altool" and "notarytool" only options: r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_name", PROPERTY_HINT_PLACEHOLDER_TEXT, "Apple ID email"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_id_password", PROPERTY_HINT_PASSWORD, "Enable two-factor authentication and provide app-specific password"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/apple_team_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide team ID if your Apple ID belongs to multiple teams"), "")); - // "altool" and "rcodesign" only options: - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID"), "")); - r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), "")); + // "altool", "notarytool" and "rcodesign" only options: + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_uuid", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect issuer ID UUID"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key", PROPERTY_HINT_GLOBAL_FILE, "*.p8"), "")); + r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "notarization/api_key_id", PROPERTY_HINT_PLACEHOLDER_TEXT, "App Store Connect API key ID"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "privacy/microphone_usage_description", PROPERTY_HINT_PLACEHOLDER_TEXT, "Provide a message if you need to use the microphone"), "")); r_options->push_back(ExportOption(PropertyInfo(Variant::DICTIONARY, "privacy/microphone_usage_description_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary())); @@ -498,7 +502,12 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres args.push_back(p_preset->get("notarization/api_uuid")); args.push_back("--api-key"); - args.push_back(p_preset->get("notarization/api_key")); + args.push_back(p_preset->get("notarization/api_key_id")); + + if (!p_preset->get("notarization/api_key").operator String().is_empty()) { + args.push_back("--api-key-path"); + args.push_back(p_preset->get("notarization/api_key")); + } args.push_back(p_path); @@ -519,7 +528,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } else { print_verbose("rcodesign (" + p_path + "):\n" + str); int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 23, -1) : str.substr(rq_offset + 23, next_nl - rq_offset - 23); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); @@ -529,7 +538,91 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } } break; #ifdef MACOS_ENABLED - case 2: { // "altool" + case 2: { // "notarytool" + print_verbose("using notarytool notarization..."); + + if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Xcode command line tools are not installed.")); + return Error::FAILED; + } + + List<String> args; + + args.push_back("notarytool"); + args.push_back("submit"); + + args.push_back(p_path); + + if (p_preset->get("notarization/apple_id_name") == "" && p_preset->get("notarization/api_uuid") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Neither Apple ID name nor App Store Connect issuer ID name not specified.")); + return Error::FAILED; + } + if (p_preset->get("notarization/apple_id_name") != "" && p_preset->get("notarization/api_uuid") != "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Both Apple ID name and App Store Connect issuer ID name are specified, only one should be set at the same time.")); + return Error::FAILED; + } + + if (p_preset->get("notarization/apple_id_name") != "") { + if (p_preset->get("notarization/apple_id_password") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("Apple ID password not specified.")); + return Error::FAILED; + } + args.push_back("--apple-id"); + args.push_back(p_preset->get("notarization/apple_id_name")); + + args.push_back("--password"); + args.push_back(p_preset->get("notarization/apple_id_password")); + } else { + if (p_preset->get("notarization/api_key_id") == "") { + add_message(EXPORT_MESSAGE_ERROR, TTR("Notarization"), TTR("App Store Connect API key ID not specified.")); + return Error::FAILED; + } + args.push_back("--issuer"); + args.push_back(p_preset->get("notarization/api_uuid")); + + if (!p_preset->get("notarization/api_key").operator String().is_empty()) { + args.push_back("--key"); + args.push_back(p_preset->get("notarization/api_key")); + } + + args.push_back("--key-id"); + args.push_back(p_preset->get("notarization/api_key_id")); + } + + args.push_back("--no-progress"); + + if (p_preset->get("notarization/apple_team_id")) { + args.push_back("--team-id"); + args.push_back(p_preset->get("notarization/apple_team_id")); + } + + String str; + int exitcode = 0; + Error err = OS::get_singleton()->execute("xcrun", args, &str, &exitcode, true); + if (err != OK) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Could not start xcrun executable.")); + return err; + } + + int rq_offset = str.find("id:"); + if (exitcode != 0 || rq_offset == -1) { + print_line("notarytool (" + p_path + "):\n" + str); + add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); + return Error::FAILED; + } else { + print_verbose("notarytool (" + p_path + "):\n" + str); + int next_nl = str.find("\n", rq_offset); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 4, -1) : str.substr(rq_offset + 4, next_nl - rq_offset - 4); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour.")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --issuer <api uuid> --key-id <api key id> --key <api key path>\" or"); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun notarytool log <request uuid> --apple-id <your email> --password <app-specific pwd>>\""); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("Run the following command to staple the notarization ticket to the exported application (optional):")); + add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t\t\"xcrun stapler staple <app path>\""); + } + } break; + case 3: { // "altool" print_verbose("using altool notarization..."); if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { @@ -573,7 +666,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres args.push_back(p_preset->get("notarization/api_uuid")); args.push_back("--apiKey"); - args.push_back(p_preset->get("notarization/api_key")); + args.push_back(p_preset->get("notarization/api_key_id")); } args.push_back("--type"); @@ -595,7 +688,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres return err; } - int rq_offset = str.find("RequestUUID"); + int rq_offset = str.find("RequestUUID:"); if (exitcode != 0 || rq_offset == -1) { print_line("xcrun altool (" + p_path + "):\n" + str); add_message(EXPORT_MESSAGE_WARNING, TTR("Notarization"), TTR("Notarization failed, see editor log for details.")); @@ -603,7 +696,7 @@ Error EditorExportPlatformMacOS::_notarize(const Ref<EditorExportPreset> &p_pres } else { print_verbose("xcrun altool (" + p_path + "):\n" + str); int next_nl = str.find("\n", rq_offset); - String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 14, -1) : str.substr(rq_offset + 14, next_nl - rq_offset - 14); + String request_uuid = (next_nl == -1) ? str.substr(rq_offset + 13, -1) : str.substr(rq_offset + 13, next_nl - rq_offset - 13); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), vformat(TTR("Notarization request UUID: \"%s\""), request_uuid)); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), TTR("The notarization process generally takes less than an hour. When the process is completed, you'll receive an email.")); add_message(EXPORT_MESSAGE_INFO, TTR("Notarization"), "\t" + TTR("You can check progress manually by opening a Terminal and running the following command:")); @@ -1819,7 +1912,7 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor err += TTR("Notarization: Code signing is required for notarization.") + "\n"; valid = false; } - if (notary_tool == 2) { + if (notary_tool == 2 || notary_tool == 3) { if (!FileAccess::exists("/usr/bin/xcrun") && !FileAccess::exists("/bin/xcrun")) { err += TTR("Notarization: Xcode command line tools are not installed.") + "\n"; valid = false; @@ -1838,7 +1931,7 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor } } if (p_preset->get("notarization/api_uuid") != "") { - if (p_preset->get("notarization/api_key") == "") { + if (p_preset->get("notarization/api_key_id") == "") { err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; valid = false; } @@ -1849,7 +1942,7 @@ bool EditorExportPlatformMacOS::has_valid_project_configuration(const Ref<Editor err += TTR("Notarization: App Store Connect issuer ID name not specified.") + "\n"; valid = false; } - if (p_preset->get("notarization/api_key") == "") { + if (p_preset->get("notarization/api_key_id") == "") { err += TTR("Notarization: App Store Connect API key ID not specified.") + "\n"; valid = false; } diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index f704124704..d057010c02 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -579,8 +579,8 @@ void DisplayServerWeb::touch_callback(int p_type, int p_count) { } } -bool DisplayServerWeb::screen_is_touchscreen(int p_screen) const { - return godot_js_display_touchscreen_is_available(); +bool DisplayServerWeb::is_touchscreen_available() const { + return godot_js_display_touchscreen_is_available() || (Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse()); } // Virtual Keyboard @@ -943,7 +943,11 @@ void DisplayServerWeb::window_set_current_screen(int p_screen, WindowID p_window } Point2i DisplayServerWeb::window_get_position(WindowID p_window) const { - return Point2i(); // TODO Does this need implementation? + return Point2i(); +} + +Point2i DisplayServerWeb::window_get_position_with_decorations(WindowID p_window) const { + return Point2i(); } void DisplayServerWeb::window_set_position(const Point2i &p_position, WindowID p_window) { @@ -980,7 +984,7 @@ Size2i DisplayServerWeb::window_get_size(WindowID p_window) const { return Size2i(size[0], size[1]); } -Size2i DisplayServerWeb::window_get_real_size(WindowID p_window) const { +Size2i DisplayServerWeb::window_get_size_with_decorations(WindowID p_window) const { return window_get_size(p_window); } diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h index 1919736802..fce98ec3d0 100644 --- a/platform/web/display_server_web.h +++ b/platform/web/display_server_web.h @@ -143,7 +143,7 @@ public: virtual Point2i mouse_get_position() const override; // touch - virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const override; + virtual bool is_touchscreen_available() const override; // clipboard virtual void clipboard_set(const String &p_text) override; @@ -182,6 +182,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; @@ -194,7 +195,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index c704a26b7a..e7864ebac0 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -909,6 +909,24 @@ Point2i DisplayServerWindows::window_get_position(WindowID p_window) const { return Point2i(point.x, point.y); } +Point2i DisplayServerWindows::window_get_position_with_decorations(WindowID p_window) const { + _THREAD_SAFE_METHOD_ + + ERR_FAIL_COND_V(!windows.has(p_window), Point2i()); + const WindowData &wd = windows[p_window]; + + if (wd.minimized) { + return wd.last_pos; + } + + RECT r; + if (GetWindowRect(wd.hWnd, &r)) { + return Point2i(r.left, r.top); + } + + return Point2i(); +} + void DisplayServerWindows::_update_real_mouse_position(WindowID p_window) { ERR_FAIL_COND(!windows.has(p_window)); @@ -1124,7 +1142,7 @@ Size2i DisplayServerWindows::window_get_size(WindowID p_window) const { return Size2(); } -Size2i DisplayServerWindows::window_get_real_size(WindowID p_window) const { +Size2i DisplayServerWindows::window_get_size_with_decorations(WindowID p_window) const { _THREAD_SAFE_METHOD_ ERR_FAIL_COND_V(!windows.has(p_window), Size2i()); @@ -2414,7 +2432,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA case WM_GETMINMAXINFO: { if (windows[window_id].resizable && !windows[window_id].fullscreen) { // Size of window decorations. - Size2 decor = window_get_real_size(window_id) - window_get_size(window_id); + Size2 decor = window_get_size_with_decorations(window_id) - window_get_size(window_id); MINMAXINFO *min_max_info = (MINMAXINFO *)lParam; if (windows[window_id].min_size != Size2()) { @@ -2473,7 +2491,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA window_mouseover_id = INVALID_WINDOW_ID; _send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT); - } else if (window_mouseover_id != INVALID_WINDOW_ID) { + } else if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) { // This is reached during drag and drop, after dropping in a different window. // Once-off notification, must call again. track_mouse_leave_event(windows[window_mouseover_id].hWnd); @@ -2712,7 +2730,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA // Mouse enter. if (mouse_mode != MOUSE_MODE_CAPTURED) { - if (window_mouseover_id != INVALID_WINDOW_ID) { + if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) { // Leave previous window. _send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT); } @@ -2814,7 +2832,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } DisplayServer::WindowID over_id = get_window_at_screen_position(mouse_get_position()); - if (!Rect2(window_get_position(over_id), Point2(windows[over_id].width, windows[over_id].height)).has_point(mouse_get_position())) { + if (windows.has(over_id) && !Rect2(window_get_position(over_id), Point2(windows[over_id].width, windows[over_id].height)).has_point(mouse_get_position())) { // Don't consider the windowborder as part of the window. over_id = INVALID_WINDOW_ID; } @@ -2822,12 +2840,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA // Mouse enter. if (mouse_mode != MOUSE_MODE_CAPTURED) { - if (window_mouseover_id != INVALID_WINDOW_ID) { + if (window_mouseover_id != INVALID_WINDOW_ID && windows.has(window_mouseover_id)) { // Leave previous window. _send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT); } - if (over_id != INVALID_WINDOW_ID) { + if (over_id != INVALID_WINDOW_ID && windows.has(over_id)) { _send_window_event(windows[over_id], WINDOW_EVENT_MOUSE_ENTER); } } @@ -3520,7 +3538,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode, DWORD dwExStyle; DWORD dwStyle; - _get_window_style(window_id_counter == MAIN_WINDOW_ID, (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN), p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN, p_flags & WINDOW_FLAG_BORDERLESS_BIT, !(p_flags & WINDOW_FLAG_RESIZE_DISABLED_BIT), p_mode == WINDOW_MODE_MAXIMIZED, (p_flags & WINDOW_FLAG_NO_FOCUS_BIT), dwStyle, dwExStyle); + _get_window_style(window_id_counter == MAIN_WINDOW_ID, (p_mode == WINDOW_MODE_FULLSCREEN || p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN), p_mode == WINDOW_MODE_EXCLUSIVE_FULLSCREEN, p_flags & WINDOW_FLAG_BORDERLESS_BIT, !(p_flags & WINDOW_FLAG_RESIZE_DISABLED_BIT), p_mode == WINDOW_MODE_MAXIMIZED, (p_flags & WINDOW_FLAG_NO_FOCUS_BIT) | (p_flags & WINDOW_FLAG_POPUP), dwStyle, dwExStyle); RECT WindowRect; diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 8ac0086d69..4702bb7765 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -555,6 +555,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_transient(WindowID p_window, WindowID p_parent) override; @@ -568,7 +569,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override; //wtf is this? should probable use proper name + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override; diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp index aa4ae01fd9..9c332123e3 100644 --- a/scene/2d/back_buffer_copy.cpp +++ b/scene/2d/back_buffer_copy.cpp @@ -71,12 +71,19 @@ Rect2 BackBufferCopy::get_rect() const { void BackBufferCopy::set_copy_mode(CopyMode p_mode) { copy_mode = p_mode; _update_copy_mode(); + notify_property_list_changed(); } BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const { return copy_mode; } +void BackBufferCopy::_validate_property(PropertyInfo &p_property) const { + if (copy_mode != COPY_MODE_RECT && p_property.name == "rect") { + p_property.usage = PROPERTY_USAGE_NO_EDITOR; + } +} + void BackBufferCopy::_bind_methods() { ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect); ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect); diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h index 1f2d5810b0..caacbc83c6 100644 --- a/scene/2d/back_buffer_copy.h +++ b/scene/2d/back_buffer_copy.h @@ -51,6 +51,7 @@ private: protected: static void _bind_methods(); + void _validate_property(PropertyInfo &p_property) const; public: #ifdef TOOLS_ENABLED diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index 4b31bbddac..229625ad6d 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -39,8 +39,11 @@ void Camera2D::_update_scroll() { } if (Engine::get_singleton()->is_editor_hint()) { - queue_redraw(); //will just be drawn - return; + queue_redraw(); + // Only set viewport transform when not bound to the main viewport. + if (get_viewport() == get_tree()->get_edited_scene_root()->get_viewport()) { + return; + } } if (!viewport) { diff --git a/scene/2d/navigation_link_2d.cpp b/scene/2d/navigation_link_2d.cpp index 3f7e10eaea..d639e1cc89 100644 --- a/scene/2d/navigation_link_2d.cpp +++ b/scene/2d/navigation_link_2d.cpp @@ -279,6 +279,8 @@ PackedStringArray NavigationLink2D::get_configuration_warnings() const { NavigationLink2D::NavigationLink2D() { link = NavigationServer2D::get_singleton()->link_create(); + NavigationServer2D::get_singleton()->link_set_owner_id(link, get_instance_id()); + set_notify_transform(true); } diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index 13d371042b..7bf3eec79b 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -634,7 +634,9 @@ void NavigationRegion2D::_bind_methods() { NavigationRegion2D::NavigationRegion2D() { set_notify_transform(true); + region = NavigationServer2D::get_singleton()->region_create(); + NavigationServer2D::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer2D::get_singleton()->region_set_enter_cost(region, get_enter_cost()); NavigationServer2D::get_singleton()->region_set_travel_cost(region, get_travel_cost()); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 0159e9f313..8b27dbe3db 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -995,9 +995,11 @@ void TileMap::_recompute_rect_cache() { } } + bool changed = rect_cache != r_total; + rect_cache = r_total; - item_rect_changed(); + item_rect_changed(changed); rect_cache_dirty = false; #endif @@ -1733,6 +1735,7 @@ void TileMap::_navigation_update_dirty_quadrants(SelfList<TileMapQuadrant>::List tile_transform.set_origin(map_to_local(E_cell)); RID region = NavigationServer2D::get_singleton()->region_create(); + NavigationServer2D::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer2D::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); NavigationServer2D::get_singleton()->region_set_transform(region, tilemap_xform * tile_transform); NavigationServer2D::get_singleton()->region_set_navpoly(region, navpoly); @@ -3838,7 +3841,7 @@ void TileMap::set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) { } } -TypedArray<Vector2i> TileMap::get_surrounding_tiles(Vector2i coords) { +TypedArray<Vector2i> TileMap::get_surrounding_cells(Vector2i coords) { if (!tile_set.is_valid()) { return TypedArray<Vector2i>(); } @@ -4012,7 +4015,7 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("force_update", "layer"), &TileMap::force_update, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("get_surrounding_tiles", "coords"), &TileMap::get_surrounding_tiles); + ClassDB::bind_method(D_METHOD("get_surrounding_cells", "coords"), &TileMap::get_surrounding_cells); ClassDB::bind_method(D_METHOD("get_used_cells", "layer"), &TileMap::get_used_cells); ClassDB::bind_method(D_METHOD("get_used_rect"), &TileMap::get_used_rect); diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 68a5d3c80b..19f0e5a553 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -400,7 +400,7 @@ public: void force_update(int p_layer = -1); // Helpers? - TypedArray<Vector2i> get_surrounding_tiles(Vector2i coords); + TypedArray<Vector2i> get_surrounding_cells(Vector2i coords); void draw_cells_outline(Control *p_control, RBSet<Vector2i> p_cells, Color p_color, Transform2D p_transform = Transform2D()); // Virtual function to modify the TileData at runtime diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index a02f322ef1..11b4718802 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -100,7 +100,7 @@ void TouchScreenButton::_notification(int p_what) { if (!is_inside_tree()) { return; } - if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { + if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { return; } @@ -137,7 +137,7 @@ void TouchScreenButton::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { + if (!Engine::get_singleton()->is_editor_hint() && !DisplayServer::get_singleton()->is_touchscreen_available() && visibility == VISIBILITY_TOUCHSCREEN_ONLY) { return; } queue_redraw(); diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 304e56326d..2a50575749 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -112,6 +112,12 @@ void Camera3D::_notification(int p_what) { if (current || first_camera) { viewport->_camera_3d_set(this); } + +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + viewport->connect(SNAME("size_changed"), callable_mp((Node3D *)this, &Camera3D::update_gizmos)); + } +#endif } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -133,6 +139,11 @@ void Camera3D::_notification(int p_what) { } if (viewport) { +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + viewport->disconnect(SNAME("size_changed"), callable_mp((Node3D *)this, &Camera3D::update_gizmos)); + } +#endif viewport->_camera_3d_remove(this); viewport = nullptr; } diff --git a/scene/3d/navigation_link_3d.cpp b/scene/3d/navigation_link_3d.cpp index 78fe4754ea..bee7c7f39b 100644 --- a/scene/3d/navigation_link_3d.cpp +++ b/scene/3d/navigation_link_3d.cpp @@ -221,6 +221,8 @@ void NavigationLink3D::_notification(int p_what) { NavigationLink3D::NavigationLink3D() { link = NavigationServer3D::get_singleton()->link_create(); + NavigationServer3D::get_singleton()->link_set_owner_id(link, get_instance_id()); + set_notify_transform(true); } diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index 06182d921c..bd96c55512 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -339,7 +339,9 @@ void NavigationRegion3D::_navigation_map_changed(RID p_map) { NavigationRegion3D::NavigationRegion3D() { set_notify_transform(true); + region = NavigationServer3D::get_singleton()->region_create(); + NavigationServer3D::get_singleton()->region_set_owner_id(region, get_instance_id()); NavigationServer3D::get_singleton()->region_set_enter_cost(region, get_enter_cost()); NavigationServer3D::get_singleton()->region_set_travel_cost(region, get_travel_cost()); diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 1327bdd6e9..a60ccd2169 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -188,7 +188,7 @@ void Node3D::_notification(int p_what) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) { - get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this); + get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id()); } #endif } break; @@ -482,7 +482,7 @@ void Node3D::update_gizmos() { } if (data.gizmos.is_empty()) { - get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this); + get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id()); return; } if (data.gizmos_dirty) { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index f7baa7facc..cc6fadd9b2 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -956,8 +956,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double } if (player->is_playing()) { - player->play(anim_name); player->seek(at_anim_pos); + player->play(anim_name); nc->animation_playing = true; playing_caches.insert(nc); } else { @@ -985,8 +985,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double nc->animation_playing = false; } } else { + player->seek(0.0); player->play(anim_name); - player->seek(0.0, true); nc->animation_playing = true; playing_caches.insert(nc); } @@ -1001,6 +1001,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta, float p_blend, bool p_seeked, bool p_started) { double delta = p_delta * speed_scale * cd.speed_scale; double next_pos = cd.pos + delta; + bool backwards = signbit(delta); // Negative zero means playing backwards too. real_t len = cd.from->animation->get_length(); Animation::LoopedFlag looped_flag = Animation::LOOPED_FLAG_NONE; @@ -1012,23 +1013,7 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta, } else if (next_pos > len) { next_pos = len; } - - bool backwards = signbit(delta); // Negative zero means playing backwards too - delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here) - - if (&cd == &playback.current) { - if (!backwards && cd.pos <= len && next_pos == len) { - //playback finished - end_reached = true; - end_notify = cd.pos < len; // Notify only if not already at the end - } - - if (backwards && cd.pos >= 0 && next_pos == 0) { - //playback finished - end_reached = true; - end_notify = cd.pos > 0; // Notify only if not already at the beginning - } - } + delta = next_pos - cd.pos; // Fix delta (after determination of backwards because negative zero is lost here). } break; case Animation::LOOP_LINEAR: { @@ -1057,8 +1042,28 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, double p_delta, break; } - _animation_process_animation(cd.from, cd.pos, next_pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started, looped_flag); + double prev_pos = cd.pos; // The animation may be changed during process, so it is safer that the state is changed before process. cd.pos = next_pos; + + AnimationData *prev_from = cd.from; + _animation_process_animation(cd.from, prev_pos, cd.pos, delta, p_blend, &cd == &playback.current, p_seeked, p_started, looped_flag); + + // End detection. + if (cd.from->animation->get_loop_mode() == Animation::LOOP_NONE) { + if (prev_from != playback.current.from) { + return; // Animation has been changed in the process (may be caused by method track), abort process. + } + if (!backwards && prev_pos <= len && next_pos == len) { + // Playback finished. + end_reached = true; + end_notify = prev_pos < len; // Notify only if not already at the end. + } + if (backwards && prev_pos >= 0 && next_pos == 0) { + // Playback finished. + end_reached = true; + end_notify = prev_pos > 0; // Notify only if not already at the beginning. + } + } } void AnimationPlayer::_animation_process2(double p_delta, bool p_started) { @@ -1066,23 +1071,25 @@ void AnimationPlayer::_animation_process2(double p_delta, bool p_started) { accum_pass++; - _animation_process_data(c.current, p_delta, 1.0f, c.seeked, p_started); + bool seeked = c.seeked; // The animation may be changed during process, so it is safer that the state is changed before process. if (p_delta != 0) { c.seeked = false; } + _animation_process_data(c.current, p_delta, 1.0f, seeked, p_started); + List<Blend>::Element *prev = nullptr; for (List<Blend>::Element *E = c.blend.back(); E; E = prev) { Blend &b = E->get(); float blend = b.blend_left / b.blend_time; - _animation_process_data(b.data, p_delta, blend, false, false); - b.blend_left -= Math::absf(speed_scale * p_delta); - prev = E->prev(); if (b.blend_left < 0) { c.blend.erase(E); } + // The effect of animation changes during blending is unknown... + // In that case, we recommends to use method call mode "deferred", not "immediate". + _animation_process_data(b.data, p_delta, blend, false, false); } } @@ -1123,8 +1130,6 @@ void AnimationPlayer::_animation_update_transforms() { } } - cache_update_size = 0; - for (int i = 0; i < cache_update_prop_size; i++) { TrackNodeCache::PropertyAnim *pa = cache_update_prop[i]; @@ -1186,29 +1191,35 @@ void AnimationPlayer::_animation_update_transforms() { } } - cache_update_prop_size = 0; - for (int i = 0; i < cache_update_bezier_size; i++) { TrackNodeCache::BezierAnim *ba = cache_update_bezier[i]; ERR_CONTINUE(ba->accum_pass != accum_pass); ba->object->set_indexed(ba->bezier_property, ba->bezier_accum); } - - cache_update_bezier_size = 0; } void AnimationPlayer::_animation_process(double p_delta) { if (playback.current.from) { end_reached = false; end_notify = false; - _animation_process2(p_delta, playback.started); + bool started = playback.started; // The animation may be changed during process, so it is safer that the state is changed before process. if (playback.started) { playback.started = false; } + cache_update_size = 0; + cache_update_prop_size = 0; + cache_update_bezier_size = 0; + + AnimationData *prev_from = playback.current.from; + _animation_process2(p_delta, started); + if (prev_from != playback.current.from) { + return; // Animation has been changed in the process (may be caused by method track), abort process. + } _animation_update_transforms(); + if (end_reached) { if (queued.size()) { String old = playback.assigned; @@ -2060,7 +2071,7 @@ Ref<AnimatedValuesBackup> AnimationPlayer::apply_reset(bool p_user_initiated) { old_values->restore(); Ref<EditorUndoRedoManager> &ur = EditorNode::get_undo_redo(); - ur->create_action(TTR("Anim Apply Reset")); + ur->create_action(TTR("Animation Apply Reset")); ur->add_do_method(new_values.ptr(), "restore"); ur->add_undo_method(old_values.ptr(), "restore"); ur->commit_action(); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index bd9b918900..fbc85bd5e1 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -1031,7 +1031,9 @@ void AnimationTree::_process_graph(double p_delta) { } NodePath path = a->track_get_path(i); - ERR_CONTINUE(!track_cache.has(path)); + if (!track_cache.has(path)) { + continue; // No path, but avoid error spamming. + } TrackCache *track = track_cache[path]; ERR_CONTINUE(!state.track_map.has(path)); @@ -1582,8 +1584,8 @@ void AnimationTree::_process_graph(double p_delta) { } if (player2->is_playing() || seeked) { - player2->play(anim_name); player2->seek(at_anim_pos); + player2->play(anim_name); t->playing = true; playing_caches.insert(t); } else { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index e90a6a69ab..50ffc0509c 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -257,36 +257,36 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) { if (name.begins_with("theme_override_icons/")) { String dname = name.get_slicec('/', 1); - if (data.icon_override.has(dname)) { - data.icon_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_icon_override.has(dname)) { + data.theme_icon_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.icon_override.erase(dname); + data.theme_icon_override.erase(dname); _notify_theme_override_changed(); } else if (name.begins_with("theme_override_styles/")) { String dname = name.get_slicec('/', 1); - if (data.style_override.has(dname)) { - data.style_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_style_override.has(dname)) { + data.theme_style_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.style_override.erase(dname); + data.theme_style_override.erase(dname); _notify_theme_override_changed(); } else if (name.begins_with("theme_override_fonts/")) { String dname = name.get_slicec('/', 1); - if (data.font_override.has(dname)) { - data.font_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_font_override.has(dname)) { + data.theme_font_override[dname]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.font_override.erase(dname); + data.theme_font_override.erase(dname); _notify_theme_override_changed(); } else if (name.begins_with("theme_override_font_sizes/")) { String dname = name.get_slicec('/', 1); - data.font_size_override.erase(dname); + data.theme_font_size_override.erase(dname); _notify_theme_override_changed(); } else if (name.begins_with("theme_override_colors/")) { String dname = name.get_slicec('/', 1); - data.color_override.erase(dname); + data.theme_color_override.erase(dname); _notify_theme_override_changed(); } else if (name.begins_with("theme_override_constants/")) { String dname = name.get_slicec('/', 1); - data.constant_override.erase(dname); + data.theme_constant_override.erase(dname); _notify_theme_override_changed(); } else { return false; @@ -326,22 +326,22 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const { if (sname.begins_with("theme_override_icons/")) { String name = sname.get_slicec('/', 1); - r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant(); + r_ret = data.theme_icon_override.has(name) ? Variant(data.theme_icon_override[name]) : Variant(); } else if (sname.begins_with("theme_override_styles/")) { String name = sname.get_slicec('/', 1); - r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant(); + r_ret = data.theme_style_override.has(name) ? Variant(data.theme_style_override[name]) : Variant(); } else if (sname.begins_with("theme_override_fonts/")) { String name = sname.get_slicec('/', 1); - r_ret = data.font_override.has(name) ? Variant(data.font_override[name]) : Variant(); + r_ret = data.theme_font_override.has(name) ? Variant(data.theme_font_override[name]) : Variant(); } else if (sname.begins_with("theme_override_font_sizes/")) { String name = sname.get_slicec('/', 1); - r_ret = data.font_size_override.has(name) ? Variant(data.font_size_override[name]) : Variant(); + r_ret = data.theme_font_size_override.has(name) ? Variant(data.theme_font_size_override[name]) : Variant(); } else if (sname.begins_with("theme_override_colors/")) { String name = sname.get_slicec('/', 1); - r_ret = data.color_override.has(name) ? Variant(data.color_override[name]) : Variant(); + r_ret = data.theme_color_override.has(name) ? Variant(data.theme_color_override[name]) : Variant(); } else if (sname.begins_with("theme_override_constants/")) { String name = sname.get_slicec('/', 1); - r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant(); + r_ret = data.theme_constant_override.has(name) ? Variant(data.theme_constant_override[name]) : Variant(); } else { return false; } @@ -350,16 +350,16 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const { } void Control::_get_property_list(List<PropertyInfo> *p_list) const { - Ref<Theme> theme = ThemeDB::get_singleton()->get_default_theme(); + Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme(); p_list->push_back(PropertyInfo(Variant::NIL, TTRC("Theme Overrides"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP)); { List<StringName> names; - theme->get_color_list(get_class_name(), &names); + default_theme->get_color_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.color_override.has(E)) { + if (data.theme_color_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -368,10 +368,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } { List<StringName> names; - theme->get_constant_list(get_class_name(), &names); + default_theme->get_constant_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.constant_override.has(E)) { + if (data.theme_constant_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -380,10 +380,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } { List<StringName> names; - theme->get_font_list(get_class_name(), &names); + default_theme->get_font_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.font_override.has(E)) { + if (data.theme_font_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -392,10 +392,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } { List<StringName> names; - theme->get_font_size_list(get_class_name(), &names); + default_theme->get_font_size_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.font_size_override.has(E)) { + if (data.theme_font_size_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -404,10 +404,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } { List<StringName> names; - theme->get_icon_list(get_class_name(), &names); + default_theme->get_icon_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.icon_override.has(E)) { + if (data.theme_icon_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -416,10 +416,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } { List<StringName> names; - theme->get_stylebox_list(get_class_name(), &names); + default_theme->get_stylebox_list(get_class_name(), &names); for (const StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.style_override.has(E)) { + if (data.theme_style_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } @@ -2381,7 +2381,7 @@ StringName Control::get_theme_type_variation() const { Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); + const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name); if (tex) { return *tex; } @@ -2400,7 +2400,7 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const Ref<StyleBox> *style = data.style_override.getptr(p_name); + const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name); if (style) { return *style; } @@ -2419,7 +2419,7 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const Ref<Font> *font = data.font_override.getptr(p_name); + const Ref<Font> *font = data.theme_font_override.getptr(p_name); if (font) { return *font; } @@ -2438,7 +2438,7 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const int *font_size = data.font_size_override.getptr(p_name); + const int *font_size = data.theme_font_size_override.getptr(p_name); if (font_size && (*font_size) > 0) { return *font_size; } @@ -2457,7 +2457,7 @@ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_t Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const Color *color = data.color_override.getptr(p_name); + const Color *color = data.theme_color_override.getptr(p_name); if (color) { return *color; } @@ -2476,7 +2476,7 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_the int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { - const int *constant = data.constant_override.getptr(p_name); + const int *constant = data.theme_constant_override.getptr(p_name); if (constant) { return *constant; } @@ -2570,123 +2570,123 @@ bool Control::has_theme_constant(const StringName &p_name, const StringName &p_t void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { ERR_FAIL_COND(!p_icon.is_valid()); - if (data.icon_override.has(p_name)) { - data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_icon_override.has(p_name)) { + data.theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.icon_override[p_name] = p_icon; - data.icon_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + data.theme_icon_override[p_name] = p_icon; + data.theme_icon_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); _notify_theme_override_changed(); } void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { ERR_FAIL_COND(!p_style.is_valid()); - if (data.style_override.has(p_name)) { - data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_style_override.has(p_name)) { + data.theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.style_override[p_name] = p_style; - data.style_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + data.theme_style_override[p_name] = p_style; + data.theme_style_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); _notify_theme_override_changed(); } void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { ERR_FAIL_COND(!p_font.is_valid()); - if (data.font_override.has(p_name)) { - data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_font_override.has(p_name)) { + data.theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.font_override[p_name] = p_font; - data.font_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + data.theme_font_override[p_name] = p_font; + data.theme_font_override[p_name]->connect("changed", callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); _notify_theme_override_changed(); } void Control::add_theme_font_size_override(const StringName &p_name, int p_font_size) { - data.font_size_override[p_name] = p_font_size; + data.theme_font_size_override[p_name] = p_font_size; _notify_theme_override_changed(); } void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { - data.color_override[p_name] = p_color; + data.theme_color_override[p_name] = p_color; _notify_theme_override_changed(); } void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { - data.constant_override[p_name] = p_constant; + data.theme_constant_override[p_name] = p_constant; _notify_theme_override_changed(); } void Control::remove_theme_icon_override(const StringName &p_name) { - if (data.icon_override.has(p_name)) { - data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_icon_override.has(p_name)) { + data.theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.icon_override.erase(p_name); + data.theme_icon_override.erase(p_name); _notify_theme_override_changed(); } void Control::remove_theme_style_override(const StringName &p_name) { - if (data.style_override.has(p_name)) { - data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_style_override.has(p_name)) { + data.theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.style_override.erase(p_name); + data.theme_style_override.erase(p_name); _notify_theme_override_changed(); } void Control::remove_theme_font_override(const StringName &p_name) { - if (data.font_override.has(p_name)) { - data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); + if (data.theme_font_override.has(p_name)) { + data.theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - data.font_override.erase(p_name); + data.theme_font_override.erase(p_name); _notify_theme_override_changed(); } void Control::remove_theme_font_size_override(const StringName &p_name) { - data.font_size_override.erase(p_name); + data.theme_font_size_override.erase(p_name); _notify_theme_override_changed(); } void Control::remove_theme_color_override(const StringName &p_name) { - data.color_override.erase(p_name); + data.theme_color_override.erase(p_name); _notify_theme_override_changed(); } void Control::remove_theme_constant_override(const StringName &p_name) { - data.constant_override.erase(p_name); + data.theme_constant_override.erase(p_name); _notify_theme_override_changed(); } bool Control::has_theme_icon_override(const StringName &p_name) const { - const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); + const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name); return tex != nullptr; } bool Control::has_theme_stylebox_override(const StringName &p_name) const { - const Ref<StyleBox> *style = data.style_override.getptr(p_name); + const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name); return style != nullptr; } bool Control::has_theme_font_override(const StringName &p_name) const { - const Ref<Font> *font = data.font_override.getptr(p_name); + const Ref<Font> *font = data.theme_font_override.getptr(p_name); return font != nullptr; } bool Control::has_theme_font_size_override(const StringName &p_name) const { - const int *font_size = data.font_size_override.getptr(p_name); + const int *font_size = data.theme_font_size_override.getptr(p_name); return font_size != nullptr; } bool Control::has_theme_color_override(const StringName &p_name) const { - const Color *color = data.color_override.getptr(p_name); + const Color *color = data.theme_color_override.getptr(p_name); return color != nullptr; } bool Control::has_theme_constant_override(const StringName &p_name) const { - const int *constant = data.constant_override.getptr(p_name); + const int *constant = data.theme_constant_override.getptr(p_name); return constant != nullptr; } @@ -3359,21 +3359,21 @@ Control::~Control() { memdelete(data.theme_owner); // Resources need to be disconnected. - for (KeyValue<StringName, Ref<Texture2D>> &E : data.icon_override) { + for (KeyValue<StringName, Ref<Texture2D>> &E : data.theme_icon_override) { E.value->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - for (KeyValue<StringName, Ref<StyleBox>> &E : data.style_override) { + for (KeyValue<StringName, Ref<StyleBox>> &E : data.theme_style_override) { E.value->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } - for (KeyValue<StringName, Ref<Font>> &E : data.font_override) { + for (KeyValue<StringName, Ref<Font>> &E : data.theme_font_override) { E.value->disconnect("changed", callable_mp(this, &Control::_notify_theme_override_changed)); } // Then override maps can be simply cleared. - data.icon_override.clear(); - data.style_override.clear(); - data.font_override.clear(); - data.font_size_override.clear(); - data.color_override.clear(); - data.constant_override.clear(); + data.theme_icon_override.clear(); + data.theme_style_override.clear(); + data.theme_font_override.clear(); + data.theme_font_size_override.clear(); + data.theme_color_override.clear(); + data.theme_constant_override.clear(); } diff --git a/scene/gui/control.h b/scene/gui/control.h index 3e9bb48a4a..12710f3a93 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -228,12 +228,12 @@ private: StringName theme_type_variation; bool bulk_theme_override = false; - Theme::ThemeIconMap icon_override; - Theme::ThemeStyleMap style_override; - Theme::ThemeFontMap font_override; - Theme::ThemeFontSizeMap font_size_override; - Theme::ThemeColorMap color_override; - Theme::ThemeConstantMap constant_override; + Theme::ThemeIconMap theme_icon_override; + Theme::ThemeStyleMap theme_style_override; + Theme::ThemeFontMap theme_font_override; + Theme::ThemeFontSizeMap theme_font_size_override; + Theme::ThemeColorMap theme_color_override; + Theme::ThemeConstantMap theme_constant_override; mutable HashMap<StringName, Theme::ThemeIconMap> theme_icon_cache; mutable HashMap<StringName, Theme::ThemeStyleMap> theme_style_cache; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index ab74979777..5d8e106e26 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -221,7 +221,7 @@ void PopupMenu::_activate_submenu(int p_over, bool p_by_keyboard) { Rect2 safe_area = this_rect; safe_area.position.y += items[p_over]._ofs_cache + scroll_offset + theme_cache.panel_style->get_offset().height - theme_cache.v_separation / 2; - safe_area.size.y = items[p_over]._height_cache; + safe_area.size.y = items[p_over]._height_cache + theme_cache.v_separation; DisplayServer::get_singleton()->window_set_popup_safe_rect(submenu_popup->get_window_id(), safe_area); // Make the position of the parent popup relative to submenu popup. diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h index 66b8a21760..886442bc80 100644 --- a/scene/gui/rich_text_effect.h +++ b/scene/gui/rich_text_effect.h @@ -79,7 +79,7 @@ public: uint32_t get_glyph_index() const { return glyph_index; }; void set_glyph_index(uint32_t p_glyph_index) { glyph_index = p_glyph_index; }; - uint16_t get_glyph_flags() const { return glyph_index; }; + uint16_t get_glyph_flags() const { return glyph_flags; }; void set_glyph_flags(uint16_t p_glyph_flags) { glyph_flags = p_glyph_flags; }; uint8_t get_glyph_count() const { return glyph_count; }; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 60d107cce6..f26e05518e 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1854,10 +1854,6 @@ void RichTextLabel::_notification(int p_what) { } Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const { - if (!underline_meta) { - return get_default_cursor_shape(); - } - if (selection.click_item) { return CURSOR_IBEAM; } diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 6899178885..a44ddff507 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -550,7 +550,7 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { drag_node_accum = Vector2(); last_drag_node_accum = Vector2(); drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0); - drag_node_touching = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); + drag_node_touching = DisplayServer::get_singleton()->is_touchscreen_available(); drag_node_touching_deaccel = false; time_since_motion = 0; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 531226f938..73d30b7568 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -164,8 +164,8 @@ void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) { } } - bool screen_is_touchscreen = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); - if (!screen_is_touchscreen) { + bool is_touchscreen_available = DisplayServer::get_singleton()->is_touchscreen_available(); + if (!is_touchscreen_available) { return; } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index c0990211aa..35cc29d080 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2471,6 +2471,8 @@ bool Tree::_is_sibling_branch_selected(TreeItem *p_from) const { } void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev, bool *r_in_range, bool p_force_deselect) { + popup_editor->hide(); + TreeItem::Cell &selected_cell = p_selected->cells.write[p_col]; bool switched = false; @@ -3671,7 +3673,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) { drag_accum = 0; //last_drag_accum=0; drag_from = v_scroll->get_value(); - drag_touching = DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())); + drag_touching = DisplayServer::get_singleton()->is_touchscreen_available(); drag_touching_deaccel = false; if (drag_touching) { set_physics_process_internal(true); @@ -4216,7 +4218,9 @@ Tree::SelectMode Tree::get_select_mode() const { void Tree::deselect_all() { TreeItem *item = get_next_selected(get_root()); while (item) { - item->deselect(selected_col); + for (int i = 0; i < columns.size(); i++) { + item->deselect(i); + } TreeItem *prev_item = item; item = get_next_selected(get_root()); ERR_FAIL_COND(item == prev_item); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index aff2c594d9..c71c3e195b 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -40,6 +40,218 @@ #include "scene/theme/theme_db.h" #include "scene/theme/theme_owner.h" +// Dynamic properties. + +bool Window::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + if (!name.begins_with("theme_override")) { + return false; + } + + if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) { + if (name.begins_with("theme_override_icons/")) { + String dname = name.get_slicec('/', 1); + if (theme_icon_override.has(dname)) { + theme_icon_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + theme_icon_override.erase(dname); + _notify_theme_override_changed(); + } else if (name.begins_with("theme_override_styles/")) { + String dname = name.get_slicec('/', 1); + if (theme_style_override.has(dname)) { + theme_style_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + theme_style_override.erase(dname); + _notify_theme_override_changed(); + } else if (name.begins_with("theme_override_fonts/")) { + String dname = name.get_slicec('/', 1); + if (theme_font_override.has(dname)) { + theme_font_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + theme_font_override.erase(dname); + _notify_theme_override_changed(); + } else if (name.begins_with("theme_override_font_sizes/")) { + String dname = name.get_slicec('/', 1); + theme_font_size_override.erase(dname); + _notify_theme_override_changed(); + } else if (name.begins_with("theme_override_colors/")) { + String dname = name.get_slicec('/', 1); + theme_color_override.erase(dname); + _notify_theme_override_changed(); + } else if (name.begins_with("theme_override_constants/")) { + String dname = name.get_slicec('/', 1); + theme_constant_override.erase(dname); + _notify_theme_override_changed(); + } else { + return false; + } + + } else { + if (name.begins_with("theme_override_icons/")) { + String dname = name.get_slicec('/', 1); + add_theme_icon_override(dname, p_value); + } else if (name.begins_with("theme_override_styles/")) { + String dname = name.get_slicec('/', 1); + add_theme_style_override(dname, p_value); + } else if (name.begins_with("theme_override_fonts/")) { + String dname = name.get_slicec('/', 1); + add_theme_font_override(dname, p_value); + } else if (name.begins_with("theme_override_font_sizes/")) { + String dname = name.get_slicec('/', 1); + add_theme_font_size_override(dname, p_value); + } else if (name.begins_with("theme_override_colors/")) { + String dname = name.get_slicec('/', 1); + add_theme_color_override(dname, p_value); + } else if (name.begins_with("theme_override_constants/")) { + String dname = name.get_slicec('/', 1); + add_theme_constant_override(dname, p_value); + } else { + return false; + } + } + return true; +} + +bool Window::_get(const StringName &p_name, Variant &r_ret) const { + String sname = p_name; + if (!sname.begins_with("theme_override")) { + return false; + } + + if (sname.begins_with("theme_override_icons/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_icon_override.has(name) ? Variant(theme_icon_override[name]) : Variant(); + } else if (sname.begins_with("theme_override_styles/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_style_override.has(name) ? Variant(theme_style_override[name]) : Variant(); + } else if (sname.begins_with("theme_override_fonts/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_font_override.has(name) ? Variant(theme_font_override[name]) : Variant(); + } else if (sname.begins_with("theme_override_font_sizes/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_font_size_override.has(name) ? Variant(theme_font_size_override[name]) : Variant(); + } else if (sname.begins_with("theme_override_colors/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_color_override.has(name) ? Variant(theme_color_override[name]) : Variant(); + } else if (sname.begins_with("theme_override_constants/")) { + String name = sname.get_slicec('/', 1); + r_ret = theme_constant_override.has(name) ? Variant(theme_constant_override[name]) : Variant(); + } else { + return false; + } + + return true; +} + +void Window::_get_property_list(List<PropertyInfo> *p_list) const { + Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme(); + + p_list->push_back(PropertyInfo(Variant::NIL, TTRC("Theme Overrides"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP)); + + { + List<StringName> names; + default_theme->get_color_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_color_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::COLOR, "theme_override_colors/" + E, PROPERTY_HINT_NONE, "", usage)); + } + } + { + List<StringName> names; + default_theme->get_constant_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_constant_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::INT, "theme_override_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage)); + } + } + { + List<StringName> names; + default_theme->get_font_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_font_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); + } + } + { + List<StringName> names; + default_theme->get_font_size_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_font_size_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::INT, "theme_override_font_sizes/" + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage)); + } + } + { + List<StringName> names; + default_theme->get_icon_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_icon_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); + } + } + { + List<StringName> names; + default_theme->get_stylebox_list(get_class_name(), &names); + for (const StringName &E : names) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; + if (theme_style_override.has(E)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + + p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); + } + } +} + +void Window::_validate_property(PropertyInfo &p_property) const { + if (p_property.name == "theme_type_variation") { + List<StringName> names; + + // Only the default theme and the project theme are used for the list of options. + // This is an imposed limitation to simplify the logic needed to leverage those options. + ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names); + if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { + ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names); + } + names.sort_custom<StringName::AlphCompare>(); + + Vector<StringName> unique_names; + String hint_string; + for (const StringName &E : names) { + // Skip duplicate values. + if (unique_names.has(E)) { + continue; + } + + hint_string += String(E) + ","; + unique_names.append(E); + } + + p_property.hint_string = hint_string; + } +} + +// + void Window::set_title(const String &p_title) { title = p_title; @@ -106,9 +318,16 @@ void Window::reset_size() { set_size(Size2i()); } -Size2i Window::get_real_size() const { +Point2i Window::get_position_with_decorations() const { + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + return DisplayServer::get_singleton()->window_get_position_with_decorations(window_id); + } + return position; +} + +Size2i Window::get_size_with_decorations() const { if (window_id != DisplayServer::INVALID_WINDOW_ID) { - return DisplayServer::get_singleton()->window_get_real_size(window_id); + return DisplayServer::get_singleton()->window_get_size_with_decorations(window_id); } return size; } @@ -1316,6 +1535,8 @@ void Window::remove_child_notify(Node *p_child) { } } +// Theming. + void Window::set_theme_owner_node(Node *p_node) { theme_owner->set_owner_node(p_node); } @@ -1369,6 +1590,12 @@ void Window::_theme_changed() { } } +void Window::_notify_theme_override_changed() { + if (!bulk_theme_override && is_inside_tree()) { + notification(NOTIFICATION_THEME_CHANGED); + } +} + void Window::_invalidate_theme_cache() { theme_icon_cache.clear(); theme_style_cache.clear(); @@ -1379,6 +1606,9 @@ void Window::_invalidate_theme_cache() { } void Window::_update_theme_item_cache() { + // Request an update on the next frame to reflect theme changes. + // Updating without a delay can cause a lot of lag. + child_controls_changed(); } void Window::set_theme_type_variation(const StringName &p_theme_type) { @@ -1392,7 +1622,16 @@ StringName Window::get_theme_type_variation() const { return theme_type_variation; } +/// Theme property lookup. + Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name); + if (tex) { + return *tex; + } + } + if (theme_icon_cache.has(p_theme_type) && theme_icon_cache[p_theme_type].has(p_name)) { return theme_icon_cache[p_theme_type][p_name]; } @@ -1405,6 +1644,13 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName } Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const Ref<StyleBox> *style = theme_style_override.getptr(p_name); + if (style) { + return *style; + } + } + if (theme_style_cache.has(p_theme_type) && theme_style_cache[p_theme_type].has(p_name)) { return theme_style_cache[p_theme_type][p_name]; } @@ -1417,6 +1663,13 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN } Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const Ref<Font> *font = theme_font_override.getptr(p_name); + if (font) { + return *font; + } + } + if (theme_font_cache.has(p_theme_type) && theme_font_cache[p_theme_type].has(p_name)) { return theme_font_cache[p_theme_type][p_name]; } @@ -1429,6 +1682,13 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t } int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const int *font_size = theme_font_size_override.getptr(p_name); + if (font_size && (*font_size) > 0) { + return *font_size; + } + } + if (theme_font_size_cache.has(p_theme_type) && theme_font_size_cache[p_theme_type].has(p_name)) { return theme_font_size_cache[p_theme_type][p_name]; } @@ -1441,6 +1701,13 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th } Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const Color *color = theme_color_override.getptr(p_name); + if (color) { + return *color; + } + } + if (theme_color_cache.has(p_theme_type) && theme_color_cache[p_theme_type].has(p_name)) { return theme_color_cache[p_theme_type][p_name]; } @@ -1453,6 +1720,13 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them } int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + const int *constant = theme_constant_override.getptr(p_name); + if (constant) { + return *constant; + } + } + if (theme_constant_cache.has(p_theme_type) && theme_constant_cache[p_theme_type].has(p_name)) { return theme_constant_cache[p_theme_type][p_name]; } @@ -1465,41 +1739,204 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the } bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_icon_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types); } bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_stylebox_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types); } bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_font_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types); } bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_font_size_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types); } bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_color_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types); } bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { + if (has_theme_constant_override(p_name)) { + return true; + } + } + List<StringName> theme_types; theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types); return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types); } +/// Local property overrides. + +void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { + ERR_FAIL_COND(!p_icon.is_valid()); + + if (theme_icon_override.has(p_name)) { + theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_icon_override[p_name] = p_icon; + theme_icon_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + _notify_theme_override_changed(); +} + +void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { + ERR_FAIL_COND(!p_style.is_valid()); + + if (theme_style_override.has(p_name)) { + theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_style_override[p_name] = p_style; + theme_style_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + _notify_theme_override_changed(); +} + +void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { + ERR_FAIL_COND(!p_font.is_valid()); + + if (theme_font_override.has(p_name)) { + theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_font_override[p_name] = p_font; + theme_font_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); + _notify_theme_override_changed(); +} + +void Window::add_theme_font_size_override(const StringName &p_name, int p_font_size) { + theme_font_size_override[p_name] = p_font_size; + _notify_theme_override_changed(); +} + +void Window::add_theme_color_override(const StringName &p_name, const Color &p_color) { + theme_color_override[p_name] = p_color; + _notify_theme_override_changed(); +} + +void Window::add_theme_constant_override(const StringName &p_name, int p_constant) { + theme_constant_override[p_name] = p_constant; + _notify_theme_override_changed(); +} + +void Window::remove_theme_icon_override(const StringName &p_name) { + if (theme_icon_override.has(p_name)) { + theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_icon_override.erase(p_name); + _notify_theme_override_changed(); +} + +void Window::remove_theme_style_override(const StringName &p_name) { + if (theme_style_override.has(p_name)) { + theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_style_override.erase(p_name); + _notify_theme_override_changed(); +} + +void Window::remove_theme_font_override(const StringName &p_name) { + if (theme_font_override.has(p_name)) { + theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + theme_font_override.erase(p_name); + _notify_theme_override_changed(); +} + +void Window::remove_theme_font_size_override(const StringName &p_name) { + theme_font_size_override.erase(p_name); + _notify_theme_override_changed(); +} + +void Window::remove_theme_color_override(const StringName &p_name) { + theme_color_override.erase(p_name); + _notify_theme_override_changed(); +} + +void Window::remove_theme_constant_override(const StringName &p_name) { + theme_constant_override.erase(p_name); + _notify_theme_override_changed(); +} + +bool Window::has_theme_icon_override(const StringName &p_name) const { + const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name); + return tex != nullptr; +} + +bool Window::has_theme_stylebox_override(const StringName &p_name) const { + const Ref<StyleBox> *style = theme_style_override.getptr(p_name); + return style != nullptr; +} + +bool Window::has_theme_font_override(const StringName &p_name) const { + const Ref<Font> *font = theme_font_override.getptr(p_name); + return font != nullptr; +} + +bool Window::has_theme_font_size_override(const StringName &p_name) const { + const int *font_size = theme_font_size_override.getptr(p_name); + return font_size != nullptr; +} + +bool Window::has_theme_color_override(const StringName &p_name) const { + const Color *color = theme_color_override.getptr(p_name); + return color != nullptr; +} + +bool Window::has_theme_constant_override(const StringName &p_name) const { + const int *constant = theme_constant_override.getptr(p_name); + return constant != nullptr; +} + +/// Default theme properties. + float Window::get_theme_default_base_scale() const { return theme_owner->get_theme_default_base_scale(); } @@ -1512,6 +1949,21 @@ int Window::get_theme_default_font_size() const { return theme_owner->get_theme_default_font_size(); } +/// Bulk actions. + +void Window::begin_bulk_theme_override() { + bulk_theme_override = true; +} + +void Window::end_bulk_theme_override() { + ERR_FAIL_COND(!bulk_theme_override); + + bulk_theme_override = false; + _notify_theme_override_changed(); +} + +// + Rect2i Window::get_parent_rect() const { ERR_FAIL_COND_V(!is_inside_tree(), Rect2i()); if (is_embedded()) { @@ -1604,34 +2056,6 @@ bool Window::is_auto_translating() const { return auto_translate; } -void Window::_validate_property(PropertyInfo &p_property) const { - if (p_property.name == "theme_type_variation") { - List<StringName> names; - - // Only the default theme and the project theme are used for the list of options. - // This is an imposed limitation to simplify the logic needed to leverage those options. - ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names); - if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { - ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names); - } - names.sort_custom<StringName::AlphCompare>(); - - Vector<StringName> unique_names; - String hint_string; - for (const StringName &E : names) { - // Skip duplicate values. - if (unique_names.has(E)) { - continue; - } - - hint_string += String(E) + ","; - unique_names.append(E); - } - - p_property.hint_string = hint_string; - } -} - Transform2D Window::get_screen_transform() const { Transform2D embedder_transform; if (_get_embedder()) { @@ -1655,7 +2079,8 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("get_size"), &Window::get_size); ClassDB::bind_method(D_METHOD("reset_size"), &Window::reset_size); - ClassDB::bind_method(D_METHOD("get_real_size"), &Window::get_real_size); + ClassDB::bind_method(D_METHOD("get_position_with_decorations"), &Window::get_position_with_decorations); + ClassDB::bind_method(D_METHOD("get_size_with_decorations"), &Window::get_size_with_decorations); ClassDB::bind_method(D_METHOD("set_max_size", "max_size"), &Window::set_max_size); ClassDB::bind_method(D_METHOD("get_max_size"), &Window::get_max_size); @@ -1725,6 +2150,23 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Window::set_theme_type_variation); ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Window::get_theme_type_variation); + ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Window::begin_bulk_theme_override); + ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Window::end_bulk_theme_override); + + ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Window::add_theme_icon_override); + ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Window::add_theme_style_override); + ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Window::add_theme_font_override); + ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Window::add_theme_font_size_override); + ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Window::add_theme_color_override); + ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Window::add_theme_constant_override); + + ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Window::remove_theme_icon_override); + ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Window::remove_theme_style_override); + ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Window::remove_theme_font_override); + ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Window::remove_theme_font_size_override); + ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Window::remove_theme_color_override); + ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Window::remove_theme_constant_override); + ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Window::get_theme_icon, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Window::get_theme_stylebox, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Window::get_theme_font, DEFVAL("")); @@ -1732,6 +2174,13 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Window::get_theme_color, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Window::get_theme_constant, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Window::has_theme_icon_override); + ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Window::has_theme_stylebox_override); + ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Window::has_theme_font_override); + ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Window::has_theme_font_size_override); + ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Window::has_theme_color_override); + ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Window::has_theme_constant_override); + ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Window::has_theme_icon, DEFVAL("")); ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Window::has_theme_stylebox, DEFVAL("")); ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Window::has_theme_font, DEFVAL("")); @@ -1785,13 +2234,13 @@ void Window::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor"), "set_content_scale_factor", "get_content_scale_factor"); + ADD_GROUP("Localization", ""); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating"); + ADD_GROUP("Theme", "theme_"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation"); - ADD_GROUP("Auto Translate", ""); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating"); - ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); ADD_SIGNAL(MethodInfo("mouse_entered")); @@ -1851,4 +2300,23 @@ Window::Window() { Window::~Window() { memdelete(theme_owner); + + // Resources need to be disconnected. + for (KeyValue<StringName, Ref<Texture2D>> &E : theme_icon_override) { + E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + for (KeyValue<StringName, Ref<StyleBox>> &E : theme_style_override) { + E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + for (KeyValue<StringName, Ref<Font>> &E : theme_font_override) { + E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed)); + } + + // Then override maps can be simply cleared. + theme_icon_override.clear(); + theme_style_override.clear(); + theme_font_override.clear(); + theme_font_size_override.clear(); + theme_color_override.clear(); + theme_constant_override.clear(); } diff --git a/scene/main/window.h b/scene/main/window.h index 03597b309a..5024b42587 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -140,6 +140,14 @@ private: Ref<Theme> theme; StringName theme_type_variation; + bool bulk_theme_override = false; + Theme::ThemeIconMap theme_icon_override; + Theme::ThemeStyleMap theme_style_override; + Theme::ThemeFontMap theme_font_override; + Theme::ThemeFontSizeMap theme_font_size_override; + Theme::ThemeColorMap theme_color_override; + Theme::ThemeConstantMap theme_constant_override; + mutable HashMap<StringName, Theme::ThemeIconMap> theme_icon_cache; mutable HashMap<StringName, Theme::ThemeStyleMap> theme_style_cache; mutable HashMap<StringName, Theme::ThemeFontMap> theme_font_cache; @@ -148,6 +156,7 @@ private: mutable HashMap<StringName, Theme::ThemeConstantMap> theme_constant_cache; void _theme_changed(); + void _notify_theme_override_changed(); void _invalidate_theme_cache(); Viewport *embedder = nullptr; @@ -173,6 +182,10 @@ protected: virtual Size2 _get_contents_minimum_size() const; static void _bind_methods(); void _notification(int p_what); + + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; void _validate_property(PropertyInfo &p_property) const; virtual void add_child_notify(Node *p_child) override; @@ -198,7 +211,8 @@ public: Size2i get_size() const; void reset_size(); - Size2i get_real_size() const; + Point2i get_position_with_decorations() const; + Size2i get_size_with_decorations() const; void set_max_size(const Size2i &p_max_size); Size2i get_max_size() const; @@ -270,16 +284,6 @@ public: void popup_centered(const Size2i &p_minsize = Size2i()); void popup_centered_clamped(const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75); - void set_theme_owner_node(Node *p_node); - Node *get_theme_owner_node() const; - bool has_theme_owner_node() const; - - void set_theme(const Ref<Theme> &p_theme); - Ref<Theme> get_theme() const; - - void set_theme_type_variation(const StringName &p_theme_type); - StringName get_theme_type_variation() const; - Size2 get_contents_minimum_size() const; void grab_focus(); @@ -295,6 +299,35 @@ public: Rect2i get_usable_parent_rect() const; + // Theming. + + void set_theme_owner_node(Node *p_node); + Node *get_theme_owner_node() const; + bool has_theme_owner_node() const; + + void set_theme(const Ref<Theme> &p_theme); + Ref<Theme> get_theme() const; + + void set_theme_type_variation(const StringName &p_theme_type); + StringName get_theme_type_variation() const; + + void begin_bulk_theme_override(); + void end_bulk_theme_override(); + + void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); + void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); + void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font); + void add_theme_font_size_override(const StringName &p_name, int p_font_size); + void add_theme_color_override(const StringName &p_name, const Color &p_color); + void add_theme_constant_override(const StringName &p_name, int p_constant); + + void remove_theme_icon_override(const StringName &p_name); + void remove_theme_style_override(const StringName &p_name); + void remove_theme_font_override(const StringName &p_name); + void remove_theme_font_size_override(const StringName &p_name); + void remove_theme_color_override(const StringName &p_name); + void remove_theme_constant_override(const StringName &p_name); + Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; @@ -302,6 +335,13 @@ public: Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const; int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + bool has_theme_icon_override(const StringName &p_name) const; + bool has_theme_stylebox_override(const StringName &p_name) const; + bool has_theme_font_override(const StringName &p_name) const; + bool has_theme_font_size_override(const StringName &p_name) const; + bool has_theme_color_override(const StringName &p_name) const; + bool has_theme_constant_override(const StringName &p_name) const; + bool has_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; bool has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; bool has_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; @@ -313,6 +353,8 @@ public: Ref<Font> get_theme_default_font() const; int get_theme_default_font_size() const; + // + virtual Transform2D get_screen_transform() const override; Rect2i get_parent_rect() const; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index f4b7f3d0b2..5316b524ba 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -450,7 +450,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { callable = callable.bindp(argptrs, binds.size()); } - cfrom->connect(snames[c.signal], callable, CONNECT_PERSIST | c.flags); + cfrom->connect(snames[c.signal], callable, CONNECT_PERSIST | c.flags | (p_edit_state == GEN_EDIT_STATE_MAIN ? 0 : CONNECT_INHERITED)); } //Node *s = ret_nodes[0]; diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 461dccfbdd..6b8f8097a8 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -2066,10 +2066,9 @@ Error VisualShader::_write_node(Type type, StringBuilder *p_global_code, StringB } if (!node_code.is_empty()) { - r_code += "\n"; + r_code += "\n\n"; } - r_code += "\n"; // r_processed.insert(p_node); return OK; @@ -2366,71 +2365,62 @@ void VisualShader::_update_shader() const { String global_compute_code; if (shader_mode == Shader::MODE_PARTICLES) { - bool has_start = !code_map[TYPE_START].is_empty(); bool has_start_custom = !code_map[TYPE_START_CUSTOM].is_empty(); bool has_process = !code_map[TYPE_PROCESS].is_empty(); bool has_process_custom = !code_map[TYPE_PROCESS_CUSTOM].is_empty(); bool has_collide = !code_map[TYPE_COLLIDE].is_empty(); shader_code += "void start() {\n"; - if (has_start || has_start_custom) { - shader_code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; - shader_code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; - shader_code += " float __radians;\n"; - shader_code += " vec3 __vec3_buff1;\n"; - shader_code += " vec3 __vec3_buff2;\n"; - shader_code += " float __scalar_buff1;\n"; - shader_code += " float __scalar_buff2;\n"; - shader_code += " int __scalar_ibuff;\n"; - shader_code += " vec4 __vec4_buff;\n"; - shader_code += " vec3 __ndiff = normalize(__diff);\n\n"; - } - if (has_start) { - shader_code += " {\n"; - shader_code += code_map[TYPE_START].replace("\n ", "\n "); - shader_code += " }\n"; - if (has_start_custom) { - shader_code += " \n"; - } - } + shader_code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; + shader_code += "\n"; + shader_code += " {\n"; + shader_code += code_map[TYPE_START].replace("\n ", "\n "); + shader_code += " }\n"; if (has_start_custom) { + shader_code += " \n"; shader_code += " {\n"; shader_code += code_map[TYPE_START_CUSTOM].replace("\n ", "\n "); shader_code += " }\n"; } shader_code += "}\n\n"; - shader_code += "void process() {\n"; + if (has_process || has_process_custom || has_collide) { + shader_code += "void process() {\n"; shader_code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; - shader_code += " vec3 __vec3_buff1;\n"; - shader_code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; - shader_code += " vec3 __ndiff = normalize(__diff);\n\n"; - } - shader_code += " {\n"; - String tab = " "; - if (has_collide) { - shader_code += " if (COLLIDED) {\n\n"; - shader_code += code_map[TYPE_COLLIDE].replace("\n ", "\n "); + shader_code += "\n"; + if (has_process || has_collide) { + shader_code += " {\n"; + } + String tab = " "; + if (has_collide) { + shader_code += " if (COLLIDED) {\n\n"; + shader_code += code_map[TYPE_COLLIDE].replace("\n ", "\n "); + if (has_process) { + shader_code += " } else {\n\n"; + tab += " "; + } + } if (has_process) { - shader_code += " } else {\n\n"; - tab += " "; + shader_code += code_map[TYPE_PROCESS].replace("\n ", "\n " + tab); + } + if (has_collide) { + shader_code += " }\n"; + } + if (has_process || has_collide) { + shader_code += " }\n"; } - } - if (has_process) { - shader_code += code_map[TYPE_PROCESS].replace("\n ", "\n " + tab); - } - if (has_collide) { - shader_code += " }\n"; - } - shader_code += " }\n"; - if (has_process_custom) { - shader_code += " {\n\n"; - shader_code += code_map[TYPE_PROCESS_CUSTOM].replace("\n ", "\n "); - shader_code += " }\n"; - } + if (has_process_custom) { + if (has_process || has_collide) { + shader_code += " \n"; + } + shader_code += " {\n"; + shader_code += code_map[TYPE_PROCESS_CUSTOM].replace("\n ", "\n "); + shader_code += " }\n"; + } - shader_code += "}\n\n"; + shader_code += "}\n\n"; + } global_compute_code += "float __rand_from_seed(inout uint seed) {\n"; global_compute_code += " int k;\n"; diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp index f125b05a26..d61a343688 100644 --- a/scene/resources/visual_shader_particle_nodes.cpp +++ b/scene/resources/visual_shader_particle_nodes.cpp @@ -374,13 +374,13 @@ String VisualShaderNodeParticleMeshEmitter::_generate_code(VisualShader::Type p_ if (is_output_port_connected(p_index)) { switch (p_port_type) { case PORT_TYPE_VECTOR_2D: { - code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); + code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); } break; case PORT_TYPE_VECTOR_3D: { if (mode_2d) { - code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); + code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); } else { - code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xyz;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); + code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xyz;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name)); } } break; default: @@ -392,25 +392,27 @@ String VisualShaderNodeParticleMeshEmitter::_generate_code(VisualShader::Type p_ String VisualShaderNodeParticleMeshEmitter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { String code; - code += " __scalar_ibuff = int(__rand_from_seed(__seed) * 65535.0) % " + itos(position_texture->get_width()) + ";\n"; + code += " {\n"; + code += " int __scalar_ibuff = int(__rand_from_seed(__seed) * 65535.0) % " + itos(position_texture->get_width()) + ";\n"; code += _generate_code(p_type, p_id, p_output_vars, 0, "mesh_vx", VisualShaderNode::PORT_TYPE_VECTOR_3D); code += _generate_code(p_type, p_id, p_output_vars, 1, "mesh_nm", VisualShaderNode::PORT_TYPE_VECTOR_3D); if (is_output_port_connected(2) || is_output_port_connected(3)) { - code += vformat(" __vec4_buff = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0);\n", make_unique_id(p_type, p_id, "mesh_col")); + code += vformat(" vec4 __vec4_buff = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0);\n", make_unique_id(p_type, p_id, "mesh_col")); if (is_output_port_connected(2)) { - code += " " + p_output_vars[2] + " = __vec4_buff.rgb;\n"; + code += " " + p_output_vars[2] + " = __vec4_buff.rgb;\n"; } if (is_output_port_connected(3)) { - code += " " + p_output_vars[3] + " = __vec4_buff.a;\n"; + code += " " + p_output_vars[3] + " = __vec4_buff.a;\n"; } } code += _generate_code(p_type, p_id, p_output_vars, 4, "mesh_uv", VisualShaderNode::PORT_TYPE_VECTOR_2D); code += _generate_code(p_type, p_id, p_output_vars, 5, "mesh_uv2", VisualShaderNode::PORT_TYPE_VECTOR_2D); + code += " }\n"; return code; } @@ -737,6 +739,8 @@ VisualShaderNodeParticleMeshEmitter::VisualShaderNodeParticleMeshEmitter() { color_texture.instantiate(); uv_texture.instantiate(); uv2_texture.instantiate(); + + simple_decl = false; } // VisualShaderNodeParticleMultiplyByAxisAngle @@ -879,22 +883,26 @@ bool VisualShaderNodeParticleConeVelocity::has_output_port_preview(int p_port) c String VisualShaderNodeParticleConeVelocity::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { String code; - code += " __radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n"; - code += " __scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; - code += " __scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; - code += " __vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n"; - code += " __scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n"; - code += " __scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n"; - code += " __vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n"; - code += " __vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n"; - code += " __vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n"; - code += " " + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n"; + code += " {\n"; + code += " float __radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n"; + code += " float __scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; + code += " float __scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; + code += " vec3 __vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n"; + code += " __scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n"; + code += " __scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n"; + code += " __vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n"; + code += " vec3 __vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n"; + code += " __vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n"; + code += " " + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n"; + code += " }\n"; return code; } VisualShaderNodeParticleConeVelocity::VisualShaderNodeParticleConeVelocity() { set_input_port_default_value(0, Vector3(1, 0, 0)); set_input_port_default_value(1, 45.0); + + simple_decl = false; } // VisualShaderNodeParticleRandomness @@ -1086,21 +1094,26 @@ String VisualShaderNodeParticleAccelerator::get_input_port_name(int p_port) cons String VisualShaderNodeParticleAccelerator::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { String code; + code += " {\n"; switch (mode) { case MODE_LINEAR: - code += " " + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; + code += " " + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; break; case MODE_RADIAL: - code += " " + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; + code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; + code += " vec3 __ndiff = normalize(__diff);\n\n"; + code += " " + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; break; case MODE_TANGENTIAL: - code += " __vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n"; - code += " " + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n"; + code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; + code += " vec3 __ndiff = normalize(__diff);\n\n"; + code += " vec3 __vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n"; + code += " " + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n"; break; default: break; } - + code += " }\n"; return code; } @@ -1125,6 +1138,8 @@ VisualShaderNodeParticleAccelerator::VisualShaderNodeParticleAccelerator() { set_input_port_default_value(0, Vector3(1, 1, 1)); set_input_port_default_value(1, 0.0); set_input_port_default_value(2, Vector3(0, -9.8, 0)); + + simple_decl = false; } // VisualShaderNodeParticleOutput diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 4b68515e18..113e728106 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -555,8 +555,9 @@ Ref<AudioStreamPlayback> AudioStreamRandomizer::instance_playback_no_repeats() { } } if (local_pool.is_empty()) { + // There is only one sound to choose from. + // Always play a random sound while allowing repeats (which always plays the same sound). playback = instance_playback_random(); - WARN_PRINT("Playback stream pool is too small to prevent repeats."); return playback; } diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 52d7f66203..523cc714f0 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -367,8 +367,7 @@ float DisplayServer::screen_get_scale(int p_screen) const { return 1.0f; }; -bool DisplayServer::screen_is_touchscreen(int p_screen) const { - //return false; +bool DisplayServer::is_touchscreen_available() const { return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse(); } @@ -618,7 +617,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("screen_get_usable_rect", "screen"), &DisplayServer::screen_get_usable_rect, DEFVAL(SCREEN_OF_MAIN_WINDOW)); ClassDB::bind_method(D_METHOD("screen_get_dpi", "screen"), &DisplayServer::screen_get_dpi, DEFVAL(SCREEN_OF_MAIN_WINDOW)); ClassDB::bind_method(D_METHOD("screen_get_scale", "screen"), &DisplayServer::screen_get_scale, DEFVAL(SCREEN_OF_MAIN_WINDOW)); - ClassDB::bind_method(D_METHOD("screen_is_touchscreen", "screen"), &DisplayServer::screen_is_touchscreen, DEFVAL(SCREEN_OF_MAIN_WINDOW)); + ClassDB::bind_method(D_METHOD("is_touchscreen_available"), &DisplayServer::is_touchscreen_available, DEFVAL(SCREEN_OF_MAIN_WINDOW)); ClassDB::bind_method(D_METHOD("screen_get_max_scale"), &DisplayServer::screen_get_max_scale); ClassDB::bind_method(D_METHOD("screen_get_refresh_rate", "screen"), &DisplayServer::screen_get_refresh_rate, DEFVAL(SCREEN_OF_MAIN_WINDOW)); @@ -643,6 +642,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("window_set_current_screen", "screen", "window_id"), &DisplayServer::window_set_current_screen, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_get_position", "window_id"), &DisplayServer::window_get_position, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_get_position_with_decorations", "window_id"), &DisplayServer::window_get_position_with_decorations, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_set_position", "position", "window_id"), &DisplayServer::window_set_position, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_get_size", "window_id"), &DisplayServer::window_get_size, DEFVAL(MAIN_WINDOW_ID)); @@ -661,7 +661,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("window_get_min_size", "window_id"), &DisplayServer::window_get_min_size, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_set_min_size", "min_size", "window_id"), &DisplayServer::window_set_min_size, DEFVAL(MAIN_WINDOW_ID)); - ClassDB::bind_method(D_METHOD("window_get_real_size", "window_id"), &DisplayServer::window_get_real_size, DEFVAL(MAIN_WINDOW_ID)); + ClassDB::bind_method(D_METHOD("window_get_size_with_decorations", "window_id"), &DisplayServer::window_get_size_with_decorations, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_get_mode", "window_id"), &DisplayServer::window_get_mode, DEFVAL(MAIN_WINDOW_ID)); ClassDB::bind_method(D_METHOD("window_set_mode", "mode", "window_id"), &DisplayServer::window_set_mode, DEFVAL(MAIN_WINDOW_ID)); diff --git a/servers/display_server.h b/servers/display_server.h index a796377f88..4c36b0acb9 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -262,7 +262,7 @@ public: return scale; } virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const = 0; - virtual bool screen_is_touchscreen(int p_screen = SCREEN_OF_MAIN_WINDOW) const; + virtual bool is_touchscreen_available() const; // Keep the ScreenOrientation enum values in sync with the `display/window/handheld/orientation` // project setting hint. @@ -353,6 +353,7 @@ public: virtual void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) = 0; virtual Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const = 0; + virtual Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0; virtual void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) = 0; virtual void window_set_transient(WindowID p_window, WindowID p_parent) = 0; @@ -366,7 +367,7 @@ public: virtual void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) = 0; virtual Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; - virtual Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const = 0; // FIXME: Find clearer name for this. + virtual Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const = 0; virtual void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) = 0; virtual WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const = 0; diff --git a/servers/display_server_headless.h b/servers/display_server_headless.h index e1a27b6137..94b5f3c1e9 100644 --- a/servers/display_server_headless.h +++ b/servers/display_server_headless.h @@ -90,6 +90,7 @@ public: void window_set_current_screen(int p_screen, WindowID p_window = MAIN_WINDOW_ID) override {} Point2i window_get_position(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); } + Point2i window_get_position_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Point2i(); } void window_set_position(const Point2i &p_position, WindowID p_window = MAIN_WINDOW_ID) override {} void window_set_transient(WindowID p_window, WindowID p_parent) override {} @@ -102,7 +103,7 @@ public: void window_set_size(const Size2i p_size, WindowID p_window = MAIN_WINDOW_ID) override {} Size2i window_get_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } - Size2i window_get_real_size(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } + Size2i window_get_size_with_decorations(WindowID p_window = MAIN_WINDOW_ID) const override { return Size2i(); } void window_set_mode(WindowMode p_mode, WindowID p_window = MAIN_WINDOW_ID) override {} WindowMode window_get_mode(WindowID p_window = MAIN_WINDOW_ID) const override { return WINDOW_MODE_MINIMIZED; } diff --git a/servers/navigation_server_2d.cpp b/servers/navigation_server_2d.cpp index 04e5d2f6a1..bfe95ddef1 100644 --- a/servers/navigation_server_2d.cpp +++ b/servers/navigation_server_2d.cpp @@ -152,6 +152,10 @@ static Variant var_to_var(const Variant &d) { return d; } +static ObjectID id_to_id(const ObjectID &id) { + return id; +} + static Ref<NavigationMesh> poly_to_mesh(Ref<NavigationPolygon> d) { if (d.is_valid()) { return d->get_mesh(); @@ -250,6 +254,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer2D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer2D::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer2D::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer2D::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer2D::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer2D::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer2D::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer2D::region_get_map); @@ -276,6 +282,8 @@ void NavigationServer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer2D::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer2D::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer2D::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer2D::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer2D::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer2D::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer2D::agent_set_map); @@ -348,6 +356,8 @@ void FORWARD_2_C(region_set_enter_cost, RID, p_region, real_t, p_enter_cost, rid real_t FORWARD_1_C(region_get_enter_cost, RID, p_region, rid_to_rid); void FORWARD_2_C(region_set_travel_cost, RID, p_region, real_t, p_travel_cost, rid_to_rid, real_to_real); real_t FORWARD_1_C(region_get_travel_cost, RID, p_region, rid_to_rid); +void FORWARD_2_C(region_set_owner_id, RID, p_region, ObjectID, p_owner_id, rid_to_rid, id_to_id); +ObjectID FORWARD_1_C(region_get_owner_id, RID, p_region, rid_to_rid); bool FORWARD_2_C(region_owns_point, RID, p_region, const Vector2 &, p_point, rid_to_rid, v2_to_v3); void FORWARD_2_C(region_set_map, RID, p_region, RID, p_map, rid_to_rid, rid_to_rid); @@ -379,6 +389,8 @@ void FORWARD_2_C(link_set_enter_cost, RID, p_link, real_t, p_enter_cost, rid_to_ real_t FORWARD_1_C(link_get_enter_cost, RID, p_link, rid_to_rid); void FORWARD_2_C(link_set_travel_cost, RID, p_link, real_t, p_travel_cost, rid_to_rid, real_to_real); real_t FORWARD_1_C(link_get_travel_cost, RID, p_link, rid_to_rid); +void FORWARD_2_C(link_set_owner_id, RID, p_link, ObjectID, p_owner_id, rid_to_rid, id_to_id); +ObjectID FORWARD_1_C(link_get_owner_id, RID, p_link, rid_to_rid); RID NavigationServer2D::agent_create() const { RID agent = NavigationServer3D::get_singleton()->agent_create(); diff --git a/servers/navigation_server_2d.h b/servers/navigation_server_2d.h index 54cfc6b14e..4c78bc40c7 100644 --- a/servers/navigation_server_2d.h +++ b/servers/navigation_server_2d.h @@ -108,6 +108,10 @@ public: virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const; virtual real_t region_get_travel_cost(RID p_region) const; + /// Set the node which manages this region. + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const; + virtual ObjectID region_get_owner_id(RID p_region) const; + virtual bool region_owns_point(RID p_region, const Vector2 &p_point) const; /// Set the map of this region. @@ -160,6 +164,10 @@ public: virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const; virtual real_t link_get_travel_cost(RID p_link) const; + /// Set the node which manages this link. + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const; + virtual ObjectID link_get_owner_id(RID p_link) const; + /// Creates the agent. virtual RID agent_create() const; diff --git a/servers/navigation_server_3d.cpp b/servers/navigation_server_3d.cpp index cab8816747..31e8b9a864 100644 --- a/servers/navigation_server_3d.cpp +++ b/servers/navigation_server_3d.cpp @@ -69,6 +69,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer3D::region_get_enter_cost); ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer3D::region_set_travel_cost); ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer3D::region_get_travel_cost); + ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer3D::region_set_owner_id); + ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer3D::region_get_owner_id); ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer3D::region_owns_point); ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer3D::region_set_map); ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer3D::region_get_map); @@ -96,6 +98,8 @@ void NavigationServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer3D::link_get_enter_cost); ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer3D::link_set_travel_cost); ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer3D::link_get_travel_cost); + ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer3D::link_set_owner_id); + ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer3D::link_get_owner_id); ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer3D::agent_create); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer3D::agent_set_map); diff --git a/servers/navigation_server_3d.h b/servers/navigation_server_3d.h index 0f537383a2..31ae149aff 100644 --- a/servers/navigation_server_3d.h +++ b/servers/navigation_server_3d.h @@ -120,6 +120,10 @@ public: virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) const = 0; virtual real_t region_get_travel_cost(RID p_region) const = 0; + /// Set the node which manages this region. + virtual void region_set_owner_id(RID p_region, ObjectID p_owner_id) const = 0; + virtual ObjectID region_get_owner_id(RID p_region) const = 0; + virtual bool region_owns_point(RID p_region, const Vector3 &p_point) const = 0; /// Set the map of this region. @@ -175,6 +179,10 @@ public: virtual void link_set_travel_cost(RID p_link, real_t p_travel_cost) const = 0; virtual real_t link_get_travel_cost(RID p_link) const = 0; + /// Set the node which manages this link. + virtual void link_set_owner_id(RID p_link, ObjectID p_owner_id) const = 0; + virtual ObjectID link_get_owner_id(RID p_link) const = 0; + /// Creates the agent. virtual RID agent_create() const = 0; diff --git a/servers/physics_2d/godot_step_2d.cpp b/servers/physics_2d/godot_step_2d.cpp index 46718c8819..b7d79bc0e3 100644 --- a/servers/physics_2d/godot_step_2d.cpp +++ b/servers/physics_2d/godot_step_2d.cpp @@ -71,7 +71,7 @@ void GodotStep2D::_populate_island(GodotBody2D *p_body, LocalVector<GodotBody2D } } -void GodotStep2D::_setup_contraint(uint32_t p_constraint_index, void *p_userdata) { +void GodotStep2D::_setup_constraint(uint32_t p_constraint_index, void *p_userdata) { GodotConstraint2D *constraint = all_constraints[p_constraint_index]; constraint->setup(delta); } @@ -238,8 +238,8 @@ void GodotStep2D::step(GodotSpace2D *p_space, real_t p_delta) { /* SETUP CONSTRAINTS / PROCESS COLLISIONS */ - uint32_t total_contraint_count = all_constraints.size(); - WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &GodotStep2D::_setup_contraint, nullptr, total_contraint_count, -1, true, SNAME("Physics2DConstraintSetup")); + uint32_t total_constraint_count = all_constraints.size(); + WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &GodotStep2D::_setup_constraint, nullptr, total_constraint_count, -1, true, SNAME("Physics2DConstraintSetup")); WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group_task); { //profile diff --git a/servers/physics_2d/godot_step_2d.h b/servers/physics_2d/godot_step_2d.h index 9f8fdd6ce3..4b3b6fc966 100644 --- a/servers/physics_2d/godot_step_2d.h +++ b/servers/physics_2d/godot_step_2d.h @@ -47,7 +47,7 @@ class GodotStep2D { LocalVector<GodotConstraint2D *> all_constraints; void _populate_island(GodotBody2D *p_body, LocalVector<GodotBody2D *> &p_body_island, LocalVector<GodotConstraint2D *> &p_constraint_island); - void _setup_contraint(uint32_t p_constraint_index, void *p_userdata = nullptr); + void _setup_constraint(uint32_t p_constraint_index, void *p_userdata = nullptr); void _pre_solve_island(LocalVector<GodotConstraint2D *> &p_constraint_island) const; void _solve_island(uint32_t p_island_index, void *p_userdata = nullptr) const; void _check_suspend(LocalVector<GodotBody2D *> &p_body_island) const; diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp index 22553bd3d8..1a016fbc72 100644 --- a/servers/physics_3d/godot_shape_3d.cpp +++ b/servers/physics_3d/godot_shape_3d.cpp @@ -1996,7 +1996,7 @@ void GodotHeightMapShape3D::_get_cell(const Vector3 &p_point, int &r_x, int &r_y Vector3 clamped_point(p_point); clamped_point.x = CLAMP(p_point.x, pos_local.x, pos_local.x + shape_aabb.size.x); clamped_point.y = CLAMP(p_point.y, pos_local.y, pos_local.y + shape_aabb.size.y); - clamped_point.z = CLAMP(p_point.z, pos_local.z, pos_local.x + shape_aabb.size.z); + clamped_point.z = CLAMP(p_point.z, pos_local.z, pos_local.z + shape_aabb.size.z); r_x = (clamped_point.x < 0.0) ? (clamped_point.x - 0.5) : (clamped_point.x + 0.5); r_y = (clamped_point.y < 0.0) ? (clamped_point.y - 0.5) : (clamped_point.y + 0.5); diff --git a/servers/physics_3d/godot_step_3d.cpp b/servers/physics_3d/godot_step_3d.cpp index bfedcd29c0..634523d0b9 100644 --- a/servers/physics_3d/godot_step_3d.cpp +++ b/servers/physics_3d/godot_step_3d.cpp @@ -111,7 +111,7 @@ void GodotStep3D::_populate_island_soft_body(GodotSoftBody3D *p_soft_body, Local } } -void GodotStep3D::_setup_contraint(uint32_t p_constraint_index, void *p_userdata) { +void GodotStep3D::_setup_constraint(uint32_t p_constraint_index, void *p_userdata) { GodotConstraint3D *constraint = all_constraints[p_constraint_index]; constraint->setup(delta); } @@ -342,8 +342,8 @@ void GodotStep3D::step(GodotSpace3D *p_space, real_t p_delta) { /* SETUP CONSTRAINTS / PROCESS COLLISIONS */ - uint32_t total_contraint_count = all_constraints.size(); - WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &GodotStep3D::_setup_contraint, nullptr, total_contraint_count, -1, true, SNAME("Physics3DConstraintSetup")); + uint32_t total_constraint_count = all_constraints.size(); + WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &GodotStep3D::_setup_constraint, nullptr, total_constraint_count, -1, true, SNAME("Physics3DConstraintSetup")); WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group_task); { //profile diff --git a/servers/physics_3d/godot_step_3d.h b/servers/physics_3d/godot_step_3d.h index 189487757f..a0854a720c 100644 --- a/servers/physics_3d/godot_step_3d.h +++ b/servers/physics_3d/godot_step_3d.h @@ -48,7 +48,7 @@ class GodotStep3D { void _populate_island(GodotBody3D *p_body, LocalVector<GodotBody3D *> &p_body_island, LocalVector<GodotConstraint3D *> &p_constraint_island); void _populate_island_soft_body(GodotSoftBody3D *p_soft_body, LocalVector<GodotBody3D *> &p_body_island, LocalVector<GodotConstraint3D *> &p_constraint_island); - void _setup_contraint(uint32_t p_constraint_index, void *p_userdata = nullptr); + void _setup_constraint(uint32_t p_constraint_index, void *p_userdata = nullptr); void _pre_solve_island(LocalVector<GodotConstraint3D *> &p_constraint_island) const; void _solve_island(uint32_t p_island_index, void *p_userdata = nullptr); void _check_suspend(const LocalVector<GodotBody3D *> &p_body_island) const; diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp index cc8238a8dd..d41daa18b4 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp @@ -398,7 +398,7 @@ void RendererCanvasRenderRD::_bind_canvas_texture(RD::DrawListID p_draw_list, RI r_last_texture = p_texture; } -void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_render_target, const Item *p_item, RD::FramebufferFormatID p_framebuffer_format, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, Light *p_lights, PipelineVariants *p_pipeline_variants) { +void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_render_target, const Item *p_item, RD::FramebufferFormatID p_framebuffer_format, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, Light *p_lights, PipelineVariants *p_pipeline_variants, bool &r_sdf_used) { //create an empty push constant RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); RendererRD::MeshStorage *mesh_storage = RendererRD::MeshStorage::get_singleton(); @@ -833,6 +833,9 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend } else { particles_storage->particles_set_canvas_sdf_collision(pt->particles, false, Transform2D(), Rect2(), RID()); } + + // Signal that SDF texture needs to be updated. + r_sdf_used |= particles_storage->particles_has_collision(pt->particles); } if (mesh.is_null()) { @@ -1045,7 +1048,7 @@ RID RendererCanvasRenderRD::_create_base_uniform_set(RID p_to_render_target, boo return uniform_set; } -void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, bool p_to_backbuffer) { +void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, bool &r_sdf_used, bool p_to_backbuffer) { RendererRD::MaterialStorage *material_storage = RendererRD::MaterialStorage::get_singleton(); RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton(); @@ -1142,7 +1145,7 @@ void RendererCanvasRenderRD::_render_items(RID p_to_render_target, int p_item_co } } - _render_item(draw_list, p_to_render_target, ci, fb_format, canvas_transform_inverse, current_clip, p_lights, pipeline_variants); + _render_item(draw_list, p_to_render_target, ci, fb_format, canvas_transform_inverse, current_clip, p_lights, pipeline_variants, r_sdf_used); prev_material = material; } @@ -1440,7 +1443,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, r_sdf_used); item_count = 0; if (ci->canvas_group_owner->canvas_group->mode != RS::CANVAS_GROUP_MODE_TRANSPARENT) { @@ -1472,7 +1475,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, true); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, r_sdf_used, true); item_count = 0; if (ci->canvas_group->blur_mipmaps) { @@ -1491,7 +1494,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, r_sdf_used); item_count = 0; texture_storage->render_target_copy_to_back_buffer(p_to_render_target, back_buffer_rect, backbuffer_gen_mipmaps); @@ -1517,7 +1520,7 @@ void RendererCanvasRenderRD::canvas_render_items(RID p_to_render_target, Item *p update_skeletons = false; } - _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list); + _render_items(p_to_render_target, item_count, canvas_transform_inverse, p_light_list, r_sdf_used, false); //then reset item_count = 0; } diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h index 3fff574098..6e876b1297 100644 --- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.h +++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.h @@ -421,8 +421,8 @@ class RendererCanvasRenderRD : public RendererCanvasRender { RID _create_base_uniform_set(RID p_to_render_target, bool p_backbuffer); inline void _bind_canvas_texture(RD::DrawListID p_draw_list, RID p_texture, RS::CanvasItemTextureFilter p_base_filter, RS::CanvasItemTextureRepeat p_base_repeat, RID &r_last_texture, PushConstant &push_constant, Size2 &r_texpixel_size); //recursive, so regular inline used instead. - void _render_item(RenderingDevice::DrawListID p_draw_list, RID p_render_target, const Item *p_item, RenderingDevice::FramebufferFormatID p_framebuffer_format, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, Light *p_lights, PipelineVariants *p_pipeline_variants); - void _render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, bool p_to_backbuffer = false); + void _render_item(RenderingDevice::DrawListID p_draw_list, RID p_render_target, const Item *p_item, RenderingDevice::FramebufferFormatID p_framebuffer_format, const Transform2D &p_canvas_transform_inverse, Item *¤t_clip, Light *p_lights, PipelineVariants *p_pipeline_variants, bool &r_sdf_used); + void _render_items(RID p_to_render_target, int p_item_count, const Transform2D &p_canvas_transform_inverse, Light *p_lights, bool &r_sdf_used, bool p_to_backbuffer = false); _FORCE_INLINE_ void _update_transform_2d_to_mat2x4(const Transform2D &p_transform, float *p_mat2x4); _FORCE_INLINE_ void _update_transform_2d_to_mat2x3(const Transform2D &p_transform, float *p_mat2x3); diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 0f4dda3f11..1b5665855f 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -1419,10 +1419,13 @@ void RendererSceneRenderRD::init() { cull_argument.set_page_pool(&cull_argument_pool); bool can_use_storage = _render_buffers_can_be_storage(); + bool can_use_vrs = is_vrs_supported(); bokeh_dof = memnew(RendererRD::BokehDOF(!can_use_storage)); copy_effects = memnew(RendererRD::CopyEffects(!can_use_storage)); tone_mapper = memnew(RendererRD::ToneMapper); - vrs = memnew(RendererRD::VRS); + if (can_use_vrs) { + vrs = memnew(RendererRD::VRS); + } if (can_use_storage) { fsr = memnew(RendererRD::FSR); } diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 23070fb7c0..ec19094537 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -286,7 +286,7 @@ static Vector<RenderingDevice::PipelineSpecializationConstant> _get_spec_constan return ret; } -RID RenderingDevice::_render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants) { +RID RenderingDevice::_render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants) { PipelineRasterizationState rasterization_state; if (p_rasterization_state.is_valid()) { rasterization_state = p_rasterization_state->base; @@ -906,13 +906,13 @@ void RenderingDevice::_bind_methods() { BIND_ENUM_CONSTANT(BLEND_OP_MAXIMUM); BIND_ENUM_CONSTANT(BLEND_OP_MAX); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_LINE_WIDTH); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_DEPTH_BIAS); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_BLEND_CONSTANTS); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_DEPTH_BOUNDS); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_STENCIL_COMPARE_MASK); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_STENCIL_WRITE_MASK); - BIND_ENUM_CONSTANT(DYNAMIC_STATE_STENCIL_REFERENCE); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_LINE_WIDTH); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_DEPTH_BIAS); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_BLEND_CONSTANTS); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_DEPTH_BOUNDS); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_STENCIL_COMPARE_MASK); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_STENCIL_WRITE_MASK); + BIND_BITFIELD_FLAG(DYNAMIC_STATE_STENCIL_REFERENCE); BIND_ENUM_CONSTANT(INITIAL_ACTION_CLEAR); //start rendering and clear the framebuffer (supply params) BIND_ENUM_CONSTANT(INITIAL_ACTION_CLEAR_REGION); //start rendering and clear the framebuffer (supply params) diff --git a/servers/rendering/rendering_device.h b/servers/rendering/rendering_device.h index 0b43b73042..27c3f77c5b 100644 --- a/servers/rendering/rendering_device.h +++ b/servers/rendering/rendering_device.h @@ -1112,7 +1112,7 @@ public: }; virtual bool render_pipeline_is_valid(RID p_pipeline) = 0; - virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, int p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0; + virtual RID render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const PipelineRasterizationState &p_rasterization_state, const PipelineMultisampleState &p_multisample_state, const PipelineDepthStencilState &p_depth_stencil_state, const PipelineColorBlendState &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags = 0, uint32_t p_for_render_pass = 0, const Vector<PipelineSpecializationConstant> &p_specialization_constants = Vector<PipelineSpecializationConstant>()) = 0; /**************************/ /**** COMPUTE PIPELINE ****/ @@ -1322,7 +1322,7 @@ protected: Error _buffer_update(RID p_buffer, uint32_t p_offset, uint32_t p_size, const Vector<uint8_t> &p_data, BitField<BarrierMask> p_post_barrier = BARRIER_MASK_ALL_BARRIERS); - RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, int p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants); + RID _render_pipeline_create(RID p_shader, FramebufferFormatID p_framebuffer_format, VertexFormatID p_vertex_format, RenderPrimitive p_render_primitive, const Ref<RDPipelineRasterizationState> &p_rasterization_state, const Ref<RDPipelineMultisampleState> &p_multisample_state, const Ref<RDPipelineDepthStencilState> &p_depth_stencil_state, const Ref<RDPipelineColorBlendState> &p_blend_state, BitField<PipelineDynamicStateFlags> p_dynamic_state_flags, uint32_t p_for_render_pass, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants); RID _compute_pipeline_create(RID p_shader, const TypedArray<RDPipelineSpecializationConstant> &p_specialization_constants); Vector<int64_t> _draw_list_begin_split(RID p_framebuffer, uint32_t p_splits, InitialAction p_initial_color_action, FinalAction p_final_color_action, InitialAction p_initial_depth_action, FinalAction p_final_depth_action, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth = 1.0, uint32_t p_clear_stencil = 0, const Rect2 &p_region = Rect2(), const TypedArray<RID> &p_storage_textures = TypedArray<RID>()); @@ -1357,7 +1357,7 @@ VARIANT_ENUM_CAST(RenderingDevice::StencilOperation) VARIANT_ENUM_CAST(RenderingDevice::LogicOperation) VARIANT_ENUM_CAST(RenderingDevice::BlendFactor) VARIANT_ENUM_CAST(RenderingDevice::BlendOperation) -VARIANT_ENUM_CAST(RenderingDevice::PipelineDynamicStateFlags) +VARIANT_BITFIELD_CAST(RenderingDevice::PipelineDynamicStateFlags) VARIANT_ENUM_CAST(RenderingDevice::PipelineSpecializationConstantType) VARIANT_ENUM_CAST(RenderingDevice::InitialAction) VARIANT_ENUM_CAST(RenderingDevice::FinalAction) diff --git a/tests/core/variant/test_dictionary.h b/tests/core/variant/test_dictionary.h index c98434d42c..0c87f11ed7 100644 --- a/tests/core/variant/test_dictionary.h +++ b/tests/core/variant/test_dictionary.h @@ -64,6 +64,19 @@ TEST_CASE("[Dictionary] Assignment using bracket notation ([])") { map["World!"] = 4; CHECK(int(map["World!"]) == 4); + map[StringName("HelloName")] = 6; + CHECK(int(map[StringName("HelloName")]) == 6); + // Check that StringName key is converted to String. + CHECK(int(map.find_key(6).get_type()) == Variant::STRING); + map[StringName("HelloName")] = 7; + CHECK(int(map[StringName("HelloName")]) == 7); + + // Test String and StringName are equivalent. + map[StringName("Hello")] = 8; + CHECK(int(map["Hello"]) == 8); + map["Hello"] = 9; + CHECK(int(map[StringName("Hello")]) == 9); + // Test non-string keys, since keys can be of any Variant type. map[12345] = -5; CHECK(int(map[12345]) == -5); diff --git a/thirdparty/README.md b/thirdparty/README.md index 937d149747..ed38fe0ec8 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -20,7 +20,7 @@ Files extracted from upstream source: ## basis_universal - Upstream: https://github.com/BinomialLLC/basis_universal -- Version: git (1531cfaf9ed5232248a0a45736686a849ca3befc, 2022) +- Version: git (a91e94c8495d7f470d3df326a364d49324cfd4a3, 2022) - License: Apache 2.0 Files extracted from upstream source: diff --git a/thirdparty/basis_universal/encoder/basisu_comp.cpp b/thirdparty/basis_universal/encoder/basisu_comp.cpp index 166a1c4fe0..41eae2b78a 100644 --- a/thirdparty/basis_universal/encoder/basisu_comp.cpp +++ b/thirdparty/basis_universal/encoder/basisu_comp.cpp @@ -1501,7 +1501,8 @@ namespace basisu if (m_params.m_compute_stats) { - printf("Slice: %u\n", slice_index); + if (m_params.m_print_stats) + printf("Slice: %u\n", slice_index); image_stats& s = m_stats[slice_index]; @@ -1511,81 +1512,100 @@ namespace basisu // ---- .basis stats em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 0, 3); - em.print(".basis RGB Avg: "); + if (m_params.m_print_stats) + em.print(".basis RGB Avg: "); s.m_basis_rgb_avg_psnr = em.m_psnr; em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 0, 4); - em.print(".basis RGBA Avg: "); + if (m_params.m_print_stats) + em.print(".basis RGBA Avg: "); s.m_basis_rgba_avg_psnr = em.m_psnr; em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 0, 1); - em.print(".basis R Avg: "); + if (m_params.m_print_stats) + em.print(".basis R Avg: "); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 1, 1); - em.print(".basis G Avg: "); + if (m_params.m_print_stats) + em.print(".basis G Avg: "); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 2, 1); - em.print(".basis B Avg: "); + if (m_params.m_print_stats) + em.print(".basis B Avg: "); if (m_params.m_uastc) { em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 3, 1); - em.print(".basis A Avg: "); + if (m_params.m_print_stats) + em.print(".basis A Avg: "); s.m_basis_a_avg_psnr = em.m_psnr; } em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 0, 0); - em.print(".basis 709 Luma: "); + if (m_params.m_print_stats) + em.print(".basis 709 Luma: "); s.m_basis_luma_709_psnr = static_cast<float>(em.m_psnr); s.m_basis_luma_709_ssim = static_cast<float>(em.m_ssim); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked[slice_index], 0, 0, true, true); - em.print(".basis 601 Luma: "); + if (m_params.m_print_stats) + em.print(".basis 601 Luma: "); s.m_basis_luma_601_psnr = static_cast<float>(em.m_psnr); if (m_slice_descs.size() == 1) { const uint32_t output_size = comp_size ? (uint32_t)comp_size : (uint32_t)comp_data.size(); - debug_printf(".basis RGB PSNR per bit/texel*10000: %3.3f\n", 10000.0f * s.m_basis_rgb_avg_psnr / ((output_size * 8.0f) / (slice_desc.m_orig_width * slice_desc.m_orig_height))); - debug_printf(".basis Luma 709 PSNR per bit/texel*10000: %3.3f\n", 10000.0f * s.m_basis_luma_709_psnr / ((output_size * 8.0f) / (slice_desc.m_orig_width * slice_desc.m_orig_height))); + if (m_params.m_print_stats) + { + debug_printf(".basis RGB PSNR per bit/texel*10000: %3.3f\n", 10000.0f * s.m_basis_rgb_avg_psnr / ((output_size * 8.0f) / (slice_desc.m_orig_width * slice_desc.m_orig_height))); + debug_printf(".basis Luma 709 PSNR per bit/texel*10000: %3.3f\n", 10000.0f * s.m_basis_luma_709_psnr / ((output_size * 8.0f) / (slice_desc.m_orig_width * slice_desc.m_orig_height))); + } } if (m_decoded_output_textures_unpacked_bc7[slice_index].get_width()) { // ---- BC7 stats em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 0, 3); - em.print("BC7 RGB Avg: "); + if (m_params.m_print_stats) + em.print("BC7 RGB Avg: "); s.m_bc7_rgb_avg_psnr = em.m_psnr; em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 0, 4); - em.print("BC7 RGBA Avg: "); + if (m_params.m_print_stats) + em.print("BC7 RGBA Avg: "); s.m_bc7_rgba_avg_psnr = em.m_psnr; em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 0, 1); - em.print("BC7 R Avg: "); + if (m_params.m_print_stats) + em.print("BC7 R Avg: "); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 1, 1); - em.print("BC7 G Avg: "); + if (m_params.m_print_stats) + em.print("BC7 G Avg: "); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 2, 1); - em.print("BC7 B Avg: "); + if (m_params.m_print_stats) + em.print("BC7 B Avg: "); if (m_params.m_uastc) { em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 3, 1); - em.print("BC7 A Avg: "); + if (m_params.m_print_stats) + em.print("BC7 A Avg: "); s.m_bc7_a_avg_psnr = em.m_psnr; } em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 0, 0); - em.print("BC7 709 Luma: "); + if (m_params.m_print_stats) + em.print("BC7 709 Luma: "); s.m_bc7_luma_709_psnr = static_cast<float>(em.m_psnr); s.m_bc7_luma_709_ssim = static_cast<float>(em.m_ssim); em.calc(m_slice_images[slice_index], m_decoded_output_textures_unpacked_bc7[slice_index], 0, 0, true, true); - em.print("BC7 601 Luma: "); + if (m_params.m_print_stats) + em.print("BC7 601 Luma: "); s.m_bc7_luma_601_psnr = static_cast<float>(em.m_psnr); } @@ -1593,16 +1613,19 @@ namespace basisu { // ---- Nearly best possible ETC1S stats em.calc(m_slice_images[slice_index], m_best_etc1s_images_unpacked[slice_index], 0, 3); - em.print("Unquantized ETC1S RGB Avg: "); + if (m_params.m_print_stats) + em.print("Unquantized ETC1S RGB Avg: "); s.m_best_etc1s_rgb_avg_psnr = static_cast<float>(em.m_psnr); em.calc(m_slice_images[slice_index], m_best_etc1s_images_unpacked[slice_index], 0, 0); - em.print("Unquantized ETC1S 709 Luma: "); + if (m_params.m_print_stats) + em.print("Unquantized ETC1S 709 Luma: "); s.m_best_etc1s_luma_709_psnr = static_cast<float>(em.m_psnr); s.m_best_etc1s_luma_709_ssim = static_cast<float>(em.m_ssim); em.calc(m_slice_images[slice_index], m_best_etc1s_images_unpacked[slice_index], 0, 0, true, true); - em.print("Unquantized ETC1S 601 Luma: "); + if (m_params.m_print_stats) + em.print("Unquantized ETC1S 601 Luma: "); s.m_best_etc1s_luma_601_psnr = static_cast<float>(em.m_psnr); } } @@ -2311,6 +2334,8 @@ namespace basisu } comp_params.m_compute_stats = (pStats != nullptr); + comp_params.m_print_stats = (flags_and_quality & cFlagPrintStats) != 0; + comp_params.m_status_output = (flags_and_quality & cFlagPrintStatus) != 0; // Create the compressor, initialize it, and process the input basis_compressor comp; @@ -2328,6 +2353,11 @@ namespace basisu return nullptr; } + if ((pStats) && (comp.get_opencl_failed())) + { + pStats->m_opencl_failed = true; + } + // Get the output file data and return it to the caller void* pFile_data = nullptr; const uint8_vec* pFile_data_vec = comp_params.m_create_ktx2_file ? &comp.get_output_ktx2_file() : &comp.get_output_basis_file(); @@ -2388,4 +2418,108 @@ namespace basisu free(p); } + bool basis_benchmark_etc1s_opencl(bool* pOpenCL_failed) + { + if (pOpenCL_failed) + *pOpenCL_failed = false; + + if (!opencl_is_available()) + { + error_printf("basis_benchmark_etc1s_opencl: OpenCL support must be enabled first!\n"); + return false; + } + + const uint32_t W = 1024, H = 1024; + basisu::vector<image> images; + image& img = images.enlarge(1)->resize(W, H); + + const uint32_t NUM_RAND_LETTERS = 6000;// 40000; + + rand r; + r.seed(200); + + for (uint32_t i = 0; i < NUM_RAND_LETTERS; i++) + { + uint32_t x = r.irand(0, W - 1), y = r.irand(0, H - 1); + uint32_t sx = r.irand(1, 4), sy = r.irand(1, 4); + color_rgba c(r.byte(), r.byte(), r.byte(), 255); + + img.debug_text(x, y, sx, sy, c, nullptr, false, "%c", static_cast<char>(r.irand(32, 127))); + } + + //save_png("test.png", img); + + image_stats stats; + + uint32_t flags_and_quality = cFlagSRGB | cFlagThreaded | 255; + size_t comp_size = 0; + + double best_cpu_time = 1e+9f, best_gpu_time = 1e+9f; + + const uint32_t TIMES_TO_ENCODE = 2; + interval_timer tm; + + for (uint32_t i = 0; i < TIMES_TO_ENCODE; i++) + { + tm.start(); + void* pComp_data = basis_compress( + images, + flags_and_quality, 1.0f, + &comp_size, + &stats); + double cpu_time = tm.get_elapsed_secs(); + if (!pComp_data) + { + error_printf("basis_benchmark_etc1s_opencl: basis_compress() failed (CPU)!\n"); + return false; + } + + best_cpu_time = minimum(best_cpu_time, cpu_time); + + basis_free_data(pComp_data); + } + + printf("Best CPU time: %3.3f\n", best_cpu_time); + + for (uint32_t i = 0; i < TIMES_TO_ENCODE; i++) + { + tm.start(); + void* pComp_data = basis_compress( + images, + flags_and_quality | cFlagUseOpenCL, 1.0f, + &comp_size, + &stats); + + if (stats.m_opencl_failed) + { + error_printf("basis_benchmark_etc1s_opencl: OpenCL failed!\n"); + + basis_free_data(pComp_data); + + if (pOpenCL_failed) + *pOpenCL_failed = true; + + return false; + } + + double gpu_time = tm.get_elapsed_secs(); + if (!pComp_data) + { + error_printf("basis_benchmark_etc1s_opencl: basis_compress() failed (GPU)!\n"); + return false; + } + + best_gpu_time = minimum(best_gpu_time, gpu_time); + + basis_free_data(pComp_data); + } + + printf("Best GPU time: %3.3f\n", best_gpu_time); + + return best_gpu_time < best_cpu_time; + } + } // namespace basisu + + + diff --git a/thirdparty/basis_universal/encoder/basisu_comp.h b/thirdparty/basis_universal/encoder/basisu_comp.h index aa5ea6fec3..b6c9fef9e2 100644 --- a/thirdparty/basis_universal/encoder/basisu_comp.h +++ b/thirdparty/basis_universal/encoder/basisu_comp.h @@ -92,6 +92,8 @@ namespace basisu m_best_etc1s_luma_709_psnr = 0.0f; m_best_etc1s_luma_601_psnr = 0.0f; m_best_etc1s_luma_709_ssim = 0.0f; + + m_opencl_failed = false; } std::string m_filename; @@ -119,6 +121,8 @@ namespace basisu float m_best_etc1s_luma_709_psnr; float m_best_etc1s_luma_601_psnr; float m_best_etc1s_luma_709_ssim; + + bool m_opencl_failed; }; template<bool def> @@ -255,6 +259,7 @@ namespace basisu m_write_output_basis_files.clear(); m_compression_level.clear(); m_compute_stats.clear(); + m_print_stats.clear(); m_check_for_alpha.clear(); m_force_alpha.clear(); m_multithreading.clear(); @@ -373,6 +378,9 @@ namespace basisu // Compute and display image metrics bool_param<false> m_compute_stats; + + // Print stats to stdout, if m_compute_stats is true. + bool_param<true> m_print_stats; // Check to see if any input image has an alpha channel, if so then the output basis file will have alpha channels bool_param<true> m_check_for_alpha; @@ -583,11 +591,16 @@ namespace basisu cFlagYFlip = 1 << 16, // flip source image on Y axis before compression cFlagUASTC = 1 << 17, // use UASTC compression vs. ETC1S - cFlagUASTCRDO = 1 << 18 // use RDO postprocessing when generating UASTC files (must set uastc_rdo_quality to the quality scalar) + cFlagUASTCRDO = 1 << 18, // use RDO postprocessing when generating UASTC files (must set uastc_rdo_quality to the quality scalar) + + cFlagPrintStats = 1 << 19, // print image stats to stdout + cFlagPrintStatus = 1 << 20 // print status to stdout }; // This function accepts an array of source images. // If more than one image is provided, it's assumed the images form a mipmap pyramid and automatic mipmap generation is disabled. + // Returns a pointer to the compressed .basis or .ktx2 file data. *pSize is the size of the compressed data. The returned block must be freed using basis_free_data(). + // basisu_encoder_init() MUST be called first! void* basis_compress( const basisu::vector<image> &source_images, uint32_t flags_and_quality, float uastc_rdo_quality, @@ -604,6 +617,12 @@ namespace basisu // Frees the dynamically allocated file data returned by basis_compress(). void basis_free_data(void* p); + // Runs a short benchmark using synthetic image data to time OpenCL encoding vs. CPU encoding, with multithreading enabled. + // Returns true if opencl is worth using on this system, otherwise false. + // If pOpenCL_failed is not null, it will be set to true if OpenCL encoding failed *on this particular machine/driver/BasisU version* and the encoder falled back to CPU encoding. + // basisu_encoder_init() MUST be called first. If OpenCL support wasn't enabled this always returns false. + bool basis_benchmark_etc1s_opencl(bool *pOpenCL_failed = nullptr); + // Parallel compression API struct parallel_results { diff --git a/thirdparty/basis_universal/encoder/basisu_enc.cpp b/thirdparty/basis_universal/encoder/basisu_enc.cpp index b427215ee3..c431ceaf12 100644 --- a/thirdparty/basis_universal/encoder/basisu_enc.cpp +++ b/thirdparty/basis_universal/encoder/basisu_enc.cpp @@ -187,6 +187,8 @@ namespace basisu opencl_init(opencl_force_serialization); } + interval_timer::init(); // make sure interval_timer globals are initialized from main thread to avoid TSAN reports + g_library_initialized = true; } @@ -227,7 +229,7 @@ namespace basisu { QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks)); } -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) +#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__EMSCRIPTEN__) #include <sys/time.h> inline void query_counter(timer_ticks* pTicks) { diff --git a/thirdparty/basis_universal/encoder/basisu_frontend.cpp b/thirdparty/basis_universal/encoder/basisu_frontend.cpp index 00210e6679..1f30a33c70 100644 --- a/thirdparty/basis_universal/encoder/basisu_frontend.cpp +++ b/thirdparty/basis_universal/encoder/basisu_frontend.cpp @@ -2328,8 +2328,6 @@ namespace basisu m_optimized_cluster_selectors.resize(total_selector_clusters); - uint32_t total_clusters_processed = 0; - // For each selector codebook entry, and for each of the 4x4 selectors, determine which selector minimizes the error across all the blocks that use that quantized selector. const uint32_t N = 256; for (uint32_t cluster_index_iter = 0; cluster_index_iter < total_selector_clusters; cluster_index_iter += N) @@ -2338,7 +2336,7 @@ namespace basisu const uint32_t last_index = minimum<uint32_t>((uint32_t)total_selector_clusters, cluster_index_iter + N); #ifndef __EMSCRIPTEN__ - m_params.m_pJob_pool->add_job([this, first_index, last_index, &total_clusters_processed, &total_selector_clusters] { + m_params.m_pJob_pool->add_job([this, first_index, last_index] { #endif for (uint32_t cluster_index = first_index; cluster_index < last_index; cluster_index++) diff --git a/thirdparty/basis_universal/transcoder/basisu_transcoder.cpp b/thirdparty/basis_universal/transcoder/basisu_transcoder.cpp index 630731900f..3aeba0ee7a 100644 --- a/thirdparty/basis_universal/transcoder/basisu_transcoder.cpp +++ b/thirdparty/basis_universal/transcoder/basisu_transcoder.cpp @@ -16867,7 +16867,7 @@ namespace basist { m_format = basist::basis_tex_format::cETC1S; - // 3.10.2: "Whether the image has 1 or 2 slices can be determined from the DFD’s sample count." + // 3.10.2: "Whether the image has 1 or 2 slices can be determined from the DFD's sample count." // If m_has_alpha is true it may be 2-channel RRRG or 4-channel RGBA, but we let the caller deal with that. m_has_alpha = (m_header.m_dfd_byte_length == 60); diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp index c98f61fa53..7f7a009a1e 100644 --- a/thirdparty/embree/common/sys/sysinfo.cpp +++ b/thirdparty/embree/common/sys/sysinfo.cpp @@ -640,6 +640,12 @@ namespace embree #if defined(__EMSCRIPTEN__) #include <emscripten.h> + +// -- GODOT start -- +extern "C" { +extern int godot_js_os_hw_concurrency_get(); +} +// -- GODOT end -- #endif namespace embree @@ -653,21 +659,9 @@ namespace embree nThreads = sysconf(_SC_NPROCESSORS_ONLN); // does not work in Linux LXC container assert(nThreads); #elif defined(__EMSCRIPTEN__) - // WebAssembly supports pthreads, but not pthread_getaffinity_np. Get the number of logical - // threads from the browser or Node.js using JavaScript. - nThreads = MAIN_THREAD_EM_ASM_INT({ - const isBrowser = typeof window !== 'undefined'; - const isNode = typeof process !== 'undefined' && process.versions != null && - process.versions.node != null; - if (isBrowser) { - // Return 1 if the browser does not expose hardwareConcurrency. - return window.navigator.hardwareConcurrency || 1; - } else if (isNode) { - return require('os').cpus().length; - } else { - return 1; - } - }); + // -- GODOT start -- + nThreads = godot_js_os_hw_concurrency_get(); + // -- GODOT end -- #else cpu_set_t set; if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0) diff --git a/thirdparty/embree/patches/emscripten-nthreads.patch b/thirdparty/embree/patches/emscripten-nthreads.patch new file mode 100644 index 0000000000..e42f203475 --- /dev/null +++ b/thirdparty/embree/patches/emscripten-nthreads.patch @@ -0,0 +1,42 @@ +diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp +index c98f61fa53..7f7a009a1e 100644 +--- a/thirdparty/embree/common/sys/sysinfo.cpp ++++ b/thirdparty/embree/common/sys/sysinfo.cpp +@@ -640,6 +640,12 @@ namespace embree + + #if defined(__EMSCRIPTEN__) + #include <emscripten.h> ++ ++// -- GODOT start -- ++extern "C" { ++extern int godot_js_os_hw_concurrency_get(); ++} ++// -- GODOT end -- + #endif + + namespace embree +@@ -653,21 +659,9 @@ namespace embree + nThreads = sysconf(_SC_NPROCESSORS_ONLN); // does not work in Linux LXC container + assert(nThreads); + #elif defined(__EMSCRIPTEN__) +- // WebAssembly supports pthreads, but not pthread_getaffinity_np. Get the number of logical +- // threads from the browser or Node.js using JavaScript. +- nThreads = MAIN_THREAD_EM_ASM_INT({ +- const isBrowser = typeof window !== 'undefined'; +- const isNode = typeof process !== 'undefined' && process.versions != null && +- process.versions.node != null; +- if (isBrowser) { +- // Return 1 if the browser does not expose hardwareConcurrency. +- return window.navigator.hardwareConcurrency || 1; +- } else if (isNode) { +- return require('os').cpus().length; +- } else { +- return 1; +- } +- }); ++ // -- GODOT start -- ++ nThreads = godot_js_os_hw_concurrency_get(); ++ // -- GODOT end -- + #else + cpu_set_t set; + if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0) |