diff --git a/weaver/jsb_script.h b/weaver/jsb_script.h index 1d0c83f8..82082223 100644 --- a/weaver/jsb_script.h +++ b/weaver/jsb_script.h @@ -42,6 +42,12 @@ class GodotJSScript : public Script */ jsb::StatelessScriptClassInfo script_class_info_; +#ifdef DEBUG_ENABLED + HashMap>> pending_reload_state_; +#endif + + friend class GodotJSScriptLanguage; + private: void load_module_immediately(); jsb_force_inline void ensure_module_loaded() const { if (jsb_unlikely(!loaded_)) const_cast(this)->load_module_immediately(); } @@ -56,6 +62,8 @@ class GodotJSScript : public Script GodotJSScript(); virtual ~GodotJSScript() override; + bool is_root_script() const { return get_base_script().is_null(); } + StringName get_module_id() const { return script_class_info_.module_id; }; // Error attach_source(const String& p_path, bool p_take_over); diff --git a/weaver/jsb_script_language.cpp b/weaver/jsb_script_language.cpp index b8ab5b42..a78e9e9e 100644 --- a/weaver/jsb_script_language.cpp +++ b/weaver/jsb_script_language.cpp @@ -287,9 +287,29 @@ Vector GodotJSScriptLanguage::get_built_in_templ } #if GODOT_4_3_OR_NEWER +struct GodotJSScriptDepSort { + //must support sorting so inheritance works properly (parent must be reloaded first) + bool operator()(const Ref &A, const Ref &B) const { + if (A == B) { + return false; //shouldn't happen but.. + } + const GodotJSScript *I = static_cast(B->get_base_script().ptr()); + while (I) { + if (I == A.ptr()) { + // A is a base of B + return true; + } + + I = static_cast(I->get_base_script().ptr()); + } + + return false; //not a base + } +}; + void GodotJSScriptLanguage::reload_scripts(const Array& p_scripts, bool p_soft_reload) { - JSB_LOG(Verbose, "TODO [GodotJSScriptLanguage::reload_scripts] NOT IMPLEMENTED"); + reload_scripts_internal(p_scripts, p_soft_reload); } void GodotJSScriptLanguage::profiling_set_save_native_calls(bool p_enable) @@ -300,14 +320,35 @@ void GodotJSScriptLanguage::profiling_set_save_native_calls(bool p_enable) void GodotJSScriptLanguage::reload_all_scripts() { - //TODO temporarily ignored because it's only called from `RemoteDebugger` - JSB_LOG(Verbose, "TODO [GodotJSScriptLanguage::reload_all_scripts] temporarily ignored because it's only called from `RemoteDebugger`"); +#ifdef DEBUG_ENABLED + print_verbose("GodotJSScript: Reloading all scripts"); + Array scripts; + { + MutexLock lock(mutex_); + + SelfList *elem = script_list_.first(); + while (elem) { + if (elem->self()->get_path().is_resource_file()) { + print_verbose("GodotJSScript: Found: " + elem->self()->get_path()); + scripts.push_back(Ref(elem->self())); //cast to gdscript to avoid being erased by accident + } + elem = elem->next(); + } + +#ifdef TOOLS_ENABLED + // TODO: Implement global mechanism. +#endif // TOOLS_ENABLED + } + + reload_scripts_internal(scripts, true); +#endif // DEBUG_ENABLED } void GodotJSScriptLanguage::reload_tool_script(const Ref