Răsfoiți Sursa

Add vararg call() method to C++ Callable

kobewi 2 ani în urmă
părinte
comite
09b30be86d

+ 2 - 9
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();

+ 2 - 0
core/variant/callable.h

@@ -69,6 +69,8 @@ public:
 		int expected = 0;
 	};
 
+	template <typename... VarArgs>
+	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;

+ 14 - 0
core/variant/variant.h

@@ -833,6 +833,20 @@ String vformat(const String &p_text, const VarArgs... p_args) {
 	return fmt;
 }
 
+template <typename... VarArgs>
+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 <typename... VarArgs>
 Callable Callable::bind(VarArgs... p_args) {
 	Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.

+ 1 - 20
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<AnimationTrackEdit>(get_script_instance()->callp("create_value_track_edit", (const Variant **)&argptrs, 6, ce).operator Object *());
+		return Object::cast_to<AnimationTrackEdit>(get_script_instance()->call("create_value_track_edit", p_object, p_type, p_property, p_hint, p_hint_string, p_usage));
 	}
 	return nullptr;
 }

+ 4 - 20
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()));
 				}

+ 2 - 9
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<Variant> 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<Node> nodes = p_base_scene->find_children("*");
 		while (nodes.size()) {
 			Node *nd = Object::cast_to<Node>(nodes.pop_back());
-			Callable::CallError ce;
-			nd->callp("_notify_skeleton_bones_renamed", argptrs, argcount, ce);
+			nd->callv("_notify_skeleton_bones_renamed", vargs);
 		}
 	}
 }

+ 1 - 5
editor/plugins/tiles/tiles_editor_plugin.cpp

@@ -134,11 +134,7 @@ void TilesEditorUtils::_thread() {
 				Ref<Image> 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();
 			}

+ 1 - 6
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) {

+ 4 - 14
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<const Variant **>(&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) {

+ 1 - 4
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);
 	}
 }
 

+ 8 - 27
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 = &rect;
-		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<InputEvent> &p_event) {
 }
 
 void DisplayServerX11::_dispatch_input_event(const Ref<InputEvent> &p_event) {
-	Variant ev = p_event;
-	Variant *evp = &ev;
-	Variant ret;
-	Callable::CallError ce;
-
 	{
 		List<WindowID>::Element *E = popup_list.back();
 		if (E && Object::cast_to<InputEventKey>(*p_event)) {
@@ -3776,7 +3764,7 @@ void DisplayServerX11::_dispatch_input_event(const Ref<InputEvent> &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<InputEvent> &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<InputEvent> &p_event) {
 		for (KeyValue<WindowID, WindowData> &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.

+ 14 - 63
platform/macos/display_server_macos.mm

@@ -402,11 +402,6 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref<InputEvent> &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<WindowID>::Element *E = popup_list.back();
 			if (E && Object::cast_to<InputEventKey>(*p_event)) {
@@ -414,7 +409,7 @@ void DisplayServerMacOS::_dispatch_input_event(const Ref<InputEvent> &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<InputEvent> &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<InputEvent> &p_event) {
 			for (KeyValue<WindowID, WindowData> &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<String>();
-								  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<String>(), [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<String>();
-								  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<String>(), [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<MenuCall>::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) {

+ 1 - 6
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;

+ 2 - 10
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()) {

+ 2 - 10
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)));
 	}
 }
 

+ 7 - 27
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<InputEventKey> 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<Image> &p_icon) {
 
 void DisplayServerWeb::_dispatch_input_event(const Ref<InputEvent> &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);
 	}
 }
 

+ 2 - 5
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);

+ 9 - 37
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<String>();
-				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<String>(), 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<InputEvent> &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<WindowID>::Element *E = popup_list.back();
@@ -2697,7 +2677,7 @@ void DisplayServerWindows::_dispatch_input_event(const Ref<InputEvent> &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<InputEvent> &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<InputEvent> &p_event)
 		for (const KeyValue<WindowID, WindowData> &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: {

+ 1 - 6
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;
 							}

+ 9 - 20
scene/gui/view_panner.cpp

@@ -47,7 +47,7 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &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<InputEvent> &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<InputEvent> &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<InputEvent> &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<InputEvent> &p_event, Rect2 p_canvas_rect)
 	Ref<InputEventMagnifyGesture> 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<InputEventPanGesture> 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<InputEventScreenDrag> screen_drag = p_event;
@@ -134,7 +134,7 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &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<Variant> 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;

+ 0 - 1
scene/gui/view_panner.h

@@ -68,7 +68,6 @@ private:
 	Callable pan_callback;
 	Callable zoom_callback;
 
-	void callback_helper(Callable p_callback, Vector<Variant> p_args);
 	ControlScheme control_scheme = SCROLL_ZOOMS;
 
 public:

+ 1 - 4
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);
 	}
 }
 

+ 1 - 4
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);
 	}
 }
 

+ 2 - 6
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();
 					}
 				}
 			}

+ 2 - 6
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();
 			}
 		}
 	}

+ 1 - 3
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) :

+ 2 - 10
tests/display_server_mock.h

@@ -64,13 +64,8 @@ private:
 	}
 
 	void _dispatch_input_event(const Ref<InputEvent> &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);
 		}
 	}