You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 19:41:11 +00:00
[Net] Move multiplayer to core subdir, split RPCManager.
Move multiplayer classes to "core/multiplayer" subdir. Move the RPCConfig and enums (TransferMode, RPCMode) to a separate file (multiplayer.h), and bind them to the global namespace. Move the RPC handling code to its own class (RPCManager). Renames "get_rpc_sender_id" to "get_remote_sender_id".
This commit is contained in:
@@ -539,10 +539,10 @@ bool Node::is_network_authority() const {
|
||||
|
||||
/***** RPC CONFIG ********/
|
||||
|
||||
uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel) {
|
||||
uint16_t Node::rpc_config(const StringName &p_method, Multiplayer::RPCMode p_rpc_mode, Multiplayer::TransferMode p_transfer_mode, int p_channel) {
|
||||
for (int i = 0; i < data.rpc_methods.size(); i++) {
|
||||
if (data.rpc_methods[i].name == p_method) {
|
||||
MultiplayerAPI::RPCConfig &nd = data.rpc_methods.write[i];
|
||||
Multiplayer::RPCConfig &nd = data.rpc_methods.write[i];
|
||||
nd.rpc_mode = p_rpc_mode;
|
||||
nd.transfer_mode = p_transfer_mode;
|
||||
nd.channel = p_channel;
|
||||
@@ -550,7 +550,7 @@ uint16_t Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_
|
||||
}
|
||||
}
|
||||
// New method
|
||||
MultiplayerAPI::RPCConfig nd;
|
||||
Multiplayer::RPCConfig nd;
|
||||
nd.name = p_method;
|
||||
nd.rpc_mode = p_rpc_mode;
|
||||
nd.transfer_mode = p_transfer_mode;
|
||||
@@ -643,7 +643,7 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal
|
||||
|
||||
void Node::rpcp(int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) {
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
get_multiplayer()->rpcp(this, p_peer_id, true, p_method, p_arg, p_argcount);
|
||||
get_multiplayer()->rpcp(this, p_peer_id, p_method, p_arg, p_argcount);
|
||||
}
|
||||
|
||||
Ref<MultiplayerAPI> Node::get_multiplayer() const {
|
||||
@@ -664,7 +664,7 @@ void Node::set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
|
||||
multiplayer = p_multiplayer;
|
||||
}
|
||||
|
||||
Vector<MultiplayerAPI::RPCConfig> Node::get_node_rpc_methods() const {
|
||||
Vector<Multiplayer::RPCConfig> Node::get_node_rpc_methods() const {
|
||||
return data.rpc_methods;
|
||||
}
|
||||
|
||||
@@ -2746,7 +2746,7 @@ void Node::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_multiplayer"), &Node::get_multiplayer);
|
||||
ClassDB::bind_method(D_METHOD("get_custom_multiplayer"), &Node::get_custom_multiplayer);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_multiplayer", "api"), &Node::set_custom_multiplayer);
|
||||
ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(MultiplayerPeer::TRANSFER_MODE_RELIABLE), DEFVAL(0));
|
||||
ClassDB::bind_method(D_METHOD("rpc_config", "method", "rpc_mode", "transfer_mode", "channel"), &Node::rpc_config, DEFVAL(Multiplayer::TRANSFER_MODE_RELIABLE), DEFVAL(0));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_editor_description", "editor_description"), &Node::set_editor_description);
|
||||
ClassDB::bind_method(D_METHOD("get_editor_description"), &Node::get_editor_description);
|
||||
|
||||
@@ -128,7 +128,7 @@ private:
|
||||
Node *process_owner = nullptr;
|
||||
|
||||
int network_authority = 1; // Server by default.
|
||||
Vector<MultiplayerAPI::RPCConfig> rpc_methods;
|
||||
Vector<Multiplayer::RPCConfig> rpc_methods;
|
||||
|
||||
// Variables used to properly sort the node when processing, ignored otherwise.
|
||||
// TODO: Should move all the stuff below to bits.
|
||||
@@ -466,8 +466,8 @@ public:
|
||||
int get_network_authority() const;
|
||||
bool is_network_authority() const;
|
||||
|
||||
uint16_t rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_rpc_mode, MultiplayerPeer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC
|
||||
Vector<MultiplayerAPI::RPCConfig> get_node_rpc_methods() const;
|
||||
uint16_t rpc_config(const StringName &p_method, Multiplayer::RPCMode p_rpc_mode, Multiplayer::TransferMode p_transfer_mode, int p_channel = 0); // config a local method for RPC
|
||||
Vector<Multiplayer::RPCConfig> get_node_rpc_methods() const;
|
||||
|
||||
void rpc(const StringName &p_method, VARIANT_ARG_LIST); // RPC, honors RPCMode, TransferMode, channel
|
||||
void rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_LIST); // RPC to specific peer(s), honors RPCMode, TransferMode, channel
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#ifndef SCENE_TREE_H
|
||||
#define SCENE_TREE_H
|
||||
|
||||
#include "core/io/multiplayer_api.h"
|
||||
#include "core/multiplayer/multiplayer_api.h"
|
||||
#include "core/os/main_loop.h"
|
||||
#include "core/os/thread_safe.h"
|
||||
#include "core/templates/self_list.h"
|
||||
|
||||
Reference in New Issue
Block a user