From fbdb7a947bd9d75ed6e2a86e58337ca4d47d085e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 28 Jun 2016 18:53:31 -0300 Subject: [PATCH] Editor properly reloads scenes if they changed on disk or were reimported --- tools/editor/editor_data.cpp | 4 + tools/editor/editor_node.cpp | 79 ++++++++++++++++++- tools/editor/editor_node.h | 4 +- .../io_plugins/editor_scene_import_plugin.cpp | 6 +- 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index 4c4fecdd836..0f10041034c 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -565,6 +565,8 @@ bool EditorData::check_and_update_scene(int p_idx) { bool must_reload = _find_updated_instances(edited_scene[p_idx].root,edited_scene[p_idx].root,checked_scenes); + print_line("MUST RELOAD? "+itos(must_reload)); + if (must_reload) { Ref pscene; pscene.instance(); @@ -762,6 +764,8 @@ Ref EditorData::get_edited_scene_import_metadata() const return edited_scene[current_edited_scene].medatata; } + + void EditorData::clear_edited_scenes() { for(int i=0;i > cached; + ResourceCache::get_cached_resources(&cached); + List > to_clear; //clear internal resources from previous scene from being used + for(List >::Element *E=cached.front();E;E=E->next()) { + + if (E->get()->get_path().begins_with(p_path+"::")) //subresources of existing scene + to_clear.push_back(E->get()); + + if (!E->get()->cast_to()) + continue; + if (!E->get()->get_path().is_resource_file() && !E->get()->get_path().is_abs_path()) + continue; + if (!FileAccess::exists(E->get()->get_path())) + continue; + uint64_t mt = FileAccess::get_modified_time(E->get()->get_path()); + if (mt!=E->get()->get_last_modified_time()) { + E->get()->reload_from_file(); + } + } + + //so reload reloads everything, clear subresources of previous scene + while(to_clear.front()) { + to_clear.front()->get()->set_path(""); + to_clear.pop_front(); + } + + int scene_idx=-1; + for(int i=0;iclear_history(); + //recover the tab + scene_tabs->set_current_tab(current_tab); + _scene_tab_changed(current_tab); +} + + void EditorNode::_bind_methods() { diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index a0a03341fc8..9b0edda75e2 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -555,7 +555,7 @@ private: void _scene_tab_script_edited(int p_tab); Dictionary _get_main_scene_state(); - void _set_main_scene_state(Dictionary p_state); + void _set_main_scene_state(Dictionary p_state,Node* p_for_scene); int _get_current_main_editor(); @@ -716,6 +716,8 @@ public: void update_keying(); + void reload_scene(const String& p_path); + bool is_exiting() const { return exiting; } ToolButton *get_pause_button() { return pause_button; } diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index d5d0fac2b6a..b27539b933e 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -2790,15 +2790,16 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c Ref packer = memnew( PackedScene ); packer->pack(scene); - packer->set_path(p_dest_path); + //packer->set_path(p_dest_path); do not take over, let the changed files reload themselves packer->set_import_metadata(from); print_line("SAVING TO: "+p_dest_path); - err = ResourceSaver::save(p_dest_path,packer,ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS); + err = ResourceSaver::save(p_dest_path,packer); //do not take over, let the changed files reload themselves //EditorFileSystem::get_singleton()->update_resource(packer); memdelete(scene); + /* scene->set_filename(p_dest_path); if (r_scene) { @@ -2818,6 +2819,7 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c */ + EditorNode::get_singleton()->reload_scene(p_dest_path); return err;