diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/gdnative/gdnative.cpp | 65 | ||||
| -rw-r--r-- | modules/gdnative/gdnative.h | 12 | ||||
| -rw-r--r-- | modules/gdnative/gdnative_api.json | 7 | ||||
| -rw-r--r-- | modules/gdnative/include/gdnative/gdnative.h | 4 | ||||
| -rw-r--r-- | modules/gdnative/include/nativearvr/godot_nativearvr.h | 22 | ||||
| -rw-r--r-- | modules/gdnative/nativearvr/arvr_interface_gdnative.cpp | 184 | ||||
| -rw-r--r-- | modules/gdnative/nativearvr/arvr_interface_gdnative.h | 8 | ||||
| -rw-r--r-- | modules/gdnative/nativearvr/register_types.cpp | 375 | ||||
| -rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 41 | ||||
| -rw-r--r-- | modules/gdnative/nativescript/register_types.cpp | 50 | ||||
| -rw-r--r-- | modules/gdnative/register_types.cpp | 70 | ||||
| -rw-r--r-- | modules/gridmap/doc_classes/GridMap.xml | 26 | ||||
| -rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.cpp | 48 | ||||
| -rw-r--r-- | modules/visual_script/visual_script_builtin_funcs.h | 2 | ||||
| -rw-r--r-- | modules/visual_script/visual_script_nodes.cpp | 1 |
15 files changed, 258 insertions, 657 deletions
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 373b98dc8b..3fc04a5498 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -199,10 +199,7 @@ void GDNative::_bind_methods() { ClassDB::bind_method(D_METHOD("initialize"), &GDNative::initialize); ClassDB::bind_method(D_METHOD("terminate"), &GDNative::terminate); - // TODO(karroffel): get_native_(raw_)call_types binding? - - // TODO(karroffel): make this a varargs function? - ClassDB::bind_method(D_METHOD("call_native", "procedure_name", "arguments"), &GDNative::call_native); + ClassDB::bind_method(D_METHOD("call_native", "calling_type", "procedure_name", "arguments"), &GDNative::call_native); 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; - err = OS::get_singleton()->get_dynamic_library_symbol_handle( - native_handle, - init_symbol, - library_init); + err = get_symbol(init_symbol, library_init); if (err || !library_init) { OS::get_singleton()->close_dynamic_library(native_handle); @@ -277,11 +271,8 @@ bool GDNative::terminate() { } void *library_terminate; - Error error = OS::get_singleton()->get_dynamic_library_symbol_handle( - native_handle, - terminate_symbol, - library_terminate); - if (error) { + Error error = get_symbol(terminate_symbol, library_terminate); + if (error || !library_terminate) { OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; 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); } -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> call_types; call_types.resize(native_calls.size()); @@ -329,18 +316,6 @@ Vector<StringName> GDNativeCallRegistry::get_native_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) { 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(); } - String procedure_name = p_procedure_name; - godot_variant result = E->get()(native_handle, (godot_string *)&procedure_name, (godot_array *)&p_arguments); + void *procedure_handle; + + 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; } -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 (!E) { - ERR_PRINT((String("No handler for native raw call type \"" + p_raw_call_type) + "\" found").utf8().get_data()); - return; + if (native_handle == NULL) { + ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); + return ERR_CANT_OPEN; } - String procedure_name = p_procedure_name; - E->get()(native_handle, (godot_string *)&procedure_name, data, num_args, args, r_return); + Error result = OS::get_singleton()->get_dynamic_library_symbol_handle( + native_handle, + p_procedure_name, + r_handle, + true); + + return result; } diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 7bbad842eb..e44cc55a79 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -100,8 +100,7 @@ public: _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 void (*native_raw_call_cb)(void *, godot_string *, void *, int, void **, void *); +typedef godot_variant (*native_call_cb)(void *, godot_array *); struct GDNativeCallRegistry { static GDNativeCallRegistry *singleton; @@ -111,17 +110,13 @@ struct GDNativeCallRegistry { } inline GDNativeCallRegistry() - : native_calls(), - native_raw_calls() {} + : 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_raw_call_type(StringName p_raw_call_type, native_raw_call_cb p_callback); Vector<StringName> get_native_call_types(); - Vector<StringName> get_native_raw_call_types(); }; class GDNative : public Reference { @@ -149,7 +144,8 @@ public: bool terminate(); 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 diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 5ebf26cbf7..31b021b751 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5231,6 +5231,13 @@ ] }, { + "name": "godot_arvr_register_interface", + "return_type": "void", + "arguments": [ + ["const godot_arvr_interface_gdnative *", "p_interface"] + ] + }, + { "name": "godot_arvr_get_worldscale", "return_type": "godot_real", "arguments": [] diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index 2d8726e5db..25d45db306 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -47,7 +47,7 @@ extern "C" { #define GDAPI GDCALLINGCONV #endif #else -#define GDCALLINGCONV __attribute__((sysv_abi, visibility("default"))) +#define GDCALLINGCONV __attribute__((sysv_abi)) #define GDAPI GDCALLINGCONV #endif @@ -255,7 +255,7 @@ godot_dictionary GDAPI godot_get_global_constants(); ////// GDNative procedure types typedef void (*godot_gdnative_init_fn)(godot_gdnative_init_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 diff --git a/modules/gdnative/include/nativearvr/godot_nativearvr.h b/modules/gdnative/include/nativearvr/godot_nativearvr.h index f86919f33a..1a8970d396 100644 --- a/modules/gdnative/include/nativearvr/godot_nativearvr.h +++ b/modules/gdnative/include/nativearvr/godot_nativearvr.h @@ -36,6 +36,26 @@ extern "C" { #endif +typedef struct { + void *(*constructor)(godot_object *); + void (*destructor)(void *); + godot_string (*get_name)(const void *); + godot_int (*get_capabilities)(const void *); + godot_bool (*get_anchor_detection_is_enabled)(const void *); + void (*set_anchor_detection_is_enabled)(void *, godot_bool); + godot_bool (*is_stereo)(const void *); + godot_bool (*is_initialized)(const void *); + godot_bool (*initialize)(void *); + void (*uninitialize)(void *); + godot_vector2 (*get_recommended_render_targetsize)(const void *); + godot_transform (*get_transform_for_eye)(void *, godot_int, godot_transform *); + void (*fill_projection_for_eye)(void *, godot_real *, godot_int, godot_real, godot_real, godot_real); + void (*commit_for_eye)(void *, godot_int, godot_rid *, godot_rect2 *); + void (*process)(void *); +} godot_arvr_interface_gdnative; + +void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface); + // helper functions to access ARVRServer data godot_real GDAPI godot_arvr_get_worldscale(); godot_transform GDAPI godot_arvr_get_reference_frame(); @@ -55,4 +75,4 @@ void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p } #endif -#endif /* !GODOT_NATIVEARVR_H */
\ No newline at end of file +#endif /* !GODOT_NATIVEARVR_H */ diff --git a/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp b/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp index 78b0d1eadd..ff8bda162f 100644 --- a/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp +++ b/modules/gdnative/nativearvr/arvr_interface_gdnative.cpp @@ -39,6 +39,8 @@ ARVRInterfaceGDNative::ARVRInterfaceGDNative() { // we won't have our data pointer until our library gets set data = NULL; + + interface = NULL; } ARVRInterfaceGDNative::~ARVRInterfaceGDNative() { @@ -53,38 +55,35 @@ ARVRInterfaceGDNative::~ARVRInterfaceGDNative() { } void ARVRInterfaceGDNative::cleanup() { - if (data != NULL) { - library->call_native_raw("arvr_call_destructor", "godot_arvr_destructor", data, 0, NULL, NULL); + if (interface != NULL) { + interface->destructor(data); data = NULL; - }; - - if (library.is_valid()) { - library->terminate(); - }; -}; + interface = NULL; + } +} -void ARVRInterfaceGDNative::set_gdnative_library(Ref<GDNativeLibrary> p_library) { - if (library.is_null()) { - library.instance(); - } else { +void ARVRInterfaceGDNative::set_interface(const godot_arvr_interface_gdnative *p_interface) { + // this should only be called once, just being paranoid.. + if (interface) { cleanup(); - }; + } - library->set_library(p_library); - library->initialize(); + // bind to our interface + interface = p_interface; // Now we do our constructing... - void *parameters[1]; - parameters[0] = (void *)this; - library->call_native_raw("arvr_call_constructor", "godot_arvr_constructor", NULL, 1, parameters, &data); + data = interface->constructor((godot_object *)this); } StringName ARVRInterfaceGDNative::get_name() const { - StringName name; - ERR_FAIL_COND_V(data == NULL, StringName()); + ERR_FAIL_COND_V(interface == NULL, StringName()); + + godot_string result = interface->get_name(data); + + StringName name = *(String *)&result; - const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_string", "godot_arvr_get_name", data, 0, NULL, &name); + godot_string_destroy(&result); return name; } @@ -92,58 +91,56 @@ StringName ARVRInterfaceGDNative::get_name() const { int ARVRInterfaceGDNative::get_capabilities() const { int capabilities; - ERR_FAIL_COND_V(data == NULL, 0); // 0 = None + ERR_FAIL_COND_V(interface == NULL, 0); // 0 = None - const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_int", "godot_arvr_get_capabilities", data, 0, NULL, &capabilities); + capabilities = interface->get_capabilities(data); return capabilities; -}; +} bool ARVRInterfaceGDNative::get_anchor_detection_is_enabled() const { bool enabled; - ERR_FAIL_COND_V(data == NULL, false); + ERR_FAIL_COND_V(interface == NULL, false); - const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_bool", "godot_arvr_get_anchor_detection_is_enabled", data, 0, NULL, &enabled); + enabled = interface->get_anchor_detection_is_enabled(data); return enabled; -}; +} void ARVRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) { - void *parameters[1]; - ERR_FAIL_COND(data == NULL); + ERR_FAIL_COND(interface == NULL); - parameters[0] = (void *)&p_enable; - library->call_native_raw("arvr_set_bool", "godot_arvr_set_anchor_detection_is_enabled", data, 1, parameters, NULL); -}; + interface->set_anchor_detection_is_enabled(data, p_enable); +} bool ARVRInterfaceGDNative::is_stereo() { bool stereo; - ERR_FAIL_COND_V(data == NULL, false); + ERR_FAIL_COND_V(interface == NULL, false); - library->call_native_raw("arvr_return_bool", "godot_arvr_is_stereo", data, 0, NULL, &stereo); + stereo = interface->is_stereo(data); return stereo; -}; +} bool ARVRInterfaceGDNative::is_initialized() { bool initialized; - ERR_FAIL_COND_V(data == NULL, false); + ERR_FAIL_COND_V(interface == NULL, false); - library->call_native_raw("arvr_return_bool", "godot_arvr_is_initialized", data, 0, NULL, &initialized); + initialized = interface->is_initialized(data); return initialized; -}; +} bool ARVRInterfaceGDNative::initialize() { bool initialized; - ERR_FAIL_COND_V(data == NULL, false); + ERR_FAIL_COND_V(interface == NULL, false); - library->call_native_raw("arvr_return_bool", "godot_arvr_initialize", data, 0, NULL, &initialized); + initialized = interface->initialize(data); if (initialized) { // if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface @@ -158,7 +155,7 @@ bool ARVRInterfaceGDNative::initialize() { } void ARVRInterfaceGDNative::uninitialize() { - ERR_FAIL_COND(data == NULL); + ERR_FAIL_COND(interface == NULL); ARVRServer *arvr_server = ARVRServer::get_singleton(); if (arvr_server != NULL) { @@ -166,78 +163,72 @@ void ARVRInterfaceGDNative::uninitialize() { arvr_server->clear_primary_interface_if(this); } - library->call_native_raw("arvr_call_method", "godot_arvr_uninitialize", data, 0, NULL, NULL); + interface->uninitialize(data); } Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() { - Size2 size; - ERR_FAIL_COND_V(data == NULL, Size2()); + ERR_FAIL_COND_V(interface == NULL, Size2()); - library->call_native_raw("arvr_return_vector2", "godot_arvr_get_recommended_render_targetsize", data, 0, NULL, &size); + godot_vector2 result = interface->get_recommended_render_targetsize(data); + Vector2 *vec = (Vector2 *)&result; - return size; + return *vec; } Transform ARVRInterfaceGDNative::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) { - void *parameters[2]; - Transform ret; + Transform *ret; - ERR_FAIL_COND_V(data == NULL, Transform()); + ERR_FAIL_COND_V(interface == NULL, Transform()); - parameters[0] = (void *)&p_eye; - 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); + godot_transform t = interface->get_transform_for_eye(data, (int)p_eye, (godot_transform *)&p_cam_transform); - return ret; + ret = (Transform *)&t; + + return *ret; } CameraMatrix ARVRInterfaceGDNative::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - void *parameters[5]; CameraMatrix cm; - ERR_FAIL_COND_V(data == NULL, CameraMatrix()); + ERR_FAIL_COND_V(interface == NULL, CameraMatrix()); - parameters[0] = (void *)cm.matrix; - parameters[1] = (void *)&p_eye; - parameters[2] = (void *)&p_aspect; - parameters[3] = (void *)&p_z_near; - 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); + interface->fill_projection_for_eye(data, (godot_real *)cm.matrix, (godot_int)p_eye, p_aspect, p_z_near, p_z_far); return cm; } void ARVRInterfaceGDNative::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { - void *parameters[3]; - ERR_FAIL_COND(data == NULL); + ERR_FAIL_COND(interface == NULL); - parameters[0] = (void *)&p_eye; - parameters[1] = (void *)&p_render_target; - parameters[2] = (void *)&p_screen_rect; - library->call_native_raw("arvr_call_commit_for_eye", "godot_arvr_commit_for_eye", data, 3, parameters, NULL); + interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect); } void ARVRInterfaceGDNative::process() { - ERR_FAIL_COND(data == NULL); + ERR_FAIL_COND(interface == NULL); - library->call_native_raw("arvr_call_method", "godot_arvr_process", data, 0, NULL, NULL); -} - -void ARVRInterfaceGDNative::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_gdnative_library", "library"), &ARVRInterfaceGDNative::set_gdnative_library); + interface->process(data); } ///////////////////////////////////////////////////////////////////////////////////// // some helper callbacks +extern "C" { + +void GDAPI godot_arvr_register_interface(const godot_arvr_interface_gdnative *p_interface) { + Ref<ARVRInterfaceGDNative> new_interface; + new_interface.instance(); + new_interface->set_interface((godot_arvr_interface_gdnative * const)p_interface); + ARVRServer::get_singleton()->add_interface(new_interface); +} + godot_real GDAPI godot_arvr_get_worldscale() { ARVRServer *arvr_server = ARVRServer::get_singleton(); ERR_FAIL_NULL_V(arvr_server, 1.0); return arvr_server->get_world_scale(); -}; +} godot_transform GDAPI godot_arvr_get_reference_frame() { godot_transform reference_frame; @@ -248,10 +239,10 @@ godot_transform GDAPI godot_arvr_get_reference_frame() { *reference_frame_ptr = arvr_server->get_reference_frame(); } else { godot_transform_new_identity(&reference_frame); - }; + } return reference_frame; -}; +} void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) { // blits out our texture as is, handy for preview display of one of the eyes that is already rendered with lens distortion on an external HMD @@ -268,7 +259,7 @@ void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_re VSG::rasterizer->set_current_render_target(RID()); VSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0); -}; +} godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target) { // In order to send off our textures to display on our hardware we need the opengl texture ID instead of the render target RID @@ -279,7 +270,7 @@ godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target) { uint32_t texid = VS::get_singleton()->texture_get_texid(eye_texture); return texid; -}; +} godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { ARVRServer *arvr_server = ARVRServer::get_singleton(); @@ -295,30 +286,30 @@ godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, new_tracker->set_hand(ARVRPositionalTracker::TRACKER_LEFT_HAND); } else if (p_hand == 2) { new_tracker->set_hand(ARVRPositionalTracker::TRACKER_RIGHT_HAND); - }; + } // also register as joystick... int joyid = input->get_unused_joy_id(); if (joyid != -1) { new_tracker->set_joy_id(joyid); input->joy_connection_changed(joyid, true, p_device_name, ""); - }; + } if (p_tracks_orientation) { Basis orientation; new_tracker->set_orientation(orientation); - }; + } if (p_tracks_position) { Vector3 position; new_tracker->set_position(position); - }; + } // add our tracker to our server and remember its pointer arvr_server->add_tracker(new_tracker); // note, this ID is only unique within controllers! return new_tracker->get_tracker_id(); -}; +} void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) { ARVRServer *arvr_server = ARVRServer::get_singleton(); @@ -334,13 +325,13 @@ void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) { if (joyid != -1) { input->joy_connection_changed(joyid, false, "", ""); remove_tracker->set_joy_id(-1); - }; + } // remove our tracker from our server arvr_server->remove_tracker(remove_tracker); memdelete(remove_tracker); - }; -}; + } +} void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) { ARVRServer *arvr_server = ARVRServer::get_singleton(); @@ -351,12 +342,12 @@ void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_ Transform *transform = (Transform *)p_transform; if (p_tracks_orientation) { tracker->set_orientation(transform->basis); - }; + } if (p_tracks_position) { tracker->set_position(transform->origin); - }; - }; -}; + } + } +} void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) { ARVRServer *arvr_server = ARVRServer::get_singleton(); @@ -370,9 +361,9 @@ void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int int joyid = tracker->get_joy_id(); if (joyid != -1) { input->joy_button(joyid, p_button, p_is_pressed); - }; - }; -}; + } + } +} void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) { ARVRServer *arvr_server = ARVRServer::get_singleton(); @@ -389,6 +380,7 @@ void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p jx.min = p_can_be_negative ? -1 : 0; jx.value = p_value; input->joy_axis(joyid, p_axis, jx); - }; - }; -}; + } + } +} +} diff --git a/modules/gdnative/nativearvr/arvr_interface_gdnative.h b/modules/gdnative/nativearvr/arvr_interface_gdnative.h index 6995e85c73..e45b51e070 100644 --- a/modules/gdnative/nativearvr/arvr_interface_gdnative.h +++ b/modules/gdnative/nativearvr/arvr_interface_gdnative.h @@ -41,22 +41,20 @@ */ class ARVRInterfaceGDNative : public ARVRInterface { - GDCLASS(ARVRInterfaceGDNative, ARVRInterface); + GDCLASS(ARVRInterfaceGDNative, ARVRInterface) void cleanup(); protected: - Ref<GDNative> library; + const godot_arvr_interface_gdnative *interface; void *data; - static void _bind_methods(); - public: /** general interface information **/ ARVRInterfaceGDNative(); ~ARVRInterfaceGDNative(); - void set_gdnative_library(Ref<GDNativeLibrary> p_library); + void set_interface(const godot_arvr_interface_gdnative *p_interface); virtual StringName get_name() const; virtual int get_capabilities() const; diff --git a/modules/gdnative/nativearvr/register_types.cpp b/modules/gdnative/nativearvr/register_types.cpp index f4dc13ed55..c7d7847a21 100644 --- a/modules/gdnative/nativearvr/register_types.cpp +++ b/modules/gdnative/nativearvr/register_types.cpp @@ -29,384 +29,9 @@ /*************************************************************************/ #include "register_types.h" - #include "arvr_interface_gdnative.h" -#include "core/os/os.h" - -void arvr_call_constructor( - 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 standard varcall 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 roll 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; - } - - void *(*proc)(godot_object *); - proc = (void *(*)(godot_object *))library_proc; - - godot_object *this_object = (godot_object *)p_args[0]; - void *p = proc(this_object); - - void **return_ptr = (void **)r_return; - - *return_ptr = p; -}; - -void arvr_call_destructor( - 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 standard varcall 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 roll 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; - } - - void (*proc)(void *); - proc = (void (*)(void *))library_proc; - - proc(p_data); -}; - -void arvr_return_string( - 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 standard varcall 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 roll 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; - } - - godot_string (*proc)(void *); - proc = (godot_string(*)(void *))library_proc; - - godot_string s = proc(p_data); - - StringName *return_ptr = (StringName *)r_return; - - String *returned_string = (String *)&s; - - *return_ptr = *returned_string; - - godot_string_destroy(&s); -}; - -void arvr_return_int( - 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 standard varcall 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 roll 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; - } - - godot_int (*proc)(void *); - proc = (godot_int(*)(void *))library_proc; - - godot_int i = proc(p_data); - - int *return_ptr = (int *)r_return; - - *return_ptr = i; -}; - -void arvr_return_bool( - 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 standard varcall 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 roll 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; - } - - godot_bool (*proc)(void *); - proc = (godot_bool(*)(void *))library_proc; - - godot_bool b = proc(p_data); - - int *return_ptr = (int *)r_return; - - *return_ptr = b; -}; - -void arvr_set_bool( - 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 standard varcall 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 roll 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; - } - - void (*proc)(void *, bool); - proc = (void (*)(void *, bool))library_proc; - - bool *set_bool = (bool *)p_args[0]; - proc(p_data, *set_bool); -}; - -void arvr_call_method( - 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 standard varcall 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 roll 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; - } - - godot_bool (*proc)(void *); - proc = (godot_bool(*)(void *))library_proc; - - proc(p_data); -}; - -void arvr_return_vector2( - 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 standard varcall 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 roll 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; - } - - godot_vector2 (*proc)(void *); - proc = (godot_vector2(*)(void *))library_proc; - - godot_vector2 v = proc(p_data); - - godot_vector2 *return_ptr = (godot_vector2 *)r_return; - - *return_ptr = v; -}; - -void arvr_return_transform_for_eye( - 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 standard varcall 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 roll 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; - } - - godot_transform (*proc)(void *, int, godot_transform *); - proc = (godot_transform(*)(void *, int, godot_transform *))library_proc; - - int *eye = (int *)p_args[0]; - godot_transform *camera_transform = (godot_transform *)p_args[1]; - godot_transform t = proc(p_data, *eye, camera_transform); - - godot_transform *return_ptr = (godot_transform *)r_return; - - *return_ptr = t; -}; - -void arvr_call_fill_projection_for_eye( - 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 standard varcall 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 roll 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; - } - - void (*proc)(void *, real_t *, int, real_t, real_t, real_t); - proc = (void (*)(void *, real_t *, int, real_t, real_t, real_t))library_proc; - - real_t *projection = (real_t *)p_args[0]; // <-- we'll be writing into this buffer, must have enough space for 16 floats! - int *eye = (int *)p_args[1]; - real_t *aspect = (real_t *)p_args[2]; - real_t *zn = (real_t *)p_args[3]; - real_t *zf = (real_t *)p_args[4]; - - proc(p_data, projection, *eye, *aspect, *zn, *zf); -}; - -void arvr_call_commit_for_eye( - 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 standard varcall 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 roll 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; - } - - void (*proc)(void *, int, godot_rid *, godot_rect2 *); - proc = (void (*)(void *, int, godot_rid *, godot_rect2 *))library_proc; - - int *eye = (int *)p_args[0]; - godot_rid *rid = (godot_rid *)p_args[1]; - godot_rect2 *screen_rect = (godot_rect2 *)p_args[2]; - - proc(p_data, *eye, rid, screen_rect); -}; 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>(); } diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index b9bd65af53..52379560b3 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -137,7 +137,6 @@ bool NativeScript::can_instance() const { #endif } -// TODO(karroffel): implement this Ref<Script> NativeScript::get_base_script() const { NativeScriptDesc *script_data = get_script_desc(); @@ -1010,17 +1009,12 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { if (!library_script_users.has(lib_path)) library_script_users.insert(lib_path, Set<NativeScript *>()); - void *args[1] = { - (void *)&lib_path - }; + void *proc_ptr; + + 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 { // already initialized. Nice. } @@ -1053,13 +1047,13 @@ 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 for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) { if (L->get()->is_initialized()) { - L->get()->call_native_raw( - _noarg_call_type, - name, - NULL, - 0, - NULL, - NULL); + + void *proc_ptr; + Error err = L->get()->get_symbol(name, proc_ptr); + + if (!err) { + ((void (*)())proc_ptr)(); + } } } } @@ -1142,12 +1136,11 @@ void NativeReloadNode::_notification(int p_what) { }; // here the library registers all the classes and stuff. - L->get()->call_native_raw(NSL->_init_call_type, - NSL->_init_call_name, - NULL, - 1, - args, - NULL); + + void *proc_ptr; + L->get()->get_symbol("godot_nativescript_init", proc_ptr); + + ((void (*)(void *))proc_ptr)((void *)&L->key()); 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()) { diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp index b846710ab8..d734bba810 100644 --- a/modules/gdnative/nativescript/register_types.cpp +++ b/modules/gdnative/nativescript/register_types.cpp @@ -38,53 +38,6 @@ 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; ResourceFormatSaverNativeScript *resource_saver_gdns = NULL; @@ -95,9 +48,6 @@ void register_nativescript_types() { 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); ResourceSaver::add_resource_format_saver(resource_saver_gdns); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 8f4eed091f..8e5f58524b 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -128,57 +128,12 @@ static void editor_init_callback() { #endif -godot_variant cb_standard_varcall(void *handle, godot_string *p_procedure, 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_variant cb_standard_varcall(void *p_procedure_handle, godot_array *p_args) { godot_gdnative_procedure_fn proc; - proc = (godot_gdnative_procedure_fn)library_proc; - - return proc(NULL, 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; - } + proc = (godot_gdnative_procedure_fn)p_procedure_handle; - 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(); + return proc(p_args); } 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_raw_call_type("gdnative_singleton_call", cb_singleton_call); - register_nativearvr_types(); register_nativescript_types(); @@ -225,13 +178,16 @@ void register_gdnative_types() { continue; } - singleton_gdnatives[i]->call_native_raw( - "gdnative_singleton_call", + void *proc_ptr; + Error err = singleton_gdnatives[i]->get_symbol( "godot_gdnative_singleton", - NULL, - 0, - NULL, - NULL); + proc_ptr); + + if (err != OK) { + 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("vector3:\t") + itos(sizeof(Vector3))); */ -}
\ No newline at end of file +} diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index cd01233ce4..ed8c27e5d0 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -1,8 +1,13 @@ <?xml version="1.0" encoding="UTF-8" ?> <class name="GridMap" inherits="Spatial" category="Core" version="3.0.alpha.custom_build"> <brief_description> + Node for 3D tile-based maps. </brief_description> <description> + GridMap lets you place meshes on a grid interactively. It works both from the editor and can help you create in-game level editors. + GridMaps use a [MeshLibrary] which contain a list of tiles: meshes with materials plus optional collisions and extra elements. + A GridMap contains a collection of cells. Each grid cell refers to a [MeshLibrary] item. All cells in the map have the same dimensions. + A GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells. </description> <tutorials> </tutorials> @@ -13,6 +18,7 @@ <return type="void"> </return> <description> + Clear all cells. </description> </method> <method name="get_cell_item" qualifiers="const"> @@ -25,6 +31,7 @@ <argument index="2" name="z" type="int"> </argument> <description> + The [MeshLibrary] item index located at the grid-based X, Y and Z coordinates. If the cell is empty, [INVALID_CELL_ITEM] will be returned. </description> </method> <method name="get_cell_item_orientation" qualifiers="const"> @@ -37,54 +44,63 @@ <argument index="2" name="z" type="int"> </argument> <description> + The orientation of the cell at the grid-based X, Y and Z coordinates. -1 is retuned if the cell is empty. </description> </method> <method name="get_cell_size" qualifiers="const"> <return type="Vector3"> </return> <description> + The dimensions of the grid's cells. </description> </method> <method name="get_center_x" qualifiers="const"> <return type="bool"> </return> <description> + Returns whether or not grid items are centered on the X axis. </description> </method> <method name="get_center_y" qualifiers="const"> <return type="bool"> </return> <description> + Returns whether or not grid items are centered on the Y axis. </description> </method> <method name="get_center_z" qualifiers="const"> <return type="bool"> </return> <description> + Returns whether or not grid items are centered on the Z axis. </description> </method> <method name="get_meshes"> <return type="Array"> </return> <description> + Array of [Transform] and [Mesh] references corresponding to the non empty cells in the grid. The transforms are specified in world space. </description> </method> <method name="get_octant_size" qualifiers="const"> <return type="int"> </return> <description> + The size of each octant measured in number of cells. This applies to all three axis. </description> </method> <method name="get_theme" qualifiers="const"> <return type="MeshLibrary"> </return> <description> + The assigned [MeshLibrary]. </description> </method> <method name="get_used_cells" qualifiers="const"> <return type="Array"> </return> <description> + Array of [Vector3] with the non empty cell coordinates in the grid map. </description> </method> <method name="resource_changed"> @@ -109,6 +125,9 @@ <argument index="4" name="orientation" type="int" default="0"> </argument> <description> + Set the mesh index for the cell referenced by its grid-based X, Y and Z coordinates. + A negative item index will clear the cell. + Optionally, the item's orientation can be passed. </description> </method> <method name="set_cell_size"> @@ -117,6 +136,7 @@ <argument index="0" name="size" type="Vector3"> </argument> <description> + Sets the height, width and depth of the grid's cells. </description> </method> <method name="set_center_x"> @@ -125,6 +145,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> + Set grid items to be centered on the X axis. By default it is enabled. </description> </method> <method name="set_center_y"> @@ -133,6 +154,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> + Set grid items to be centered on the Y axis. By default it is enabled. </description> </method> <method name="set_center_z"> @@ -141,6 +163,7 @@ <argument index="0" name="enable" type="bool"> </argument> <description> + Set grid items to be centered on the Z axis. By default it is enabled. </description> </method> <method name="set_clip"> @@ -163,6 +186,7 @@ <argument index="0" name="size" type="int"> </argument> <description> + Sets the size for each octant measured in number of cells. This applies to all three axis. </description> </method> <method name="set_theme"> @@ -171,11 +195,13 @@ <argument index="0" name="theme" type="MeshLibrary"> </argument> <description> + Sets the collection of meshes for the map. </description> </method> </methods> <constants> <constant name="INVALID_CELL_ITEM" value="-1" enum=""> + Invalid cell item that can be used in [method set_cell_item] to clear cells (or represent an empty cell in [method get_cell_item]). </constant> </constants> </class> diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 972be5f5a4..1980f86114 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -65,6 +65,8 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "decimals", "stepify", "lerp", + "inverse_lerp", + "range_lerp", "dectime", "randomize", "randi", @@ -194,9 +196,12 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case COLORN: return 2; case MATH_LERP: + case MATH_INVERSE_LERP: case MATH_DECTIME: case LOGIC_CLAMP: return 3; + case MATH_RANGE_LERP: + return 5; case FUNC_MAX: { } } @@ -297,7 +302,26 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::REAL, "to"); else return PropertyInfo(Variant::REAL, "weight"); - + } break; + case MATH_INVERSE_LERP: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "from"); + else if (p_idx == 1) + return PropertyInfo(Variant::REAL, "to"); + else + return PropertyInfo(Variant::REAL, "value"); + } break; + case MATH_RANGE_LERP: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "value"); + else if (p_idx == 1) + return PropertyInfo(Variant::REAL, "istart"); + else if (p_idx == 2) + return PropertyInfo(Variant::REAL, "istop"); + else if (p_idx == 3) + return PropertyInfo(Variant::REAL, "ostart"); + else + return PropertyInfo(Variant::REAL, "ostop"); } break; case MATH_DECTIME: { if (p_idx == 0) @@ -495,6 +519,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case MATH_STEPIFY: case MATH_LERP: + case MATH_INVERSE_LERP: + case MATH_RANGE_LERP: case MATH_DECTIME: { t = Variant::REAL; @@ -795,6 +821,22 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(2); *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; + case VisualScriptBuiltinFunc::MATH_INVERSE_LERP: { + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); + } break; + case VisualScriptBuiltinFunc::MATH_RANGE_LERP: { + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + VALIDATE_ARG_NUM(3); + VALIDATE_ARG_NUM(4); + *r_return = Math::range_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2], (double)*p_inputs[3], (double)*p_inputs[4]); + } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { VALIDATE_ARG_NUM(0); @@ -1203,6 +1245,8 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_DECIMALS); BIND_ENUM_CONSTANT(MATH_STEPIFY); BIND_ENUM_CONSTANT(MATH_LERP); + BIND_ENUM_CONSTANT(MATH_INVERSE_LERP); + BIND_ENUM_CONSTANT(MATH_RANGE_LERP); BIND_ENUM_CONSTANT(MATH_DECTIME); BIND_ENUM_CONSTANT(MATH_RANDOMIZE); BIND_ENUM_CONSTANT(MATH_RAND); @@ -1282,6 +1326,8 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/decimals", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECIMALS>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/stepify", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_STEPIFY>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LERP>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/inverse_lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_INVERSE_LERP>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/range_lerp", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANGE_LERP>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/dectime", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DECTIME>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/randomize", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RANDOMIZE>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/rand", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAND>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 97ab307039..af24f16a2f 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -64,6 +64,8 @@ public: MATH_DECIMALS, MATH_STEPIFY, MATH_LERP, + MATH_INVERSE_LERP, + MATH_RANGE_LERP, MATH_DECTIME, MATH_RANDOMIZE, MATH_RAND, diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 5a34fc3cd9..d3cd839cf3 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -532,6 +532,7 @@ String VisualScriptOperator::get_text() const { L"A or B", //OP_OR, L"A xor B", //OP_XOR, L"not A", //OP_NOT, + L"A in B", //OP_IN, }; return op_names[op]; |