[GDNative] removed native_raw_call
This commit is contained in:
parent
e82a3f0168
commit
e568f80e6e
8 changed files with 80 additions and 204 deletions
|
@ -199,10 +199,7 @@ void GDNative::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize);
|
ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize);
|
||||||
ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate);
|
ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate);
|
||||||
|
|
||||||
// TODO(karroffel): get_native_(raw_)call_types binding?
|
ClassDB::bind_method(D_METHOD("call_native", "calling_type", "procedure_name", "arguments"), &GDNative::call_native);
|
||||||
|
|
||||||
// TODO(karroffel): make this a varargs function?
|
|
||||||
ClassDB::bind_method(D_METHOD("call_native", "procedure_name", "arguments"), &GDNative::call_native);
|
|
||||||
|
|
||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library");
|
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library");
|
||||||
}
|
}
|
||||||
|
@ -239,10 +236,7 @@ bool GDNative::initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *library_init;
|
void *library_init;
|
||||||
err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
err = get_symbol(init_symbol, library_init);
|
||||||
native_handle,
|
|
||||||
init_symbol,
|
|
||||||
library_init);
|
|
||||||
|
|
||||||
if (err || !library_init) {
|
if (err || !library_init) {
|
||||||
OS::get_singleton()->close_dynamic_library(native_handle);
|
OS::get_singleton()->close_dynamic_library(native_handle);
|
||||||
|
@ -277,11 +271,8 @@ bool GDNative::terminate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *library_terminate;
|
void *library_terminate;
|
||||||
Error error = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
Error error = get_symbol(terminate_symbol, library_terminate);
|
||||||
native_handle,
|
if (error || !library_terminate) {
|
||||||
terminate_symbol,
|
|
||||||
library_terminate);
|
|
||||||
if (error) {
|
|
||||||
OS::get_singleton()->close_dynamic_library(native_handle);
|
OS::get_singleton()->close_dynamic_library(native_handle);
|
||||||
native_handle = NULL;
|
native_handle = NULL;
|
||||||
return true;
|
return true;
|
||||||
|
@ -313,10 +304,6 @@ void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, nat
|
||||||
native_calls.insert(p_call_type, p_callback);
|
native_calls.insert(p_call_type, p_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDNativeCallRegistry::register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback) {
|
|
||||||
native_raw_calls.insert(p_raw_call_type, p_callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<StringName> GDNativeCallRegistry::get_native_call_types() {
|
Vector<StringName> GDNativeCallRegistry::get_native_call_types() {
|
||||||
Vector<StringName> call_types;
|
Vector<StringName> call_types;
|
||||||
call_types.resize(native_calls.size());
|
call_types.resize(native_calls.size());
|
||||||
|
@ -329,18 +316,6 @@ Vector<StringName> GDNativeCallRegistry::get_native_call_types() {
|
||||||
return call_types;
|
return call_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringName> GDNativeCallRegistry::get_native_raw_call_types() {
|
|
||||||
Vector<StringName> call_types;
|
|
||||||
call_types.resize(native_raw_calls.size());
|
|
||||||
|
|
||||||
size_t idx = 0;
|
|
||||||
for (Map<StringName, native_raw_call_cb>::Element *E = native_raw_calls.front(); E; E = E->next(), idx++) {
|
|
||||||
call_types[idx] = E->key();
|
|
||||||
}
|
|
||||||
|
|
||||||
return call_types;
|
|
||||||
}
|
|
||||||
|
|
||||||
Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) {
|
Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) {
|
||||||
|
|
||||||
Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type);
|
Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type);
|
||||||
|
@ -349,20 +324,34 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced
|
||||||
return Variant();
|
return Variant();
|
||||||
}
|
}
|
||||||
|
|
||||||
String procedure_name = p_procedure_name;
|
void *procedure_handle;
|
||||||
godot_variant result = E->get()(native_handle, (godot_string *)&procedure_name, (godot_array *)&p_arguments);
|
|
||||||
|
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
||||||
|
native_handle,
|
||||||
|
p_procedure_name,
|
||||||
|
procedure_handle);
|
||||||
|
|
||||||
|
if (err != OK || procedure_handle == NULL) {
|
||||||
|
return Variant();
|
||||||
|
}
|
||||||
|
|
||||||
|
godot_variant result = E->get()(procedure_handle, (godot_array *)&p_arguments);
|
||||||
|
|
||||||
return *(Variant *)&result;
|
return *(Variant *)&result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GDNative::call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return) {
|
Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) {
|
||||||
|
|
||||||
Map<StringName, native_raw_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_raw_calls.find(p_raw_call_type);
|
if (native_handle == NULL) {
|
||||||
if (!E) {
|
ERR_PRINT("No valid library handle, can't get symbol from GDNative object");
|
||||||
ERR_PRINT((String("No handler for native raw call type \"" + p_raw_call_type) + "\" found").utf8().get_data());
|
return ERR_CANT_OPEN;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String procedure_name = p_procedure_name;
|
Error result = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
||||||
E->get()(native_handle, (godot_string *)&procedure_name, data, num_args, args, r_return);
|
native_handle,
|
||||||
|
p_procedure_name,
|
||||||
|
r_handle,
|
||||||
|
true);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,7 @@ public:
|
||||||
_FORCE_INLINE_ void set_singleton_gdnative(bool p_singleton) { singleton_gdnative = p_singleton; }
|
_FORCE_INLINE_ void set_singleton_gdnative(bool p_singleton) { singleton_gdnative = p_singleton; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef godot_variant (*native_call_cb)(void *, godot_string *, godot_array *);
|
typedef godot_variant (*native_call_cb)(void *, godot_array *);
|
||||||
typedef void (*native_raw_call_cb)(void *, godot_string *, void *, int, void **, void *);
|
|
||||||
|
|
||||||
struct GDNativeCallRegistry {
|
struct GDNativeCallRegistry {
|
||||||
static GDNativeCallRegistry *singleton;
|
static GDNativeCallRegistry *singleton;
|
||||||
|
@ -111,17 +110,13 @@ struct GDNativeCallRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline GDNativeCallRegistry()
|
inline GDNativeCallRegistry()
|
||||||
: native_calls(),
|
: native_calls() {}
|
||||||
native_raw_calls() {}
|
|
||||||
|
|
||||||
Map<StringName, native_call_cb> native_calls;
|
Map<StringName, native_call_cb> native_calls;
|
||||||
Map<StringName, native_raw_call_cb> native_raw_calls;
|
|
||||||
|
|
||||||
void register_native_call_type(StringName p_call_type, native_call_cb p_callback);
|
void register_native_call_type(StringName p_call_type, native_call_cb p_callback);
|
||||||
void register_native_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback);
|
|
||||||
|
|
||||||
Vector<StringName> get_native_call_types();
|
Vector<StringName> get_native_call_types();
|
||||||
Vector<StringName> get_native_raw_call_types();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GDNative : public Reference {
|
class GDNative : public Reference {
|
||||||
|
@ -149,7 +144,8 @@ public:
|
||||||
bool terminate();
|
bool terminate();
|
||||||
|
|
||||||
Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array());
|
Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array());
|
||||||
void call_native_raw(StringName p_raw_call_type, StringName p_procedure_name, void *data, int num_args, void **args, void *r_return);
|
|
||||||
|
Error get_symbol(StringName p_procedure_name, void *&r_handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GDNATIVE_H
|
#endif // GDNATIVE_H
|
||||||
|
|
|
@ -255,7 +255,7 @@ godot_dictionary GDAPI godot_get_global_constants();
|
||||||
////// GDNative procedure types
|
////// GDNative procedure types
|
||||||
typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *);
|
typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_options *);
|
||||||
typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *);
|
typedef void (*godot_gdnative_terminate_fn)(godot_gdnative_terminate_options *);
|
||||||
typedef godot_variant (*godot_gdnative_procedure_fn)(void *, godot_array *);
|
typedef godot_variant (*godot_gdnative_procedure_fn)(godot_array *);
|
||||||
|
|
||||||
////// System Functions
|
////// System Functions
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ ARVRInterfaceGDNative::~ARVRInterfaceGDNative() {
|
||||||
|
|
||||||
void ARVRInterfaceGDNative::cleanup() {
|
void ARVRInterfaceGDNative::cleanup() {
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
library->call_native_raw("arvr_call_destructor", "godot_arvr_destructor", data, 0, NULL, NULL);
|
// library->call_native_raw("arvr_call_destructor", "godot_arvr_destructor", data, 0, NULL, NULL);
|
||||||
data = NULL;
|
data = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ void ARVRInterfaceGDNative::set_gdnative_library(Ref<GDNativeLibrary> p_library)
|
||||||
// Now we do our constructing...
|
// Now we do our constructing...
|
||||||
void *parameters[1];
|
void *parameters[1];
|
||||||
parameters[0] = (void *)this;
|
parameters[0] = (void *)this;
|
||||||
library->call_native_raw("arvr_call_constructor", "godot_arvr_constructor", NULL, 1, parameters, &data);
|
// library->call_native_raw("arvr_call_constructor", "godot_arvr_constructor", NULL, 1, parameters, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringName ARVRInterfaceGDNative::get_name() const {
|
StringName ARVRInterfaceGDNative::get_name() const {
|
||||||
|
@ -84,7 +84,7 @@ StringName ARVRInterfaceGDNative::get_name() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, StringName());
|
ERR_FAIL_COND_V(data == NULL, StringName());
|
||||||
|
|
||||||
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_string", "godot_arvr_get_name", data, 0, NULL, &name);
|
// const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_string", "godot_arvr_get_name", data, 0, NULL, &name);
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ int ARVRInterfaceGDNative::get_capabilities() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, 0); // 0 = None
|
ERR_FAIL_COND_V(data == NULL, 0); // 0 = None
|
||||||
|
|
||||||
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_int", "godot_arvr_get_capabilities", data, 0, NULL, &capabilities);
|
// const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_int", "godot_arvr_get_capabilities", data, 0, NULL, &capabilities);
|
||||||
|
|
||||||
return capabilities;
|
return capabilities;
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ bool ARVRInterfaceGDNative::get_anchor_detection_is_enabled() const {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, false);
|
ERR_FAIL_COND_V(data == NULL, false);
|
||||||
|
|
||||||
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_bool", "godot_arvr_get_anchor_detection_is_enabled", data, 0, NULL, &enabled);
|
// const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_bool", "godot_arvr_get_anchor_detection_is_enabled", data, 0, NULL, &enabled);
|
||||||
|
|
||||||
return enabled;
|
return enabled;
|
||||||
};
|
};
|
||||||
|
@ -115,7 +115,7 @@ void ARVRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) {
|
||||||
ERR_FAIL_COND(data == NULL);
|
ERR_FAIL_COND(data == NULL);
|
||||||
|
|
||||||
parameters[0] = (void *)&p_enable;
|
parameters[0] = (void *)&p_enable;
|
||||||
library->call_native_raw("arvr_set_bool", "godot_arvr_set_anchor_detection_is_enabled", data, 1, parameters, NULL);
|
// library->call_native_raw("arvr_set_bool", "godot_arvr_set_anchor_detection_is_enabled", data, 1, parameters, NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ARVRInterfaceGDNative::is_stereo() {
|
bool ARVRInterfaceGDNative::is_stereo() {
|
||||||
|
@ -123,7 +123,7 @@ bool ARVRInterfaceGDNative::is_stereo() {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, false);
|
ERR_FAIL_COND_V(data == NULL, false);
|
||||||
|
|
||||||
library->call_native_raw("arvr_return_bool", "godot_arvr_is_stereo", data, 0, NULL, &stereo);
|
// library->call_native_raw("arvr_return_bool", "godot_arvr_is_stereo", data, 0, NULL, &stereo);
|
||||||
|
|
||||||
return stereo;
|
return stereo;
|
||||||
};
|
};
|
||||||
|
@ -133,7 +133,7 @@ bool ARVRInterfaceGDNative::is_initialized() {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, false);
|
ERR_FAIL_COND_V(data == NULL, false);
|
||||||
|
|
||||||
library->call_native_raw("arvr_return_bool", "godot_arvr_is_initialized", data, 0, NULL, &initialized);
|
// library->call_native_raw("arvr_return_bool", "godot_arvr_is_initialized", data, 0, NULL, &initialized);
|
||||||
|
|
||||||
return initialized;
|
return initialized;
|
||||||
};
|
};
|
||||||
|
@ -143,7 +143,7 @@ bool ARVRInterfaceGDNative::initialize() {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, false);
|
ERR_FAIL_COND_V(data == NULL, false);
|
||||||
|
|
||||||
library->call_native_raw("arvr_return_bool", "godot_arvr_initialize", data, 0, NULL, &initialized);
|
// library->call_native_raw("arvr_return_bool", "godot_arvr_initialize", data, 0, NULL, &initialized);
|
||||||
|
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
// if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface
|
// if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface
|
||||||
|
@ -166,7 +166,7 @@ void ARVRInterfaceGDNative::uninitialize() {
|
||||||
arvr_server->clear_primary_interface_if(this);
|
arvr_server->clear_primary_interface_if(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
library->call_native_raw("arvr_call_method", "godot_arvr_uninitialize", data, 0, NULL, NULL);
|
// library->call_native_raw("arvr_call_method", "godot_arvr_uninitialize", data, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() {
|
Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() {
|
||||||
|
@ -174,7 +174,7 @@ Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() {
|
||||||
|
|
||||||
ERR_FAIL_COND_V(data == NULL, Size2());
|
ERR_FAIL_COND_V(data == NULL, Size2());
|
||||||
|
|
||||||
library->call_native_raw("arvr_return_vector2", "godot_arvr_get_recommended_render_targetsize", data, 0, NULL, &size);
|
// library->call_native_raw("arvr_return_vector2", "godot_arvr_get_recommended_render_targetsize", data, 0, NULL, &size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ Transform ARVRInterfaceGDNative::get_transform_for_eye(ARVRInterface::Eyes p_eye
|
||||||
|
|
||||||
parameters[0] = (void *)&p_eye;
|
parameters[0] = (void *)&p_eye;
|
||||||
parameters[1] = (void *)&p_cam_transform;
|
parameters[1] = (void *)&p_cam_transform;
|
||||||
library->call_native_raw("arvr_return_transform_for_eye", "godot_arvr_get_transform_for_eye", data, 2, parameters, &ret);
|
// library->call_native_raw("arvr_return_transform_for_eye", "godot_arvr_get_transform_for_eye", data, 2, parameters, &ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ CameraMatrix ARVRInterfaceGDNative::get_projection_for_eye(ARVRInterface::Eyes p
|
||||||
parameters[2] = (void *)&p_aspect;
|
parameters[2] = (void *)&p_aspect;
|
||||||
parameters[3] = (void *)&p_z_near;
|
parameters[3] = (void *)&p_z_near;
|
||||||
parameters[4] = (void *)&p_z_far;
|
parameters[4] = (void *)&p_z_far;
|
||||||
library->call_native_raw("arvr_call_fill_projection_for_eye", "godot_arvr_fill_projection_for_eye", data, 5, parameters, NULL);
|
// library->call_native_raw("arvr_call_fill_projection_for_eye", "godot_arvr_fill_projection_for_eye", data, 5, parameters, NULL);
|
||||||
|
|
||||||
return cm;
|
return cm;
|
||||||
}
|
}
|
||||||
|
@ -216,13 +216,13 @@ void ARVRInterfaceGDNative::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_rend
|
||||||
parameters[0] = (void *)&p_eye;
|
parameters[0] = (void *)&p_eye;
|
||||||
parameters[1] = (void *)&p_render_target;
|
parameters[1] = (void *)&p_render_target;
|
||||||
parameters[2] = (void *)&p_screen_rect;
|
parameters[2] = (void *)&p_screen_rect;
|
||||||
library->call_native_raw("arvr_call_commit_for_eye", "godot_arvr_commit_for_eye", data, 3, parameters, NULL);
|
// library->call_native_raw("arvr_call_commit_for_eye", "godot_arvr_commit_for_eye", data, 3, parameters, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARVRInterfaceGDNative::process() {
|
void ARVRInterfaceGDNative::process() {
|
||||||
ERR_FAIL_COND(data == NULL);
|
ERR_FAIL_COND(data == NULL);
|
||||||
|
|
||||||
library->call_native_raw("arvr_call_method", "godot_arvr_process", data, 0, NULL, NULL);
|
// library->call_native_raw("arvr_call_method", "godot_arvr_process", data, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARVRInterfaceGDNative::_bind_methods() {
|
void ARVRInterfaceGDNative::_bind_methods() {
|
||||||
|
|
|
@ -395,17 +395,6 @@ void arvr_call_commit_for_eye(
|
||||||
};
|
};
|
||||||
|
|
||||||
void register_nativearvr_types() {
|
void register_nativearvr_types() {
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_constructor", arvr_call_constructor);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_destructor", arvr_call_destructor);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_string", arvr_return_string);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_int", arvr_return_int);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_bool", arvr_return_bool);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_set_bool", arvr_set_bool);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_method", arvr_call_method);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_vector2", arvr_return_vector2);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_transform_for_eye", arvr_return_transform_for_eye);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_fill_projection_for_eye", arvr_call_fill_projection_for_eye);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_commit_for_eye", arvr_call_commit_for_eye);
|
|
||||||
|
|
||||||
ClassDB::register_class<ARVRInterfaceGDNative>();
|
ClassDB::register_class<ARVRInterfaceGDNative>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -438,7 +438,7 @@ NativeScript::~NativeScript() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////// ScriptInstance stuff
|
////// ScriptInstance stuff
|
||||||
|
|
||||||
#define GET_SCRIPT_DESC() script->get_script_desc()
|
#define GET_SCRIPT_DESC() script->get_script_desc()
|
||||||
|
|
||||||
|
@ -1010,17 +1010,12 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
|
||||||
if (!library_script_users.has(lib_path))
|
if (!library_script_users.has(lib_path))
|
||||||
library_script_users.insert(lib_path, Set<NativeScript *>());
|
library_script_users.insert(lib_path, Set<NativeScript *>());
|
||||||
|
|
||||||
void *args[1] = {
|
void *proc_ptr;
|
||||||
(void *)&lib_path
|
|
||||||
};
|
gdn->get_symbol(_init_call_name, proc_ptr);
|
||||||
|
|
||||||
|
((void (*)(godot_string *))proc_ptr)((godot_string *)&lib_path);
|
||||||
|
|
||||||
// here the library registers all the classes and stuff.
|
|
||||||
gdn->call_native_raw(_init_call_type,
|
|
||||||
_init_call_name,
|
|
||||||
NULL,
|
|
||||||
1,
|
|
||||||
args,
|
|
||||||
NULL);
|
|
||||||
} else {
|
} else {
|
||||||
// already initialized. Nice.
|
// already initialized. Nice.
|
||||||
}
|
}
|
||||||
|
@ -1053,13 +1048,15 @@ void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
|
||||||
// library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
|
// library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
|
||||||
for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
|
for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
|
||||||
if (L->get()->is_initialized()) {
|
if (L->get()->is_initialized()) {
|
||||||
L->get()->call_native_raw(
|
|
||||||
_noarg_call_type,
|
void *proc_ptr;
|
||||||
name,
|
Error err = L->get()->get_symbol(name, proc_ptr);
|
||||||
NULL,
|
|
||||||
0,
|
if (err != OK) {
|
||||||
NULL,
|
ERR_PRINT((String("No godot_gdnative_init in \"" + L->get()->get_library()->get_active_library_path()) + "\" found").utf8().get_data());
|
||||||
NULL);
|
} else {
|
||||||
|
((void (*)())proc_ptr)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1142,12 +1139,11 @@ void NativeReloadNode::_notification(int p_what) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// here the library registers all the classes and stuff.
|
// here the library registers all the classes and stuff.
|
||||||
L->get()->call_native_raw(NSL->_init_call_type,
|
|
||||||
NSL->_init_call_name,
|
void *proc_ptr;
|
||||||
NULL,
|
L->get()->get_symbol("godot_nativescript_init", proc_ptr);
|
||||||
1,
|
|
||||||
args,
|
((void (*)(void *))proc_ptr)((void *)&L->key());
|
||||||
NULL);
|
|
||||||
|
|
||||||
for (Map<String, Set<NativeScript *> >::Element *U = NSL->library_script_users.front(); U; U = U->next()) {
|
for (Map<String, Set<NativeScript *> >::Element *U = NSL->library_script_users.front(); U; U = U->next()) {
|
||||||
for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) {
|
for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) {
|
||||||
|
|
|
@ -38,53 +38,6 @@
|
||||||
|
|
||||||
NativeScriptLanguage *native_script_language;
|
NativeScriptLanguage *native_script_language;
|
||||||
|
|
||||||
typedef void (*native_script_init_fn)(void *);
|
|
||||||
|
|
||||||
void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
|
|
||||||
if (p_handle == NULL) {
|
|
||||||
ERR_PRINT("No valid library handle, can't call nativescript init procedure");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *library_proc;
|
|
||||||
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
|
||||||
p_handle,
|
|
||||||
*(String *)p_proc_name,
|
|
||||||
library_proc,
|
|
||||||
true); // we print our own message
|
|
||||||
if (err != OK) {
|
|
||||||
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
native_script_init_fn fn = (native_script_init_fn)library_proc;
|
|
||||||
|
|
||||||
fn(args[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef void (*native_script_empty_callback)();
|
|
||||||
|
|
||||||
void noarg_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
|
|
||||||
if (p_handle == NULL) {
|
|
||||||
ERR_PRINT("No valid library handle, can't call nativescript callback");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *library_proc;
|
|
||||||
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
|
||||||
p_handle,
|
|
||||||
*(String *)p_proc_name,
|
|
||||||
library_proc,
|
|
||||||
true);
|
|
||||||
if (err != OK) {
|
|
||||||
// it's fine if thread callbacks are not present in the library.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
native_script_empty_callback fn = (native_script_empty_callback)library_proc;
|
|
||||||
fn();
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
|
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
|
||||||
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
|
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
|
||||||
|
|
||||||
|
@ -95,9 +48,6 @@ void register_nativescript_types() {
|
||||||
|
|
||||||
ScriptServer::register_language(native_script_language);
|
ScriptServer::register_language(native_script_language);
|
||||||
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb);
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_noarg_call_type, noarg_call_cb);
|
|
||||||
|
|
||||||
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
|
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
|
||||||
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
|
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
|
||||||
|
|
||||||
|
|
|
@ -128,57 +128,12 @@ static void editor_init_callback() {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, godot_array *p_args) {
|
godot_variant cb_standard_varcall(void *p_procedure_handle, godot_array *p_args) {
|
||||||
if (handle == NULL) {
|
|
||||||
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
|
|
||||||
godot_variant ret;
|
|
||||||
godot_variant_new_nil(&ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *library_proc;
|
|
||||||
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
|
||||||
handle,
|
|
||||||
*(String *)p_procedure,
|
|
||||||
library_proc,
|
|
||||||
true); // we roll our own message
|
|
||||||
if (err != OK) {
|
|
||||||
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_procedure) + "\" does not exists and can't be called").utf8().get_data());
|
|
||||||
godot_variant ret;
|
|
||||||
godot_variant_new_nil(&ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
godot_gdnative_procedure_fn proc;
|
godot_gdnative_procedure_fn proc;
|
||||||
proc = (godot_gdnative_procedure_fn)library_proc;
|
proc = (godot_gdnative_procedure_fn)p_procedure_handle;
|
||||||
|
|
||||||
return proc(NULL, p_args);
|
return proc(p_args);
|
||||||
}
|
|
||||||
|
|
||||||
void cb_singleton_call(
|
|
||||||
void *p_handle,
|
|
||||||
godot_string *p_proc_name,
|
|
||||||
void *p_data,
|
|
||||||
int p_num_args,
|
|
||||||
void **p_args,
|
|
||||||
void *r_return) {
|
|
||||||
if (p_handle == NULL) {
|
|
||||||
ERR_PRINT("No valid library handle, can't call singleton procedure");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *singleton_proc;
|
|
||||||
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
|
|
||||||
p_handle,
|
|
||||||
*(String *)p_proc_name,
|
|
||||||
singleton_proc);
|
|
||||||
|
|
||||||
if (err != OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void (*singleton_procedure_ptr)() = (void (*)())singleton_proc;
|
|
||||||
singleton_procedure_ptr();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GDNativeCallRegistry *GDNativeCallRegistry::singleton;
|
GDNativeCallRegistry *GDNativeCallRegistry::singleton;
|
||||||
|
@ -201,8 +156,6 @@ void register_gdnative_types() {
|
||||||
|
|
||||||
GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall);
|
GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall);
|
||||||
|
|
||||||
GDNativeCallRegistry::singleton->register_native_raw_call_type("gdnative_singleton_call", cb_singleton_call);
|
|
||||||
|
|
||||||
register_nativearvr_types();
|
register_nativearvr_types();
|
||||||
register_nativescript_types();
|
register_nativescript_types();
|
||||||
|
|
||||||
|
@ -225,13 +178,16 @@ void register_gdnative_types() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
singleton_gdnatives[i]->call_native_raw(
|
void *proc_ptr;
|
||||||
"gdnative_singleton_call",
|
Error err = singleton_gdnatives[i]->get_symbol(
|
||||||
"godot_gdnative_singleton",
|
"godot_gdnative_singleton",
|
||||||
NULL,
|
proc_ptr);
|
||||||
0,
|
|
||||||
NULL,
|
if (err != OK) {
|
||||||
NULL);
|
ERR_PRINT((String("No godot_gdnative_singleton in \"" + singleton_gdnatives[i]->get_library()->get_active_library_path()) + "\" found").utf8().get_data());
|
||||||
|
} else {
|
||||||
|
((void (*)())proc_ptr)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,4 +239,4 @@ void unregister_gdnative_types() {
|
||||||
print_line(String("vector2:\t") + itos(sizeof(Vector2)));
|
print_line(String("vector2:\t") + itos(sizeof(Vector2)));
|
||||||
print_line(String("vector3:\t") + itos(sizeof(Vector3)));
|
print_line(String("vector3:\t") + itos(sizeof(Vector3)));
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue