Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add call_deferred() method to Callable #67730

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/variant/callable.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class Callable {
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 {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_command_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/texture_region_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/3d/collision_object_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/option_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 2 additions & 9 deletions servers/display_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/renderer_canvas_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/renderer_rd/storage_rd/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down