diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-07-20 22:37:48 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-07-20 22:37:48 -0300 |
commit | 33cc480350264e15c12bf82b9198b9967e4313dc (patch) | |
tree | a2405e70104117aa52402f5d4dd98e1e2cf047d7 | |
parent | 79a7473cac40049769121a3a619b0d1e08899353 (diff) |
Fixed reloading of tool scripts within editor, they should work much better now, closes #3194
-rw-r--r-- | modules/gdscript/gd_script.cpp | 18 | ||||
-rw-r--r-- | modules/gdscript/gd_script.h | 6 |
2 files changed, 22 insertions, 2 deletions
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index d9783c218a..d1946e2a63 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1643,13 +1643,16 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof } #endif + for(Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get()->pending_reload_state.front();F;F=F->next()) { + map[F->key()]=F->get(); //pending to reload, use this one instead + } } } for(Map< Ref<GDScript>, Map<ObjectID,List<Pair<StringName,Variant> > > >::Element *E=to_reload.front();E;E=E->next()) { Ref<GDScript> scr = E->key(); - scr->reload(true); + scr->reload(p_soft_reload); //restore state if saved for (Map<ObjectID,List<Pair<StringName,Variant> > >::Element *F=E->get().front();F;F=F->next()) { @@ -1658,13 +1661,24 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof if (!obj) continue; + if (!p_soft_reload) { + //clear it just in case (may be a pending reload state) + obj->set_script(RefPtr()); + } obj->set_script(scr.get_ref_ptr()); - if (!obj->get_script_instance()) + if (!obj->get_script_instance()) { + //failed, save reload state for next time if not saved + if (!scr->pending_reload_state.has(obj->get_instance_ID())) { + scr->pending_reload_state[obj->get_instance_ID()]=F->get(); + } continue; + } for (List<Pair<StringName,Variant> >::Element *G=F->get().front();G;G=G->next()) { obj->get_script_instance()->set(G->get().first,G->get().second); } + + scr->pending_reload_state.erase(obj->get_instance_ID()); //as it reloaded, remove pending state } //if instance states were saved, set them! diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 723761c3a9..f0b6b7103c 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -120,7 +120,11 @@ friend class GDScriptLanguage; virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); #endif +#ifdef DEBUG_ENABLED + + Map<ObjectID,List<Pair<StringName,Variant> > > pending_reload_state; +#endif bool _update_exports(); @@ -265,6 +269,8 @@ class GDScriptLanguage : public ScriptLanguage { Mutex *lock; + + friend class GDScript; SelfList<GDScript>::List script_list; |