From fb8e21bd6d4bf816a144550e7cd89482054f2a57 Mon Sep 17 00:00:00 2001 From: Ninni Pipping Date: Thu, 22 Jun 2023 11:07:53 +0200 Subject: [PATCH] Fix `rpc` calls with binds (cherry picked from commit 7d174c8dfe73d29278c6101dd289f034d008c3e5) --- core/variant/callable_bind.cpp | 22 ++++++++++++++++++++++ core/variant/callable_bind.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/core/variant/callable_bind.cpp b/core/variant/callable_bind.cpp index 378d1ff618b..e493e50467d 100644 --- a/core/variant/callable_bind.cpp +++ b/core/variant/callable_bind.cpp @@ -144,6 +144,18 @@ void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Varia callable.callp(args, p_argcount + binds.size(), r_return_value, r_call_error); } +Error CallableCustomBind::rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const { + const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount)); + for (int i = 0; i < p_argcount; i++) { + args[i] = (const Variant *)p_arguments[i]; + } + for (int i = 0; i < binds.size(); i++) { + args[i + p_argcount] = (const Variant *)&binds[i]; + } + + return callable.rpcp(p_peer_id, args, p_argcount + binds.size(), r_call_error); +} + CallableCustomBind::CallableCustomBind(const Callable &p_callable, const Vector &p_binds) { callable = p_callable; binds = p_binds; @@ -242,6 +254,16 @@ void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Var callable.callp(p_arguments, p_argcount - argcount, r_return_value, r_call_error); } +Error CallableCustomUnbind::rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const { + if (argcount > p_argcount) { + r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_call_error.argument = 0; + r_call_error.expected = argcount; + return ERR_UNCONFIGURED; + } + return callable.rpcp(p_peer_id, p_arguments, p_argcount - argcount, r_call_error); +} + CallableCustomUnbind::CallableCustomUnbind(const Callable &p_callable, int p_argcount) { callable = p_callable; argcount = p_argcount; diff --git a/core/variant/callable_bind.h b/core/variant/callable_bind.h index b51076ad0ff..5798797a3d8 100644 --- a/core/variant/callable_bind.h +++ b/core/variant/callable_bind.h @@ -51,6 +51,7 @@ public: virtual StringName get_method() const override; virtual ObjectID get_object() const override; virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; + virtual Error rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const override; virtual const Callable *get_base_comparator() const override; virtual int get_bound_arguments_count() const override; virtual void get_bound_arguments(Vector &r_arguments, int &r_argcount) const override; @@ -78,6 +79,7 @@ public: virtual StringName get_method() const override; virtual ObjectID get_object() const override; virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; + virtual Error rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const override; virtual const Callable *get_base_comparator() const override; virtual int get_bound_arguments_count() const override; virtual void get_bound_arguments(Vector &r_arguments, int &r_argcount) const override;