summaryrefslogtreecommitdiff
path: root/scene/multiplayer/scene_replication_interface.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2022-02-04 16:24:16 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2022-02-05 02:00:23 +0100
commit347d2dfc42967c14daced64706ad6db0b3ebf9b5 (patch)
tree57d7a28a4b1d578f3cfb942b3119caa9871184f5 /scene/multiplayer/scene_replication_interface.cpp
parent3db1d689ce11507d9597bb434891da95168f2c69 (diff)
[Net] Move RPC, Node cache out of MultiplayerAPI.
Now uses two interfaces so it can be overridden in the future, and core no longer depends on Node. The interfaces are implements in scene/multiplayer. Replaces root_node with root_path. Remove all Node references from MultiplayerAPI.
Diffstat (limited to 'scene/multiplayer/scene_replication_interface.cpp')
-rw-r--r--scene/multiplayer/scene_replication_interface.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/scene/multiplayer/scene_replication_interface.cpp b/scene/multiplayer/scene_replication_interface.cpp
index 7155935084..2088a43ba7 100644
--- a/scene/multiplayer/scene_replication_interface.cpp
+++ b/scene/multiplayer/scene_replication_interface.cpp
@@ -186,12 +186,10 @@ Error SceneReplicationInterface::_send_spawn(Node *p_node, MultiplayerSpawner *p
}
// Prepare simplified path.
- const Node *root_node = multiplayer->get_root_node();
- ERR_FAIL_COND_V(!root_node, ERR_UNCONFIGURED);
- NodePath rel_path = (root_node->get_path()).rel_path_to(p_spawner->get_path());
+ NodePath rel_path = multiplayer->get_root_path().rel_path_to(p_spawner->get_path());
int path_id = 0;
- multiplayer->send_confirm_path(p_spawner, rel_path, p_peer, path_id);
+ multiplayer->send_object_cache(p_spawner, rel_path, p_peer, path_id);
// Encode name and parent ID.
CharString cname = p_node->get_name().operator String().utf8();
@@ -243,7 +241,7 @@ Error SceneReplicationInterface::on_spawn_receive(int p_from, const uint8_t *p_b
ofs += 1;
uint32_t node_target = decode_uint32(&p_buffer[ofs]);
ofs += 4;
- MultiplayerSpawner *spawner = Object::cast_to<MultiplayerSpawner>(multiplayer->get_cached_node(p_from, node_target));
+ MultiplayerSpawner *spawner = Object::cast_to<MultiplayerSpawner>(multiplayer->get_cached_object(p_from, node_target));
ERR_FAIL_COND_V(!spawner, ERR_DOES_NOT_EXIST);
ERR_FAIL_COND_V(p_from != spawner->get_multiplayer_authority(), ERR_UNAUTHORIZED);
@@ -349,11 +347,9 @@ void SceneReplicationInterface::_send_sync(int p_peer, uint64_t p_msec) {
uint32_t net_id = rep_state->get_net_id(oid);
if (net_id == 0) {
// First time path based ID.
- const Node *root_node = multiplayer->get_root_node();
- ERR_FAIL_COND(!root_node);
- NodePath rel_path = (root_node->get_path()).rel_path_to(sync->get_path());
+ NodePath rel_path = multiplayer->get_root_path().rel_path_to(sync->get_path());
int path_id = 0;
- multiplayer->send_confirm_path(sync, rel_path, p_peer, path_id);
+ multiplayer->send_object_cache(sync, rel_path, p_peer, path_id);
net_id = path_id;
rep_state->set_net_id(oid, net_id | 0x80000000);
}
@@ -381,7 +377,7 @@ Error SceneReplicationInterface::on_sync_receive(int p_from, const uint8_t *p_bu
ofs += 4;
Node *node = nullptr;
if (net_id & 0x80000000) {
- MultiplayerSynchronizer *sync = Object::cast_to<MultiplayerSynchronizer>(multiplayer->get_cached_node(p_from, net_id & 0x7FFFFFFF));
+ MultiplayerSynchronizer *sync = Object::cast_to<MultiplayerSynchronizer>(multiplayer->get_cached_object(p_from, net_id & 0x7FFFFFFF));
ERR_FAIL_COND_V(!sync || sync->get_multiplayer_authority() != p_from, ERR_UNAUTHORIZED);
node = sync->get_node(sync->get_root_path());
} else {