diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.h | 4 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 11 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 2 | ||||
-rw-r--r-- | core/object/script_language.h | 1 | ||||
-rw-r--r-- | core/templates/hash_map.h | 34 |
5 files changed, 45 insertions, 7 deletions
diff --git a/core/core_bind.h b/core/core_bind.h index 077bb19c80..dc0b2a1cf5 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -230,8 +230,8 @@ public: String get_cache_dir() const; Error set_thread_name(const String &p_name); - Thread::ID get_thread_caller_id() const; - Thread::ID get_main_thread_id() const; + ::Thread::ID get_thread_caller_id() const; + ::Thread::ID get_main_thread_id() const; bool has_feature(const String &p_feature) const; bool is_sandboxed() const; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index adae468d93..551d3268b8 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1970,14 +1970,17 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant if (E.usage & PROPERTY_USAGE_STORAGE) { Variant value = res->get(E.name); if (E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { + NonPersistentKey npk; + npk.base = res; + npk.property = E.name; + non_persistent_map[npk] = value; + Ref<Resource> sres = value; if (sres.is_valid()) { - NonPersistentKey npk; - npk.base = res; - npk.property = E.name; - non_persistent_map[npk] = sres; resource_set.insert(sres); saved_resources.push_back(sres); + } else { + _find_resources(value); } } else { _find_resources(value); diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 30f1664983..e64485d404 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -139,7 +139,7 @@ class ResourceFormatSaverBinaryInstance { bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; } }; - RBMap<NonPersistentKey, Ref<Resource>> non_persistent_map; + RBMap<NonPersistentKey, Variant> non_persistent_map; HashMap<StringName, int> string_map; Vector<StringName> strings; diff --git a/core/object/script_language.h b/core/object/script_language.h index 2b685c77a3..3ea6a6e4c3 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -263,6 +263,7 @@ public: }; struct ScriptError { + String path; int line = -1; int column = -1; String message; diff --git a/core/templates/hash_map.h b/core/templates/hash_map.h index 4da73f1cfb..e1745110d7 100644 --- a/core/templates/hash_map.h +++ b/core/templates/hash_map.h @@ -353,6 +353,40 @@ public: return true; } + // Replace the key of an entry in-place, without invalidating iterators or changing the entries position during iteration. + // p_old_key must exist in the map and p_new_key must not, unless it is equal to p_old_key. + bool replace_key(const TKey &p_old_key, const TKey &p_new_key) { + if (p_old_key == p_new_key) { + return true; + } + uint32_t pos = 0; + ERR_FAIL_COND_V(_lookup_pos(p_new_key, pos), false); + ERR_FAIL_COND_V(!_lookup_pos(p_old_key, pos), false); + HashMapElement<TKey, TValue> *element = elements[pos]; + + // Delete the old entries in hashes and elements. + const uint32_t capacity = hash_table_size_primes[capacity_index]; + const uint64_t capacity_inv = hash_table_size_primes_inv[capacity_index]; + uint32_t next_pos = fastmod((pos + 1), capacity_inv, capacity); + while (hashes[next_pos] != EMPTY_HASH && _get_probe_length(next_pos, hashes[next_pos], capacity, capacity_inv) != 0) { + SWAP(hashes[next_pos], hashes[pos]); + SWAP(elements[next_pos], elements[pos]); + pos = next_pos; + next_pos = fastmod((pos + 1), capacity_inv, capacity); + } + hashes[pos] = EMPTY_HASH; + elements[pos] = nullptr; + // _insert_with_hash will increment this again. + num_elements--; + + // Update the HashMapElement with the new key and reinsert it. + const_cast<TKey &>(element->data.key) = p_new_key; + uint32_t hash = _hash(p_new_key); + _insert_with_hash(hash, element); + + return true; + } + // Reserves space for a number of elements, useful to avoid many resizes and rehashes. // If adding a known (possibly large) number of elements at once, must be larger than old capacity. void reserve(uint32_t p_new_capacity) { |