| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/ref_counted.h" |
| 34 |
#include "scene/main/multiplayer_api.h" |
| 35 |
|
| 36 |
class SceneMultiplayer; |
| 37 |
class SceneCacheInterface; |
| 38 |
class SceneReplicationInterface; |
| 39 |
class Node; |
| 40 |
|
| 41 |
class SceneRPCInterface : public RefCounted { |
| 42 |
GDCLASS(SceneRPCInterface, RefCounted); |
| 43 |
|
| 44 |
private: |
| 45 |
struct RPCConfig { |
| 46 |
StringName name; |
| 47 |
MultiplayerAPI::RPCMode rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; |
| 48 |
bool call_local = false; |
| 49 |
MultiplayerPeer::TransferMode transfer_mode = MultiplayerPeer::TRANSFER_MODE_RELIABLE; |
| 50 |
int channel = 0; |
| 51 |
|
| 52 |
bool operator==(RPCConfig const &p_other) const { |
| 53 |
return name == p_other.name; |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
struct RPCConfigCache { |
| 58 |
HashMap<uint16_t, RPCConfig> configs; |
| 59 |
HashMap<StringName, uint16_t> ids; |
| 60 |
}; |
| 61 |
|
| 62 |
struct SortRPCConfig { |
| 63 |
StringName::AlphCompare compare; |
| 64 |
bool operator()(const RPCConfig &p_a, const RPCConfig &p_b) const { |
| 65 |
return compare(p_a.name, p_b.name); |
| 66 |
} |
| 67 |
}; |
| 68 |
|
| 69 |
enum NetworkNodeIdCompression { |
| 70 |
NETWORK_NODE_ID_COMPRESSION_8 = 0, |
| 71 |
NETWORK_NODE_ID_COMPRESSION_16, |
| 72 |
NETWORK_NODE_ID_COMPRESSION_32, |
| 73 |
}; |
| 74 |
|
| 75 |
enum NetworkNameIdCompression { |
| 76 |
NETWORK_NAME_ID_COMPRESSION_8 = 0, |
| 77 |
NETWORK_NAME_ID_COMPRESSION_16, |
| 78 |
}; |
| 79 |
|
| 80 |
SceneMultiplayer *multiplayer = nullptr; |
| 81 |
SceneCacheInterface *multiplayer_cache = nullptr; |
| 82 |
SceneReplicationInterface *multiplayer_replicator = nullptr; |
| 83 |
|
| 84 |
Vector<uint8_t> packet_cache; |
| 85 |
|
| 86 |
HashMap<ObjectID, RPCConfigCache> rpc_cache; |
| 87 |
|
| 88 |
#ifdef DEBUG_ENABLED |
| 89 |
_FORCE_INLINE_ void _profile_node_data(const String &p_what, ObjectID p_id, int p_size); |
| 90 |
#endif |
| 91 |
|
| 92 |
protected: |
| 93 |
void _process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset); |
| 94 |
|
| 95 |
void _send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount); |
| 96 |
Node *_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len); |
| 97 |
|
| 98 |
void _parse_rpc_config(const Variant &p_config, bool p_for_node, RPCConfigCache &r_cache); |
| 99 |
const RPCConfigCache &_get_node_config(const Node *p_node); |
| 100 |
|
| 101 |
public: |
| 102 |
Error rpcp(Object *p_obj, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount); |
| 103 |
void process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len); |
| 104 |
String get_rpc_md5(const Object *p_obj); |
| 105 |
|
| 106 |
SceneRPCInterface(SceneMultiplayer *p_multiplayer, SceneCacheInterface *p_cache, SceneReplicationInterface *p_replicator) { |
| 107 |
multiplayer = p_multiplayer; |
| 108 |
multiplayer_cache = p_cache; |
| 109 |
multiplayer_replicator = p_replicator; |
| 110 |
} |
| 111 |
}; |