Browse Source

-Make sure scenes properly update when switching tabs, even if sub-instances changed. Fixes #3201

Juan Linietsky 9 years ago
parent
commit
4248c84e20

+ 2 - 1
core/io/resource_format_binary.cpp

@@ -725,7 +725,8 @@ Error ResourceInteractiveLoaderBinary::poll(){
 		}
 	} else {
 
-		path=res_path;
+		if (!ResourceCache::has(res_path))
+			path=res_path;
 	}
 
 	uint64_t offset = internal_resources[s].offset;

+ 3 - 1
core/io/resource_format_xml.cpp

@@ -1570,7 +1570,9 @@ Error ResourceInteractiveLoaderXML::poll() {
 	if (main) {
 		f->close();
 		resource=res;
-		resource->set_path(res_path);
+		if (!ResourceCache::has(res_path)) {
+			resource->set_path(res_path);
+		}
 		error=ERR_FILE_EOF;
 		return error;
 

+ 10 - 0
scene/resources/packed_scene.cpp

@@ -1597,6 +1597,16 @@ Node *PackedScene::instance(bool p_gen_edit_state) const {
 	return s;
 }
 
+void PackedScene::replace_state(Ref<SceneState> p_by) {
+
+	state=p_by;
+	state->set_path(get_path());
+#ifdef TOOLS_ENABLED
+	state->set_last_modified_time(get_last_modified_time());
+#endif
+
+}
+
 void PackedScene::recreate_state() {
 
 	state = Ref<SceneState>( memnew( SceneState ));

+ 1 - 0
scene/resources/packed_scene.h

@@ -198,6 +198,7 @@ public:
 	Node *instance(bool p_gen_edit_state=false) const;
 
 	void recreate_state();
+	void replace_state(Ref<SceneState> p_by);
 
 	virtual void set_path(const String& p_path,bool p_take_over=false);
 #ifdef TOOLS_ENABLED

+ 7 - 0
scene/resources/scene_format_text.cpp

@@ -302,6 +302,10 @@ Error ResourceInteractiveLoaderText::poll() {
 			if (error) {
 				if (error!=ERR_FILE_EOF) {
 					_printerr();
+				} else {
+					if (!ResourceCache::has(res_path)) {
+						resource->set_path(res_path);
+					}
 				}
 				return error;
 			}
@@ -403,6 +407,9 @@ Error ResourceInteractiveLoaderText::poll() {
 					_printerr();
 				} else {
 					resource=packed_scene;
+					if (!ResourceCache::has(res_path)) {
+						packed_scene->set_path(res_path);
+					}
 				}
 				return error;
 			}

+ 2 - 2
tools/editor/editor_data.cpp

@@ -499,8 +499,8 @@ void EditorData::remove_scene(int p_idx){
 
 bool EditorData::_find_updated_instances(Node* p_root,Node *p_node,Set<String> &checked_paths) {
 
-	if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner()))
-		return false;
+//	if (p_root!=p_node && p_node->get_owner()!=p_root && !p_root->is_editable_instance(p_node->get_owner()))
+//		return false;
 
 	Ref<SceneState> ss;
 

+ 12 - 1
tools/editor/editor_node.cpp

@@ -3623,7 +3623,18 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo
 		add_io_error(txt);
 	}
 
-	sdata->set_path(lpath,true); //take over path
+	if (ResourceCache::has(lpath)) {
+		//used from somewhere else? no problem! update state
+		Ref<PackedScene> ps = Ref<PackedScene>( ResourceCache::get(lpath)->cast_to<PackedScene>() );
+		if (ps.is_valid()) {
+			ps->replace_state( sdata->get_state() );
+			ps->set_last_modified_time( sdata->get_last_modified_time() );
+			sdata=ps;
+		}
+
+	} else {
+		sdata->set_path(lpath,true); //take over path
+	}
 
 	Node*new_scene=sdata->instance(true);