summaryrefslogtreecommitdiffstats
path: root/test/src/example.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-06-30 15:50:03 +0200
committerGitHub <noreply@github.com>2023-06-30 15:50:03 +0200
commit3e44ad18672ee8b66db7cc59e810d42a4beb3d6b (patch)
tree1afe858d14209e6c5e363db8feb27379a5732e48 /test/src/example.cpp
parent80986f8497b7bec307e0987d01412360d39cbb3f (diff)
parent155f2e2a62b2e6526aeab927a217d9dbc06f21b5 (diff)
downloadredot-cpp-3e44ad18672ee8b66db7cc59e810d42a4beb3d6b.tar.gz
Merge pull request #1157 from Faless/feat/rpc_test
Add RPC tests.
Diffstat (limited to 'test/src/example.cpp')
-rw-r--r--test/src/example.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/src/example.cpp b/test/src/example.cpp
index 6c5e736..34ee355 100644
--- a/test/src/example.cpp
+++ b/test/src/example.cpp
@@ -9,6 +9,8 @@
#include <godot_cpp/classes/global_constants.hpp>
#include <godot_cpp/classes/label.hpp>
+#include <godot_cpp/classes/multiplayer_api.hpp>
+#include <godot_cpp/classes/multiplayer_peer.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
using namespace godot;
@@ -48,6 +50,14 @@ int Example::def_args(int p_a, int p_b) {
}
void Example::_notification(int p_what) {
+ if (p_what == NOTIFICATION_READY) {
+ Dictionary opts;
+ opts["rpc_mode"] = MultiplayerAPI::RPC_MODE_AUTHORITY;
+ opts["transfer_mode"] = MultiplayerPeer::TRANSFER_MODE_RELIABLE;
+ opts["call_local"] = true;
+ opts["channel"] = 0;
+ rpc_config("test_rpc", opts);
+ }
//UtilityFunctions::print("Notification: ", String::num(p_what));
}
@@ -132,6 +142,10 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_bitfield", "flags"), &Example::test_bitfield);
+ ClassDB::bind_method(D_METHOD("test_rpc", "value"), &Example::test_rpc);
+ ClassDB::bind_method(D_METHOD("test_send_rpc", "value"), &Example::test_send_rpc);
+ ClassDB::bind_method(D_METHOD("return_last_rpc_arg"), &Example::return_last_rpc_arg);
+
ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200));
ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static);
@@ -333,6 +347,18 @@ BitField<Example::Flags> Example::test_bitfield(BitField<Flags> flags) {
return flags;
}
+void Example::test_rpc(int p_value) {
+ last_rpc_arg = p_value;
+}
+
+void Example::test_send_rpc(int p_value) {
+ rpc("test_rpc", p_value);
+}
+
+int Example::return_last_rpc_arg() {
+ return last_rpc_arg;
+}
+
// Properties.
void Example::set_custom_position(const Vector2 &pos) {
custom_position = pos;