diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-06-25 14:09:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-25 14:09:28 +0200 |
commit | b1920730010854b4b470e047af3fb05e5113060c (patch) | |
tree | 325b7e7f6a67e02efd4aa85a8161472592b04b48 /editor | |
parent | b26d924f225d5181219066c4b080cc41ed349179 (diff) | |
parent | e772b65d92dbd5b36fb003458d7fe0fd528abcea (diff) |
Merge pull request #62309 from reduz/remake-resource-thread-safety
Remake ResourceCache thread safety code and API
Diffstat (limited to 'editor')
-rw-r--r-- | editor/dependency_editor.cpp | 2 | ||||
-rw-r--r-- | editor/editor_file_system.cpp | 9 | ||||
-rw-r--r-- | editor/editor_folding.cpp | 5 | ||||
-rw-r--r-- | editor/editor_node.cpp | 10 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 4 | ||||
-rw-r--r-- | editor/import/resource_importer_texture_atlas.cpp | 6 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 2 |
7 files changed, 16 insertions, 22 deletions
diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 97699d0349..9a1b2b5ff5 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -487,7 +487,7 @@ void DependencyRemoveDialog::show(const Vector<String> &p_folders, const Vector< void DependencyRemoveDialog::ok_pressed() { for (int i = 0; i < files_to_delete.size(); ++i) { if (ResourceCache::has(files_to_delete[i])) { - Resource *res = ResourceCache::get(files_to_delete[i]); + Ref<Resource> res = ResourceCache::get_ref(files_to_delete[i]); res->set_path(""); } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index f9a4c14c48..adbba98897 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1792,9 +1792,9 @@ Error EditorFileSystem::_reimport_group(const String &p_group_file, const Vector //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it //to reload properly - if (ResourceCache::has(file)) { - Resource *r = ResourceCache::get(file); + Ref<Resource> r = ResourceCache::get_ref(file); + if (r.is_valid()) { if (!r->get_import_path().is_empty()) { String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(file); r->set_import_path(dst_path); @@ -2034,9 +2034,8 @@ void EditorFileSystem::_reimport_file(const String &p_file, const HashMap<String //if file is currently up, maybe the source it was loaded from changed, so import math must be updated for it //to reload properly - if (ResourceCache::has(p_file)) { - Resource *r = ResourceCache::get(p_file); - + Ref<Resource> r = ResourceCache::get_ref(p_file); + if (r.is_valid()) { if (!r->get_import_path().is_empty()) { String dst_path = ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_file); r->set_import_path(dst_path); diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp index 9e1b361f64..8c508494c0 100644 --- a/editor/editor_folding.cpp +++ b/editor/editor_folding.cpp @@ -193,10 +193,7 @@ void EditorFolding::load_scene_folding(Node *p_scene, const String &p_path) { for (int i = 0; i < res_unfolds.size(); i += 2) { String path2 = res_unfolds[i]; - Ref<Resource> res; - if (ResourceCache::has(path2)) { - res = Ref<Resource>(ResourceCache::get(path2)); - } + Ref<Resource> res = ResourceCache::get_ref(path2); if (res.is_null()) { continue; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 93caf7944c..9b0ac305d1 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -881,7 +881,7 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) { int rc = p_resources.size(); for (int i = 0; i < rc; i++) { - Ref<Resource> res(ResourceCache::get(p_resources.get(i))); + Ref<Resource> res = ResourceCache::get_ref(p_resources.get(i)); if (res.is_null()) { continue; } @@ -1011,8 +1011,8 @@ void EditorNode::_resources_reimported(const Vector<String> &p_resources) { continue; } // Reload normally. - Resource *resource = ResourceCache::get(p_resources[i]); - if (resource) { + Ref<Resource> resource = ResourceCache::get_ref(p_resources[i]); + if (resource.is_valid()) { resource->reload_from_file(); } } @@ -1725,7 +1725,7 @@ void EditorNode::_save_scene(String p_file, int idx) { // We must update it, but also let the previous scene state go, as // old version still work for referencing changes in instantiated or inherited scenes. - sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file))); + sdata = ResourceCache::get_ref(p_file); if (sdata.is_valid()) { sdata->recreate_state(); } else { @@ -3717,7 +3717,7 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b if (ResourceCache::has(lpath)) { // Used from somewhere else? No problem! Update state and replace sdata. - Ref<PackedScene> ps = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(lpath))); + Ref<PackedScene> ps = ResourceCache::get_ref(lpath); if (ps.is_valid()) { ps->replace_state(sdata->get_state()); ps->set_last_modified_time(sdata->get_last_modified_time()); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index f2975b1d7a..171ef5bf4c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1115,7 +1115,7 @@ Ref<Animation> ResourceImporterScene::_save_animation_to_file(Ref<Animation> ani } if (ResourceCache::has(p_save_to_path)) { - Ref<Animation> old_anim = Ref<Resource>(ResourceCache::get(p_save_to_path)); + Ref<Animation> old_anim = ResourceCache::get_ref(p_save_to_path); if (old_anim.is_valid()) { old_anim->copy_from(anim); anim = old_anim; @@ -1711,7 +1711,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } if (!save_to_file.is_empty()) { - Ref<Mesh> existing = Ref<Resource>(ResourceCache::get(save_to_file)); + Ref<Mesh> existing = ResourceCache::get_ref(save_to_file); if (existing.is_valid()) { //if somehow an existing one is useful, create existing->reset_state(); diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index aa338a6c0d..e5fe99890e 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -306,10 +306,8 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file //update cache if existing, else create Ref<Texture2D> cache; - if (ResourceCache::has(p_group_file)) { - Resource *resptr = ResourceCache::get(p_group_file); - cache.reference_ptr(resptr); - } else { + cache = ResourceCache::get_ref(p_group_file); + if (!cache.is_valid()) { Ref<ImageTexture> res_cache; res_cache.instantiate(); res_cache->create_from_image(new_atlas); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 1ea0299d4e..dea4aaded7 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5455,7 +5455,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & } child->set_name(name); - Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path))); + Ref<Texture2D> texture = ResourceCache::get_ref(path); if (parent) { editor_data->get_undo_redo().add_do_method(parent, "add_child", child, true); |