2017-05-13 11:55:04 +00:00
|
|
|
#include "GodotGlobal.hpp"
|
|
|
|
|
|
|
|
#include "String.hpp"
|
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
#include "Wrapped.hpp"
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance) {
|
|
|
|
godot::_Wrapped *wrapper_memory = (godot::_Wrapped *)godot::api->godot_alloc(sizeof(godot::_Wrapped));
|
2018-02-11 14:50:01 +00:00
|
|
|
|
|
|
|
if (!wrapper_memory)
|
|
|
|
return NULL;
|
|
|
|
wrapper_memory->_owner = instance;
|
2018-11-23 22:09:41 +00:00
|
|
|
wrapper_memory->_type_tag = (size_t)type_tag;
|
2018-02-11 14:50:01 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
return (void *)wrapper_memory;
|
2018-02-11 14:50:01 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper) {
|
2018-02-11 14:50:01 +00:00
|
|
|
if (wrapper)
|
|
|
|
godot::api->godot_free(wrapper);
|
|
|
|
}
|
|
|
|
|
2017-05-13 11:55:04 +00:00
|
|
|
namespace godot {
|
|
|
|
|
2017-07-24 12:23:09 +00:00
|
|
|
void *_RegisterState::nativescript_handle;
|
2018-02-11 14:50:01 +00:00
|
|
|
int _RegisterState::language_index;
|
2019-05-22 09:06:01 +00:00
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
const godot_gdnative_core_api_struct *api = nullptr;
|
2019-05-22 09:06:01 +00:00
|
|
|
const godot_gdnative_core_1_1_api_struct *core_1_1_api = nullptr;
|
2019-08-12 09:55:29 +00:00
|
|
|
const godot_gdnative_core_1_2_api_struct *core_1_2_api = nullptr;
|
2019-05-22 09:06:01 +00:00
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = nullptr;
|
2018-02-11 14:50:01 +00:00
|
|
|
const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = nullptr;
|
2019-08-12 09:55:29 +00:00
|
|
|
const godot_gdnative_ext_pluginscript_api_struct *pluginscript_api = nullptr;
|
|
|
|
const godot_gdnative_ext_android_api_struct *android_api = nullptr;
|
|
|
|
const godot_gdnative_ext_arvr_api_struct *arvr_api = nullptr;
|
|
|
|
const godot_gdnative_ext_videodecoder_api_struct *videodecoder_api = nullptr;
|
|
|
|
const godot_gdnative_ext_net_api_struct *net_api = nullptr;
|
|
|
|
const godot_gdnative_ext_net_3_2_api_struct *net_3_2_api = nullptr;
|
2018-02-11 14:50:01 +00:00
|
|
|
|
|
|
|
const void *gdnlib = NULL;
|
2017-07-24 12:23:09 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::print(const String &message) {
|
|
|
|
godot::api->godot_print((godot_string *)&message);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::print_warning(const String &description, const String &function, const String &file, int line) {
|
2017-11-23 11:50:05 +00:00
|
|
|
int len;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
char *c_desc = description.alloc_c_string();
|
|
|
|
char *c_func = function.alloc_c_string();
|
|
|
|
char *c_file = file.alloc_c_string();
|
2017-11-24 22:54:35 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
if (c_desc != nullptr && c_func != nullptr && c_file != nullptr) {
|
2017-11-24 22:54:35 +00:00
|
|
|
godot::api->godot_print_warning(c_desc, c_func, c_file, line);
|
|
|
|
};
|
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr) godot::api->godot_free(c_desc);
|
|
|
|
if (c_func != nullptr) godot::api->godot_free(c_func);
|
|
|
|
if (c_file != nullptr) godot::api->godot_free(c_file);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::print_error(const String &description, const String &function, const String &file, int line) {
|
2017-11-23 11:50:05 +00:00
|
|
|
int len;
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
char *c_desc = description.alloc_c_string();
|
|
|
|
char *c_func = function.alloc_c_string();
|
|
|
|
char *c_file = file.alloc_c_string();
|
2017-11-23 11:50:05 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
if (c_desc != nullptr && c_func != nullptr && c_file != nullptr) {
|
2017-11-24 22:54:35 +00:00
|
|
|
godot::api->godot_print_error(c_desc, c_func, c_file, line);
|
|
|
|
};
|
2017-11-23 11:50:05 +00:00
|
|
|
|
2018-02-23 13:08:36 +00:00
|
|
|
if (c_desc != nullptr) godot::api->godot_free(c_desc);
|
|
|
|
if (c_func != nullptr) godot::api->godot_free(c_func);
|
|
|
|
if (c_file != nullptr) godot::api->godot_free(c_file);
|
2017-05-13 11:55:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-11 14:50:01 +00:00
|
|
|
void ___register_types();
|
2019-04-21 01:24:13 +00:00
|
|
|
void ___init_method_bindings();
|
2018-02-11 14:50:01 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::gdnative_init(godot_gdnative_init_options *options) {
|
2017-10-20 23:42:10 +00:00
|
|
|
godot::api = options->api_struct;
|
2018-02-11 14:50:01 +00:00
|
|
|
godot::gdnlib = options->gd_native_library;
|
2017-11-23 11:50:05 +00:00
|
|
|
|
2019-05-22 09:06:01 +00:00
|
|
|
const godot_gdnative_api_struct *core_extension = godot::api->next;
|
|
|
|
|
|
|
|
while (core_extension) {
|
|
|
|
if (core_extension->version.major == 1 && core_extension->version.minor == 1) {
|
|
|
|
godot::core_1_1_api = (const godot_gdnative_core_1_1_api_struct *)core_extension;
|
2019-08-12 09:55:29 +00:00
|
|
|
} else if (core_extension->version.major == 1 && core_extension->version.minor == 2) {
|
|
|
|
godot::core_1_2_api = (const godot_gdnative_core_1_2_api_struct *)core_extension;
|
2019-05-22 09:06:01 +00:00
|
|
|
}
|
|
|
|
core_extension = core_extension->next;
|
|
|
|
}
|
|
|
|
|
2017-11-23 11:50:05 +00:00
|
|
|
// now find our extensions
|
|
|
|
for (int i = 0; i < godot::api->num_extensions; i++) {
|
|
|
|
switch (godot::api->extensions[i]->type) {
|
2018-11-23 22:09:41 +00:00
|
|
|
case GDNATIVE_EXT_NATIVESCRIPT: {
|
|
|
|
godot::nativescript_api = (const godot_gdnative_ext_nativescript_api_struct *)godot::api->extensions[i];
|
2018-02-11 14:50:01 +00:00
|
|
|
|
|
|
|
const godot_gdnative_api_struct *extension = godot::nativescript_api->next;
|
|
|
|
|
|
|
|
while (extension) {
|
|
|
|
if (extension->version.major == 1 && extension->version.minor == 1) {
|
2018-11-23 22:09:41 +00:00
|
|
|
godot::nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *)extension;
|
2018-02-11 14:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension = extension->next;
|
|
|
|
}
|
|
|
|
} break;
|
2019-08-12 09:55:29 +00:00
|
|
|
case GDNATIVE_EXT_PLUGINSCRIPT: {
|
|
|
|
godot::pluginscript_api = (const godot_gdnative_ext_pluginscript_api_struct *)godot::api->extensions[i];
|
|
|
|
} break;
|
|
|
|
case GDNATIVE_EXT_ANDROID: {
|
|
|
|
godot::android_api = (const godot_gdnative_ext_android_api_struct *)godot::api->extensions[i];
|
|
|
|
} break;
|
|
|
|
case GDNATIVE_EXT_ARVR: {
|
|
|
|
godot::arvr_api = (const godot_gdnative_ext_arvr_api_struct *)godot::api->extensions[i];
|
|
|
|
} break;
|
|
|
|
case GDNATIVE_EXT_VIDEODECODER: {
|
|
|
|
godot::videodecoder_api = (const godot_gdnative_ext_videodecoder_api_struct *)godot::api->extensions[i];
|
|
|
|
} break;
|
|
|
|
case GDNATIVE_EXT_NET: {
|
|
|
|
godot::net_api = (const godot_gdnative_ext_net_api_struct *)godot::api->extensions[i];
|
|
|
|
|
|
|
|
const godot_gdnative_api_struct *extension = godot::net_api->next;
|
|
|
|
|
|
|
|
while (extension) {
|
|
|
|
if (extension->version.major == 3 && extension->version.minor == 2) {
|
|
|
|
godot::net_3_2_api = (const godot_gdnative_ext_net_3_2_api_struct *)extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
extension = extension->next;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2017-11-23 11:50:05 +00:00
|
|
|
default: break;
|
2018-02-11 14:50:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-24 12:23:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options) {
|
2018-01-11 16:57:52 +00:00
|
|
|
// reserved for future use.
|
2017-07-24 12:23:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 15:18:12 +00:00
|
|
|
void Godot::gdnative_profiling_add_data(const char *p_signature, uint64_t p_time) {
|
|
|
|
godot::nativescript_1_1_api->godot_nativescript_profiling_add_data(p_signature, p_time);
|
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::nativescript_init(void *handle) {
|
2017-07-24 12:23:09 +00:00
|
|
|
godot::_RegisterState::nativescript_handle = handle;
|
2018-02-11 14:50:01 +00:00
|
|
|
|
|
|
|
godot_instance_binding_functions binding_funcs = {};
|
|
|
|
binding_funcs.alloc_instance_binding_data = wrapper_create;
|
|
|
|
binding_funcs.free_instance_binding_data = wrapper_destroy;
|
|
|
|
|
|
|
|
godot::_RegisterState::language_index = godot::nativescript_1_1_api->godot_nativescript_register_instance_binding_data_functions(binding_funcs);
|
|
|
|
|
|
|
|
___register_types();
|
2019-04-21 01:24:13 +00:00
|
|
|
___init_method_bindings();
|
2017-07-24 12:23:09 +00:00
|
|
|
}
|
2018-01-11 16:57:52 +00:00
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
void Godot::nativescript_terminate(void *handle) {
|
2018-02-11 14:50:01 +00:00
|
|
|
godot::nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(godot::_RegisterState::language_index);
|
|
|
|
}
|
|
|
|
|
2018-11-23 22:09:41 +00:00
|
|
|
} // namespace godot
|