summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/object/worker_thread_pool.cpp11
-rw-r--r--core/variant/callable.h2
-rw-r--r--core/variant/variant.h14
-rw-r--r--editor/animation_track_editor.cpp21
-rw-r--r--editor/editor_inspector.cpp24
-rw-r--r--editor/import/post_import_plugin_skeleton_renamer.cpp11
-rw-r--r--editor/plugins/tiles/tiles_editor_plugin.cpp6
-rw-r--r--modules/navigation/nav_agent.cpp7
-rw-r--r--platform/android/display_server_android.cpp18
-rw-r--r--platform/ios/display_server_ios.mm5
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp35
-rw-r--r--platform/macos/display_server_macos.mm77
-rw-r--r--platform/macos/godot_content_view.mm7
-rw-r--r--platform/macos/godot_menu_delegate.mm12
-rw-r--r--platform/macos/godot_window_delegate.mm12
-rw-r--r--platform/web/display_server_web.cpp34
-rw-r--r--platform/web/javascript_bridge_singleton.cpp7
-rw-r--r--platform/windows/display_server_windows.cpp46
-rw-r--r--scene/gui/text_edit.cpp7
-rw-r--r--scene/gui/view_panner.cpp29
-rw-r--r--scene/gui/view_panner.h1
-rw-r--r--servers/physics_2d/godot_body_2d.cpp5
-rw-r--r--servers/physics_3d/godot_body_3d.cpp5
-rw-r--r--servers/rendering/renderer_canvas_cull.cpp8
-rw-r--r--servers/rendering/renderer_rd/storage_rd/utilities.cpp8
-rw-r--r--servers/rendering/rendering_server_default.cpp4
-rw-r--r--tests/display_server_mock.h12
27 files changed, 96 insertions, 332 deletions
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index cfc3ac3bcf..2fcd0867e6 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 086e5d2a00..3ae424e9bf 100644
--- a/core/variant/callable.h
+++ b/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;
diff --git a/core/variant/variant.h b/core/variant/variant.h
index d698f85754..21342ae6ef 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -834,6 +834,20 @@ String vformat(const String &p_text, const VarArgs... p_args) {
}
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.
const Variant *argptrs[sizeof...(p_args) + 1];
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index e2852d5a31..919e335d21 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<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;
}
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 91a3181747..395f4faa39 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 0c48c8ef76..6704347877 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<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);
}
}
}
diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp
index 4d4b1fa734..e50d21bbf8 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> 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 010bd2d7c0..cb219ac6c0 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 11c0945ce0..445a6ea6ea 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<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) {
diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm
index 489894a135..8508b67f1e 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 31846c80a2..02a5208e11 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 = &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.
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index 67d6f4214f..03cb8f231a 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<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) {
diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm
index 22a9aa14c0..139411249c 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 1bfcfa7d9e..e393a87134 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 002ab0155f..1756f2d676 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 aac1401f23..dcc4ac4bf7 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<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);
}
}
diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp
index 41206f14a5..1bb72456e8 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 ded80ba5f1..cc5ae9ad45 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<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: {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 3d426b8bf3..2f5c05859f 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 6d1905f111..fc03f2d887 100644
--- a/scene/gui/view_panner.cpp
+++ b/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;
diff --git a/scene/gui/view_panner.h b/scene/gui/view_panner.h
index 60d36ca04c..5aec2d4f6b 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<Variant> 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 1bcb1ba310..4a7b470768 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 260cb84ccd..21d5e49828 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 7c533f207c..d6040e8820 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 8df14d04db..cb035c494c 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 2c8265b7d7..65a6da8ac3 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 fe36fa0b69..8d8a678e20 100644
--- a/tests/display_server_mock.h
+++ b/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);
}
}