diff options
author | kobewi <kobewi4e@gmail.com> | 2022-10-21 23:40:06 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-11-04 17:24:34 +0100 |
commit | 1778301cd008bb791fd27239e0f2659ae640e351 (patch) | |
tree | 8eb98e2e6175b5b86b18113f7a4fa4e7181e7474 | |
parent | 191c8ed12f624ec97b650b2726fed4e8c4bcf04c (diff) |
Add call_deferred() method to Callable
-rw-r--r-- | core/variant/callable.h | 10 | ||||
-rw-r--r-- | editor/editor_command_palette.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | scene/3d/collision_object_3d.cpp | 2 | ||||
-rw-r--r-- | scene/gui/option_button.cpp | 2 | ||||
-rw-r--r-- | servers/display_server.cpp | 11 | ||||
-rw-r--r-- | servers/rendering/renderer_canvas_cull.cpp | 4 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/utilities.cpp | 4 |
8 files changed, 20 insertions, 17 deletions
diff --git a/core/variant/callable.h b/core/variant/callable.h index 0305dc55c3..32770bd663 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -73,6 +73,16 @@ public: void call_deferredp(const Variant **p_arguments, int p_argcount) const; Variant callv(const Array &p_arguments) const; + template <typename... VarArgs> + void call_deferred(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]; + } + return call_deferredp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); + } + Error rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const; _FORCE_INLINE_ bool is_null() const { diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index a0913265eb..3f93fa1f41 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -226,7 +226,7 @@ void EditorCommandPalette::_add_command(String p_command_name, String p_key_name void EditorCommandPalette::execute_command(String &p_command_key) { ERR_FAIL_COND_MSG(!commands.has(p_command_key), p_command_key + " not found."); commands[p_command_key].last_used = OS::get_singleton()->get_unix_time(); - commands[p_command_key].callable.call_deferredp(nullptr, 0); + commands[p_command_key].callable.call_deferred(); _save_history(); } diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index a7a8d526d0..b0c8597adf 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -242,7 +242,7 @@ void TextureRegionEditor::_region_draw() { hscroll->set_value((hscroll->get_min() + hscroll->get_max() - hscroll->get_page()) / 2); vscroll->set_value((vscroll->get_min() + vscroll->get_max() - vscroll->get_page()) / 2); // This ensures that the view is updated correctly. - callable_mp(this, &TextureRegionEditor::_pan_callback).bind(Vector2(1, 0)).call_deferredp(nullptr, 0); + callable_mp(this, &TextureRegionEditor::_pan_callback).bind(Vector2(1, 0)).call_deferred(); request_center = false; } diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index a98be62dfa..ca23fe03a2 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -330,7 +330,7 @@ bool CollisionObject3D::_are_collision_shapes_visible() { void CollisionObject3D::_update_shape_data(uint32_t p_owner) { if (_are_collision_shapes_visible()) { if (debug_shapes_to_update.is_empty()) { - callable_mp(this, &CollisionObject3D::_update_debug_shapes).call_deferredp({}, 0); + callable_mp(this, &CollisionObject3D::_update_debug_shapes).call_deferred(); } debug_shapes_to_update.insert(p_owner); } diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 2cbece69f2..0940b4c07b 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -451,7 +451,7 @@ void OptionButton::_queue_refresh_cache() { } cache_refresh_pending = true; - callable_mp(this, &OptionButton::_refresh_size_cache).call_deferredp(nullptr, 0); + callable_mp(this, &OptionButton::_refresh_size_cache).call_deferred(); } void OptionButton::select(int p_idx) { diff --git a/servers/display_server.cpp b/servers/display_server.cpp index 07cb59aaee..1897612562 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -302,19 +302,12 @@ void DisplayServer::tts_post_utterance_event(TTSUtteranceEvent p_event, int p_id case DisplayServer::TTS_UTTERANCE_ENDED: case DisplayServer::TTS_UTTERANCE_CANCELED: { if (utterance_callback[p_event].is_valid()) { - Variant args[1]; - args[0] = p_id; - const Variant *argp[] = { &args[0] }; - utterance_callback[p_event].call_deferredp(argp, 1); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession. + utterance_callback[p_event].call_deferred(p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession. } } break; case DisplayServer::TTS_UTTERANCE_BOUNDARY: { if (utterance_callback[p_event].is_valid()) { - Variant args[2]; - args[0] = p_pos; - args[1] = p_id; - const Variant *argp[] = { &args[0], &args[1] }; - utterance_callback[p_event].call_deferredp(argp, 2); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession. + utterance_callback[p_event].call_deferred(p_pos, p_id); // Should be deferred, on some platforms utterance events can be called from different threads in a rapid succession. } } break; default: diff --git a/servers/rendering/renderer_canvas_cull.cpp b/servers/rendering/renderer_canvas_cull.cpp index 41d4ca8d5e..16d382a5f3 100644 --- a/servers/rendering/renderer_canvas_cull.cpp +++ b/servers/rendering/renderer_canvas_cull.cpp @@ -1964,7 +1964,7 @@ void RendererCanvasCull::update_visibility_notifiers() { if (!visibility_notifier->enter_callable.is_null()) { if (RSG::threaded) { - visibility_notifier->enter_callable.call_deferredp(nullptr, 0); + visibility_notifier->enter_callable.call_deferred(); } else { Callable::CallError ce; Variant ret; @@ -1977,7 +1977,7 @@ void RendererCanvasCull::update_visibility_notifiers() { if (!visibility_notifier->exit_callable.is_null()) { if (RSG::threaded) { - visibility_notifier->exit_callable.call_deferredp(nullptr, 0); + visibility_notifier->exit_callable.call_deferred(); } else { Callable::CallError ce; Variant ret; diff --git a/servers/rendering/renderer_rd/storage_rd/utilities.cpp b/servers/rendering/renderer_rd/storage_rd/utilities.cpp index 4048c46d28..625f089f66 100644 --- a/servers/rendering/renderer_rd/storage_rd/utilities.cpp +++ b/servers/rendering/renderer_rd/storage_rd/utilities.cpp @@ -200,7 +200,7 @@ void Utilities::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_de if (p_enter) { if (!vn->enter_callback.is_null()) { if (p_deferred) { - vn->enter_callback.call_deferredp(nullptr, 0); + vn->enter_callback.call_deferred(); } else { Variant r; Callable::CallError ce; @@ -210,7 +210,7 @@ void Utilities::visibility_notifier_call(RID p_notifier, bool p_enter, bool p_de } else { if (!vn->exit_callback.is_null()) { if (p_deferred) { - vn->exit_callback.call_deferredp(nullptr, 0); + vn->exit_callback.call_deferred(); } else { Variant r; Callable::CallError ce; |