Browse Source

Merge pull request #21602 from karroffel/gdnative-core-1.1

[GDNative] add initial core 1.1 extension
Thomas Herzog 7 years ago
parent
commit
a1019c2c82

+ 34 - 0
modules/gdnative/gdnative/basis.cpp

@@ -113,6 +113,40 @@ godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self) {
 	return dest;
 	return dest;
 }
 }
 
 
+godot_quat GDAPI godot_basis_get_quat(const godot_basis *p_self) {
+	godot_quat dest;
+	const Basis *self = (const Basis *)p_self;
+	*((Quat *)&dest) = self->get_quat();
+	return dest;
+}
+
+void GDAPI godot_basis_set_quat(godot_basis *p_self, const godot_quat *p_quat) {
+	Basis *self = (Basis *)p_self;
+	const Quat *quat = (const Quat *)p_quat;
+	self->set_quat(*quat);
+}
+
+void GDAPI godot_basis_set_axis_angle_scale(godot_basis *p_self, const godot_vector3 *p_axis, godot_real p_phi, const godot_vector3 *p_scale) {
+	Basis *self = (Basis *)p_self;
+	const Vector3 *axis = (const Vector3 *)p_axis;
+	const Vector3 *scale = (const Vector3 *)p_scale;
+	self->set_axis_angle_scale(*axis, p_phi, *scale);
+}
+
+void GDAPI godot_basis_set_euler_scale(godot_basis *p_self, const godot_vector3 *p_euler, const godot_vector3 *p_scale) {
+	Basis *self = (Basis *)p_self;
+	const Vector3 *euler = (const Vector3 *)p_euler;
+	const Vector3 *scale = (const Vector3 *)p_scale;
+	self->set_euler_scale(*euler, *scale);
+}
+
+void GDAPI godot_basis_set_quat_scale(godot_basis *p_self, const godot_quat *p_quat, const godot_vector3 *p_scale) {
+	Basis *self = (Basis *)p_self;
+	const Quat *quat = (const Quat *)p_quat;
+	const Vector3 *scale = (const Vector3 *)p_scale;
+	self->set_quat_scale(*quat, *scale);
+}
+
 godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self) {
 godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self) {
 	godot_vector3 dest;
 	godot_vector3 dest;
 	const Basis *self = (const Basis *)p_self;
 	const Basis *self = (const Basis *)p_self;

+ 6 - 0
modules/gdnative/gdnative/dictionary.cpp

@@ -155,6 +155,12 @@ godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) {
 	return raw_dest;
 	return raw_dest;
 }
 }
 
 
+godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key) {
+	Dictionary *self = (Dictionary *)p_self;
+	const Variant *key = (const Variant *)p_key;
+	return self->erase(*key);
+}
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 4 - 0
modules/gdnative/gdnative/gdnative.cpp

@@ -166,6 +166,10 @@ void _gdnative_report_loading_error(const godot_object *p_library, const char *p
 	_err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
 	_err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr());
 }
 }
 
 
+bool GDAPI godot_is_instance_valid(const godot_object *p_object) {
+	return ObjectDB::instance_validate((Object *)p_object);
+}
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 12 - 0
modules/gdnative/gdnative/quat.cpp

@@ -49,6 +49,18 @@ void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector
 	*dest = Quat(*axis, p_angle);
 	*dest = Quat(*axis, p_angle);
 }
 }
 
 
+void GDAPI godot_quat_new_with_basis(godot_quat *r_dest, const godot_basis *p_basis) {
+	const Basis *basis = (const Basis *)p_basis;
+	Quat *dest = (Quat *)r_dest;
+	*dest = Quat(*basis);
+}
+
+void GDAPI godot_quat_new_with_euler(godot_quat *r_dest, const godot_vector3 *p_euler) {
+	const Vector3 *euler = (const Vector3 *)p_euler;
+	Quat *dest = (Quat *)r_dest;
+	*dest = Quat(*euler);
+}
+
 godot_real GDAPI godot_quat_get_x(const godot_quat *p_self) {
 godot_real GDAPI godot_quat_get_x(const godot_quat *p_self) {
 	const Quat *self = (const Quat *)p_self;
 	const Quat *self = (const Quat *)p_self;
 	return self->x;
 	return self->x;

+ 6 - 0
modules/gdnative/gdnative/transform.cpp

@@ -56,6 +56,12 @@ void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_bas
 	*dest = Transform(*basis, *origin);
 	*dest = Transform(*basis, *origin);
 }
 }
 
 
+void GDAPI godot_transform_new_with_quat(godot_transform *r_dest, const godot_quat *p_quat) {
+	const Quat *quat = (const Quat *)p_quat;
+	Transform *dest = (Transform *)r_dest;
+	*dest = Transform(*quat);
+}
+
 godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self) {
 godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self) {
 	godot_basis dest;
 	godot_basis dest;
 	const Transform *self = (const Transform *)p_self;
 	const Transform *self = (const Transform *)p_self;

+ 110 - 19
modules/gdnative/gdnative_api.json

@@ -5,7 +5,98 @@
       "major": 1,
       "major": 1,
       "minor": 0
       "minor": 0
     },
     },
-    "next": null,
+    "next": {
+      "type": "CORE",
+      "version": {
+        "major": 1,
+        "minor": 1
+      },
+      "next": null,
+      "api": [
+        {
+          "name": "godot_basis_get_quat",
+          "return_type": "godot_quat",
+          "arguments": [
+            ["const godot_basis *", "p_self"]
+          ]
+        },
+        {
+          "name": "godot_basis_set_quat",
+          "return_type": "void",
+          "arguments": [
+            ["godot_basis *", "p_self"],
+            ["const godot_quat *", "p_quat"]
+          ]
+        },
+        {
+          "name": "godot_basis_set_axis_angle_scale",
+          "return_type": "void",
+          "arguments": [
+            ["godot_basis *", "p_self"],
+            ["const godot_vector3 *", "p_axis"],
+            ["godot_real", "p_phi"],
+            ["const godot_vector3 *", "p_scale"]
+          ]
+        },
+        {
+          "name": "godot_basis_set_euler_scale",
+          "return_type": "void",
+          "arguments": [
+            ["godot_basis *", "p_self"],
+            ["const godot_vector3 *", "p_euler"],
+            ["const godot_vector3 *", "p_scale"]
+          ]
+        },
+        {
+          "name": "godot_basis_set_quat_scale",
+          "return_type": "void",
+          "arguments": [
+            ["godot_basis *", "p_self"],
+            ["const godot_quat *", "p_quat"],
+            ["const godot_vector3 *", "p_scale"]
+          ]
+        },
+        {
+          "name": "godot_dictionary_erase_with_return",
+          "return_type": "bool",
+          "arguments": [
+            ["godot_dictionary *", "p_self"],
+            ["const godot_variant *", "p_key"]
+          ]
+        },
+        {
+          "name": "godot_is_instance_valid",
+          "return_type": "bool",
+          "arguments": [
+            ["const godot_object *", "p_object"]
+          ]
+        },
+        {
+          "name": "godot_quat_new_with_basis",
+          "return_type": "void",
+          "arguments": [
+            ["godot_quat *", "r_dest"],
+            ["const godot_basis *", "p_basis"]
+          ]
+        },
+        {
+          "name": "godot_quat_new_with_euler",
+          "return_type": "void",
+          "arguments": [
+            ["godot_quat *", "r_dest"],
+            ["const godot_vector3 *", "p_euler"]
+          ]
+        },
+        {
+          "name": "godot_transform_new_with_quat",
+          "return_type": "void",
+          "arguments": [
+            ["godot_transform *", "r_dest"],
+            ["const godot_quat *", "p_quat"]
+          ]
+        }
+      ]
+    },
     "api": [
     "api": [
       {
       {
         "name": "godot_color_new_rgba",
         "name": "godot_color_new_rgba",
@@ -4484,7 +4575,7 @@
         ]
         ]
       },
       },
       {
       {
-	"name": "godot_string_wide_str",
+        "name": "godot_string_wide_str",
         "return_type": "const wchar_t *",
         "return_type": "const wchar_t *",
         "arguments": [
         "arguments": [
           ["const godot_string *", "p_self"]
           ["const godot_string *", "p_self"]
@@ -5253,21 +5344,21 @@
         "name": "godot_string_ascii",
         "name": "godot_string_ascii",
         "return_type": "godot_char_string",
         "return_type": "godot_char_string",
         "arguments": [
         "arguments": [
-	  ["const godot_string *", "p_self"]
+          ["const godot_string *", "p_self"]
         ]
         ]
       },
       },
       {
       {
         "name": "godot_string_ascii_extended",
         "name": "godot_string_ascii_extended",
         "return_type": "godot_char_string",
         "return_type": "godot_char_string",
         "arguments": [
         "arguments": [
-	  ["const godot_string *", "p_self"]
+          ["const godot_string *", "p_self"]
         ]
         ]
       },
       },
       {
       {
         "name": "godot_string_utf8",
         "name": "godot_string_utf8",
         "return_type": "godot_char_string",
         "return_type": "godot_char_string",
         "arguments": [
         "arguments": [
-	  ["const godot_string *", "p_self"]
+          ["const godot_string *", "p_self"]
         ]
         ]
       },
       },
       {
       {
@@ -5765,15 +5856,15 @@
         "minor": 0
         "minor": 0
       },
       },
       "next": {
       "next": {
-	"type": "NATIVESCRIPT",
-	"version": {
-	  "major": 1,
-	  "minor": 1
-	},
-	"next": null,
-	"api": [
+        "type": "NATIVESCRIPT",
+        "version": {
+          "major": 1,
+          "minor": 1
+        },
+        "next": null,
+        "api": [
           {
           {
-	    "name": "godot_nativescript_set_method_argument_information",
+            "name": "godot_nativescript_set_method_argument_information",
             "return_type": "void",
             "return_type": "void",
             "arguments": [
             "arguments": [
               ["void *", "p_gdnative_handle"],
               ["void *", "p_gdnative_handle"],
@@ -5784,7 +5875,7 @@
             ]
             ]
           },
           },
           {
           {
-	    "name": "godot_nativescript_set_class_documentation",
+            "name": "godot_nativescript_set_class_documentation",
             "return_type": "void",
             "return_type": "void",
             "arguments": [
             "arguments": [
               ["void *", "p_gdnative_handle"],
               ["void *", "p_gdnative_handle"],
@@ -5793,7 +5884,7 @@
             ]
             ]
           },
           },
           {
           {
-	    "name": "godot_nativescript_set_method_documentation",
+            "name": "godot_nativescript_set_method_documentation",
             "return_type": "void",
             "return_type": "void",
             "arguments": [
             "arguments": [
               ["void *", "p_gdnative_handle"],
               ["void *", "p_gdnative_handle"],
@@ -5803,7 +5894,7 @@
             ]
             ]
           },
           },
           {
           {
-	    "name": "godot_nativescript_set_property_documentation",
+            "name": "godot_nativescript_set_property_documentation",
             "return_type": "void",
             "return_type": "void",
             "arguments": [
             "arguments": [
               ["void *", "p_gdnative_handle"],
               ["void *", "p_gdnative_handle"],
@@ -5813,7 +5904,7 @@
             ]
             ]
           },
           },
           {
           {
-	    "name": "godot_nativescript_set_signal_documentation",
+            "name": "godot_nativescript_set_signal_documentation",
             "return_type": "void",
             "return_type": "void",
             "arguments": [
             "arguments": [
               ["void *", "p_gdnative_handle"],
               ["void *", "p_gdnative_handle"],
@@ -5874,7 +5965,7 @@
             "return_type": "void *",
             "return_type": "void *",
             "arguments": [
             "arguments": [
               ["int", "p_idx"],
               ["int", "p_idx"],
-	      ["godot_object *", "p_object"]
+              ["godot_object *", "p_object"]
             ]
             ]
           },
           },
           {
           {
@@ -5885,7 +5976,7 @@
               ["uint64_t", "p_line"]
               ["uint64_t", "p_line"]
             ]
             ]
           }
           }
-	]
+        ]
       },
       },
       "api": [
       "api": [
         {
         {

+ 49 - 0
modules/gdnative/gdnative_builders.py

@@ -82,10 +82,35 @@ def _build_gdnative_api_struct_header(api):
 
 
         return ret_val
         return ret_val
 
 
+
+    def generate_core_extension_struct(core):
+        ret_val = []
+        if core['next']:
+            ret_val += generate_core_extension_struct(core['next'])
+        
+        ret_val += [
+            'typedef struct godot_gdnative_core_' + ('{0}_{1}'.format(core['version']['major'], core['version']['minor'])) + '_api_struct {',
+            '\tunsigned int type;',
+            '\tgodot_gdnative_api_version version;',
+            '\tconst godot_gdnative_api_struct *next;',
+        ]
+        
+        for funcdef in core['api']:
+            args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
+            ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
+        
+        ret_val += ['} godot_gdnative_core_' + '{0}_{1}'.format(core['version']['major'], core['version']['minor']) + '_api_struct;', '']
+        
+        return ret_val
+
+
     for ext in api['extensions']:
     for ext in api['extensions']:
         name = ext['name']
         name = ext['name']
         out += generate_extension_struct(name, ext, False)
         out += generate_extension_struct(name, ext, False)
 
 
+    if api['core']['next']:
+        out += generate_core_extension_struct(api['core']['next'])
+
     out += [
     out += [
         'typedef struct godot_gdnative_core_api_struct {',
         'typedef struct godot_gdnative_core_api_struct {',
         '\tunsigned int type;',
         '\tunsigned int type;',
@@ -146,6 +171,27 @@ def _build_gdnative_api_struct_source(api):
         ret_val += ['};\n']
         ret_val += ['};\n']
 
 
         return ret_val
         return ret_val
+    
+    
+    def get_core_struct_definition(core):
+        ret_val = []
+        
+        if core['next']:
+            ret_val += get_core_struct_definition(core['next'])
+        
+        ret_val += [
+            'extern const godot_gdnative_core_' + ('{0}_{1}_api_struct api_{0}_{1}'.format(core['version']['major'], core['version']['minor'])) + ' = {',
+            '\tGDNATIVE_' + core['type'] + ',',
+            '\t{' + str(core['version']['major']) + ', ' + str(core['version']['minor']) + '},',
+            '\t' + ('NULL' if not core['next'] else ('(const godot_gdnative_api_struct *)& api_{0}_{1}'.format(core['version']['major'], core['version']['minor']))) + ','
+        ]
+        
+        for funcdef in core['api']:
+            ret_val.append('\t%s,' % funcdef['name'])
+        
+        ret_val += ['};\n']
+        
+        return ret_val
 
 
     for ext in api['extensions']:
     for ext in api['extensions']:
         name = ext['name']
         name = ext['name']
@@ -158,6 +204,9 @@ def _build_gdnative_api_struct_source(api):
         out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
         out += ['\t(godot_gdnative_api_struct *)&api_extension_' + name + '_struct,']
 
 
     out += ['};\n']
     out += ['};\n']
+    
+    if api['core']['next']:
+        out += get_core_struct_definition(api['core']['next'])
 
 
     out += [
     out += [
         'extern const godot_gdnative_core_api_struct api_struct = {',
         'extern const godot_gdnative_core_api_struct api_struct = {',

+ 11 - 2
modules/gdnative/include/gdnative/basis.h

@@ -62,6 +62,7 @@ extern "C" {
 void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis);
 void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis);
 void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi);
 void GDAPI godot_basis_new_with_axis_and_angle(godot_basis *r_dest, const godot_vector3 *p_axis, const godot_real p_phi);
 void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler);
 void GDAPI godot_basis_new_with_euler(godot_basis *r_dest, const godot_vector3 *p_euler);
+void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler);
 
 
 godot_string GDAPI godot_basis_as_string(const godot_basis *p_self);
 godot_string GDAPI godot_basis_as_string(const godot_basis *p_self);
 
 
@@ -81,6 +82,16 @@ godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self);
 
 
 godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self);
 godot_vector3 GDAPI godot_basis_get_euler(const godot_basis *p_self);
 
 
+godot_quat GDAPI godot_basis_get_quat(const godot_basis *p_self);
+
+void GDAPI godot_basis_set_quat(godot_basis *p_self, const godot_quat *p_quat);
+
+void GDAPI godot_basis_set_axis_angle_scale(godot_basis *p_self, const godot_vector3 *p_axis, godot_real p_phi, const godot_vector3 *p_scale);
+
+void GDAPI godot_basis_set_euler_scale(godot_basis *p_self, const godot_vector3 *p_euler, const godot_vector3 *p_scale);
+
+void GDAPI godot_basis_set_quat_scale(godot_basis *p_self, const godot_quat *p_quat, const godot_vector3 *p_scale);
+
 godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with);
 godot_real GDAPI godot_basis_tdotx(const godot_basis *p_self, const godot_vector3 *p_with);
 
 
 godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with);
 godot_real GDAPI godot_basis_tdoty(const godot_basis *p_self, const godot_vector3 *p_with);
@@ -95,8 +106,6 @@ godot_int GDAPI godot_basis_get_orthogonal_index(const godot_basis *p_self);
 
 
 void GDAPI godot_basis_new(godot_basis *r_dest);
 void GDAPI godot_basis_new(godot_basis *r_dest);
 
 
-void GDAPI godot_basis_new_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler);
-
 // p_elements is a pointer to an array of 3 (!!) vector3
 // p_elements is a pointer to an array of 3 (!!) vector3
 void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements);
 void GDAPI godot_basis_get_elements(const godot_basis *p_self, godot_vector3 *p_elements);
 
 

