From 5e5ae4000945b63aeb61e26b95d0e6e1a49de985 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 8 Aug 2022 00:39:35 +0200 Subject: [PATCH] Cleaned up GLTFDocumentExtension aswell. --- modules/gltf/SCsub | 1 + modules/gltf/gltf_document_extension.cpp | 125 +++++++++++++---------- modules/gltf/gltf_document_extension.h | 24 ++--- modules/gltf/register_types.cpp | 6 +- 4 files changed, 89 insertions(+), 67 deletions(-) diff --git a/modules/gltf/SCsub b/modules/gltf/SCsub index f0d31e372..820434e4a 100644 --- a/modules/gltf/SCsub +++ b/modules/gltf/SCsub @@ -9,6 +9,7 @@ env_gltf = env_modules.Clone() env_gltf.add_source_files(env.modules_sources, "register_types.cpp") env_gltf.add_source_files(env.modules_sources, "gltf_state.cpp") +env_gltf.add_source_files(env.modules_sources, "gltf_document_extension.cpp") #env_gltf.add_source_files(env.modules_sources, "*.cpp") env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp") diff --git a/modules/gltf/gltf_document_extension.cpp b/modules/gltf/gltf_document_extension.cpp index d0bd7651e..cb4e437ca 100644 --- a/modules/gltf/gltf_document_extension.cpp +++ b/modules/gltf/gltf_document_extension.cpp @@ -30,79 +30,100 @@ #include "gltf_document_extension.h" -void GLTFDocumentExtension::_bind_methods() { - GDVIRTUAL_BIND(_import_preflight, "state"); - GDVIRTUAL_BIND(_import_post_parse, "state"); - GDVIRTUAL_BIND(_import_node, "state", "gltf_node", "json", "node"); - GDVIRTUAL_BIND(_import_post, "state", "root"); - GDVIRTUAL_BIND(_export_preflight, "root"); - GDVIRTUAL_BIND(_export_node, "state", "gltf_node", "json", "node"); - GDVIRTUAL_BIND(_export_post, "state"); -} +#include "gltf_state.h" +#include "structures/gltf_node.h" Error GLTFDocumentExtension::import_post(Ref p_state, Node *p_root) { ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_import_post, p_state, p_root, err)) { - return Error(err); - } - return OK; + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + + int err = call("_import_post", p_state, p_root); + return static_cast(err); } Error GLTFDocumentExtension::import_preflight(Ref p_state) { - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_import_preflight, p_state, err)) { - return Error(err); - } - return OK; + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + + int err = call("_import_preflight", p_state); + return static_cast(err); } Error GLTFDocumentExtension::import_post_parse(Ref p_state) { - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_import_post_parse, p_state, err)) { - return Error(err); - } - return OK; + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + + int err = call("_import_post_parse", p_state); + return static_cast(err); } Error GLTFDocumentExtension::export_post(Ref p_state) { - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_export_post, p_state, err)) { - return Error(err); - } - return OK; + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + + int err = call("_export_post", p_state); + return static_cast(err); } Error GLTFDocumentExtension::export_preflight(Node *p_root) { ERR_FAIL_NULL_V(p_root, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_export_preflight, p_root, err)) { - return Error(err); - } - return OK; + + int err = call("_export_preflight", p_root); + return static_cast(err); } Error GLTFDocumentExtension::import_node(Ref p_state, Ref p_gltf_node, Dictionary &r_dict, Node *p_node) { - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_import_node, p_state, p_gltf_node, r_dict, p_node, err)) { - return Error(err); - } - return OK; + + int err = call("_import_node", p_state, p_gltf_node, r_dict, p_node); + return static_cast(err); } Error GLTFDocumentExtension::export_node(Ref p_state, Ref p_gltf_node, Dictionary &r_dict, Node *p_node) { - ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER); - ERR_FAIL_NULL_V(p_gltf_node, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_gltf_node.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); - int err = OK; - if (GDVIRTUAL_CALL(_export_node, p_state, p_gltf_node, r_dict, p_node, err)) { - return Error(err); - } - return OK; + + int err = call("_export_node", p_state, p_gltf_node, r_dict, p_node); + return static_cast(err); +} + +GLTFDocumentExtension::GLTFDocumentExtension() { +} +GLTFDocumentExtension::~GLTFDocumentExtension() { +} + +void GLTFDocumentExtension::_bind_methods() { + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_import_preflight", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_import_post_parse", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_import_node", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"), + PropertyInfo(Variant::OBJECT, "gltf_node", PROPERTY_HINT_RESOURCE_TYPE, "GLTFNode"), + PropertyInfo(Variant::DICTIONARY, "json"), + PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_import_post", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"), + PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_export_preflight", + PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_export_node", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"), + PropertyInfo(Variant::OBJECT, "gltf_node", PROPERTY_HINT_RESOURCE_TYPE, "GLTFNode"), + PropertyInfo(Variant::DICTIONARY, "json"), + PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); + + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), + "_export_post", + PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "GLTFState"))); } diff --git a/modules/gltf/gltf_document_extension.h b/modules/gltf/gltf_document_extension.h index 156a8ce69..49319a35f 100644 --- a/modules/gltf/gltf_document_extension.h +++ b/modules/gltf/gltf_document_extension.h @@ -31,15 +31,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gltf_state.h" -#include "structures/gltf_node.h" +#include "core/reference.h" + +#include "core/resource.h" + +class GLTFNode; +class GLTFState; class GLTFDocumentExtension : public Resource { GDCLASS(GLTFDocumentExtension, Resource); -protected: - static void _bind_methods(); - public: virtual Error import_preflight(Ref p_state); virtual Error import_post_parse(Ref p_state); @@ -48,13 +49,12 @@ public: virtual Error export_preflight(Node *p_state); virtual Error import_node(Ref p_state, Ref p_gltf_node, Dictionary &r_json, Node *p_node); virtual Error export_node(Ref p_state, Ref p_gltf_node, Dictionary &r_json, Node *p_node); - GDVIRTUAL1R(int, _import_preflight, Ref); - GDVIRTUAL1R(int, _import_post_parse, Ref); - GDVIRTUAL4R(int, _import_node, Ref, Ref, Dictionary, Node *); - GDVIRTUAL2R(int, _import_post, Ref, Node *); - GDVIRTUAL1R(int, _export_preflight, Node *); - GDVIRTUAL4R(int, _export_node, Ref, Ref, Dictionary, Node *); - GDVIRTUAL1R(int, _export_post, Ref); + + GLTFDocumentExtension(); + ~GLTFDocumentExtension(); + +protected: + static void _bind_methods(); }; #endif // GLTF_DOCUMENT_EXTENSION_H diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index 45d550459..4dc665520 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -45,6 +45,7 @@ #include "extensions/gltf_light.h" #include "extensions/gltf_spec_gloss.h" +#include "gltf_document_extension.h" #include "gltf_state.h" void register_gltf_types() { @@ -62,18 +63,17 @@ void register_gltf_types() { ClassDB::register_class(); //ClassDB::register_class(); - //ClassDB::register_class(); + ClassDB::register_class(); //ClassDB::register_class(); ClassDB::register_class(); } -void unregister_gltf_types() { +void unregister_gltf_types() { } /* #include "gltf_document.h" -#include "gltf_document_extension.h" #include "gltf_document_extension_convert_importer_mesh.h"