diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-10-11 18:55:32 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2023-10-13 14:03:40 +0200 |
commit | f79b90a6c0962f398ea17f1f47b99697baad7a3e (patch) | |
tree | b022c1b846ce69d4633b2612791c2f6269b93e32 | |
parent | 51f81e1c88499f04d2ebdcc0be0b34e73f5e90eb (diff) | |
download | redot-engine-f79b90a6c0962f398ea17f1f47b99697baad7a3e.tar.gz |
[MP] Fix synchronizer init and reset
Fix set_multiplayer_authority not resetting the synchronizer.
Fix the reset function not clearing the watchers state.
Skip wrap around check for the first sync packet after reset.
-rw-r--r-- | modules/multiplayer/multiplayer_synchronizer.cpp | 19 | ||||
-rw-r--r-- | modules/multiplayer/multiplayer_synchronizer.h | 1 |
2 files changed, 13 insertions, 7 deletions
diff --git a/modules/multiplayer/multiplayer_synchronizer.cpp b/modules/multiplayer/multiplayer_synchronizer.cpp index 21f1f86dbf..7ea03ad58e 100644 --- a/modules/multiplayer/multiplayer_synchronizer.cpp +++ b/modules/multiplayer/multiplayer_synchronizer.cpp @@ -107,6 +107,9 @@ void MultiplayerSynchronizer::reset() { net_id = 0; last_sync_usec = 0; last_inbound_sync = 0; + last_watch_usec = 0; + sync_started = false; + watchers.clear(); } uint32_t MultiplayerSynchronizer::get_net_id() const { @@ -131,7 +134,9 @@ bool MultiplayerSynchronizer::update_outbound_sync_time(uint64_t p_usec) { } bool MultiplayerSynchronizer::update_inbound_sync_time(uint16_t p_network_time) { - if (p_network_time <= last_inbound_sync && last_inbound_sync - p_network_time < 32767) { + if (!sync_started) { + sync_started = true; + } else if (p_network_time <= last_inbound_sync && last_inbound_sync - p_network_time < 32767) { return false; } last_inbound_sync = p_network_time; @@ -343,6 +348,9 @@ void MultiplayerSynchronizer::update_visibility(int p_for_peer) { } void MultiplayerSynchronizer::set_root_path(const NodePath &p_path) { + if (p_path == root_path) { + return; + } _stop(); root_path = p_path; _start(); @@ -353,15 +361,12 @@ NodePath MultiplayerSynchronizer::get_root_path() const { } void MultiplayerSynchronizer::set_multiplayer_authority(int p_peer_id, bool p_recursive) { - Node *node = is_inside_tree() ? get_node_or_null(root_path) : nullptr; - if (!node || get_multiplayer_authority() == p_peer_id) { - Node::set_multiplayer_authority(p_peer_id, p_recursive); + if (get_multiplayer_authority() == p_peer_id) { return; } - - get_multiplayer()->object_configuration_remove(node, this); + _stop(); Node::set_multiplayer_authority(p_peer_id, p_recursive); - get_multiplayer()->object_configuration_add(node, this); + _start(); } Error MultiplayerSynchronizer::_watch_changes(uint64_t p_usec) { diff --git a/modules/multiplayer/multiplayer_synchronizer.h b/modules/multiplayer/multiplayer_synchronizer.h index 99613de29b..192d7a5920 100644 --- a/modules/multiplayer/multiplayer_synchronizer.h +++ b/modules/multiplayer/multiplayer_synchronizer.h @@ -66,6 +66,7 @@ private: uint64_t last_sync_usec = 0; uint16_t last_inbound_sync = 0; uint32_t net_id = 0; + bool sync_started = false; static Object *_get_prop_target(Object *p_obj, const NodePath &p_prop); void _start(); |