From 180e5d30286279c979507a571bf6d336aa49da9d Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 3 May 2022 01:43:50 +0200 Subject: Remove `RES` and `REF` typedefs in favor of spelled out `Ref<>` These typedefs don't save much typing compared to the full `Ref` and `Ref`, yet they sometimes introduce confusion among new contributors. --- core/core_bind.cpp | 14 +++--- core/core_bind.h | 8 ++-- core/crypto/crypto.cpp | 8 ++-- core/crypto/crypto.h | 8 ++-- core/extension/native_extension.cpp | 10 ++-- core/extension/native_extension.h | 2 +- core/input/input.cpp | 4 +- core/input/input.h | 4 +- core/io/image_loader.cpp | 10 ++-- core/io/image_loader.h | 2 +- core/io/marshalls.cpp | 2 +- core/io/resource.cpp | 12 ++--- core/io/resource.h | 2 - core/io/resource_format_binary.cpp | 44 +++++++++--------- core/io/resource_format_binary.h | 30 ++++++------ core/io/resource_importer.cpp | 6 +-- core/io/resource_importer.h | 2 +- core/io/resource_loader.cpp | 38 +++++++-------- core/io/resource_loader.h | 12 ++--- core/io/resource_saver.cpp | 12 ++--- core/io/resource_saver.h | 16 +++---- core/io/translation_loader_po.cpp | 36 +++++++-------- core/io/translation_loader_po.h | 4 +- core/object/object.cpp | 2 +- core/object/ref_counted.cpp | 4 +- core/object/ref_counted.h | 4 +- core/object/script_language.h | 2 +- core/variant/variant_parser.cpp | 12 ++--- core/variant/variant_parser.h | 2 +- core/variant/variant_utility.cpp | 2 +- drivers/gles3/storage/material_storage.cpp | 2 +- drivers/gles3/texture_loader_gles3.cpp | 2 +- drivers/gles3/texture_loader_gles3.h | 2 +- drivers/png/resource_saver_png.cpp | 6 +-- drivers/png/resource_saver_png.h | 6 +-- editor/animation_track_editor.cpp | 16 +++---- editor/debugger/editor_debugger_inspector.cpp | 4 +- editor/debugger/editor_debugger_inspector.h | 2 +- editor/debugger/editor_debugger_node.h | 2 +- editor/editor_autoload_settings.cpp | 2 +- editor/editor_data.cpp | 2 +- editor/editor_data.h | 2 +- editor/editor_folding.cpp | 22 ++++----- editor/editor_folding.h | 10 ++-- editor/editor_inspector.cpp | 2 +- editor/editor_inspector.h | 2 +- editor/editor_node.cpp | 30 ++++++------ editor/editor_node.h | 14 +++--- editor/editor_properties.cpp | 16 +++---- editor/editor_properties.h | 6 +-- editor/editor_properties_array_dict.cpp | 2 +- editor/editor_resource_picker.cpp | 16 +++---- editor/editor_resource_picker.h | 6 +-- editor/editor_resource_preview.cpp | 4 +- editor/editor_resource_preview.h | 4 +- editor/filesystem_dock.cpp | 2 +- editor/import/resource_importer_scene.cpp | 8 ++-- editor/import/resource_importer_scene.h | 4 +- editor/inspector_dock.cpp | 26 +++++------ editor/inspector_dock.h | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 6 +-- editor/plugins/editor_preview_plugins.cpp | 22 ++++----- editor/plugins/editor_preview_plugins.h | 22 ++++----- editor/plugins/light_occluder_2d_editor_plugin.cpp | 2 +- .../plugins/navigation_polygon_editor_plugin.cpp | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 10 ++-- .../packed_scene_translation_parser_plugin.cpp | 2 +- .../plugins/resource_preloader_editor_plugin.cpp | 16 +++---- editor/plugins/script_editor_plugin.cpp | 54 +++++++++++----------- editor/plugins/script_editor_plugin.h | 28 +++++------ editor/plugins/script_text_editor.cpp | 6 +-- editor/plugins/script_text_editor.h | 4 +- editor/plugins/sprite_frames_editor_plugin.cpp | 6 +-- editor/plugins/text_editor.cpp | 6 +-- editor/plugins/text_editor.h | 4 +- editor/plugins/theme_editor_plugin.cpp | 20 ++++---- editor/plugins/theme_editor_plugin.h | 2 +- editor/plugins/visual_shader_editor_plugin.cpp | 16 +++---- editor/plugins/visual_shader_editor_plugin.h | 2 +- editor/property_editor.cpp | 26 +++++------ editor/property_editor.h | 4 +- editor/scene_tree_dock.cpp | 14 +++--- editor/scene_tree_dock.h | 8 ++-- editor/script_create_dialog.cpp | 2 +- editor/shader_create_dialog.cpp | 4 +- editor/shader_globals_editor.cpp | 2 +- main/main.cpp | 2 +- modules/dds/texture_loader_dds.cpp | 20 ++++---- modules/dds/texture_loader_dds.h | 2 +- .../editor/gdscript_translation_parser_plugin.cpp | 2 +- modules/gdscript/gdscript.cpp | 14 +++--- modules/gdscript/gdscript.h | 8 ++-- modules/gdscript/gdscript_compiler.cpp | 2 +- modules/gdscript/gdscript_editor.cpp | 2 +- .../language_server/gdscript_extend_parser.cpp | 2 +- .../language_server/gdscript_workspace.cpp | 2 +- modules/gdscript/tests/gdscript_test_runner.cpp | 2 +- modules/gridmap/grid_map.cpp | 2 +- modules/gridmap/grid_map.h | 2 +- modules/mono/csharp_script.cpp | 16 +++---- modules/mono/csharp_script.h | 8 ++-- modules/mono/glue/base_object_glue.cpp | 2 +- modules/theora/video_stream_theora.cpp | 4 +- modules/theora/video_stream_theora.h | 2 +- .../visual_script/editor/visual_script_editor.cpp | 8 ++-- .../visual_script/editor/visual_script_editor.h | 6 +-- .../visual_script/visual_script_builtin_funcs.cpp | 2 +- platform/javascript/display_server_javascript.cpp | 2 +- platform/javascript/display_server_javascript.h | 2 +- platform/javascript/http_client_javascript.cpp | 2 +- platform/linuxbsd/display_server_x11.cpp | 2 +- platform/linuxbsd/display_server_x11.h | 2 +- platform/osx/display_server_osx.h | 2 +- platform/osx/display_server_osx.mm | 2 +- platform/uwp/os_uwp.cpp | 2 +- platform/uwp/os_uwp.h | 2 +- platform/windows/display_server_windows.cpp | 2 +- platform/windows/display_server_windows.h | 2 +- scene/3d/collision_shape_3d.cpp | 2 +- scene/3d/collision_shape_3d.h | 2 +- scene/animation/animation_player.cpp | 2 +- scene/animation/animation_player.h | 2 +- scene/animation/animation_tree.cpp | 2 +- scene/debugger/scene_debugger.cpp | 12 ++--- scene/gui/code_edit.cpp | 4 +- scene/gui/code_edit.h | 2 +- scene/main/node.cpp | 22 ++++----- scene/main/node.h | 8 ++-- scene/main/resource_preloader.cpp | 16 +++---- scene/main/resource_preloader.h | 6 +-- scene/resources/animation.cpp | 12 ++--- scene/resources/animation.h | 8 ++-- scene/resources/resource_format_text.cpp | 44 +++++++++--------- scene/resources/resource_format_text.h | 42 ++++++++--------- scene/resources/shader.cpp | 8 ++-- scene/resources/shader.h | 8 ++-- scene/resources/sprite_frames.cpp | 2 +- scene/resources/texture.cpp | 14 +++--- scene/resources/texture.h | 6 +-- servers/display_server.cpp | 4 +- servers/display_server.h | 4 +- servers/physics_server_2d.cpp | 4 +- servers/physics_server_2d.h | 6 +-- servers/physics_server_3d.cpp | 4 +- servers/physics_server_3d.h | 6 +-- .../renderer_rd/storage_rd/material_storage.cpp | 2 +- tests/scene/test_code_edit.h | 4 +- 147 files changed, 607 insertions(+), 611 deletions(-) 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 ResourceLoader::load_threaded_get(const String &p_path) { Error error; - RES res = ::ResourceLoader::load_threaded_get(p_path, &error); + Ref 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 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 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 &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 ResourceSaver::get_recognized_extensions(const RES &p_resource) { +Vector ResourceSaver::get_recognized_extensions(const Ref &p_resource) { ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector(), "It's not a reference to a valid Resource object."); List 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(obj); if (r) { - return REF(r); + return Ref(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 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 load(const String &p_path, const String &p_type_hint = "", CacheMode p_cache_mode = CACHE_MODE_REUSE); Vector 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 get_recognized_extensions(const RES &p_resource); + Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags); + Vector get_recognized_extensions(const Ref &p_resource); ResourceSaver() { singleton = this; } }; 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 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 &p_resource, uint32_t p_flags) { Error err; Ref cert = p_resource; Ref 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 *p_extensions) const { +void ResourceFormatSaverCrypto::get_recognized_extensions(const Ref &p_resource, List *p_extensions) const { const X509Certificate *cert = Object::cast_to(*p_resource); const CryptoKey *key = Object::cast_to(*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 &p_resource) const { return Object::cast_to(*p_resource) || Object::cast_to(*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 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 *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 *p_extensions) const; - virtual bool recognize(const RES &p_resource) const; + virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; + virtual bool recognize(const Ref &p_resource) const; }; #endif // CRYPTO_H diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 076d04a5eb..7e51d221a7 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -356,7 +356,7 @@ void NativeExtension::initialize_native_extensions() { gdnative_interface.classdb_unregister_extension_class = _unregister_extension_class; } -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 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 config; config.instantiate(); @@ -367,14 +367,14 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or } if (err != OK) { - return RES(); + return Ref(); } if (!config->has_section_key("configuration", "entry_symbol")) { if (r_error) { *r_error = ERR_INVALID_DATA; } - return RES(); + return Ref(); } String entry_symbol = config->get_value("configuration", "entry_symbol"); @@ -406,7 +406,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(); } if (!library_path.is_resource_file()) { @@ -423,7 +423,7 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or } if (err != OK) { - return RES(); + return Ref(); } return lib; diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h index ebfedfb29a..d148200035 100644 --- a/core/extension/native_extension.h +++ b/core/extension/native_extension.h @@ -90,7 +90,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 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 *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 &, 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 &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 23c7ebee02..5a7cb84ece 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -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 &, 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 &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/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 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 f = FileAccess::open(p_path, FileAccess::READ); if (f.is_null()) { if (r_error) { *r_error = ERR_CANT_OPEN; } - return RES(); + return Ref(); } 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()); } 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()); } Ref 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(); } 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 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 *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/marshalls.cpp b/core/io/marshalls.cpp index d0bc05566e..0c767c102d 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(obj)) { - REF ref = REF(Object::cast_to(obj)); + Ref ref = Ref(Object::cast_to(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::duplicate_for_local_scene(Node *p_for_scene, Map 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 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, R } Variant p = get(E.name); if (p.get_type() == Variant::OBJECT) { - RES sr = p; + Ref sr = p; if (sr.is_valid()) { if (sr->is_local_to_scene()) { if (!remap_cache.has(sr)) { @@ -269,7 +269,7 @@ Ref 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 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(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 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 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 bc7e524892..dec78aa218 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 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 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 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(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 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 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 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(), "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(); } 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 res = loader.get_resource(); ERR_FAIL_COND_V(!res.is_valid(), ERR_FILE_CORRUPT); return ResourceFormatSaverBinary::singleton->save(p_path, res); @@ -1353,7 +1353,7 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(Ref f, int p_byt } } -void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const Variant &p_property, Map &resource_map, Map &external_resources, Map &string_map, const PropertyInfo &p_hint) { +void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const Variant &p_property, Map, int> &resource_map, Map, int> &external_resources, Map &string_map, const PropertyInfo &p_hint) { switch (p_property.get_type()) { case Variant::NIL: { f->store_32(VARIANT_NIL); @@ -1562,7 +1562,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const V } break; case Variant::OBJECT: { f->store_32(VARIANT_OBJECT); - RES res = p_property; + Ref res = p_property; if (res.is_null()) { f->store_32(OBJECT_EMPTY); return; // don't save it @@ -1728,7 +1728,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref 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 res = p_variant; if (res.is_null() || external_resources.has(res)) { return; @@ -1756,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 sres = value; if (sres.is_valid()) { NonPersistentKey npk; npk.base = res; @@ -1833,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 &p_resource, uint32_t p_flags) { Error err; Ref f; if (p_flags & ResourceSaver::FLAG_COMPRESS) { @@ -1903,7 +1903,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p List resources; { - for (const RES &E : saved_resources) { + for (const Ref &E : saved_resources) { ResourceData &rd = resources.push_back(ResourceData())->get(); rd.type = E->get_class(); @@ -1950,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 save_order; + Vector> save_order; save_order.resize(external_resources.size()); - for (const KeyValue &E : external_resources) { + for (const KeyValue, int> &E : external_resources) { save_order.write[E.value] = E.key; } @@ -1970,7 +1970,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p Vector ofs_pos; Set used_unique_ids; - for (RES &r : saved_resources) { + for (Ref &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())) { @@ -1982,9 +1982,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } } - Map resource_map; + Map, int> resource_map; int res_index = 0; - for (RES &r : saved_resources) { + for (Ref &r : saved_resources) { if (r->is_built_in()) { if (r->get_scene_unique_id().is_empty()) { String new_id; @@ -2045,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 &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 &p_resource) const { return true; //all recognized } -void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { +void ResourceFormatSaverBinary::get_recognized_extensions(const Ref &p_resource, List *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 str_buf; - List resource_cache; + List> resource_cache; Vector string_map; @@ -60,7 +60,7 @@ class ResourceLoaderBinary { String path; String type; ResourceUID::ID uid = ResourceUID::INVALID_ID; - RES cache; + Ref cache; }; bool using_named_scene_ids = false; @@ -75,7 +75,7 @@ class ResourceLoaderBinary { }; Vector internal_resources; - Map internal_index_cache; + Map> 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 dependency_cache; + Map> 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 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 *p_extensions) const; virtual void get_recognized_extensions(List *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 resource_set; + Set> resource_set; struct NonPersistentKey { //for resource properties generated on the fly - RES base; + Ref base; StringName property; bool operator<(const NonPersistentKey &p_key) const { return base == p_key.base ? property < p_key.property : base < p_key.base; } }; - Map non_persistent_map; + Map> non_persistent_map; Map string_map; Vector strings; - Map external_resources; - List saved_resources; + Map, int> external_resources; + List> 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 f, const Variant &p_property, Map &resource_map, Map &external_resources, Map &string_map, const PropertyInfo &p_hint = PropertyInfo()); + Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + static void write_variant(Ref f, const Variant &p_property, Map, int> &resource_map, Map, int> &external_resources, Map &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 *p_extensions) const; + virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const Ref &p_resource) const; + virtual void get_recognized_extensions(const Ref &p_resource, List *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 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(); } - RES res = ResourceLoader::_load(pat.path, p_path, pat.type, p_cache_mode, r_error, p_use_sub_threads, r_progress); + Ref 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 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 *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List *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 *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 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(); } 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(), "Failed to load resource '" + p_path + "'. ResourceFormatLoader::load was not implemented for this resource type."); } void ResourceFormatLoader::get_dependencies(const String &p_path, List *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 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 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(), 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 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 file not found: " + p_path + "."); #endif - ERR_FAIL_V_MSG(RES(), "No loader found for resource: " + p_path + "."); + ERR_FAIL_V_MSG(Ref(), "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 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 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(); } 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(); } } - RES resource = load_task.resource; + Ref 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 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(); } 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 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(), "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 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(); } 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 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 *p_extensions) const; virtual void get_recognized_extensions_for_type(const String &p_type, List *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 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 _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; 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 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 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 *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 &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 &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 *p_extensions) const { +void ResourceFormatSaver::get_recognized_extensions(const Ref &p_resource, List *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 &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 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 *p_extensions) { +void ResourceSaver::get_recognized_extensions(const Ref &p_resource, List *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, _get_recognized_extensions, RES) + GDVIRTUAL3R(int64_t, _save, String, Ref, uint32_t) + GDVIRTUAL1RC(bool, _recognize, Ref) + GDVIRTUAL1RC(Vector, _get_recognized_extensions, Ref) 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 *p_extensions) const; + virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const Ref &p_resource) const; + virtual void get_recognized_extensions(const Ref &p_resource, List *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 *p_extensions); + static Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = (uint32_t)FLAG_NONE); + static void get_recognized_extensions(const Ref &p_resource, List *p_extensions); static void add_resource_format_saver(Ref p_format_saver, bool p_at_front = false); static void remove_resource_format_saver(Ref 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 f, Error *r_error) { +Ref TranslationLoaderPO::load_translation(Ref f, Error *r_error) { if (r_error) { *r_error = ERR_FILE_CORRUPT; } @@ -49,7 +49,7 @@ RES TranslationLoaderPO::load_translation(Ref 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(), 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 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(), "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(), "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 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(), "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 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(), "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(), "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 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(), "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(), "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 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(), "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(), "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 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(), "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 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(), "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 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(), "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 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(), "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(), "No config found in file: " + path + "."); Vector configs = config.split("\n"); for (int i = 0; i < configs.size(); i++) { @@ -344,13 +344,13 @@ RES TranslationLoaderPO::load_translation(Ref 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 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 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(), "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 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 load_translation(Ref f, Error *r_error = nullptr); + virtual Ref 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 *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/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 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(obj); if (r) { - return REF(r); + return Ref(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 &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 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 &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 icon; Variant default_value; Vector> matches; int location = LOCATION_OTHER; diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 5fc6df8f39..bd13f66a09 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(obj)); + Ref ref = Ref(Object::cast_to(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 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 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 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 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 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 &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_utility.cpp b/core/variant/variant_utility.cpp index 7c821ad41d..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 wref = memnew(WeakRef); - REF r = obj; + Ref r = obj; if (r.is_valid()) { wref->set_ref(r); } diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 1b97e268df..8bfb09b83b 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -2232,7 +2232,7 @@ void MaterialStorage::global_variables_load_settings(bool p_load_textures) { } String path = value; - RES resource = ResourceLoader::load(path); + Ref resource = ResourceLoader::load(path); ERR_CONTINUE(resource.is_null()); value = resource; } diff --git a/drivers/gles3/texture_loader_gles3.cpp b/drivers/gles3/texture_loader_gles3.cpp index 8c8724686d..ba4ddb3b37 100644 --- a/drivers/gles3/texture_loader_gles3.cpp +++ b/drivers/gles3/texture_loader_gles3.cpp @@ -37,7 +37,7 @@ #include -RES ResourceFormatGLES2Texture::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 ResourceFormatGLES2Texture::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) { unsigned int width = 8; unsigned int height = 8; diff --git a/drivers/gles3/texture_loader_gles3.h b/drivers/gles3/texture_loader_gles3.h index 54ddf80a96..6873858b89 100644 --- a/drivers/gles3/texture_loader_gles3.h +++ b/drivers/gles3/texture_loader_gles3.h @@ -38,7 +38,7 @@ class ResourceFormatGLES2Texture : 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 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 *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/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 8633d2dc4e..704ddca726 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -35,7 +35,7 @@ #include "drivers/png/png_driver_common.h" #include "scene/resources/texture.h" -Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { +Error ResourceSaverPNG::save(const String &p_path, const Ref &p_resource, uint32_t p_flags) { Ref texture = p_resource; ERR_FAIL_COND_V_MSG(!texture.is_valid(), ERR_INVALID_PARAMETER, "Can't save invalid texture as PNG."); @@ -72,11 +72,11 @@ Vector ResourceSaverPNG::save_image_to_buffer(const Ref &p_img) return buffer; } -bool ResourceSaverPNG::recognize(const RES &p_resource) const { +bool ResourceSaverPNG::recognize(const Ref &p_resource) const { return (p_resource.is_valid() && p_resource->is_class("ImageTexture")); } -void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { +void ResourceSaverPNG::get_recognized_extensions(const Ref &p_resource, List *p_extensions) const { if (Object::cast_to(*p_resource)) { p_extensions->push_back("png"); } diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h index f39e52c7ec..1a681faaec 100644 --- a/drivers/png/resource_saver_png.h +++ b/drivers/png/resource_saver_png.h @@ -39,9 +39,9 @@ public: static Error save_image(const String &p_path, const Ref &p_img); static Vector save_image_to_buffer(const Ref &p_img); - 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 *p_extensions) const; + virtual Error save(const String &p_path, const Ref &p_resource, uint32_t p_flags = 0); + virtual bool recognize(const Ref &p_resource) const; + virtual void get_recognized_extensions(const Ref &p_resource, List *p_extensions) const; ResourceSaverPNG(); }; diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 462622fec5..c425613262 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -358,7 +358,7 @@ public: setting = true; undo_redo->create_action(TTR("Anim Change Keyframe Value"), UndoRedo::MERGE_ENDS); - RES prev = animation->audio_track_get_key_stream(track, key); + Ref prev = animation->audio_track_get_key_stream(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_stream", track, key, stream); undo_redo->add_undo_method(animation.ptr(), "audio_track_set_key_stream", track, key, prev); undo_redo->add_do_method(this, "_update_obj", animation); @@ -992,7 +992,7 @@ public: setting = true; undo_redo->create_action(TTR("Anim Multi Change Keyframe Value"), UndoRedo::MERGE_ENDS); } - RES prev = animation->audio_track_get_key_stream(track, key); + Ref prev = animation->audio_track_get_key_stream(track, key); undo_redo->add_do_method(animation.ptr(), "audio_track_set_key_stream", track, key, stream); undo_redo->add_undo_method(animation.ptr(), "audio_track_set_key_stream", track, key, prev); update_obj = true; @@ -2528,7 +2528,7 @@ bool AnimationTrackEdit::_is_value_key_valid(const Variant &p_key_value, Variant return false; } - RES res; + Ref res; Vector leftover_path; Node *node = root->get_node_and_resource(animation->track_get_path(track), res, leftover_path); @@ -2689,7 +2689,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } break; case Animation::TYPE_AUDIO: { String stream_name = "null"; - RES stream = animation->audio_track_get_key_stream(track, key_idx); + Ref stream = animation->audio_track_get_key_stream(track, key_idx); if (stream.is_valid()) { if (stream->get_path().is_resource_file()) { stream_name = stream->get_path().get_file(); @@ -4114,7 +4114,7 @@ PropertyInfo AnimationTrackEditor::_find_hint_for_track(int p_idx, NodePath &r_b return PropertyInfo(); } - RES res; + Ref res; Vector leftover_path; Node *node = root->get_node_and_resource(path, res, leftover_path, true); @@ -4410,7 +4410,7 @@ void AnimationTrackEditor::_update_tracks() { NodePath path = animation->track_get_path(i); if (root && root->has_node_and_resource(path)) { - RES res; + Ref res; NodePath base_path; Vector leftover_path; Node *node = root->get_node_and_resource(path, res, leftover_path, true); @@ -5016,7 +5016,7 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) { } break; case Animation::TYPE_AUDIO: { Dictionary ak; - ak["stream"] = RES(); + ak["stream"] = Ref(); ak["start_offset"] = 0; ak["end_offset"] = 0; @@ -6015,7 +6015,7 @@ void AnimationTrackEditor::_cleanup_animation(Ref p_animation) { Variant::Type valid_type = Variant::NIL; Object *obj = nullptr; - RES res; + Ref res; Vector leftover_path; Node *node = root->get_node_and_resource(p_animation->track_get_path(i), res, leftover_path); diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index 936b8ca626..854c050793 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -157,7 +157,7 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { if (path.contains("::")) { // built-in resource String base_path = path.get_slice("::", 0); - RES dependency = ResourceLoader::load(base_path); + Ref dependency = ResourceLoader::load(base_path); if (dependency.is_valid()) { remote_dependencies.insert(dependency); } @@ -166,7 +166,7 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { if (pinfo.hint_string == "Script") { if (debugObj->get_script() != var) { - debugObj->set_script(REF()); + debugObj->set_script(Ref()); Ref