diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index cfc3ac3bcfa..2fcd0867e6e 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -75,10 +75,6 @@ void WorkerThreadPool::_process_task(Task *p_task) { if (p_task->group) { // Handling a group bool do_post = false; - Callable::CallError ce; - Variant ret; - Variant arg; - Variant *argptr = &arg; while (true) { uint32_t work_index = p_task->group->index.postincrement(); @@ -91,8 +87,7 @@ void WorkerThreadPool::_process_task(Task *p_task) { } else if (p_task->template_userdata) { p_task->template_userdata->callback_indexed(work_index); } else { - arg = work_index; - p_task->callable.callp((const Variant **)&argptr, 1, ret, ce); + p_task->callable.call(work_index); } // This is the only way to ensure posting is done when all tasks are really complete. @@ -141,9 +136,7 @@ void WorkerThreadPool::_process_task(Task *p_task) { p_task->template_userdata->callback(); memdelete(p_task->template_userdata); } else { - Callable::CallError ce; - Variant ret; - p_task->callable.callp(nullptr, 0, ret, ce); + p_task->callable.call(); } task_mutex.lock(); diff --git a/core/variant/callable.h b/core/variant/callable.h index 086e5d2a004..3ae424e9bf8 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -69,6 +69,8 @@ public: int expected = 0; }; + template + Variant call(VarArgs... p_args) const; void callp(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const; void call_deferredp(const Variant **p_arguments, int p_argcount) const; Variant callv(const Array &p_arguments) const; diff --git a/core/variant/variant.h b/core/variant/variant.h index d698f857546..21342ae6ef4 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -833,6 +833,20 @@ String vformat(const String &p_text, const VarArgs... p_args) { return fmt; } +template +Variant Callable::call(VarArgs... p_args) const { + Variant args[sizeof...(p_args) + 1] = { p_args..., 0 }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + + Variant ret; + CallError ce; + callp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), ret, ce); + return ret; +} + template Callable Callable::bind(VarArgs... p_args) { Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported. diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index e2852d5a310..919e335d21d 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -3169,26 +3169,7 @@ AnimationTrackEdit::AnimationTrackEdit() { AnimationTrackEdit *AnimationTrackEditPlugin::create_value_track_edit(Object *p_object, Variant::Type p_type, const String &p_property, PropertyHint p_hint, const String &p_hint_string, int p_usage) { if (get_script_instance()) { - Variant args[6] = { - p_object, - p_type, - p_property, - p_hint, - p_hint_string, - p_usage - }; - - Variant *argptrs[6] = { - &args[0], - &args[1], - &args[2], - &args[3], - &args[4], - &args[5] - }; - - Callable::CallError ce; - return Object::cast_to(get_script_instance()->callp("create_value_track_edit", (const Variant **)&argptrs, 6, ce).operator Object *()); + return Object::cast_to(get_script_instance()->call("create_value_track_edit", p_object, p_type, p_property, p_hint, p_hint_string, p_usage)); } return nullptr; } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 91a3181747f..395f4faa39b 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -1726,11 +1726,7 @@ void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) { // Call the function. Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); if (move_function.is_valid()) { - Variant args[] = { undo_redo, object, array_element_prefix, p_element_index, p_to_pos }; - const Variant *args_p[] = { &args[0], &args[1], &args[2], &args[3], &args[4] }; - Variant return_value; - Callable::CallError call_error; - move_function.callp(args_p, 5, return_value, call_error); + move_function.call(undo_redo, object, array_element_prefix, p_element_index, p_to_pos); } else { WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); } @@ -1875,11 +1871,7 @@ void EditorInspectorArray::_clear_array() { // Call the function. Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); if (move_function.is_valid()) { - Variant args[] = { undo_redo, object, array_element_prefix, i, -1 }; - const Variant *args_p[] = { &args[0], &args[1], &args[2], &args[3], &args[4] }; - Variant return_value; - Callable::CallError call_error; - move_function.callp(args_p, 5, return_value, call_error); + move_function.call(undo_redo, object, array_element_prefix, i, -1); } else { WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); } @@ -1929,11 +1921,7 @@ void EditorInspectorArray::_resize_array(int p_size) { // Call the function. Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); if (move_function.is_valid()) { - Variant args[] = { undo_redo, object, array_element_prefix, -1, -1 }; - const Variant *args_p[] = { &args[0], &args[1], &args[2], &args[3], &args[4] }; - Variant return_value; - Callable::CallError call_error; - move_function.callp(args_p, 5, return_value, call_error); + move_function.call(undo_redo, object, array_element_prefix, -1, -1); } else { WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); } @@ -1948,11 +1936,7 @@ void EditorInspectorArray::_resize_array(int p_size) { // Call the function. Callable move_function = EditorNode::get_editor_data().get_move_array_element_function(object->get_class_name()); if (move_function.is_valid()) { - Variant args[] = { undo_redo, object, array_element_prefix, i, -1 }; - const Variant *args_p[] = { &args[0], &args[1], &args[2], &args[3], &args[4] }; - Variant return_value; - Callable::CallError call_error; - move_function.callp(args_p, 5, return_value, call_error); + move_function.call(undo_redo, object, array_element_prefix, i, -1); } else { WARN_PRINT(vformat("Could not find a function to move arrays elements for class %s. Register a move element function using EditorData::add_move_array_element_function", object->get_class_name())); } diff --git a/editor/import/post_import_plugin_skeleton_renamer.cpp b/editor/import/post_import_plugin_skeleton_renamer.cpp index 0c48c8ef76e..6704347877b 100644 --- a/editor/import/post_import_plugin_skeleton_renamer.cpp +++ b/editor/import/post_import_plugin_skeleton_renamer.cpp @@ -119,7 +119,7 @@ void PostImportPluginSkeletonRenamer::_internal_process(InternalImportCategory p // Rename bones in all Nodes by calling method. { - Vector vargs; + Array vargs; vargs.push_back(p_base_scene); vargs.push_back(skeleton); Dictionary rename_map_dict; @@ -127,18 +127,11 @@ void PostImportPluginSkeletonRenamer::_internal_process(InternalImportCategory p rename_map_dict[E->key] = E->value; } vargs.push_back(rename_map_dict); - const Variant **argptrs = (const Variant **)alloca(sizeof(const Variant **) * vargs.size()); - const Variant *args = vargs.ptr(); - uint32_t argcount = vargs.size(); - for (uint32_t i = 0; i < argcount; i++) { - argptrs[i] = &args[i]; - } TypedArray nodes = p_base_scene->find_children("*"); while (nodes.size()) { Node *nd = Object::cast_to(nodes.pop_back()); - Callable::CallError ce; - nd->callp("_notify_skeleton_bones_renamed", argptrs, argcount, ce); + nd->callv("_notify_skeleton_bones_renamed", vargs); } } } diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 4d4b1fa734f..e50d21bbf85 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -134,11 +134,7 @@ void TilesEditorUtils::_thread() { Ref image = viewport->get_texture()->get_image(); // Find the index for the given pattern. TODO: optimize. - Variant args[] = { item.pattern, ImageTexture::create_from_image(image) }; - const Variant *args_ptr[] = { &args[0], &args[1] }; - Variant r; - Callable::CallError error; - item.callback.callp(args_ptr, 2, r, error); + item.callback.call(item.pattern, ImageTexture::create_from_image(image)); viewport->queue_free(); } diff --git a/modules/navigation/nav_agent.cpp b/modules/navigation/nav_agent.cpp index 010bd2d7c01..cb219ac6c04 100644 --- a/modules/navigation/nav_agent.cpp +++ b/modules/navigation/nav_agent.cpp @@ -145,12 +145,7 @@ void NavAgent::dispatch_avoidance_callback() { } // Invoke the callback with the new velocity. - Variant args[] = { new_velocity }; - const Variant *args_p[] = { &args[0] }; - Variant return_value; - Callable::CallError call_error; - - avoidance_callback.callp(args_p, 1, return_value, call_error); + avoidance_callback.call(new_velocity); } void NavAgent::set_neighbor_distance(real_t p_neighbor_distance) { diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 11c0945ce02..445a6ea6ea7 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -309,13 +309,10 @@ void DisplayServerAndroid::window_set_drop_files_callback(const Callable &p_call void DisplayServerAndroid::_window_callback(const Callable &p_callable, const Variant &p_arg, bool p_deferred) const { if (!p_callable.is_null()) { - const Variant *argp = &p_arg; - Variant ret; - Callable::CallError ce; if (p_deferred) { - p_callable.callp((const Variant **)&argp, 1, ret, ce); + p_callable.call(p_arg); } else { - p_callable.call_deferredp((const Variant **)&argp, 1); + p_callable.call_deferred(p_arg); } } } @@ -538,16 +535,9 @@ void DisplayServerAndroid::reset_window() { } void DisplayServerAndroid::notify_surface_changed(int p_width, int p_height) { - if (rect_changed_callback.is_null()) { - return; + if (rect_changed_callback.is_valid()) { + rect_changed_callback.call(Rect2i(0, 0, p_width, p_height)); } - - const Variant size = Rect2i(0, 0, p_width, p_height); - const Variant *sizep = &size; - Variant ret; - Callable::CallError ce; - - rect_changed_callback.callp(reinterpret_cast(&sizep), 1, ret, ce); } DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error) { diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index 489894a1359..8508b67f1e7 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -195,10 +195,7 @@ void DisplayServerIOS::send_window_event(DisplayServer::WindowEvent p_event) con void DisplayServerIOS::_window_callback(const Callable &p_callable, const Variant &p_arg) const { if (!p_callable.is_null()) { - const Variant *argp = &p_arg; - Variant ret; - Callable::CallError ce; - p_callable.callp((const Variant **)&argp, 1, ret, ce); + p_callable.call(p_arg); } } diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index 31846c80a21..02a5208e119 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -3738,15 +3738,8 @@ void DisplayServerX11::_window_changed(XEvent *event) { } #endif - if (!wd.rect_changed_callback.is_null()) { - Rect2i r = new_rect; - - Variant rect = r; - - Variant *rectp = ▭ - Variant ret; - Callable::CallError ce; - wd.rect_changed_callback.callp((const Variant **)&rectp, 1, ret, ce); + if (wd.rect_changed_callback.is_valid()) { + wd.rect_changed_callback.call(new_rect); } } @@ -3764,11 +3757,6 @@ void DisplayServerX11::_dispatch_input_events(const Ref &p_event) { } void DisplayServerX11::_dispatch_input_event(const Ref &p_event) { - Variant ev = p_event; - Variant *evp = &ev; - Variant ret; - Callable::CallError ce; - { List::Element *E = popup_list.back(); if (E && Object::cast_to(*p_event)) { @@ -3776,7 +3764,7 @@ void DisplayServerX11::_dispatch_input_event(const Ref &p_event) { if (windows.has(E->get())) { Callable callable = windows[E->get()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } return; @@ -3789,7 +3777,7 @@ void DisplayServerX11::_dispatch_input_event(const Ref &p_event) { if (windows.has(event_from_window->get_window_id())) { Callable callable = windows[event_from_window->get_window_id()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } else { @@ -3797,19 +3785,16 @@ void DisplayServerX11::_dispatch_input_event(const Ref &p_event) { for (KeyValue &E : windows) { Callable callable = E.value.input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } } void DisplayServerX11::_send_window_event(const WindowData &wd, WindowEvent p_event) { - if (!wd.event_callback.is_null()) { + if (wd.event_callback.is_valid()) { Variant event = int(p_event); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - wd.event_callback.callp((const Variant **)&eventp, 1, ret, ce); + wd.event_callback.call(event); } } @@ -4754,11 +4739,7 @@ void DisplayServerX11::process_events() { } if (!windows[window_id].drop_files_callback.is_null()) { - Variant v = files; - Variant *vp = &v; - Variant ret; - Callable::CallError ce; - windows[window_id].drop_files_callback.callp((const Variant **)&vp, 1, ret, ce); + windows[window_id].drop_files_callback.call(files); } //Reply that all is well. diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 67d6f4214fd..03cb8f231a2 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -402,11 +402,6 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref &p_event) { if (!in_dispatch_input_event) { in_dispatch_input_event = true; - Variant ev = p_event; - Variant *evp = &ev; - Variant ret; - Callable::CallError ce; - { List::Element *E = popup_list.back(); if (E && Object::cast_to(*p_event)) { @@ -414,7 +409,7 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref &p_event) { if (windows.has(E->get())) { Callable callable = windows[E->get()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } in_dispatch_input_event = false; @@ -428,7 +423,7 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref &p_event) { if (windows.has(event_from_window->get_window_id())) { Callable callable = windows[event_from_window->get_window_id()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } else { @@ -436,7 +431,7 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref &p_event) { for (KeyValue &E : windows) { Callable callable = E.value.input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } @@ -615,9 +610,7 @@ void DisplayServerMacOS::menu_open(NSMenu *p_menu) { MenuData &md = submenu[submenu_inv[p_menu]]; md.is_open = true; if (md.open.is_valid()) { - Variant ret; - Callable::CallError ce; - md.open.callp(nullptr, 0, ret, ce); + md.open.call(); } } } @@ -627,9 +620,7 @@ void DisplayServerMacOS::menu_close(NSMenu *p_menu) { MenuData &md = submenu[submenu_inv[p_menu]]; md.is_open = false; if (md.close.is_valid()) { - Variant ret; - Callable::CallError ce; - md.close.callp(nullptr, 0, ret, ce); + md.close.call(); } } } @@ -699,12 +690,9 @@ void DisplayServerMacOS::send_event(NSEvent *p_event) { void DisplayServerMacOS::send_window_event(const WindowData &wd, WindowEvent p_event) { _THREAD_SAFE_METHOD_ - if (!wd.event_callback.is_null()) { + if (wd.event_callback.is_valid()) { Variant event = int(p_event); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - wd.event_callback.callp((const Variant **)&eventp, 1, ret, ce); + wd.event_callback.call(event); } } @@ -2002,11 +1990,7 @@ Error DisplayServerMacOS::dialog_show(String p_title, String p_description, Vect } if (!p_callback.is_null()) { - Variant button = button_pressed; - Variant *buttonp = &button; - Variant fun_ret; - Callable::CallError ce; - p_callback.callp((const Variant **)&buttonp, 1, fun_ret, ce); + p_callback.call(button_pressed); } return OK; @@ -2181,23 +2165,11 @@ Error DisplayServerMacOS::file_dialog_show(const String &p_title, const String & url.parse_utf8([[[panel URL] path] UTF8String]); files.push_back(url); if (!callback.is_null()) { - Variant v_status = true; - Variant v_files = files; - Variant v_index = [handler getIndex]; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - callback.callp((const Variant **)&v_args, 3, ret, ce); + callback.call(true, files, [handler getIndex]); } } else { if (!callback.is_null()) { - Variant v_status = false; - Variant v_files = Vector(); - Variant v_index = [handler getIndex]; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - callback.callp((const Variant **)&v_args, 3, ret, ce); + callback.call(false, Vector(), [handler getIndex]); } } if (prev_focus != INVALID_WINDOW_ID) { @@ -2258,23 +2230,11 @@ Error DisplayServerMacOS::file_dialog_show(const String &p_title, const String & files.push_back(url); } if (!callback.is_null()) { - Variant v_status = true; - Variant v_files = files; - Variant v_index = [handler getIndex]; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - callback.callp((const Variant **)&v_args, 3, ret, ce); + callback.call(true, files, [handler getIndex]); } } else { if (!callback.is_null()) { - Variant v_status = false; - Variant v_files = Vector(); - Variant v_index = [handler getIndex]; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - callback.callp((const Variant **)&v_args, 3, ret, ce); + callback.call(false, Vector(), [handler getIndex]); } } if (prev_focus != INVALID_WINDOW_ID) { @@ -2308,11 +2268,7 @@ Error DisplayServerMacOS::dialog_input_text(String p_title, String p_description ret.parse_utf8([[input stringValue] UTF8String]); if (!p_callback.is_null()) { - Variant text = ret; - Variant *textp = &text; - Variant fun_ret; - Callable::CallError ce; - p_callback.callp((const Variant **)&textp, 1, fun_ret, ce); + p_callback.call(ret); } return OK; @@ -4063,12 +4019,7 @@ void DisplayServerMacOS::process_events() { while (List::Element *call_p = deferred_menu_calls.front()) { MenuCall call = call_p->get(); deferred_menu_calls.pop_front(); // Remove before call to avoid infinite loop in case callback is using `process_events` (e.g. EditorProgress). - - Variant tag = call.tag; - Variant *tagp = &tag; - Variant ret; - Callable::CallError ce; - call.callback.callp((const Variant **)&tagp, 1, ret, ce); + call.callback.call(call.tag); } if (!drop_events) { diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm index 22a9aa14c0e..139411249c7 100644 --- a/platform/macos/godot_content_view.mm +++ b/platform/macos/godot_content_view.mm @@ -323,12 +323,7 @@ NSString *file = [NSURL URLWithString:url].path; files.push_back(String::utf8([file UTF8String])); } - - Variant v = files; - Variant *vp = &v; - Variant ret; - Callable::CallError ce; - wd.drop_files_callback.callp((const Variant **)&vp, 1, ret, ce); + wd.drop_files_callback.call(files); } return NO; diff --git a/platform/macos/godot_menu_delegate.mm b/platform/macos/godot_menu_delegate.mm index 1bfcfa7d9e2..e393a871344 100644 --- a/platform/macos/godot_menu_delegate.mm +++ b/platform/macos/godot_menu_delegate.mm @@ -58,11 +58,7 @@ GodotMenuItem *value = [item representedObject]; if (value && value->hover_callback != Callable()) { // If custom callback is set, use it. - Variant tag = value->meta; - Variant *tagp = &tag; - Variant ret; - Callable::CallError ce; - value->hover_callback.callp((const Variant **)&tagp, 1, ret, ce); + value->hover_callback.call(value->meta); } } } @@ -79,11 +75,7 @@ GodotMenuItem *value = [menu_item representedObject]; if (value->key_callback != Callable()) { // If custom callback is set, use it. - Variant tag = value->meta; - Variant *tagp = &tag; - Variant ret; - Callable::CallError ce; - value->key_callback.callp((const Variant **)&tagp, 1, ret, ce); + value->key_callback.call(value->meta); } else { // Otherwise redirect event to the engine. if (DisplayServer::get_singleton()) { diff --git a/platform/macos/godot_window_delegate.mm b/platform/macos/godot_window_delegate.mm index 002ab0155f9..1756f2d676a 100644 --- a/platform/macos/godot_window_delegate.mm +++ b/platform/macos/godot_window_delegate.mm @@ -256,11 +256,7 @@ ds->window_resize(window_id, wd.size.width, wd.size.height); if (!wd.rect_changed_callback.is_null()) { - Variant size = Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id)); - Variant *sizep = &size; - Variant ret; - Callable::CallError ce; - wd.rect_changed_callback.callp((const Variant **)&sizep, 1, ret, ce); + wd.rect_changed_callback.call(Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id))); } } @@ -283,11 +279,7 @@ ds->release_pressed_events(); if (!wd.rect_changed_callback.is_null()) { - Variant size = Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id)); - Variant *sizep = &size; - Variant ret; - Callable::CallError ce; - wd.rect_changed_callback.callp((const Variant **)&sizep, 1, ret, ce); + wd.rect_changed_callback.call(Rect2i(ds->window_get_position(window_id), ds->window_get_size(window_id))); } } diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index aac1401f233..dcc4ac4bf74 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -60,10 +60,7 @@ bool DisplayServerWeb::check_size_force_redraw() { bool size_changed = godot_js_display_size_update() != 0; if (size_changed && !rect_changed_callback.is_null()) { Variant size = Rect2i(Point2i(), window_get_size()); // TODO use window_get_position if implemented. - Variant *vp = &size; - Variant ret; - Callable::CallError ce; - rect_changed_callback.callp((const Variant **)&vp, 1, ret, ce); + rect_changed_callback.call(size); } return size_changed; } @@ -90,11 +87,7 @@ void DisplayServerWeb::drop_files_js_callback(char **p_filev, int p_filec) { for (int i = 0; i < p_filec; i++) { files.push_back(String::utf8(p_filev[i])); } - Variant v = files; - Variant *vp = &v; - Variant ret; - Callable::CallError ce; - ds->drop_files_callback.callp((const Variant **)&vp, 1, ret, ce); + ds->drop_files_callback.call(files); } // Web quit request callback. @@ -102,10 +95,7 @@ void DisplayServerWeb::request_quit_callback() { DisplayServerWeb *ds = get_singleton(); if (ds && !ds->window_event_callback.is_null()) { Variant event = int(DisplayServer::WINDOW_EVENT_CLOSE_REQUEST); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - ds->window_event_callback.callp((const Variant **)&eventp, 1, ret, ce); + ds->window_event_callback.call(event); } } @@ -619,10 +609,7 @@ void DisplayServerWeb::vk_input_text_callback(const char *p_text, int p_cursor) } // Call input_text Variant event = String::utf8(p_text); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - ds->input_text_callback.callp((const Variant **)&eventp, 1, ret, ce); + ds->input_text_callback.call(event); // Insert key right to reach position. Input *input = Input::get_singleton(); Ref k; @@ -724,10 +711,7 @@ void DisplayServerWeb::send_window_event_callback(int p_notification) { } if (!ds->window_event_callback.is_null()) { Variant event = int(p_notification); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - ds->window_event_callback.callp((const Variant **)&eventp, 1, ret, ce); + ds->window_event_callback.call(event); } } @@ -770,12 +754,8 @@ void DisplayServerWeb::set_icon(const Ref &p_icon) { void DisplayServerWeb::_dispatch_input_event(const Ref &p_event) { Callable cb = get_singleton()->input_event_callback; - if (!cb.is_null()) { - Variant ev = p_event; - Variant *evp = &ev; - Variant ret; - Callable::CallError ce; - cb.callp((const Variant **)&evp, 1, ret, ce); + if (cb.is_valid()) { + cb.call(p_event); } } diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp index 41206f14a56..1bb72456e8f 100644 --- a/platform/web/javascript_bridge_singleton.cpp +++ b/platform/web/javascript_bridge_singleton.cpp @@ -256,15 +256,12 @@ void JavaScriptObjectImpl::_callback(void *p_ref, int p_args_id, int p_argc) { int type = godot_js_wrapper_object_getvar(p_args_id, Variant::INT, &exchange); arg_arr.push_back(_js2variant(type, &exchange)); } - Variant arg = arg_arr; - const Variant *argv[1] = { &arg }; - Callable::CallError err; - Variant ret; - obj->_callable.callp(argv, 1, ret, err); + obj->_callable.call(arg_arr); // Set return value godot_js_wrapper_ex exchange; void *lock = nullptr; + Variant ret; const Variant *v = &ret; int type = _variant2js((const void **)&v, 0, &exchange, &lock); godot_js_wrapper_object_set_cb_ret(type, &exchange); diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index ded80ba5f19..cc5ae9ad45a 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -346,23 +346,11 @@ Error DisplayServerWindows::file_dialog_show(const String &p_title, const String } } if (!p_callback.is_null()) { - Variant v_status = true; - Variant v_files = file_names; - Variant v_index = index; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - p_callback.callp((const Variant **)&v_args, 3, ret, ce); + p_callback.call(true, file_names, index); } } else { if (!p_callback.is_null()) { - Variant v_status = false; - Variant v_files = Vector(); - Variant v_index = index; - Variant *v_args[3] = { &v_status, &v_files, &v_index }; - Variant ret; - Callable::CallError ce; - p_callback.callp((const Variant **)&v_args, 3, ret, ce); + p_callback.call(false, Vector(), index); } } pfd->Release(); @@ -2665,12 +2653,9 @@ void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, } void DisplayServerWindows::_send_window_event(const WindowData &wd, WindowEvent p_event) { - if (!wd.event_callback.is_null()) { + if (wd.event_callback.is_valid()) { Variant event = int(p_event); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - wd.event_callback.callp((const Variant **)&eventp, 1, ret, ce); + wd.event_callback.call(event); } } @@ -2683,12 +2668,7 @@ void DisplayServerWindows::_dispatch_input_event(const Ref &p_event) if (in_dispatch_input_event) { return; } - in_dispatch_input_event = true; - Variant ev = p_event; - Variant *evp = &ev; - Variant ret; - Callable::CallError ce; { List::Element *E = popup_list.back(); @@ -2697,7 +2677,7 @@ void DisplayServerWindows::_dispatch_input_event(const Ref &p_event) if (windows.has(E->get())) { Callable callable = windows[E->get()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } in_dispatch_input_event = false; @@ -2711,7 +2691,7 @@ void DisplayServerWindows::_dispatch_input_event(const Ref &p_event) if (windows.has(event_from_window->get_window_id())) { Callable callable = windows[event_from_window->get_window_id()].input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } else { @@ -2719,7 +2699,7 @@ void DisplayServerWindows::_dispatch_input_event(const Ref &p_event) for (const KeyValue &E : windows) { const Callable callable = E.value.input_event_callback; if (callable.is_valid()) { - callable.callp((const Variant **)&evp, 1, ret, ce); + callable.call(p_event); } } } @@ -3782,11 +3762,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA if (rect_changed) { if (!window.rect_changed_callback.is_null()) { - Variant size = Rect2i(window.last_pos.x, window.last_pos.y, window.width, window.height); - const Variant *args[] = { &size }; - Variant ret; - Callable::CallError ce; - window.rect_changed_callback.callp(args, 1, ret, ce); + window.rect_changed_callback.call(Rect2i(window.last_pos.x, window.last_pos.y, window.width, window.height)); } // Update cursor clip region after window rect has changed. @@ -4003,11 +3979,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } if (files.size() && !windows[window_id].drop_files_callback.is_null()) { - Variant v = files; - Variant *vp = &v; - Variant ret; - Callable::CallError ce; - windows[window_id].drop_files_callback.callp((const Variant **)&vp, 1, ret, ce); + windows[window_id].drop_files_callback.call(files); } } break; default: { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 3d426b8bf3a..2f5c05859f0 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1072,12 +1072,7 @@ void TextEdit::_notification(int p_what) { if (rtl) { gutter_rect.position.x = size.width - gutter_rect.position.x - gutter_rect.size.x; } - - Variant args[3] = { line, g, Rect2(gutter_rect) }; - const Variant *argp[] = { &args[0], &args[1], &args[2] }; - Callable::CallError ce; - Variant ret; - gutter.custom_draw_callback.callp(argp, 3, ret, ce); + gutter.custom_draw_callback.call(line, g, Rect2(gutter_rect)); } } break; } diff --git a/scene/gui/view_panner.cpp b/scene/gui/view_panner.cpp index 6d1905f1115..fc03f2d887c 100644 --- a/scene/gui/view_panner.cpp +++ b/scene/gui/view_panner.cpp @@ -47,7 +47,7 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) float zoom_factor = mb->get_factor() <= 0 ? 1.0 : mb->get_factor(); zoom_factor = ((scroll_zoom_factor - 1.0) * zoom_factor) + 1.0; float zoom = (scroll_vec.x + scroll_vec.y) > 0 ? 1.0 / scroll_zoom_factor : scroll_zoom_factor; - callback_helper(zoom_callback, varray(zoom, mb->get_position(), p_event)); + zoom_callback.call(zoom, mb->get_position(), p_event); return true; } else { Vector2 panning = scroll_vec * mb->get_factor(); @@ -58,7 +58,7 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) } else if (mb->is_shift_pressed()) { panning = Vector2(panning.y, panning.x); } - callback_helper(pan_callback, varray(-panning * scroll_speed, p_event)); + pan_callback.call(-panning * scroll_speed, p_event); return true; } } else { @@ -71,14 +71,14 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) } else if (mb->is_shift_pressed()) { panning = Vector2(panning.y, panning.x); } - callback_helper(pan_callback, varray(-panning * scroll_speed, p_event)); + pan_callback.call(-panning * scroll_speed, p_event); return true; } else if (!mb->is_shift_pressed()) { // Compute the zoom factor. float zoom_factor = mb->get_factor() <= 0 ? 1.0 : mb->get_factor(); zoom_factor = ((scroll_zoom_factor - 1.0) * zoom_factor) + 1.0; float zoom = (scroll_vec.x + scroll_vec.y) > 0 ? 1.0 / scroll_zoom_factor : scroll_zoom_factor; - callback_helper(zoom_callback, varray(zoom, mb->get_position(), p_event)); + zoom_callback.call(zoom, mb->get_position(), p_event); return true; } } @@ -108,9 +108,9 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) if (mm.is_valid()) { if (is_dragging) { if (p_canvas_rect != Rect2()) { - callback_helper(pan_callback, varray(Input::get_singleton()->warp_mouse_motion(mm, p_canvas_rect), p_event)); + pan_callback.call(Input::get_singleton()->warp_mouse_motion(mm, p_canvas_rect), p_event); } else { - callback_helper(pan_callback, varray(mm->get_relative(), p_event)); + pan_callback.call(mm->get_relative(), p_event); } return true; } @@ -119,13 +119,13 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) Ref magnify_gesture = p_event; if (magnify_gesture.is_valid()) { // Zoom gesture - callback_helper(zoom_callback, varray(magnify_gesture->get_factor(), magnify_gesture->get_position(), p_event)); + zoom_callback.call(magnify_gesture->get_factor(), magnify_gesture->get_position(), p_event); return true; } Ref pan_gesture = p_event; if (pan_gesture.is_valid()) { - callback_helper(pan_callback, varray(-pan_gesture->get_delta() * scroll_speed, p_event)); + pan_callback.call(-pan_gesture->get_delta() * scroll_speed, p_event); } Ref screen_drag = p_event; @@ -134,7 +134,7 @@ bool ViewPanner::gui_input(const Ref &p_event, Rect2 p_canvas_rect) // This set of events also generates/is generated by // InputEventMouseButton/InputEventMouseMotion events which will be processed instead. } else { - callback_helper(pan_callback, varray(screen_drag->get_relative(), p_event)); + pan_callback.call(screen_drag->get_relative(), p_event); } } @@ -157,17 +157,6 @@ void ViewPanner::release_pan_key() { is_dragging = false; } -void ViewPanner::callback_helper(Callable p_callback, Vector p_args) { - const Variant **argptr = (const Variant **)alloca(sizeof(Variant *) * p_args.size()); - for (int i = 0; i < p_args.size(); i++) { - argptr[i] = &p_args[i]; - } - - Variant result; - Callable::CallError ce; - p_callback.callp(argptr, p_args.size(), result, ce); -} - void ViewPanner::set_callbacks(Callable p_pan_callback, Callable p_zoom_callback) { pan_callback = p_pan_callback; zoom_callback = p_zoom_callback; diff --git a/scene/gui/view_panner.h b/scene/gui/view_panner.h index 60d36ca04cd..5aec2d4f6b5 100644 --- a/scene/gui/view_panner.h +++ b/scene/gui/view_panner.h @@ -68,7 +68,6 @@ private: Callable pan_callback; Callable zoom_callback; - void callback_helper(Callable p_callback, Vector p_args); ControlScheme control_scheme = SCROLL_ZOOMS; public: diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp index 1bcb1ba310e..4a7b4707682 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/servers/physics_2d/godot_body_2d.cpp @@ -693,10 +693,7 @@ void GodotBody2D::call_queries() { } if (body_state_callback.get_object()) { - const Variant *vp[1] = { &direct_state_variant }; - Callable::CallError ce; - Variant rv; - body_state_callback.callp(vp, 1, rv, ce); + body_state_callback.call(direct_state_variant); } } diff --git a/servers/physics_3d/godot_body_3d.cpp b/servers/physics_3d/godot_body_3d.cpp index 260cb84ccdf..21d5e49828c 100644 --- a/servers/physics_3d/godot_body_3d.cpp +++ b/servers/physics_3d/godot_body_3d.cpp @@ -772,10 +772,7 @@ void GodotBody3D::call_queries() { } if (body_state_callback.get_object()) { - const Variant *vp[1] = { &direct_state_variant }; - Callable::CallError ce; - Variant rv; - body_state_callback.callp(vp, 1, rv, ce); + body_state_callback.call(direct_state_variant); } } diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 7c533f207cf..d6040e88208 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -2005,9 +2005,7 @@ void RendererCanvasCull::update_visibility_notifiers() { if (RSG::threaded) { visibility_notifier->enter_callable.call_deferred(); } else { - Callable::CallError ce; - Variant ret; - visibility_notifier->enter_callable.callp(nullptr, 0, ret, ce); + visibility_notifier->enter_callable.call(); } } } else { @@ -2018,9 +2016,7 @@ void RendererCanvasCull::update_visibility_notifiers() { if (RSG::threaded) { visibility_notifier->exit_callable.call_deferred(); } else { - Callable::CallError ce; - Variant ret; - visibility_notifier->exit_callable.callp(nullptr, 0, ret, ce); + visibility_notifier->exit_callable.call(); } } } diff --git a/servers/rendering/renderer_rd/storage_rd/utilities.cpp b/servers/rendering/renderer_rd/storage_rd/utilities.cpp index 8df14d04dbc..cb035c494c2 100644 --- a/servers/rendering/renderer_rd/storage_rd/utilities.cpp +++ b/servers/rendering/renderer_rd/storage_rd/utilities.cpp @@ -202,9 +202,7 @@ void Utilities::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_de if (p_deferred) { vn->enter_callback.call_deferred(); } else { - Variant r; - Callable::CallError ce; - vn->enter_callback.callp(nullptr, 0, r, ce); + vn->enter_callback.call(); } } } else { @@ -212,9 +210,7 @@ void Utilities::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_de if (p_deferred) { vn->exit_callback.call_deferred(); } else { - Variant r; - Callable::CallError ce; - vn->exit_callback.callp(nullptr, 0, r, ce); + vn->exit_callback.call(); } } } diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index 2c8265b7d7a..65a6da8ac30 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -387,9 +387,7 @@ void RenderingServerDefault::draw(bool p_swap_buffers, double frame_step) { } void RenderingServerDefault::_call_on_render_thread(const Callable &p_callable) { - Variant ret; - Callable::CallError ce; - p_callable.callp(nullptr, 0, ret, ce); + p_callable.call(); } RenderingServerDefault::RenderingServerDefault(bool p_create_thread) : diff --git a/tests/display_server_mock.h b/tests/display_server_mock.h index fe36fa0b696..8d8a678e200 100644 --- a/tests/display_server_mock.h +++ b/tests/display_server_mock.h @@ -64,13 +64,8 @@ private: } void _dispatch_input_event(const Ref &p_event) { - Variant ev = p_event; - Variant *evp = &ev; - Variant ret; - Callable::CallError ce; - if (input_event_callback.is_valid()) { - input_event_callback.callp((const Variant **)&evp, 1, ret, ce); + input_event_callback.call(p_event); } } @@ -93,10 +88,7 @@ private: void _send_window_event(WindowEvent p_event) { if (!event_callback.is_null()) { Variant event = int(p_event); - Variant *eventp = &event; - Variant ret; - Callable::CallError ce; - event_callback.callp((const Variant **)&eventp, 1, ret, ce); + event_callback.call(event); } }