From e82f0fefbcc1d80d8737c26a3cfa8fab82059ec7 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 8 Jul 2018 09:47:22 +0200 Subject: [PATCH] MultiplayerAPI::send_bytes transfer mode support. Added as extra parameter, allow you to specify which transfer mode to use for those specific bytes --- core/io/multiplayer_api.cpp | 7 +++++-- core/io/multiplayer_api.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 846c89510ee..ffd3ecaed03 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -704,7 +704,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const _send_rpc(p_node, p_peer_id, p_unreliable, true, p_property, &vptr, 1); } -Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to) { +Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) { ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); ERR_FAIL_COND_V(!network_peer.is_valid(), ERR_UNCONFIGURED); @@ -714,7 +714,10 @@ Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to) { PoolVector::Read r = p_data.read(); packet_cache[0] = NETWORK_COMMAND_RAW; memcpy(&packet_cache[1], &r[0], p_data.size()); + network_peer->set_target_peer(p_to); + network_peer->set_transfer_mode(p_mode); + return network_peer->put_packet(packet_cache.ptr(), p_data.size() + 1); } @@ -770,7 +773,7 @@ Vector MultiplayerAPI::get_network_connected_peers() const { void MultiplayerAPI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node); - ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST)); + ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST), DEFVAL(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE)); ClassDB::bind_method(D_METHOD("has_network_peer"), &MultiplayerAPI::has_network_peer); ClassDB::bind_method(D_METHOD("get_network_peer"), &MultiplayerAPI::get_network_peer); ClassDB::bind_method(D_METHOD("get_network_unique_id"), &MultiplayerAPI::get_network_unique_id); diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index ef56c4c7f29..e47b1830e8d 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -104,7 +104,7 @@ public: void set_root_node(Node *p_node); void set_network_peer(const Ref &p_peer); Ref get_network_peer() const; - Error send_bytes(PoolVector p_data, int p_to = NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST); + Error send_bytes(PoolVector p_data, int p_to = NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST, NetworkedMultiplayerPeer::TransferMode p_mode = NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); // Called by Node.rpc void rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount);