diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 45 | ||||
-rw-r--r-- | core/extension/gdnative_interface.h | 2 | ||||
-rw-r--r-- | core/io/ip.cpp | 63 | ||||
-rw-r--r-- | core/io/marshalls.cpp | 25 | ||||
-rw-r--r-- | core/io/marshalls.h | 2 | ||||
-rw-r--r-- | core/io/multiplayer_api.cpp | 4 | ||||
-rw-r--r-- | core/io/multiplayer_peer.cpp | 24 | ||||
-rw-r--r-- | core/io/multiplayer_peer.h | 1 | ||||
-rw-r--r-- | core/io/resource_format_binary.cpp | 11 | ||||
-rw-r--r-- | core/io/resource_format_binary.h | 2 | ||||
-rw-r--r-- | core/math/a_star.cpp | 10 | ||||
-rw-r--r-- | core/math/math_funcs.cpp | 10 | ||||
-rw-r--r-- | core/math/math_funcs.h | 1 | ||||
-rw-r--r-- | core/os/main_loop.cpp | 4 | ||||
-rw-r--r-- | core/os/main_loop.h | 4 | ||||
-rw-r--r-- | core/templates/set.h | 7 | ||||
-rw-r--r-- | core/variant/binder_common.h | 6 | ||||
-rw-r--r-- | core/variant/method_ptrcall.h | 2 | ||||
-rw-r--r-- | core/variant/variant.h | 5 | ||||
-rw-r--r-- | core/variant/variant_parser.h | 6 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 5 |
21 files changed, 154 insertions, 85 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 12fca4215a..d34ed29691 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -355,20 +355,20 @@ void _OS::print_all_textures_by_size() { List<Ref<Resource>> rsrc; ResourceCache::get_cached_resources(&rsrc); - for (Ref<Resource> E : rsrc) { - if (!E->is_class("ImageTexture")) { + for (Ref<Resource> &res : rsrc) { + if (!res->is_class("ImageTexture")) { continue; } - Size2 size = E->call("get_size"); - int fmt = E->call("get_format"); + Size2 size = res->call("get_size"); + int fmt = res->call("get_format"); _OSCoreBindImg img; img.size = size; img.fmt = fmt; - img.path = E->get_path(); + img.path = res->get_path(); img.vram = Image::get_image_data_size(img.size.width, img.size.height, Image::Format(img.fmt)); - img.id = E->get_instance_id(); + img.id = res->get_instance_id(); total += img.vram; imgs.push_back(img); } @@ -387,7 +387,7 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) { List<Ref<Resource>> resources; ResourceCache::get_cached_resources(&resources); - for (Ref<Resource> r : resources) { + for (const Ref<Resource> &r : resources) { bool found = false; for (int i = 0; i < p_types.size(); i++) { @@ -1733,7 +1733,36 @@ void _Thread::_start_func(void *ud) { memdelete(tud); Callable::CallError ce; const Variant *arg[1] = { &t->userdata }; - int argc = (int)(arg[0]->get_type() != Variant::NIL); + int argc = 0; + if (arg[0]->get_type() != Variant::NIL) { + // Just pass to the target function whatever came as user data + argc = 1; + } else { + // There are two cases of null user data: + // a) The target function has zero parameters and the caller is just honoring that. + // b) The target function has at least one parameter with no default and the caller is + // leveraging the fact that user data defaults to null in Thread.start(). + // We care about the case of more than one parameter because, even if a thread + // function can have one at most, out mindset here is to do our best with the + // only/first one and let the call handle any other error conditions, like too + // much arguments. + // We must check if we are in case b). + int target_param_count = 0; + int target_default_arg_count = 0; + Ref<Script> script = t->target_instance->get_script(); + if (script.is_valid()) { + MethodInfo mi = script->get_method_info(t->target_method); + target_param_count = mi.arguments.size(); + target_default_arg_count = mi.default_arguments.size(); + } else { + MethodBind *method = ClassDB::get_method(t->target_instance->get_class_name(), t->target_method); + target_param_count = method->get_argument_count(); + target_default_arg_count = method->get_default_argument_count(); + } + if (target_param_count >= 1 && target_default_arg_count == target_param_count) { + argc = 1; + } + } Thread::set_name(t->target_method); diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index c1ebb3e76a..3e69a28d59 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -134,7 +134,7 @@ typedef void *GDNativeObjectPtr; typedef void *GDNativeTypePtr; typedef void *GDNativeMethodBindPtr; typedef int64_t GDNativeInt; -typedef uint32_t GDNativeBool; +typedef uint8_t GDNativeBool; typedef uint64_t GDObjectInstanceID; /* VARIANT DATA I/O */ diff --git a/core/io/ip.cpp b/core/io/ip.cpp index cd1b6d1994..e3102508a3 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -83,8 +83,23 @@ struct _IP_ResolverPrivate { continue; } - IP::get_singleton()->_resolve_hostname(queue[i].response, queue[i].hostname, queue[i].type); - queue[i].status.set(queue[i].response.is_empty() ? IP::RESOLVER_STATUS_ERROR : IP::RESOLVER_STATUS_DONE); + mutex.lock(); + List<IPAddress> response; + String hostname = queue[i].hostname; + IP::Type type = queue[i].type; + mutex.unlock(); + + // We should not lock while resolving the hostname, + // only when modifying the queue. + IP::get_singleton()->_resolve_hostname(response, hostname, type); + + MutexLock lock(mutex); + // Could have been completed by another function, or deleted. + if (queue[i].status.get() != IP::RESOLVER_STATUS_WAITING) { + continue; + } + queue[i].response = response; + queue[i].status.set(response.is_empty() ? IP::RESOLVER_STATUS_ERROR : IP::RESOLVER_STATUS_DONE); } } @@ -93,8 +108,6 @@ struct _IP_ResolverPrivate { while (!ipr->thread_abort) { ipr->sem.wait(); - - MutexLock lock(ipr->mutex); ipr->resolve_queues(); } } @@ -107,17 +120,23 @@ struct _IP_ResolverPrivate { }; IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { - MutexLock lock(resolver->mutex); - List<IPAddress> res; - String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); + + resolver->mutex.lock(); if (resolver->cache.has(key)) { res = resolver->cache[key]; } else { + // This should be run unlocked so the resolver thread can keep + // resolving other requests. + resolver->mutex.unlock(); _resolve_hostname(res, p_hostname, p_type); + resolver->mutex.lock(); + // We might be overriding another result, but we don't care (they are the + // same hostname). resolver->cache[key] = res; } + resolver->mutex.unlock(); for (int i = 0; i < res.size(); ++i) { if (res[i].is_valid()) { @@ -128,14 +147,23 @@ IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { } Array IP::resolve_hostname_addresses(const String &p_hostname, Type p_type) { - MutexLock lock(resolver->mutex); - + List<IPAddress> res; String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); - if (!resolver->cache.has(key)) { - _resolve_hostname(resolver->cache[key], p_hostname, p_type); - } - List<IPAddress> res = resolver->cache[key]; + resolver->mutex.lock(); + if (resolver->cache.has(key)) { + res = resolver->cache[key]; + } else { + // This should be run unlocked so the resolver thread can keep resolving + // other requests. + resolver->mutex.unlock(); + _resolve_hostname(res, p_hostname, p_type); + resolver->mutex.lock(); + // We might be overriding another result, but we don't care (they are the + // same hostname). + resolver->cache[key] = res; + } + resolver->mutex.unlock(); Array result; for (int i = 0; i < res.size(); ++i) { @@ -178,13 +206,12 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE); - MutexLock lock(resolver->mutex); - - if (resolver->queue[p_id].status.get() == IP::RESOLVER_STATUS_NONE) { + IP::ResolverStatus res = resolver->queue[p_id].status.get(); + if (res == IP::RESOLVER_STATUS_NONE) { ERR_PRINT("Condition status == IP::RESOLVER_STATUS_NONE"); return IP::RESOLVER_STATUS_NONE; } - return resolver->queue[p_id].status.get(); + return res; } IPAddress IP::get_resolve_item_address(ResolverID p_id) const { @@ -230,8 +257,6 @@ Array IP::get_resolve_item_addresses(ResolverID p_id) const { void IP::erase_resolve_item(ResolverID p_id) { ERR_FAIL_INDEX(p_id, IP::RESOLVER_MAX_QUERIES); - MutexLock lock(resolver->mutex); - resolver->queue[p_id].status.set(IP::RESOLVER_STATUS_NONE); } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 4a1d3e5212..e7d5b78d14 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -746,7 +746,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_INT64_ARRAY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); - int64_t count = decode_uint64(buf); + int32_t count = decode_uint32(buf); buf += 4; len -= 4; ERR_FAIL_MUL_OF(count, 8, ERR_INVALID_DATA); @@ -795,7 +795,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PACKED_FLOAT64_ARRAY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); - int64_t count = decode_uint64(buf); + int32_t count = decode_uint32(buf); buf += 4; len -= 4; ERR_FAIL_MUL_OF(count, 8, ERR_INVALID_DATA); @@ -804,7 +804,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Vector<double> data; if (count) { - //const double*rbuf=(const double*)buf; data.resize(count); double *w = data.ptrw(); for (int64_t i = 0; i < count; i++) { @@ -1031,7 +1030,8 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { } } -Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) { +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects, int p_depth) { + ERR_FAIL_COND_V_MSG(p_depth > Variant::MAX_RECURSION_DEPTH, ERR_OUT_OF_MEMORY, "Potential inifite recursion detected. Bailing."); uint8_t *buf = r_buffer; r_len = 0; @@ -1380,10 +1380,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo _encode_string(E.name, buf, r_len); int len; - Error err = encode_variant(obj->get(E.name), buf, len, p_full_objects); - if (err) { - return err; - } + Error err = encode_variant(obj->get(E.name), buf, len, p_full_objects, p_depth + 1); + ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) { @@ -1433,7 +1431,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len++; //pad */ int len; - encode_variant(E, buf, len, p_full_objects); + Error err = encode_variant(E, buf, len, p_full_objects, p_depth + 1); + ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) { @@ -1441,7 +1440,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } Variant *v = d.getptr(E); ERR_FAIL_COND_V(!v, ERR_BUG); - encode_variant(*v, buf, len, p_full_objects); + err = encode_variant(*v, buf, len, p_full_objects, p_depth + 1); + ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) { @@ -1462,7 +1462,8 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo for (int i = 0; i < v.size(); i++) { int len; - encode_variant(v.get(i), buf, len, p_full_objects); + Error err = encode_variant(v.get(i), buf, len, p_full_objects, p_depth + 1); + ERR_FAIL_COND_V(err, err); ERR_FAIL_COND_V(len % 4, ERR_BUG); r_len += len; if (buf) { @@ -1517,7 +1518,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int datasize = sizeof(int64_t); if (buf) { - encode_uint64(datalen, buf); + encode_uint32(datalen, buf); buf += 4; const int64_t *r = data.ptr(); for (int64_t i = 0; i < datalen; i++) { diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 3ebed914a3..05804d5a46 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -213,6 +213,6 @@ public: }; Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = nullptr, bool p_allow_objects = false); -Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false); +Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects = false, int p_depth = 0); #endif // MARSHALLS_H diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 80610e12cb..d4f09b2135 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -63,7 +63,7 @@ const MultiplayerAPI::RPCConfig _get_rpc_config(const Node *p_node, const String const Vector<MultiplayerAPI::RPCConfig> node_config = p_node->get_node_rpc_methods(); for (int i = 0; i < node_config.size(); i++) { if (node_config[i].name == p_method) { - r_id = ((uint16_t)i) & (1 << 15); + r_id = ((uint16_t)i) | (1 << 15); return node_config[i]; } } @@ -89,7 +89,7 @@ const MultiplayerAPI::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_i config = p_node->get_script_instance()->get_rpc_methods(); } if (id < config.size()) { - return config[p_id]; + return config[id]; } return MultiplayerAPI::RPCConfig(); } diff --git a/core/io/multiplayer_peer.cpp b/core/io/multiplayer_peer.cpp index 8126b4cea3..8b3b1eef8e 100644 --- a/core/io/multiplayer_peer.cpp +++ b/core/io/multiplayer_peer.cpp @@ -30,6 +30,29 @@ #include "multiplayer_peer.h" +#include "core/os/os.h" + +uint32_t MultiplayerPeer::generate_unique_id() const { + uint32_t hash = 0; + + while (hash == 0 || hash == 1) { + hash = hash_djb2_one_32( + (uint32_t)OS::get_singleton()->get_ticks_usec()); + hash = hash_djb2_one_32( + (uint32_t)OS::get_singleton()->get_unix_time(), hash); + hash = hash_djb2_one_32( + (uint32_t)OS::get_singleton()->get_user_data_dir().hash64(), hash); + hash = hash_djb2_one_32( + (uint32_t)((uint64_t)this), hash); // Rely on ASLR heap + hash = hash_djb2_one_32( + (uint32_t)((uint64_t)&hash), hash); // Rely on ASLR stack + + hash = hash & 0x7FFFFFFF; // Make it compatible with unsigned, since negative ID is used for exclusion + } + + return hash; +} + void MultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &MultiplayerPeer::set_transfer_mode); ClassDB::bind_method(D_METHOD("get_transfer_mode"), &MultiplayerPeer::get_transfer_mode); @@ -41,6 +64,7 @@ void MultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_connection_status"), &MultiplayerPeer::get_connection_status); ClassDB::bind_method(D_METHOD("get_unique_id"), &MultiplayerPeer::get_unique_id); + ClassDB::bind_method(D_METHOD("generate_unique_id"), &MultiplayerPeer::generate_unique_id); ClassDB::bind_method(D_METHOD("set_refuse_new_connections", "enable"), &MultiplayerPeer::set_refuse_new_connections); ClassDB::bind_method(D_METHOD("is_refusing_new_connections"), &MultiplayerPeer::is_refusing_new_connections); diff --git a/core/io/multiplayer_peer.h b/core/io/multiplayer_peer.h index 432f47280f..91a3ad7954 100644 --- a/core/io/multiplayer_peer.h +++ b/core/io/multiplayer_peer.h @@ -72,6 +72,7 @@ public: virtual bool is_refusing_new_connections() const = 0; virtual ConnectionStatus get_connection_status() const = 0; + uint32_t generate_unique_id() const; MultiplayerPeer() {} }; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index a3ebc32cc5..00d4d093da 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -903,10 +903,11 @@ void ResourceLoaderBinary::open(FileAccess *p_f, bool p_no_resources, bool p_kee if (using_uids) { uid = f->get_64(); } else { + f->get_64(); // skip over uid field uid = ResourceUID::INVALID_ID; } - for (int i = 0; i < 5; i++) { + for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { f->get_32(); //skip a few reserved fields } @@ -1209,8 +1210,8 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(flags); fw->store_64(uid_data); - for (int i = 0; i < 5; i++) { - f->store_32(0); // reserved + for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { + fw->store_32(0); // reserved f->get_32(); } @@ -1264,7 +1265,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons if (using_uids) { ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(full_path); - f->store_64(uid); + fw->store_64(uid); } } @@ -1902,7 +1903,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p f->store_32(FORMAT_FLAG_NAMED_SCENE_IDS | FORMAT_FLAG_UIDS); ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(p_path, true); f->store_64(uid); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { f->store_32(0); // reserved } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index ac964d2053..a6e6d1848e 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -164,6 +164,8 @@ public: enum { FORMAT_FLAG_NAMED_SCENE_IDS = 1, FORMAT_FLAG_UIDS = 2, + // Amount of reserved 32-bit fields in resource header + RESERVED_FIELDS = 11 }; Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); static void write_variant(FileAccess *f, const Variant &p_property, Map<RES, int> &resource_map, Map<RES, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint = PropertyInfo()); diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 88e11a630c..322eb7ac61 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -35,18 +35,12 @@ #include "scene/scene_string_names.h" int AStar::get_available_point_id() const { - if (points.is_empty()) { - return 1; - } - - // calculate our new next available point id if bigger than before or next id already contained in set of points. if (points.has(last_free_id)) { - int cur_new_id = last_free_id; + int cur_new_id = last_free_id + 1; while (points.has(cur_new_id)) { cur_new_id++; } - int &non_const = const_cast<int &>(last_free_id); - non_const = cur_new_id; + const_cast<int &>(last_free_id) = cur_new_id; } return last_free_id; diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index e92bb9f4aa..bbed257f60 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -88,16 +88,6 @@ int Math::range_step_decimals(double p_step) { return step_decimals(p_step); } -double Math::dectime(double p_value, double p_amount, double p_step) { - double sgn = p_value < 0 ? -1.0 : 1.0; - double val = Math::abs(p_value); - val -= p_amount * p_step; - if (val < 0.0) { - val = 0.0; - } - return val * sgn; -} - double Math::ease(double p_x, double p_c) { if (p_x < 0) { p_x = 0; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 3389407e72..4e4f566517 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -296,7 +296,6 @@ public: static int step_decimals(double p_step); static int range_step_decimals(double p_step); static double snapped(double p_value, double p_step); - static double dectime(double p_value, double p_amount, double p_step); static uint32_t larger_prime(uint32_t p_val); diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 016d9d0a09..3c0e56f5a8 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -66,7 +66,7 @@ void MainLoop::initialize() { } } -bool MainLoop::physics_process(float p_time) { +bool MainLoop::physics_process(double p_time) { if (get_script_instance()) { return get_script_instance()->call("_physics_process", p_time); } @@ -74,7 +74,7 @@ bool MainLoop::physics_process(float p_time) { return false; } -bool MainLoop::process(float p_time) { +bool MainLoop::process(double p_time) { if (get_script_instance()) { return get_script_instance()->call("_process", p_time); } diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 34e944709b..b42e9b18ff 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -60,8 +60,8 @@ public: }; virtual void initialize(); - virtual bool physics_process(float p_time); - virtual bool process(float p_time); + virtual bool physics_process(double p_time); + virtual bool process(double p_time); virtual void finalize(); void set_initialize_script(const Ref<Script> &p_initialize_script); diff --git a/core/templates/set.h b/core/templates/set.h index 245c174862..9261d2d3d2 100644 --- a/core/templates/set.h +++ b/core/templates/set.h @@ -71,6 +71,9 @@ public: Element *prev() { return _prev; } + T &get() { + return value; + } const T &get() const { return value; }; @@ -118,8 +121,8 @@ public: return *this; } - _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } - _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; } _FORCE_INLINE_ ConstIterator(const Element *p_E) { E = p_E; } _FORCE_INLINE_ ConstIterator() {} diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index ef5867c685..3cb2a6bfb5 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -69,17 +69,17 @@ struct VariantCaster<const T &> { template <> \ struct VariantCaster<m_enum> { \ static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ - return (m_enum)p_variant.operator int(); \ + return (m_enum)p_variant.operator int64_t(); \ } \ }; \ template <> \ struct PtrToArg<m_enum> { \ _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \ - return m_enum(*reinterpret_cast<const int *>(p_ptr)); \ + return m_enum(*reinterpret_cast<const int64_t *>(p_ptr)); \ } \ typedef int64_t EncodeT; \ _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ - *(int *)p_ptr = p_val; \ + *(int64_t *)p_ptr = p_val; \ } \ }; diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 7852187b77..8836e257a9 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -105,7 +105,7 @@ struct PtrToArg {}; } \ } -MAKE_PTRARGCONV(bool, uint32_t); +MAKE_PTRARGCONV(bool, uint8_t); // Integer types. MAKE_PTRARGCONV(uint8_t, int64_t); MAKE_PTRARGCONV(int8_t, int64_t); diff --git a/core/variant/variant.h b/core/variant/variant.h index 4dc706e853..780f9b4e70 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -118,6 +118,11 @@ public: VARIANT_MAX }; + enum { + // Maximum recursion depth allowed when serializing variants. + MAX_RECURSION_DEPTH = 1024, + }; + private: friend struct _VariantCall; friend class VariantInternal; diff --git a/core/variant/variant_parser.h b/core/variant/variant_parser.h index 05fc29b5e0..1ba26db6ed 100644 --- a/core/variant/variant_parser.h +++ b/core/variant/variant_parser.h @@ -73,9 +73,9 @@ public: struct ResourceParser { void *userdata = nullptr; - ParseResourceFunc func; - ParseResourceFunc ext_func; - ParseResourceFunc sub_func; + ParseResourceFunc func = nullptr; + ParseResourceFunc ext_func = nullptr; + ParseResourceFunc sub_func = nullptr; }; enum TokenType { diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 64f07e075e..34dbf130b6 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -249,10 +249,6 @@ struct VariantUtilityFunctions { return Math::move_toward(from, to, delta); } - static inline double dectime(double value, double amount, double step) { - return Math::dectime(value, amount, step); - } - static inline double deg2rad(double angle_deg) { return Math::deg2rad(angle_deg); } @@ -1195,7 +1191,6 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(smoothstep, sarray("from", "to", "x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH); - FUNCBINDR(dectime, sarray("value", "amount", "step"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(deg2rad, sarray("deg"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(rad2deg, sarray("rad"), Variant::UTILITY_FUNC_TYPE_MATH); |