diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-12-16 14:26:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-16 14:26:56 +0100 |
commit | 9df7ed59fb39e38db30326365adc18afb79903bb (patch) | |
tree | 59d2220e78fe5295dd6ac4aa5607da6501a96eb6 /modules/gdnative | |
parent | 3914bdb82eafa558bc1512c7cf3c4f77565d0847 (diff) | |
parent | 065e2670af53ae2f71b78d57f8a217b4539cbbe2 (diff) |
Merge pull request #19501 from Zylann/custom_loaders
Added basic support for custom resource savers and loaders
Diffstat (limited to 'modules/gdnative')
-rw-r--r-- | modules/gdnative/gdnative.h | 2 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.h | 2 | ||||
-rw-r--r-- | modules/gdnative/nativescript/register_types.cpp | 14 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_language.cpp | 6 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_language.h | 8 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_loader.h | 6 | ||||
-rw-r--r-- | modules/gdnative/register_types.cpp | 15 |
7 files changed, 33 insertions, 20 deletions
diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index c5364a72ac..528344a814 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -161,6 +161,7 @@ public: }; class GDNativeLibraryResourceLoader : public ResourceFormatLoader { + GDCLASS(GDNativeLibraryResourceLoader, ResourceFormatLoader) public: virtual RES load(const String &p_path, const String &p_original_path, Error *r_error); virtual void get_recognized_extensions(List<String> *p_extensions) const; @@ -169,6 +170,7 @@ public: }; class GDNativeLibraryResourceSaver : public ResourceFormatSaver { + GDCLASS(GDNativeLibraryResourceSaver, ResourceFormatSaver) public: virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags); virtual bool recognize(const RES &p_resource) const; diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index e6f3c06ee5..67fb54387d 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -380,6 +380,7 @@ public: }; class ResourceFormatLoaderNativeScript : public ResourceFormatLoader { + GDCLASS(ResourceFormatLoaderNativeScript, ResourceFormatLoader) public: virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions(List<String> *p_extensions) const; @@ -388,6 +389,7 @@ public: }; class ResourceFormatSaverNativeScript : public ResourceFormatSaver { + GDCLASS(ResourceFormatSaverNativeScript, ResourceFormatSaver) virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); virtual bool recognize(const RES &p_resource) const; virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp index 4433c0a638..1e0c3d9fd8 100644 --- a/modules/gdnative/nativescript/register_types.cpp +++ b/modules/gdnative/nativescript/register_types.cpp @@ -39,8 +39,8 @@ NativeScriptLanguage *native_script_language; -ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL; -ResourceFormatSaverNativeScript *resource_saver_gdns = NULL; +Ref<ResourceFormatLoaderNativeScript> resource_loader_gdns; +Ref<ResourceFormatSaverNativeScript> resource_saver_gdns; void register_nativescript_types() { native_script_language = memnew(NativeScriptLanguage); @@ -50,18 +50,20 @@ void register_nativescript_types() { native_script_language->set_language_index(ScriptServer::get_language_count()); ScriptServer::register_language(native_script_language); - resource_saver_gdns = memnew(ResourceFormatSaverNativeScript); + resource_saver_gdns.instance(); ResourceSaver::add_resource_format_saver(resource_saver_gdns); - resource_loader_gdns = memnew(ResourceFormatLoaderNativeScript); + resource_loader_gdns.instance(); ResourceLoader::add_resource_format_loader(resource_loader_gdns); } void unregister_nativescript_types() { - memdelete(resource_loader_gdns); + ResourceLoader::remove_resource_format_loader(resource_loader_gdns); + resource_loader_gdns.unref(); - memdelete(resource_saver_gdns); + ResourceSaver::remove_resource_format_saver(resource_saver_gdns); + resource_saver_gdns.unref(); if (native_script_language) { ScriptServer::unregister_language(native_script_language); diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp index 2b538c4a36..0cda8859dd 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.cpp +++ b/modules/gdnative/pluginscript/pluginscript_language.cpp @@ -417,8 +417,8 @@ void PluginScriptLanguage::unlock() { PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_desc *desc) : _desc(*desc) { - _resource_loader = memnew(ResourceFormatLoaderPluginScript(this)); - _resource_saver = memnew(ResourceFormatSaverPluginScript(this)); + _resource_loader = Ref<ResourceFormatLoaderPluginScript>(memnew(ResourceFormatLoaderPluginScript(this))); + _resource_saver = Ref<ResourceFormatSaverPluginScript>(memnew(ResourceFormatSaverPluginScript(this))); // TODO: totally remove _lock attribute if NO_THREADS is set #ifdef NO_THREADS @@ -429,8 +429,6 @@ PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_des } PluginScriptLanguage::~PluginScriptLanguage() { - memdelete(_resource_loader); - memdelete(_resource_saver); #ifndef NO_THREADS if (_lock) { memdelete(_lock); diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h index c4df6f3a33..f749e900f5 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.h +++ b/modules/gdnative/pluginscript/pluginscript_language.h @@ -48,8 +48,8 @@ class PluginScriptLanguage : public ScriptLanguage { friend class PluginScript; friend class PluginScriptInstance; - ResourceFormatLoaderPluginScript *_resource_loader; - ResourceFormatSaverPluginScript *_resource_saver; + Ref<ResourceFormatLoaderPluginScript> _resource_loader; + Ref<ResourceFormatSaverPluginScript> _resource_saver; const godot_pluginscript_language_desc _desc; godot_pluginscript_language_data *_data; @@ -59,8 +59,8 @@ class PluginScriptLanguage : public ScriptLanguage { public: virtual String get_name() const; - _FORCE_INLINE_ ResourceFormatLoaderPluginScript *get_resource_loader() { return _resource_loader; }; - _FORCE_INLINE_ ResourceFormatSaverPluginScript *get_resource_saver() { return _resource_saver; }; + _FORCE_INLINE_ Ref<ResourceFormatLoaderPluginScript> get_resource_loader() { return _resource_loader; } + _FORCE_INLINE_ Ref<ResourceFormatSaverPluginScript> get_resource_saver() { return _resource_saver; } /* LANGUAGE FUNCTIONS */ virtual void init(); diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h index 5c17bb932e..ee9869be84 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.h +++ b/modules/gdnative/pluginscript/pluginscript_loader.h @@ -39,6 +39,9 @@ class PluginScriptLanguage; class ResourceFormatLoaderPluginScript : public ResourceFormatLoader { + + GDCLASS(ResourceFormatLoaderPluginScript, ResourceFormatLoader) + PluginScriptLanguage *_language; public: @@ -50,6 +53,9 @@ public: }; class ResourceFormatSaverPluginScript : public ResourceFormatSaver { + + GDCLASS(ResourceFormatSaverPluginScript, ResourceFormatSaver) + PluginScriptLanguage *_language; public: diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 62e87c3651..51f0b9afcc 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -299,8 +299,8 @@ GDNativeCallRegistry *GDNativeCallRegistry::singleton; Vector<Ref<GDNative> > singleton_gdnatives; -GDNativeLibraryResourceLoader *resource_loader_gdnlib = NULL; -GDNativeLibraryResourceSaver *resource_saver_gdnlib = NULL; +Ref<GDNativeLibraryResourceLoader> resource_loader_gdnlib; +Ref<GDNativeLibraryResourceSaver> resource_saver_gdnlib; void register_gdnative_types() { @@ -312,8 +312,8 @@ void register_gdnative_types() { ClassDB::register_class<GDNativeLibrary>(); ClassDB::register_class<GDNative>(); - resource_loader_gdnlib = memnew(GDNativeLibraryResourceLoader); - resource_saver_gdnlib = memnew(GDNativeLibraryResourceSaver); + resource_loader_gdnlib.instance(); + resource_saver_gdnlib.instance(); ResourceLoader::add_resource_format_loader(resource_loader_gdnlib); ResourceSaver::add_resource_format_saver(resource_saver_gdnlib); @@ -391,8 +391,11 @@ void unregister_gdnative_types() { } #endif - memdelete(resource_loader_gdnlib); - memdelete(resource_saver_gdnlib); + ResourceLoader::remove_resource_format_loader(resource_loader_gdnlib); + ResourceSaver::remove_resource_format_saver(resource_saver_gdnlib); + + resource_loader_gdnlib.unref(); + resource_saver_gdnlib.unref(); // This is for printing out the sizes of the core types |