+ 2 - 0
modules/gdnative/include/gdnative/dictionary.h

@@ -94,6 +94,8 @@ godot_bool GDAPI godot_dictionary_operator_equal(const godot_dictionary *p_self,
 
 
 godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self);
 godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self);
 
 
+godot_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 4 - 0
modules/gdnative/include/gdnative/gdnative.h

@@ -282,6 +282,10 @@ void GDAPI godot_print_error(const char *p_description, const char *p_function,
 void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
 void GDAPI godot_print_warning(const char *p_description, const char *p_function, const char *p_file, int p_line);
 void GDAPI godot_print(const godot_string *p_message);
 void GDAPI godot_print(const godot_string *p_message);
 
 
+// GDNATIVE CORE 1.0.1
+
+bool GDAPI godot_is_instance_valid(const godot_object *p_object);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 2 - 0
modules/gdnative/include/gdnative/quat.h

@@ -60,6 +60,8 @@ extern "C" {
 
 
 void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w);
 void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w);
 void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle);
 void GDAPI godot_quat_new_with_axis_angle(godot_quat *r_dest, const godot_vector3 *p_axis, const godot_real p_angle);
+void GDAPI godot_quat_new_with_basis(godot_quat *r_dest, const godot_basis *p_basis);
+void GDAPI godot_quat_new_with_euler(godot_quat *r_dest, const godot_vector3 *p_euler);
 
 
 godot_real GDAPI godot_quat_get_x(const godot_quat *p_self);
 godot_real GDAPI godot_quat_get_x(const godot_quat *p_self);
 void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val);
 void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val);

+ 1 - 0
modules/gdnative/include/gdnative/transform.h

@@ -62,6 +62,7 @@ extern "C" {
 
 
 void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin);
 void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin);
 void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin);
 void GDAPI godot_transform_new(godot_transform *r_dest, const godot_basis *p_basis, const godot_vector3 *p_origin);
+void GDAPI godot_transform_new_with_quat(godot_transform *r_dest, const godot_quat *p_quat);
 
 
 godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self);
 godot_basis GDAPI godot_transform_get_basis(const godot_transform *p_self);
 void GDAPI godot_transform_set_basis(godot_transform *p_self, const godot_basis *p_v);
 void GDAPI godot_transform_set_basis(godot_transform *p_self, const godot_basis *p_v);