diff options
Diffstat (limited to 'core')
50 files changed, 283 insertions, 490 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 06bfc0c562..79fa6a0895 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -321,9 +321,9 @@ bool ProjectSettings::_get(const StringName &p_name, Variant &r_ret) const { struct _VCSort { String name; - Variant::Type type; - int order; - uint32_t flags; + Variant::Type type = Variant::VARIANT_MAX; + int order = 0; + uint32_t flags = 0; bool operator<(const _VCSort &p_vcs) const { return order == p_vcs.order ? name < p_vcs.name : order < p_vcs.order; } }; diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 8308c4fe53..0f0b8ed63f 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -58,15 +58,15 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const return (ThreadLoadStatus)tls; } -RES ResourceLoader::load_threaded_get(const String &p_path) { +Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) { Error error; - RES res = ::ResourceLoader::load_threaded_get(p_path, &error); + Ref<Resource> res = ::ResourceLoader::load_threaded_get(p_path, &error); return res; } -RES ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) { +Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) { Error err = OK; - RES ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err); + Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err); ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'."); return ret; @@ -137,12 +137,12 @@ void ResourceLoader::_bind_methods() { ////// ResourceSaver ////// -Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceSaver::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'."); return ::ResourceSaver::save(p_path, p_resource, p_flags); } -Vector<String> ResourceSaver::get_recognized_extensions(const RES &p_resource) { +Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) { ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object."); List<String> exts; ::ResourceSaver::get_recognized_extensions(p_resource, &exts); @@ -1970,7 +1970,7 @@ Variant ClassDB::instantiate(const StringName &p_class) const { RefCounted *r = Object::cast_to<RefCounted>(obj); if (r) { - return REF(r); + return Ref<RefCounted>(r); } else { return obj; } diff --git a/core/core_bind.h b/core/core_bind.h index bc68be3f62..f6f2791006 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -73,9 +73,9 @@ public: Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false); ThreadLoadStatus load_threaded_get_status(const String &p_path, Array r_progress = Array()); - RES load_threaded_get(const String &p_path); + Ref<Resource> load_threaded_get(const String &p_path); - RES load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE); + Ref<Resource> load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE); Vector<String> get_recognized_extensions_for_type(const String &p_type); void set_abort_on_missing_resources(bool p_abort); PackedStringArray get_dependencies(const String &p_path); @@ -107,8 +107,8 @@ public: static ResourceSaver *get_singleton() { return singleton; } - Error save(const String &p_path, const RES &p_resource, uint32_t p_flags); - Vector<String> get_recognized_extensions(const RES &p_resource); + Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags); + Vector<String> get_recognized_extensions(const Ref<Resource> &p_resource); ResourceSaver() { singleton = this; } }; diff --git a/core/core_constants.cpp b/core/core_constants.cpp index 98b720ab65..2a514b68d8 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -41,7 +41,7 @@ struct _CoreConstant { StringName enum_name; bool ignore_value_in_docs = false; #endif - const char *name; + const char *name = nullptr; int value = 0; _CoreConstant() {} diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index f62d2cce1f..d0fd4feaa5 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -141,7 +141,7 @@ void Crypto::_bind_methods() { /// Resource loader/saver -RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); @@ -185,7 +185,7 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const return ""; } -Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceFormatSaverCrypto::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { Error err; Ref<X509Certificate> cert = p_resource; Ref<CryptoKey> key = p_resource; @@ -201,7 +201,7 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc return OK; } -void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { +void ResourceFormatSaverCrypto::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const { const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource); const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource); if (cert) { @@ -215,6 +215,6 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, } } -bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const { +bool ResourceFormatSaverCrypto::recognize(const Ref<Resource> &p_resource) const { return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource); } diff --git a/core/crypto/crypto.h b/core/crypto/crypto.h index 9de2c16fbc..fb4f7dd88f 100644 --- a/core/crypto/crypto.h +++ b/core/crypto/crypto.h @@ -117,7 +117,7 @@ public: class ResourceFormatLoaderCrypto : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; @@ -125,9 +125,9 @@ public: class ResourceFormatSaverCrypto : public ResourceFormatSaver { public: - virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); - virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; - virtual bool recognize(const RES &p_resource) const; + virtual Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = 0); + virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const; + virtual bool recognize(const Ref<Resource> &p_resource) const; }; #endif // CRYPTO_H diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index a312ce4ebd..a1d54f9c6d 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -1069,4 +1069,6 @@ void gdnative_setup_interface(GDNativeInterface *p_interface) { gdni.classdb_register_extension_class_property_subgroup = nullptr; gdni.classdb_register_extension_class_signal = nullptr; gdni.classdb_unregister_extension_class = nullptr; + + gdni.get_library_path = nullptr; } diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index 2bac52dc4a..ad4c8917df 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -545,6 +545,9 @@ typedef struct { void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix); void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */ + + void (*get_library_path)(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path); + } GDNativeInterface; /* INITIALIZATION */ diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 076d04a5eb..5c02cb9190 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -261,8 +261,14 @@ void NativeExtension::_unregister_extension_class(const GDNativeExtensionClassLi self->extension_classes.erase(class_name); } +void NativeExtension::_get_library_path(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path) { + NativeExtension *self = static_cast<NativeExtension *>(p_library); + + *(String *)r_path = self->library_path; +} + Error NativeExtension::open_library(const String &p_path, const String &p_entry_symbol) { - Error err = OS::get_singleton()->open_dynamic_library(p_path, library, true); + Error err = OS::get_singleton()->open_dynamic_library(p_path, library, true, &library_path); if (err != OK) { return err; } @@ -354,9 +360,10 @@ void NativeExtension::initialize_native_extensions() { gdnative_interface.classdb_register_extension_class_property_subgroup = _register_extension_class_property_subgroup; gdnative_interface.classdb_register_extension_class_signal = _register_extension_class_signal; gdnative_interface.classdb_unregister_extension_class = _unregister_extension_class; + gdnative_interface.get_library_path = _get_library_path; } -RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> NativeExtensionResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<ConfigFile> config; config.instantiate(); @@ -367,14 +374,14 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or } if (err != OK) { - return RES(); + return Ref<Resource>(); } if (!config->has_section_key("configuration", "entry_symbol")) { if (r_error) { *r_error = ERR_INVALID_DATA; } - return RES(); + return Ref<Resource>(); } String entry_symbol = config->get_value("configuration", "entry_symbol"); @@ -406,7 +413,7 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or if (r_error) { *r_error = ERR_FILE_NOT_FOUND; } - return RES(); + return Ref<Resource>(); } if (!library_path.is_resource_file()) { @@ -423,7 +430,7 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or } if (err != OK) { - return RES(); + return Ref<Resource>(); } return lib; diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h index ebfedfb29a..028a627b2e 100644 --- a/core/extension/native_extension.h +++ b/core/extension/native_extension.h @@ -39,6 +39,7 @@ class NativeExtension : public Resource { GDCLASS(NativeExtension, Resource) void *library = nullptr; // pointer if valid, + String library_path; struct Extension { ObjectNativeExtension native_extension; @@ -54,6 +55,7 @@ class NativeExtension : public Resource { static void _register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix); static void _register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); static void _unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); + static void _get_library_path(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path); GDNativeInitialization initialization; int32_t level_initialized = -1; @@ -90,7 +92,7 @@ VARIANT_ENUM_CAST(NativeExtension::InitializationLevel) class NativeExtensionResourceLoader : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/input/input.cpp b/core/input/input.cpp index c0c029fda0..40cea2cd80 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -74,7 +74,7 @@ void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr; Input::MouseMode (*Input::get_mouse_mode_func)() = nullptr; void (*Input::warp_mouse_func)(const Vector2 &p_position) = nullptr; Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr; -void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr; +void (*Input::set_custom_mouse_cursor_func)(const Ref<Resource> &, Input::CursorShape, const Vector2 &) = nullptr; Input *Input::get_singleton() { return singleton; @@ -850,7 +850,7 @@ Input::CursorShape Input::get_current_cursor_shape() const { return get_current_cursor_shape_func(); } -void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { +void Input::set_custom_mouse_cursor(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { if (Engine::get_singleton()->is_editor_hint()) { return; } diff --git a/core/input/input.h b/core/input/input.h index 42016f2417..5a7cb84ece 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -113,10 +113,10 @@ private: int mouse_from_touch_index = -1; struct VelocityTrack { - uint64_t last_tick; + uint64_t last_tick = 0; Vector2 velocity; Vector2 accum; - float accum_t; + float accum_t = 0.0f; float min_ref_frame; float max_ref_frame; @@ -219,7 +219,7 @@ private: static void (*warp_mouse_func)(const Vector2 &p_position); static CursorShape (*get_current_cursor_shape_func)(); - static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); + static void (*set_custom_mouse_cursor_func)(const Ref<Resource> &, CursorShape, const Vector2 &); EventDispatchFunc event_dispatch_function = nullptr; @@ -305,7 +305,7 @@ public: CursorShape get_default_cursor_shape() const; void set_default_cursor_shape(CursorShape p_shape); CursorShape get_current_cursor_shape() const; - void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); + void set_custom_mouse_cursor(const Ref<Resource> &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); void parse_mapping(String p_mapping); void joy_button(int p_device, JoyButton p_button, bool p_pressed); diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index 6afbf6adf5..214d391c95 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -86,15 +86,15 @@ class FileAccessNetwork : public FileAccess { Semaphore page_sem; Mutex buffer_mutex; bool opened = false; - uint64_t total_size; + uint64_t total_size = 0; mutable uint64_t pos = 0; - int32_t id; + int32_t id = -1; mutable bool eof_flag = false; mutable int32_t last_page = -1; mutable uint8_t *last_page_buff = nullptr; - int32_t page_size; - int32_t read_ahead; + int32_t page_size = 0; + int32_t read_ahead = 0; mutable int waiting_on_page = -1; @@ -108,7 +108,8 @@ class FileAccessNetwork : public FileAccess { mutable Error response; - uint64_t exists_modtime; + uint64_t exists_modtime = 0; + friend class FileAccessNetworkClient; void _queue_page(int32_t p_page) const; void _respond(uint64_t p_len, Error p_status); diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index 2504aeedc4..ae58d99a66 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -80,7 +80,7 @@ class FileAccessZip : public FileAccess { unzFile zfile = nullptr; unz_file_info64 file_info; - mutable bool at_eof; + mutable bool at_eof = false; void _close(); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 2ccc95f0de..9cf7c9caba 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -111,13 +111,13 @@ void ImageLoader::cleanup() { ///////////////// -RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); if (f.is_null()) { if (r_error) { *r_error = ERR_CANT_OPEN; } - return RES(); + return Ref<Resource>(); } uint8_t header[4] = { 0, 0, 0, 0 }; @@ -128,7 +128,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin if (r_error) { *r_error = ERR_FILE_UNRECOGNIZED; } - ERR_FAIL_V(RES()); + ERR_FAIL_V(Ref<Resource>()); } String extension = f->get_pascal_string(); @@ -146,7 +146,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin if (r_error) { *r_error = ERR_FILE_UNRECOGNIZED; } - ERR_FAIL_V(RES()); + ERR_FAIL_V(Ref<Resource>()); } Ref<Image> image; @@ -158,7 +158,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin if (r_error) { *r_error = err; } - return RES(); + return Ref<Resource>(); } if (r_error) { diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 9409617268..c91d382c25 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -72,7 +72,7 @@ public: class ResourceFormatLoaderImage : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 52674150bb..5156a5cb99 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -74,8 +74,7 @@ struct _IP_ResolverPrivate { Semaphore sem; Thread thread; - //Semaphore* semaphore; - bool thread_abort; + bool thread_abort = false; void resolve_queues() { for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 87fb4c825c..bb9606c94b 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -601,7 +601,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } if (Object::cast_to<RefCounted>(obj)) { - REF ref = REF(Object::cast_to<RefCounted>(obj)); + Ref<RefCounted> ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj)); r_variant = ref; } else { r_variant = obj; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 96efffd49b..e6535c67a4 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -208,13 +208,13 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res } Variant p = get(E.name); if (p.get_type() == Variant::OBJECT) { - RES sr = p; + Ref<Resource> sr = p; if (sr.is_valid()) { if (sr->is_local_to_scene()) { if (remap_cache.has(sr)) { p = remap_cache[sr]; } else { - RES dupe = sr->duplicate_for_local_scene(p_for_scene, remap_cache); + Ref<Resource> dupe = sr->duplicate_for_local_scene(p_for_scene, remap_cache); p = dupe; remap_cache[sr] = dupe; } @@ -240,7 +240,7 @@ void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, R } Variant p = get(E.name); if (p.get_type() == Variant::OBJECT) { - RES sr = p; + Ref<Resource> sr = p; if (sr.is_valid()) { if (sr->is_local_to_scene()) { if (!remap_cache.has(sr)) { @@ -269,7 +269,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const { if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) { r->set(E.name, p.duplicate(p_subresources)); } else if (p.get_type() == Variant::OBJECT && (p_subresources || (E.usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) { - RES sr = p; + Ref<Resource> sr = p; if (sr.is_valid()) { r->set(E.name, sr->duplicate(p_subresources)); } @@ -321,7 +321,7 @@ void Resource::notify_change_to_owners() { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE_MSG(!obj, "Object was deleted, while still owning a resource."); //wtf //TODO store string - obj->call("resource_changed", RES(this)); + obj->call("resource_changed", Ref<Resource>(this)); } } @@ -335,7 +335,7 @@ uint32_t Resource::hash_edited_version() const { for (const PropertyInfo &E : plist) { if (E.usage & PROPERTY_USAGE_STORAGE && E.type == Variant::OBJECT && E.hint == PROPERTY_HINT_RESOURCE_TYPE) { - RES res = get(E.name); + Ref<Resource> res = get(E.name); if (res.is_valid()) { hash = hash_djb2_one_32(res->hash_edited_version(), hash); } diff --git a/core/io/resource.h b/core/io/resource.h index 8068000f32..43ae104da5 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -150,8 +150,6 @@ public: ~Resource(); }; -typedef Ref<Resource> RES; - class ResourceCache { friend class Resource; friend class ResourceLoader; //need the lock diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index c535c2bfeb..c9eb0e5234 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -388,7 +388,7 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { path = remaps[path]; } - RES res = ResourceLoader::load(path, exttype); + Ref<Resource> res = ResourceLoader::load(path, exttype); if (res.is_null()) { WARN_PRINT(String("Couldn't load resource: " + path).utf8().get_data()); @@ -696,7 +696,7 @@ Error ResourceLoaderBinary::load() { } if (cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE && ResourceCache::has(path)) { - RES cached = ResourceCache::get(path); + Ref<Resource> cached = ResourceCache::get(path); if (cached.is_valid()) { //already loaded, don't do anything stage++; @@ -717,7 +717,7 @@ Error ResourceLoaderBinary::load() { String t = get_unicode_string(); - RES res; + Ref<Resource> res; if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(path)) { //use the existing one @@ -745,7 +745,7 @@ Error ResourceLoaderBinary::load() { ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource type in resource field not a resource, type is: " + obj_class + "."); } - res = RES(r); + res = Ref<Resource>(r); if (!path.is_empty() && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) { r->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); //if got here because the resource with same path has different type, replace it } @@ -1026,7 +1026,7 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) { return type; } -RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; } @@ -1034,7 +1034,7 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi Error err; Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err); - ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'."); + ERR_FAIL_COND_V_MSG(err != OK, Ref<Resource>(), "Cannot open file '" + p_path + "'."); ResourceLoaderBinary loader; loader.cache_mode = p_cache_mode; @@ -1052,7 +1052,7 @@ RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_origi } if (err) { - return RES(); + return Ref<Resource>(); } return loader.resource; } @@ -1178,7 +1178,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons err = loader.load(); ERR_FAIL_COND_V(err != ERR_FILE_EOF, ERR_FILE_CORRUPT); - RES res = loader.get_resource(); + Ref<Resource> res = loader.get_resource(); ERR_FAIL_COND_V(!res.is_valid(), ERR_FILE_CORRUPT); return ResourceFormatSaverBinary::singleton->save(p_path, res); @@ -1287,6 +1287,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_8(b); b = f->get_8(); } + f.unref(); bool all_ok = fw->get_error() == OK; @@ -1352,7 +1353,7 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(Ref<FileAccess> f, int p_byt } } -void ResourceFormatSaverBinaryInstance::write_variant(Ref<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) { +void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const Variant &p_property, Map<Ref<Resource>, int> &resource_map, Map<Ref<Resource>, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint) { switch (p_property.get_type()) { case Variant::NIL: { f->store_32(VARIANT_NIL); @@ -1561,7 +1562,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V } break; case Variant::OBJECT: { f->store_32(VARIANT_OBJECT); - RES res = p_property; + Ref<Resource> res = p_property; if (res.is_null()) { f->store_32(OBJECT_EMPTY); return; // don't save it @@ -1727,7 +1728,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) { switch (p_variant.get_type()) { case Variant::OBJECT: { - RES res = p_variant; + Ref<Resource> res = p_variant; if (res.is_null() || external_resources.has(res)) { return; @@ -1755,7 +1756,7 @@ 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) { - RES sres = value; + Ref<Resource> sres = value; if (sres.is_valid()) { NonPersistentKey npk; npk.base = res; @@ -1832,7 +1833,7 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) return strings.size() - 1; } -Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { Error err; Ref<FileAccess> f; if (p_flags & ResourceSaver::FLAG_COMPRESS) { @@ -1902,7 +1903,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p List<ResourceData> resources; { - for (const RES &E : saved_resources) { + for (const Ref<Resource> &E : saved_resources) { ResourceData &rd = resources.push_back(ResourceData())->get(); rd.type = E->get_class(); @@ -1949,10 +1950,10 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p // save external resource table f->store_32(external_resources.size()); //amount of external resources - Vector<RES> save_order; + Vector<Ref<Resource>> save_order; save_order.resize(external_resources.size()); - for (const KeyValue<RES, int> &E : external_resources) { + for (const KeyValue<Ref<Resource>, int> &E : external_resources) { save_order.write[E.value] = E.key; } @@ -1969,7 +1970,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p Vector<uint64_t> ofs_pos; Set<String> used_unique_ids; - for (RES &r : saved_resources) { + for (Ref<Resource> &r : saved_resources) { if (r->is_built_in()) { if (!r->get_scene_unique_id().is_empty()) { if (used_unique_ids.has(r->get_scene_unique_id())) { @@ -1981,9 +1982,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } } - Map<RES, int> resource_map; + Map<Ref<Resource>, int> resource_map; int res_index = 0; - for (RES &r : saved_resources) { + for (Ref<Resource> &r : saved_resources) { if (r->is_built_in()) { if (r->get_scene_unique_id().is_empty()) { String new_id; @@ -2044,17 +2045,17 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p return OK; } -Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceFormatSaverBinary::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { String local_path = ProjectSettings::get_singleton()->localize_path(p_path); ResourceFormatSaverBinaryInstance saver; return saver.save(local_path, p_resource, p_flags); } -bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const { +bool ResourceFormatSaverBinary::recognize(const Ref<Resource> &p_resource) const { return true; //all recognized } -void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { +void ResourceFormatSaverBinary::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const { String base = p_resource->get_base_extension().to_lower(); p_extensions->push_back(base); if (base != "res") { diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 72a3c6751d..92d4e4eeaa 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -50,7 +50,7 @@ class ResourceLoaderBinary { ResourceUID::ID uid = ResourceUID::INVALID_ID; Vector<char> str_buf; - List<RES> resource_cache; + List<Ref<Resource>> resource_cache; Vector<StringName> string_map; @@ -60,7 +60,7 @@ class ResourceLoaderBinary { String path; String type; ResourceUID::ID uid = ResourceUID::INVALID_ID; - RES cache; + Ref<Resource> cache; }; bool using_named_scene_ids = false; @@ -75,7 +75,7 @@ class ResourceLoaderBinary { }; Vector<IntResource> internal_resources; - Map<String, RES> internal_index_cache; + Map<String, Ref<Resource>> internal_index_cache; String get_unicode_string(); void _advance_padding(uint32_t p_len); @@ -89,7 +89,7 @@ class ResourceLoaderBinary { Error parse_variant(Variant &r_v); - Map<String, RES> dependency_cache; + Map<String, Ref<Resource>> dependency_cache; public: void set_local_path(const String &p_local_path); @@ -107,7 +107,7 @@ public: class ResourceFormatLoaderBinary : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; @@ -127,20 +127,20 @@ class ResourceFormatSaverBinaryInstance { bool big_endian; bool takeover_paths; String magic; - Set<RES> resource_set; + Set<Ref<Resource>> resource_set; struct NonPersistentKey { //for resource properties generated on the fly - RES base; + Ref<Resource> base; StringName property; bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; } }; - Map<NonPersistentKey, RES> non_persistent_map; + Map<NonPersistentKey, Ref<Resource>> non_persistent_map; Map<StringName, int> string_map; Vector<StringName> strings; - Map<RES, int> external_resources; - List<RES> saved_resources; + Map<Ref<Resource>, int> external_resources; + List<Ref<Resource>> saved_resources; struct Property { int name_idx; @@ -167,16 +167,16 @@ public: // 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(Ref<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()); + Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = 0); + static void write_variant(Ref<FileAccess> f, const Variant &p_property, Map<Ref<Resource>, int> &resource_map, Map<Ref<Resource>, int> &external_resources, Map<StringName, int> &string_map, const PropertyInfo &p_hint = PropertyInfo()); }; class ResourceFormatSaverBinary : public ResourceFormatSaver { public: static ResourceFormatSaverBinary *singleton; - virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); - virtual bool recognize(const RES &p_resource) const; - virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; + virtual Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const Ref<Resource> &p_resource) const; + virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const; ResourceFormatSaverBinary(); }; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index b4f73b3b25..984cf06d2b 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -114,7 +114,7 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy return OK; } -RES ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> ResourceFormatImporter::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { PathAndType pat; Error err = _get_path_and_type(p_path, pat); @@ -123,10 +123,10 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_ *r_error = err; } - return RES(); + return Ref<Resource>(); } - RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_cache_mode, r_error, p_use_sub_threads, r_progress); + Ref<Resource> res = ResourceLoader::_load(pat.path, p_path, pat.type, p_cache_mode, r_error, p_use_sub_threads, r_progress); #ifdef TOOLS_ENABLED if (res.is_valid()) { diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index 2fffc16ad8..b3d777847b 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -58,7 +58,7 @@ class ResourceFormatImporter : public ResourceFormatLoader { public: static ResourceFormatImporter *get_singleton() { return singleton; } - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual bool recognize_path(const String &p_path, const String &p_for_type = String()) const; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index fe9693aa20..c8cebd672a 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -125,14 +125,14 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) } } -RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { Variant res; if (GDVIRTUAL_CALL(_load, p_path, p_original_path, p_use_sub_threads, p_cache_mode, res)) { if (res.get_type() == Variant::INT) { // Error code, abort. if (r_error) { *r_error = (Error)res.operator int64_t(); } - return RES(); + return Ref<Resource>(); } else { // Success, pass on result. if (r_error) { *r_error = OK; @@ -141,7 +141,7 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa } } - ERR_FAIL_V_MSG(RES(), "Failed to load resource '" + p_path + "'. ResourceFormatLoader::load was not implemented for this resource type."); + ERR_FAIL_V_MSG(Ref<Resource>(), "Failed to load resource '" + p_path + "'. ResourceFormatLoader::load was not implemented for this resource type."); } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { @@ -185,7 +185,7 @@ void ResourceFormatLoader::_bind_methods() { /////////////////////////////////// -RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress) { +Ref<Resource> ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress) { bool found = false; // Try all loaders and pick the first match for the type hint @@ -194,7 +194,7 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c continue; } found = true; - RES res = loader[i]->load(p_path, !p_original_path.is_empty() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode); + Ref<Resource> res = loader[i]->load(p_path, !p_original_path.is_empty() ? p_original_path : p_path, r_error, p_use_sub_threads, r_progress, p_cache_mode); if (res.is_null()) { continue; } @@ -202,15 +202,15 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c return res; } - ERR_FAIL_COND_V_MSG(found, RES(), + ERR_FAIL_COND_V_MSG(found, Ref<Resource>(), vformat("Failed loading resource: %s. Make sure resources have been imported by opening the project in the editor at least once.", p_path)); #ifdef TOOLS_ENABLED Ref<FileAccess> file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES); - ERR_FAIL_COND_V_MSG(!file_check->file_exists(p_path), RES(), "Resource file not found: " + p_path + "."); + ERR_FAIL_COND_V_MSG(!file_check->file_exists(p_path), Ref<Resource>(), "Resource file not found: " + p_path + "."); #endif - ERR_FAIL_V_MSG(RES(), "No loader found for resource: " + p_path + "."); + ERR_FAIL_V_MSG(Ref<Resource>(), "No loader found for resource: " + p_path + "."); } void ResourceLoader::_thread_load_function(void *p_userdata) { @@ -342,7 +342,7 @@ Error ResourceLoader::load_threaded_request(const String &p_path, const String & Resource **rptr = ResourceCache::resources.getptr(local_path); if (rptr) { - RES res(*rptr); + Ref<Resource> res(*rptr); //it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached if (res.is_valid()) { //referencing is fine @@ -427,7 +427,7 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const return status; } -RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { +Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { String local_path = _validate_local_path(p_path); thread_load_mutex->lock(); @@ -436,7 +436,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { if (r_error) { *r_error = ERR_INVALID_PARAMETER; } - return RES(); + return Ref<Resource>(); } ThreadLoadTask &load_task = thread_load_tasks[local_path]; @@ -480,11 +480,11 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { if (r_error) { *r_error = ERR_INVALID_PARAMETER; } - return RES(); + return Ref<Resource>(); } } - RES resource = load_task.resource; + Ref<Resource> resource = load_task.resource; if (r_error) { *r_error = load_task.error; } @@ -504,7 +504,7 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) { return resource; } -RES ResourceLoader::load(const String &p_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error) { +Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error) { if (r_error) { *r_error = ERR_CANT_OPEN; } @@ -522,7 +522,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, Resour *r_error = err; } thread_load_mutex->unlock(); - return RES(); + return Ref<Resource>(); } thread_load_mutex->unlock(); @@ -535,7 +535,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, Resour Resource **rptr = ResourceCache::resources.getptr(local_path); if (rptr) { - RES res(*rptr); + Ref<Resource> res(*rptr); //it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached if (res.is_valid()) { @@ -575,16 +575,16 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, Resour String path = _path_remap(local_path, &xl_remapped); if (path.is_empty()) { - ERR_FAIL_V_MSG(RES(), "Remapping '" + local_path + "' failed."); + ERR_FAIL_V_MSG(Ref<Resource>(), "Remapping '" + local_path + "' failed."); } print_verbose("Loading resource: " + path); float p; - RES res = _load(path, local_path, p_type_hint, p_cache_mode, r_error, false, &p); + Ref<Resource> res = _load(path, local_path, p_type_hint, p_cache_mode, r_error, false, &p); if (res.is_null()) { print_verbose("Failed loading resource: " + path); - return RES(); + return Ref<Resource>(); } if (xl_remapped) { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index a3fdefa0f1..15ecfacf4a 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -61,7 +61,7 @@ protected: GDVIRTUAL4RC(Variant, _load, String, String, bool, int) public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual bool exists(const String &p_path) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; @@ -85,7 +85,7 @@ typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text); typedef void (*DependencyErrorNotify)(void *p_ud, const String &p_loading, const String &p_which, const String &p_type); typedef Error (*ResourceLoaderImport)(const String &p_path); -typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path); +typedef void (*ResourceLoadedCallback)(Ref<Resource> p_resource, const String &p_path); class ResourceLoader { enum { @@ -121,7 +121,7 @@ private: friend class ResourceFormatImporter; friend class ResourceInteractiveLoader; // Internal load function. - static RES _load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress); + static Ref<Resource> _load(const String &p_path, const String &p_original_path, const String &p_type_hint, ResourceFormatLoader::CacheMode p_cache_mode, Error *r_error, bool p_use_sub_threads, float *r_progress); static ResourceLoadedCallback _loaded_callback; @@ -138,7 +138,7 @@ private: ThreadLoadStatus status = THREAD_LOAD_IN_PROGRESS; ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE; Error error = OK; - RES resource; + Ref<Resource> resource; bool xl_remapped = false; bool use_sub_threads = false; bool start_next = true; @@ -161,9 +161,9 @@ private: public: static Error load_threaded_request(const String &p_path, const String &p_type_hint = "", bool p_use_sub_threads = false, ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE, const String &p_source_resource = String()); static ThreadLoadStatus load_threaded_get_status(const String &p_path, float *r_progress = nullptr); - static RES load_threaded_get(const String &p_path, Error *r_error = nullptr); + static Ref<Resource> load_threaded_get(const String &p_path, Error *r_error = nullptr); - static RES load(const String &p_path, const String &p_type_hint = "", ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE, Error *r_error = nullptr); + static Ref<Resource> load(const String &p_path, const String &p_type_hint = "", ResourceFormatLoader::CacheMode p_cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE, Error *r_error = nullptr); static bool exists(const String &p_path, const String &p_type_hint = ""); static void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index c883e8502f..2f5c5b54dd 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -41,7 +41,7 @@ bool ResourceSaver::timestamp_on_save = false; ResourceSavedCallback ResourceSaver::save_callback = nullptr; ResourceSaverGetResourceIDForPath ResourceSaver::save_get_id_for_path = nullptr; -Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceFormatSaver::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { int64_t res; if (GDVIRTUAL_CALL(_save, p_path, p_resource, p_flags, res)) { return (Error)res; @@ -50,7 +50,7 @@ Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uin return ERR_METHOD_NOT_FOUND; } -bool ResourceFormatSaver::recognize(const RES &p_resource) const { +bool ResourceFormatSaver::recognize(const Ref<Resource> &p_resource) const { bool success; if (GDVIRTUAL_CALL(_recognize, p_resource, success)) { return success; @@ -59,7 +59,7 @@ bool ResourceFormatSaver::recognize(const RES &p_resource) const { return false; } -void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { +void ResourceFormatSaver::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const { PackedStringArray exts; if (GDVIRTUAL_CALL(_get_recognized_extensions, p_resource, exts)) { const String *r = exts.ptr(); @@ -75,7 +75,7 @@ void ResourceFormatSaver::_bind_methods() { GDVIRTUAL_BIND(_get_recognized_extensions, "resource"); } -Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceSaver::save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags) { String extension = p_path.get_extension(); Error err = ERR_FILE_UNRECOGNIZED; @@ -102,7 +102,7 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t String local_path = ProjectSettings::get_singleton()->localize_path(p_path); - RES rwcopy = p_resource; + Ref<Resource> rwcopy = p_resource; if (p_flags & FLAG_CHANGE_PATH) { rwcopy->set_path(local_path); } @@ -139,7 +139,7 @@ void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) { save_callback = p_callback; } -void ResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) { +void ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) { for (int i = 0; i < saver_count; i++) { saver[i]->get_recognized_extensions(p_resource, p_extensions); } diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index ebc3be91a1..088317bfbe 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -41,14 +41,14 @@ class ResourceFormatSaver : public RefCounted { protected: static void _bind_methods(); - GDVIRTUAL3R(int64_t, _save, String, RES, uint32_t) - GDVIRTUAL1RC(bool, _recognize, RES) - GDVIRTUAL1RC(Vector<String>, _get_recognized_extensions, RES) + GDVIRTUAL3R(int64_t, _save, String, Ref<Resource>, uint32_t) + GDVIRTUAL1RC(bool, _recognize, Ref<Resource>) + GDVIRTUAL1RC(Vector<String>, _get_recognized_extensions, Ref<Resource>) public: - virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); - virtual bool recognize(const RES &p_resource) const; - virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; + virtual Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const Ref<Resource> &p_resource) const; + virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const; virtual ~ResourceFormatSaver() {} }; @@ -81,8 +81,8 @@ public: FLAG_REPLACE_SUBRESOURCE_PATHS = 64, }; - static Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = (uint32_t)FLAG_NONE); - static void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions); + static Error save(const String &p_path, const Ref<Resource> &p_resource, uint32_t p_flags = (uint32_t)FLAG_NONE); + static void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions); static void add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front = false); static void remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver); diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index ae1ad304d7..f36eb7c763 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -34,7 +34,7 @@ #include "core/string/translation.h" #include "core/string/translation_po.h" -RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { +Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { if (r_error) { *r_error = ERR_FILE_CORRUPT; } @@ -49,7 +49,7 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { uint16_t version_maj = f->get_16(); uint16_t version_min = f->get_16(); - ERR_FAIL_COND_V_MSG(version_maj > 1, RES(), vformat("Unsupported MO file %s, version %d.%d.", path, version_maj, version_min)); + ERR_FAIL_COND_V_MSG(version_maj > 1, Ref<Resource>(), vformat("Unsupported MO file %s, version %d.%d.", path, version_maj, version_min)); uint32_t num_strings = f->get_32(); uint32_t id_table_offset = f->get_32(); @@ -170,14 +170,14 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { // If we reached last line and it's not a content line, break, otherwise let processing that last loop if (is_eof && l.is_empty()) { if (status == STATUS_READING_ID || status == STATUS_READING_CONTEXT || (status == STATUS_READING_PLURAL && plural_index != plural_forms - 1)) { - ERR_FAIL_V_MSG(RES(), "Unexpected EOF while reading PO file at: " + path + ":" + itos(line)); + ERR_FAIL_V_MSG(Ref<Resource>(), "Unexpected EOF while reading PO file at: " + path + ":" + itos(line)); } else { break; } } if (l.begins_with("msgctxt")) { - ERR_FAIL_COND_V_MSG(status != STATUS_READING_STRING && status != STATUS_READING_PLURAL, RES(), "Unexpected 'msgctxt', was expecting 'msgid_plural' or 'msgstr' before 'msgctxt' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(status != STATUS_READING_STRING && status != STATUS_READING_PLURAL, Ref<Resource>(), "Unexpected 'msgctxt', was expecting 'msgid_plural' or 'msgstr' before 'msgctxt' while parsing: " + path + ":" + itos(line)); // In PO file, "msgctxt" appears before "msgid". If we encounter a "msgctxt", we add what we have read // and set "entered_context" to true to prevent adding twice. @@ -185,7 +185,7 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { if (status == STATUS_READING_STRING) { translation->add_message(msg_id, msg_str, msg_context); } else if (status == STATUS_READING_PLURAL) { - ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, RES(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); translation->add_plural_message(msg_id, msgs_plural, msg_context); } } @@ -197,9 +197,9 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { if (l.begins_with("msgid_plural")) { if (plural_forms == 0) { - ERR_FAIL_V_MSG(RES(), "PO file uses 'msgid_plural' but 'Plural-Forms' is invalid or missing in header: " + path + ":" + itos(line)); + ERR_FAIL_V_MSG(Ref<Resource>(), "PO file uses 'msgid_plural' but 'Plural-Forms' is invalid or missing in header: " + path + ":" + itos(line)); } else if (status != STATUS_READING_ID) { - ERR_FAIL_V_MSG(RES(), "Unexpected 'msgid_plural', was expecting 'msgid' before 'msgid_plural' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_V_MSG(Ref<Resource>(), "Unexpected 'msgid_plural', was expecting 'msgid' before 'msgid_plural' while parsing: " + path + ":" + itos(line)); } // We don't record the message in "msgid_plural" itself as tr_n(), TTRN(), RTRN() interfaces provide the plural string already. // We just have to reset variables related to plurals for "msgstr[]" later on. @@ -209,14 +209,14 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { msgs_plural.resize(plural_forms); status = STATUS_READING_PLURAL; } else if (l.begins_with("msgid")) { - ERR_FAIL_COND_V_MSG(status == STATUS_READING_ID, RES(), "Unexpected 'msgid', was expecting 'msgstr' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(status == STATUS_READING_ID, Ref<Resource>(), "Unexpected 'msgid', was expecting 'msgstr' while parsing: " + path + ":" + itos(line)); if (!msg_id.is_empty()) { if (!skip_this && !entered_context) { if (status == STATUS_READING_STRING) { translation->add_message(msg_id, msg_str, msg_context); } else if (status == STATUS_READING_PLURAL) { - ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, RES(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); translation->add_plural_message(msg_id, msgs_plural, msg_context); } } @@ -245,11 +245,11 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { } if (l.begins_with("msgstr[")) { - ERR_FAIL_COND_V_MSG(status != STATUS_READING_PLURAL, RES(), "Unexpected 'msgstr[]', was expecting 'msgid_plural' before 'msgstr[]' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(status != STATUS_READING_PLURAL, Ref<Resource>(), "Unexpected 'msgstr[]', was expecting 'msgid_plural' before 'msgstr[]' while parsing: " + path + ":" + itos(line)); plural_index++; // Increment to add to the next slot in vector msgs_plural. l = l.substr(9, l.length()).strip_edges(); } else if (l.begins_with("msgstr")) { - ERR_FAIL_COND_V_MSG(status != STATUS_READING_ID, RES(), "Unexpected 'msgstr', was expecting 'msgid' before 'msgstr' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(status != STATUS_READING_ID, Ref<Resource>(), "Unexpected 'msgstr', was expecting 'msgid' before 'msgstr' while parsing: " + path + ":" + itos(line)); l = l.substr(6, l.length()).strip_edges(); status = STATUS_READING_STRING; } @@ -262,7 +262,7 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { continue; // Nothing to read or comment. } - ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, RES(), "Invalid line '" + l + "' while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, Ref<Resource>(), "Invalid line '" + l + "' while parsing: " + path + ":" + itos(line)); l = l.substr(1, l.length()); // Find final quote, ignoring escaped ones (\"). @@ -284,7 +284,7 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { escape_next = false; } - ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), "Expected '\"' at end of message while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(end_pos == -1, Ref<Resource>(), "Expected '\"' at end of message while parsing: " + path + ":" + itos(line)); l = l.substr(0, end_pos); l = l.c_unescape(); @@ -296,7 +296,7 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { } else if (status == STATUS_READING_CONTEXT) { msg_context += l; } else if (status == STATUS_READING_PLURAL && plural_index >= 0) { - ERR_FAIL_COND_V_MSG(plural_index >= plural_forms, RES(), "Unexpected plural form while parsing: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(plural_index >= plural_forms, Ref<Resource>(), "Unexpected plural form while parsing: " + path + ":" + itos(line)); msgs_plural.write[plural_index] = msgs_plural[plural_index] + l; } @@ -314,13 +314,13 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { } } else if (status == STATUS_READING_PLURAL) { if (!skip_this && !msg_id.is_empty()) { - ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, RES(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); + ERR_FAIL_COND_V_MSG(plural_index != plural_forms - 1, Ref<Resource>(), "Number of 'msgstr[]' doesn't match with number of plural forms: " + path + ":" + itos(line)); translation->add_plural_message(msg_id, msgs_plural, msg_context); } } } - ERR_FAIL_COND_V_MSG(config.is_empty(), RES(), "No config found in file: " + path + "."); + ERR_FAIL_COND_V_MSG(config.is_empty(), Ref<Resource>(), "No config found in file: " + path + "."); Vector<String> configs = config.split("\n"); for (int i = 0; i < configs.size(); i++) { @@ -344,13 +344,13 @@ RES TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_error) { return translation; } -RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { +Ref<Resource> TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_CANT_OPEN; } Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); - ERR_FAIL_COND_V_MSG(f.is_null(), RES(), "Cannot open file '" + p_path + "'."); + ERR_FAIL_COND_V_MSG(f.is_null(), Ref<Resource>(), "Cannot open file '" + p_path + "'."); return load_translation(f, r_error); } diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h index 7da361cf24..4477ad7714 100644 --- a/core/io/translation_loader_po.h +++ b/core/io/translation_loader_po.h @@ -37,8 +37,8 @@ class TranslationLoaderPO : public ResourceFormatLoader { public: - static RES load_translation(Ref<FileAccess> f, Error *r_error = nullptr); - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); + static Ref<Resource> load_translation(Ref<FileAccess> f, Error *r_error = nullptr); + virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE); virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp index 23a0b5dd54..996f4f4d67 100644 --- a/core/math/convex_hull.cpp +++ b/core/math/convex_hull.cpp @@ -666,7 +666,7 @@ public: face_pool.reset(true); } - Vertex *vertex_list; + Vertex *vertex_list = nullptr; void compute(const Vector3 *p_coords, int32_t p_count); diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index 46b7d99b43..31fade5a99 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -74,14 +74,14 @@ Vector<Vector<Vector2>> Geometry2D::decompose_polygon_in_convex(Vector<Point2> p struct _AtlasWorkRect { Size2i s; Point2i p; - int idx; + int idx = 0; _FORCE_INLINE_ bool operator<(const _AtlasWorkRect &p_r) const { return s.width > p_r.s.width; }; }; struct _AtlasWorkRectResult { Vector<_AtlasWorkRect> result; - int max_w; - int max_h; + int max_w = 0; + int max_h = 0; }; void Geometry2D::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) { diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index 65fcf67664..a088b30d17 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -61,8 +61,8 @@ static int __bsr_clz32(uint32_t x) { class RandomPCG { pcg32_random_t pcg; - uint64_t current_seed; // The seed the current generator state started from. - uint64_t current_inc; + uint64_t current_seed = 0; // The seed the current generator state started from. + uint64_t current_inc = 0; public: static const uint64_t DEFAULT_SEED = 12047754176567800795U; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 61ce965bc3..593f27b7cf 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -39,190 +39,13 @@ #ifdef DEBUG_METHODS_ENABLED -MethodDefinition D_METHOD(const char *p_name) { +MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount) { MethodDefinition md; md.name = StaticCString::create(p_name); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.push_back(StaticCString::create(p_arg1)); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(2); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(3); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(4); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(5); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(6); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(7); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(8); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(9); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - md.args.write[8] = StaticCString::create(p_arg9); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(10); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - md.args.write[8] = StaticCString::create(p_arg9); - md.args.write[9] = StaticCString::create(p_arg10); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(11); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - md.args.write[8] = StaticCString::create(p_arg9); - md.args.write[9] = StaticCString::create(p_arg10); - md.args.write[10] = StaticCString::create(p_arg11); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(12); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - md.args.write[8] = StaticCString::create(p_arg9); - md.args.write[9] = StaticCString::create(p_arg10); - md.args.write[10] = StaticCString::create(p_arg11); - md.args.write[11] = StaticCString::create(p_arg12); - return md; -} - -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) { - MethodDefinition md; - md.name = StaticCString::create(p_name); - md.args.resize(13); - md.args.write[0] = StaticCString::create(p_arg1); - md.args.write[1] = StaticCString::create(p_arg2); - md.args.write[2] = StaticCString::create(p_arg3); - md.args.write[3] = StaticCString::create(p_arg4); - md.args.write[4] = StaticCString::create(p_arg5); - md.args.write[5] = StaticCString::create(p_arg6); - md.args.write[6] = StaticCString::create(p_arg7); - md.args.write[7] = StaticCString::create(p_arg8); - md.args.write[8] = StaticCString::create(p_arg9); - md.args.write[9] = StaticCString::create(p_arg10); - md.args.write[10] = StaticCString::create(p_arg11); - md.args.write[11] = StaticCString::create(p_arg12); - md.args.write[12] = StaticCString::create(p_arg13); + md.args.resize(p_argcount); + for (uint32_t i = 0; i < p_argcount; i++) { + md.args.write[i] = StaticCString::create(*p_args[i]); + } return md; } diff --git a/core/object/class_db.h b/core/object/class_db.h index 333a3307e2..d4e1fc4e76 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -35,10 +35,6 @@ #include "core/object/object.h" #include "core/string/print_string.h" -/** To bind more then 6 parameters include this: - * - */ - // Makes callable_mp readily available in all classes connecting signals. // Needs to come after method_bind and object have been included. #include "core/object/callable_method_pointer.h" @@ -57,20 +53,18 @@ struct MethodDefinition { name(p_name) {} }; -MethodDefinition D_METHOD(const char *p_name); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12); -MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13); +MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount); + +template <typename... VarArgs> +MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) { + const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported. + const char *const *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + + return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args)); +} #else diff --git a/core/object/object.cpp b/core/object/object.cpp index 897b5d18de..1defd85a14 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1476,7 +1476,7 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu void Object::_clear_internal_resource_paths(const Variant &p_var) { switch (p_var.get_type()) { case Variant::OBJECT: { - RES r = p_var; + Ref<Resource> r = p_var; if (!r.is_valid()) { return; } diff --git a/core/object/ref_counted.cpp b/core/object/ref_counted.cpp index c9a7b2a608..726e2c012c 100644 --- a/core/object/ref_counted.cpp +++ b/core/object/ref_counted.cpp @@ -108,7 +108,7 @@ Variant WeakRef::get_ref() const { } RefCounted *r = cast_to<RefCounted>(obj); if (r) { - return REF(r); + return Ref<RefCounted>(r); } return obj; @@ -118,7 +118,7 @@ void WeakRef::set_obj(Object *p_object) { ref = p_object ? p_object->get_instance_id() : ObjectID(); } -void WeakRef::set_ref(const REF &p_ref) { +void WeakRef::set_ref(const Ref<RefCounted> &p_ref) { ref = p_ref.is_valid() ? p_ref->get_instance_id() : ObjectID(); } diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index dcacf19890..bd06a84bd8 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -234,8 +234,6 @@ public: } }; -typedef Ref<RefCounted> REF; - class WeakRef : public RefCounted { GDCLASS(WeakRef, RefCounted); @@ -247,7 +245,7 @@ protected: public: Variant get_ref() const; void set_obj(Object *p_object); - void set_ref(const REF &p_ref); + void set_ref(const Ref<RefCounted> &p_ref); WeakRef() {} }; diff --git a/core/object/script_language.h b/core/object/script_language.h index 69002c81f4..f58ef45743 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -323,7 +323,7 @@ public: String display; String insert_text; Color font_color; - RES icon; + Ref<Resource> icon; Variant default_value; Vector<Pair<int, int>> matches; int location = LOCATION_OTHER; diff --git a/core/os/os.h b/core/os/os.h index 9ec0dd7728..a7cf3f1679 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -54,7 +54,6 @@ class OS { bool _single_window = false; String _local_clipboard; int _exit_code = EXIT_FAILURE; // unexpected exit is marked as failure - int _orientation; bool _allow_hidpi = false; bool _allow_layered = false; bool _stdout_enabled = true; @@ -68,7 +67,7 @@ class OS { // for the user interface we keep a record of the current display driver // so we can retrieve the rendering drivers available int _display_driver_id = -1; - String _current_rendering_driver_name = ""; + String _current_rendering_driver_name; protected: void _set_logger(CompositeLogger *p_logger); @@ -138,7 +137,7 @@ public: virtual void alert(const String &p_alert, const String &p_title = "ALERT!"); - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false) { return ERR_UNAVAILABLE; } + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) { return ERR_UNAVAILABLE; } virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; } virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; } diff --git a/core/os/pool_allocator.h b/core/os/pool_allocator.h index 27a936ed78..a7a8523aa4 100644 --- a/core/os/pool_allocator.h +++ b/core/os/pool_allocator.h @@ -77,20 +77,20 @@ private: Entry *entry_array = nullptr; int *entry_indices = nullptr; - int entry_max; - int entry_count; + int entry_max = 0; + int entry_count = 0; uint8_t *pool = nullptr; void *mem_ptr = nullptr; - int pool_size; + int pool_size = 0; - int free_mem; - int free_mem_peak; + int free_mem = 0; + int free_mem_peak = 0; - unsigned int check_count; - int align; + unsigned int check_count = 0; + int align = 1; - bool needs_locking; + bool needs_locking = false; inline int entry_end(const Entry &p_entry) const { return p_entry.pos + aligned(p_entry.len); diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index 07b58f2418..93429744fc 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -37,9 +37,9 @@ extern "C" { } struct CompressedString { - int orig_len; + int orig_len = 0; CharString compressed; - int offset; + int offset = 0; }; void OptimizedTranslation::generate(const Ref<Translation> &p_from) { diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index a2b1e4c428..5d998d22d4 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -4427,7 +4427,7 @@ String String::sprintf(const Array &values, bool *error) const { int min_chars = 0; int min_decimals = 0; bool in_decimals = false; - bool pad_with_zeroes = false; + bool pad_with_zeros = false; bool left_justified = false; bool show_sign = false; @@ -4480,7 +4480,7 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. int pad_chars_count = (value < 0 || show_sign) ? min_chars - 1 : min_chars; - String pad_char = pad_with_zeroes ? String("0") : String(" "); + String pad_char = pad_with_zeros ? String("0") : String(" "); if (left_justified) { str = str.rpad(pad_chars_count, pad_char); } else { @@ -4488,10 +4488,13 @@ String String::sprintf(const Array &values, bool *error) const { } // Sign. - if (show_sign && value >= 0) { - str = str.insert(pad_with_zeroes ? 0 : str.length() - number_len, "+"); - } else if (value < 0) { - str = str.insert(pad_with_zeroes ? 0 : str.length() - number_len, "-"); + if (show_sign || value < 0) { + String sign_char = value < 0 ? "-" : "+"; + if (left_justified) { + str = str.insert(0, sign_char); + } else { + str = str.insert(pad_with_zeros ? 0 : str.length() - number_len, sign_char); + } } formatted += str; @@ -4520,13 +4523,9 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. Leave room for sign later if required. int pad_chars_count = (is_negative || show_sign) ? min_chars - 1 : min_chars; - String pad_char = pad_with_zeroes ? String("0") : String(" "); + String pad_char = pad_with_zeros ? String("0") : String(" "); if (left_justified) { - if (pad_with_zeroes) { - return "left justification cannot be used with zeros as the padding"; - } else { - str = str.rpad(pad_chars_count, pad_char); - } + str = str.rpad(pad_chars_count, pad_char); } else { str = str.lpad(pad_chars_count, pad_char); } @@ -4537,7 +4536,7 @@ String String::sprintf(const Array &values, bool *error) const { if (left_justified) { str = str.insert(0, sign_char); } else { - str = str.insert(pad_with_zeroes ? 0 : str.length() - initial_len, sign_char); + str = str.insert(pad_with_zeros ? 0 : str.length() - initial_len, sign_char); } } @@ -4626,7 +4625,11 @@ String String::sprintf(const Array &values, bool *error) const { min_decimals += n; } else { if (c == '0' && min_chars == 0) { - pad_with_zeroes = true; + if (left_justified) { + WARN_PRINT("'0' flag ignored with '-' flag in string format"); + } else { + pad_with_zeros = true; + } } else { min_chars *= 10; min_chars += n; @@ -4675,7 +4678,7 @@ String String::sprintf(const Array &values, bool *error) const { // Back to defaults: min_chars = 0; min_decimals = 6; - pad_with_zeroes = false; + pad_with_zeros = false; left_justified = false; show_sign = false; in_decimals = false; diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index c41af32c3f..e79da748e9 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -3341,27 +3341,7 @@ String Variant::get_construct_string() const { } String Variant::get_call_error_text(const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { - String err_text; - - if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { - int errorarg = ce.argument; - if (p_argptrs) { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; - } else { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; - } - } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { - err_text = "Method not found."; - } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { - err_text = "Instance is null"; - } else if (ce.error == Callable::CallError::CALL_OK) { - return "Call OK"; - } - return "'" + String(p_method) + "': " + err_text; + return get_call_error_text(nullptr, p_method, p_argptrs, p_argcount, ce); } String Variant::get_call_error_text(Object *p_base, const StringName &p_method, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { @@ -3386,37 +3366,20 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method, return "Call OK"; } - String class_name = p_base->get_class(); - Ref<Resource> script = p_base->get_script(); - if (script.is_valid() && script->get_path().is_resource_file()) { - class_name += "(" + script->get_path().get_file() + ")"; + String base_text; + if (p_base) { + base_text = p_base->get_class(); + Ref<Resource> script = p_base->get_script(); + if (script.is_valid() && script->get_path().is_resource_file()) { + base_text += "(" + script->get_path().get_file() + ")"; + } + base_text += "::"; } - return "'" + class_name + "::" + String(p_method) + "': " + err_text; + return "'" + base_text + String(p_method) + "': " + err_text; } String Variant::get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce) { - String err_text; - - if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { - int errorarg = ce.argument; - if (p_argptrs) { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; - } else { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; - } - } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; - } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { - err_text = "Method not found."; - } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { - err_text = "Instance is null"; - } else if (ce.error == Callable::CallError::CALL_OK) { - return "Call OK"; - } - - return String(p_callable) + " : " + err_text; + return get_call_error_text(p_callable.get_object(), p_callable.get_method(), p_argptrs, p_argcount, ce); } String vformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 9dae0720d9..cc7e84203f 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -949,20 +949,20 @@ struct _VariantCall { _VariantCall::ConstantData *_VariantCall::constant_data = nullptr; struct VariantBuiltInMethodInfo { - void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error); - Variant::ValidatedBuiltInMethod validated_call; - Variant::PTRBuiltInMethod ptrcall; + void (*call)(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) = nullptr; + Variant::ValidatedBuiltInMethod validated_call = nullptr; + Variant::PTRBuiltInMethod ptrcall = nullptr; Vector<Variant> default_arguments; Vector<String> argument_names; - bool is_const; - bool is_static; - bool has_return_type; - bool is_vararg; + bool is_const = false; + bool is_static = false; + bool has_return_type = false; + bool is_vararg = false; Variant::Type return_type; - int argument_count; - Variant::Type (*get_argument_type)(int p_arg); + int argument_count = 0; + Variant::Type (*get_argument_type)(int p_arg) = nullptr; }; typedef OAHashMap<StringName, VariantBuiltInMethodInfo> BuiltinMethodMap; diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 351f4ae253..6b12b054a0 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -31,11 +31,11 @@ #include "variant_construct.h" struct VariantConstructData { - void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error); - Variant::ValidatedConstructor validated_construct; - Variant::PTRConstructor ptr_construct; - Variant::Type (*get_argument_type)(int); - int argument_count; + void (*construct)(Variant &r_base, const Variant **p_args, Callable::CallError &r_error) = nullptr; + Variant::ValidatedConstructor validated_construct = nullptr; + Variant::PTRConstructor ptr_construct = nullptr; + Variant::Type (*get_argument_type)(int) = nullptr; + int argument_count = 0; Vector<String> arg_names; }; diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 205b7fd93f..2864d0c956 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -806,7 +806,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return ERR_PARSE_ERROR; } - REF ref = REF(Object::cast_to<RefCounted>(obj)); + Ref<RefCounted> ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj)); get_token(p_stream, token, line, r_err_str); if (token.type != TK_COMMA) { @@ -887,7 +887,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } if (p_res_parser && id == "Resource" && p_res_parser->func) { - RES res; + Ref<Resource> res; Error err = p_res_parser->func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) { return err; @@ -895,7 +895,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = res; } else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) { - RES res; + Ref<Resource> res; Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) { return err; @@ -903,7 +903,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = res; } else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) { - RES res; + Ref<Resource> res; Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str); if (err) { return err; @@ -914,7 +914,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, get_token(p_stream, token, line, r_err_str); if (token.type == TK_STRING) { String path = token.value; - RES res = ResourceLoader::load(path); + Ref<Resource> res = ResourceLoader::load(path); if (res.is_null()) { r_err_str = "Can't load resource at path: '" + path + "'."; return ERR_PARSE_ERROR; @@ -1624,7 +1624,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str break; // don't save it } - RES res = p_variant; + Ref<Resource> res = p_variant; if (res.is_valid()) { //is resource String res_text; diff --git a/core/variant/variant_parser.h b/core/variant/variant_parser.h index 07d89d30cb..70ca8d8cb5 100644 --- a/core/variant/variant_parser.h +++ b/core/variant/variant_parser.h @@ -138,7 +138,7 @@ public: class VariantWriter { public: typedef Error (*StoreStringFunc)(void *ud, const String &p_string); - typedef String (*EncodeResourceFunc)(void *ud, const RES &p_resource); + typedef String (*EncodeResourceFunc)(void *ud, const Ref<Resource> &p_resource); static Error write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud, int recursion_count = 0); static Error write_to_string(const Variant &p_variant, String &r_string, EncodeResourceFunc p_encode_res_func = nullptr, void *p_encode_res_ud = nullptr); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 62ab4a343e..09097e30e0 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -805,16 +805,16 @@ INDEXED_SETGET_STRUCT_TYPED(PackedColorArray, Color) INDEXED_SETGET_STRUCT_DICT(Dictionary) struct VariantIndexedSetterGetterInfo { - void (*setter)(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob); - void (*getter)(const Variant *base, int64_t index, Variant *value, bool *oob); + void (*setter)(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) = nullptr; + void (*getter)(const Variant *base, int64_t index, Variant *value, bool *oob) = nullptr; - Variant::ValidatedIndexedSetter validated_setter; - Variant::ValidatedIndexedGetter validated_getter; + Variant::ValidatedIndexedSetter validated_setter = nullptr; + Variant::ValidatedIndexedGetter validated_getter = nullptr; - Variant::PTRIndexedSetter ptr_setter; - Variant::PTRIndexedGetter ptr_getter; + Variant::PTRIndexedSetter ptr_setter = nullptr; + Variant::PTRIndexedGetter ptr_getter = nullptr; - uint64_t (*get_indexed_size)(const Variant *base); + uint64_t (*get_indexed_size)(const Variant *base) = nullptr; Variant::Type index_type; @@ -1018,13 +1018,13 @@ struct VariantKeyedSetGetObject { }; struct VariantKeyedSetterGetterInfo { - Variant::ValidatedKeyedSetter validated_setter; - Variant::ValidatedKeyedGetter validated_getter; - Variant::ValidatedKeyedChecker validated_checker; + Variant::ValidatedKeyedSetter validated_setter = nullptr; + Variant::ValidatedKeyedGetter validated_getter = nullptr; + Variant::ValidatedKeyedChecker validated_checker = nullptr; - Variant::PTRKeyedSetter ptr_setter; - Variant::PTRKeyedGetter ptr_getter; - Variant::PTRKeyedChecker ptr_checker; + Variant::PTRKeyedSetter ptr_setter = nullptr; + Variant::PTRKeyedGetter ptr_getter = nullptr; + Variant::PTRKeyedChecker ptr_checker = nullptr; bool valid = false; }; diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 6ed85815be..66badce268 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -435,7 +435,7 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_OK; if (obj.is_ref_counted()) { Ref<WeakRef> wref = memnew(WeakRef); - REF r = obj; + Ref<RefCounted> r = obj; if (r.is_valid()) { wref->set_ref(r); } @@ -1110,14 +1110,14 @@ static _FORCE_INLINE_ Variant::Type get_ret_type_helper(void (*p_func)(P...)) { register_utility_function<Func_##m_func>(#m_func, m_args) struct VariantUtilityFunctionInfo { - void (*call_utility)(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error); - Variant::ValidatedUtilityFunction validated_call_utility; - Variant::PTRUtilityFunction ptr_call_utility; + void (*call_utility)(Variant *r_ret, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = nullptr; + Variant::ValidatedUtilityFunction validated_call_utility = nullptr; + Variant::PTRUtilityFunction ptr_call_utility = nullptr; Vector<String> argnames; - bool is_vararg; - bool returns_value; - int argcount; - Variant::Type (*get_arg_type)(int); + bool is_vararg = false; + bool returns_value = false; + int argcount = 0; + Variant::Type (*get_arg_type)(int) = nullptr; Variant::Type return_type; Variant::UtilityFunctionType type; }; |