diff --git a/modules/gdnative/gdnative/basis.cpp b/modules/gdnative/gdnative/basis.cpp index 372bdf3fb19..70d28145770 100644 --- a/modules/gdnative/gdnative/basis.cpp +++ b/modules/gdnative/gdnative/basis.cpp @@ -113,6 +113,40 @@ godot_vector3 GDAPI godot_basis_get_scale(const godot_basis *p_self) { 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 dest; const Basis *self = (const Basis *)p_self; diff --git a/modules/gdnative/gdnative/dictionary.cpp b/modules/gdnative/gdnative/dictionary.cpp index 786e6141585..34cc91129ed 100644 --- a/modules/gdnative/gdnative/dictionary.cpp +++ b/modules/gdnative/gdnative/dictionary.cpp @@ -155,6 +155,12 @@ godot_string GDAPI godot_dictionary_to_json(const godot_dictionary *p_self) { 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 } #endif diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 041990e137b..73fca655a87 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/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()); } +bool GDAPI godot_is_instance_valid(const godot_object *p_object) { + return ObjectDB::instance_validate((Object *)p_object); +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/gdnative/quat.cpp b/modules/gdnative/gdnative/quat.cpp index 56ff7fe3a8e..ddec77edcdc 100644 --- a/modules/gdnative/gdnative/quat.cpp +++ b/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); } +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) { const Quat *self = (const Quat *)p_self; return self->x; diff --git a/modules/gdnative/gdnative/transform.cpp b/modules/gdnative/gdnative/transform.cpp index 715f2e3c08e..ee6140c7d0d 100644 --- a/modules/gdnative/gdnative/transform.cpp +++ b/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); } +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 dest; const Transform *self = (const Transform *)p_self; diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index e326d11a841..dce3d7e96b3 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5,7 +5,98 @@ "major": 1, "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": [ { "name": "godot_color_new_rgba", @@ -4484,7 +4575,7 @@ ] }, { - "name": "godot_string_wide_str", + "name": "godot_string_wide_str", "return_type": "const wchar_t *", "arguments": [ ["const godot_string *", "p_self"] @@ -5253,21 +5344,21 @@ "name": "godot_string_ascii", "return_type": "godot_char_string", "arguments": [ - ["const godot_string *", "p_self"] + ["const godot_string *", "p_self"] ] }, { "name": "godot_string_ascii_extended", "return_type": "godot_char_string", "arguments": [ - ["const godot_string *", "p_self"] + ["const godot_string *", "p_self"] ] }, { "name": "godot_string_utf8", "return_type": "godot_char_string", "arguments": [ - ["const godot_string *", "p_self"] + ["const godot_string *", "p_self"] ] }, { @@ -5765,15 +5856,15 @@ "minor": 0 }, "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", "arguments": [ ["void *", "p_gdnative_handle"], @@ -5784,7 +5875,7 @@ ] }, { - "name": "godot_nativescript_set_class_documentation", + "name": "godot_nativescript_set_class_documentation", "return_type": "void", "arguments": [ ["void *", "p_gdnative_handle"], @@ -5793,7 +5884,7 @@ ] }, { - "name": "godot_nativescript_set_method_documentation", + "name": "godot_nativescript_set_method_documentation", "return_type": "void", "arguments": [ ["void *", "p_gdnative_handle"], @@ -5803,7 +5894,7 @@ ] }, { - "name": "godot_nativescript_set_property_documentation", + "name": "godot_nativescript_set_property_documentation", "return_type": "void", "arguments": [ ["void *", "p_gdnative_handle"], @@ -5813,7 +5904,7 @@ ] }, { - "name": "godot_nativescript_set_signal_documentation", + "name": "godot_nativescript_set_signal_documentation", "return_type": "void", "arguments": [ ["void *", "p_gdnative_handle"], @@ -5874,7 +5965,7 @@ "return_type": "void *", "arguments": [ ["int", "p_idx"], - ["godot_object *", "p_object"] + ["godot_object *", "p_object"] ] }, { @@ -5885,7 +5976,7 @@ ["uint64_t", "p_line"] ] } - ] + ] }, "api": [ { diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 8a1cd049af4..f9d1ed9dc55 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -82,10 +82,35 @@ def _build_gdnative_api_struct_header(api): 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']: name = ext['name'] out += generate_extension_struct(name, ext, False) + if api['core']['next']: + out += generate_core_extension_struct(api['core']['next']) + out += [ 'typedef struct godot_gdnative_core_api_struct {', '\tunsigned int type;', @@ -146,6 +171,27 @@ def _build_gdnative_api_struct_source(api): ret_val += ['};\n'] 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']: 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 += ['};\n'] + + if api['core']['next']: + out += get_core_struct_definition(api['core']['next']) out += [ 'extern const godot_gdnative_core_api_struct api_struct = {', diff --git a/modules/gdnative/include/gdnative/basis.h b/modules/gdnative/include/gdnative/basis.h index 53e950b4a28..ebe2b1125bd 100644 --- a/modules/gdnative/include/gdnative/basis.h +++ b/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_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_quat(godot_basis *r_dest, const godot_quat *p_euler); 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_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_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_with_euler_quat(godot_basis *r_dest, const godot_quat *p_euler); - // 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); diff --git a/modules/gdnative/include/gdnative/dictionary.h b/modules/gdnative/include/gdnative/dictionary.h index a86d60dc720..faace818ee8 100644 --- a/modules/gdnative/include/gdnative/dictionary.h +++ b/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_bool GDAPI godot_dictionary_erase_with_return(godot_dictionary *p_self, const godot_variant *p_key); + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 4cf6e99b06a..616c305f255 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/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(const godot_string *p_message); +// GDNATIVE CORE 1.0.1 + +bool GDAPI godot_is_instance_valid(const godot_object *p_object); + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/include/gdnative/quat.h b/modules/gdnative/include/gdnative/quat.h index 4e86960aafb..b1290f745c8 100644 --- a/modules/gdnative/include/gdnative/quat.h +++ b/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_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); void GDAPI godot_quat_set_x(godot_quat *p_self, const godot_real val); diff --git a/modules/gdnative/include/gdnative/transform.h b/modules/gdnative/include/gdnative/transform.h index a646da146a2..880f21c88ae 100644 --- a/modules/gdnative/include/gdnative/transform.h +++ b/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(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); void GDAPI godot_transform_set_basis(godot_transform *p_self, const godot_basis *p_v);