diff options
Diffstat (limited to 'modules/gdnative')
-rw-r--r-- | modules/gdnative/doc_classes/GDNativeLibrary.xml | 2 | ||||
-rw-r--r-- | modules/gdnative/gdnative.cpp | 21 | ||||
-rw-r--r-- | modules/gdnative/gdnative.h | 9 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 31 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.h | 2 |
5 files changed, 50 insertions, 15 deletions
diff --git a/modules/gdnative/doc_classes/GDNativeLibrary.xml b/modules/gdnative/doc_classes/GDNativeLibrary.xml index 647d27929f..14bd0e9654 100644 --- a/modules/gdnative/doc_classes/GDNativeLibrary.xml +++ b/modules/gdnative/doc_classes/GDNativeLibrary.xml @@ -31,6 +31,8 @@ <members> <member name="load_once" type="bool" setter="set_load_once" getter="should_load_once"> </member> + <member name="reloadable" type="bool" setter="set_reloadable" getter="is_reloadable"> + </member> <member name="singleton" type="bool" setter="set_singleton" getter="is_singleton"> </member> <member name="symbol_prefix" type="String" setter="set_symbol_prefix" getter="get_symbol_prefix"> diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 73754a72fa..1379083b42 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -38,9 +38,12 @@ #include "scene/main/scene_tree.h" -const String init_symbol = "gdnative_init"; -const String terminate_symbol = "gdnative_terminate"; -const String default_symbol_prefix = "godot_"; +static const String init_symbol = "gdnative_init"; +static const String terminate_symbol = "gdnative_terminate"; +static const String default_symbol_prefix = "godot_"; +static const bool default_singleton = false; +static const bool default_load_once = true; +static const bool default_reloadable = true; // Defined in gdnative_api_struct.gen.cpp extern const godot_gdnative_core_api_struct api_struct; @@ -51,6 +54,9 @@ GDNativeLibrary::GDNativeLibrary() { config_file.instance(); symbol_prefix = default_symbol_prefix; + load_once = default_load_once; + singleton = default_singleton; + reloadable = default_reloadable; if (GDNativeLibrary::loaded_libraries == NULL) { GDNativeLibrary::loaded_libraries = memnew((Map<String, Vector<Ref<GDNative> > >)); @@ -69,14 +75,17 @@ void GDNativeLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("should_load_once"), &GDNativeLibrary::should_load_once); ClassDB::bind_method(D_METHOD("is_singleton"), &GDNativeLibrary::is_singleton); ClassDB::bind_method(D_METHOD("get_symbol_prefix"), &GDNativeLibrary::get_symbol_prefix); + ClassDB::bind_method(D_METHOD("is_reloadable"), &GDNativeLibrary::is_reloadable); ClassDB::bind_method(D_METHOD("set_load_once", "load_once"), &GDNativeLibrary::set_load_once); ClassDB::bind_method(D_METHOD("set_singleton", "singleton"), &GDNativeLibrary::set_singleton); ClassDB::bind_method(D_METHOD("set_symbol_prefix", "symbol_prefix"), &GDNativeLibrary::set_symbol_prefix); + ClassDB::bind_method(D_METHOD("set_reloadable", "reloadable"), &GDNativeLibrary::set_reloadable); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "load_once"), "set_load_once", "should_load_once"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "singleton"), "set_singleton", "is_singleton"); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "symbol_prefix"), "set_symbol_prefix", "get_symbol_prefix"); + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "reloadable"), "set_reloadable", "is_reloadable"); } GDNative::GDNative() { @@ -318,9 +327,10 @@ RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_or *r_error = err; } - lib->set_singleton(config->get_value("general", "singleton", false)); - lib->set_load_once(config->get_value("general", "load_once", true)); + lib->set_singleton(config->get_value("general", "singleton", default_singleton)); + lib->set_load_once(config->get_value("general", "load_once", default_load_once)); lib->set_symbol_prefix(config->get_value("general", "symbol_prefix", default_symbol_prefix)); + lib->set_reloadable(config->get_value("general", "reloadable", default_reloadable)); String entry_lib_path; { @@ -416,6 +426,7 @@ Error GDNativeLibraryResourceSaver::save(const String &p_path, const RES &p_reso config->set_value("general", "singleton", lib->is_singleton()); config->set_value("general", "load_once", lib->should_load_once()); config->set_value("general", "symbol_prefix", lib->get_symbol_prefix()); + config->set_value("general", "reloadable", lib->is_reloadable()); return config->save(p_path); } diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 5fe705869e..3298ea950f 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -60,6 +60,7 @@ class GDNativeLibrary : public Resource { bool singleton; bool load_once; String symbol_prefix; + bool reloadable; public: GDNativeLibrary(); @@ -87,6 +88,10 @@ public: return symbol_prefix; } + _FORCE_INLINE_ bool is_reloadable() const { + return reloadable; + } + _FORCE_INLINE_ void set_load_once(bool p_load_once) { load_once = p_load_once; } @@ -97,6 +102,10 @@ public: symbol_prefix = p_symbol_prefix; } + _FORCE_INLINE_ void set_reloadable(bool p_reloadable) { + reloadable = p_reloadable; + } + static void _bind_methods(); }; diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 61b59f92e8..e9e3180835 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -790,8 +790,13 @@ NativeScriptInstance::~NativeScriptInstance() { NativeScriptLanguage *NativeScriptLanguage::singleton; -void NativeScriptLanguage::_unload_stuff() { +void NativeScriptLanguage::_unload_stuff(bool p_reload) { for (Map<String, Map<StringName, NativeScriptDesc> >::Element *L = library_classes.front(); L; L = L->next()) { + + if (p_reload && !library_gdnatives[L->key()]->get_library()->is_reloadable()) { + continue; + } + for (Map<StringName, NativeScriptDesc>::Element *C = L->get().front(); C; C = C->next()) { // free property stuff first @@ -1108,10 +1113,16 @@ void NativeReloadNode::_notification(int p_what) { #ifndef NO_THREADS MutexLock lock(NSL->mutex); #endif - NSL->_unload_stuff(); + NSL->_unload_stuff(true); for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - L->get()->terminate(); + Ref<GDNative> gdn = L->get(); + + if (!gdn->get_library()->is_reloadable()) { + continue; + } + + gdn->terminate(); NSL->library_classes.erase(L->key()); } @@ -1129,21 +1140,23 @@ void NativeReloadNode::_notification(int p_what) { Set<StringName> libs_to_remove; for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - if (!L->get()->initialize()) { + Ref<GDNative> gdn = L->get(); + + if (!gdn->get_library()->is_reloadable()) { + continue; + } + + if (!gdn->initialize()) { libs_to_remove.insert(L->key()); continue; } NSL->library_classes.insert(L->key(), Map<StringName, NativeScriptDesc>()); - void *args[1] = { - (void *)&L->key() - }; - // here the library registers all the classes and stuff. void *proc_ptr; - Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); + Error err = gdn->get_symbol(gdn->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); if (err != OK) { ERR_PRINT(String("No godot_nativescript_init in \"" + L->key() + "\" found").utf8().get_data()); } else { diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index 38f77aea55..ac94c84bc4 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -205,7 +205,7 @@ class NativeScriptLanguage : public ScriptLanguage { private: static NativeScriptLanguage *singleton; - void _unload_stuff(); + void _unload_stuff(bool p_reload = false); #ifndef NO_THREADS Mutex *mutex; |