commit
3e44ad1867
|
@ -101,6 +101,13 @@ func _ready():
|
||||||
assert_equal(example.test_bitfield(0), 0)
|
assert_equal(example.test_bitfield(0), 0)
|
||||||
assert_equal(example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3)
|
assert_equal(example.test_bitfield(Example.FLAG_ONE | Example.FLAG_TWO), 3)
|
||||||
|
|
||||||
|
# RPCs.
|
||||||
|
assert_equal(example.return_last_rpc_arg(), 0)
|
||||||
|
example.test_rpc(42)
|
||||||
|
assert_equal(example.return_last_rpc_arg(), 42)
|
||||||
|
example.test_send_rpc(100)
|
||||||
|
assert_equal(example.return_last_rpc_arg(), 100)
|
||||||
|
|
||||||
# Virtual method.
|
# Virtual method.
|
||||||
var event = InputEventKey.new()
|
var event = InputEventKey.new()
|
||||||
event.key_label = KEY_H
|
event.key_label = KEY_H
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <godot_cpp/classes/global_constants.hpp>
|
#include <godot_cpp/classes/global_constants.hpp>
|
||||||
#include <godot_cpp/classes/label.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>
|
#include <godot_cpp/variant/utility_functions.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
@ -48,6 +50,14 @@ int Example::def_args(int p_a, int p_b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Example::_notification(int p_what) {
|
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));
|
//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_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_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);
|
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;
|
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.
|
// Properties.
|
||||||
void Example::set_custom_position(const Vector2 &pos) {
|
void Example::set_custom_position(const Vector2 &pos) {
|
||||||
custom_position = pos;
|
custom_position = pos;
|
||||||
|
|
|
@ -70,6 +70,7 @@ private:
|
||||||
Vector2 custom_position;
|
Vector2 custom_position;
|
||||||
Vector3 property_from_list;
|
Vector3 property_from_list;
|
||||||
Vector2 dprop[3];
|
Vector2 dprop[3];
|
||||||
|
int last_rpc_arg = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constants.
|
// Constants.
|
||||||
|
@ -120,6 +121,11 @@ public:
|
||||||
|
|
||||||
BitField<Flags> test_bitfield(BitField<Flags> flags);
|
BitField<Flags> test_bitfield(BitField<Flags> flags);
|
||||||
|
|
||||||
|
// RPC
|
||||||
|
void test_rpc(int p_value);
|
||||||
|
void test_send_rpc(int p_value);
|
||||||
|
int return_last_rpc_arg();
|
||||||
|
|
||||||
// Property.
|
// Property.
|
||||||
void set_custom_position(const Vector2 &pos);
|
void set_custom_position(const Vector2 &pos);
|
||||||
Vector2 get_custom_position() const;
|
Vector2 get_custom_position() const;
|
||||||
|
|
Loading…
Reference in New Issue