From 5a60973abbc0a01d1ae81e69a594be35b8432fd4 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Sun, 1 Aug 2021 17:49:33 +0300 Subject: [PATCH 1/2] Fix typo --- modules/network_synchronizer/networked_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/network_synchronizer/networked_controller.cpp b/modules/network_synchronizer/networked_controller.cpp index b2d519a78336..a646eabeb036 100644 --- a/modules/network_synchronizer/networked_controller.cpp +++ b/modules/network_synchronizer/networked_controller.cpp @@ -64,7 +64,7 @@ void NetworkedController::_bind_methods() { ClassDB::bind_method(D_METHOD("set_player_input_storage_size", "size"), &NetworkedController::set_player_input_storage_size); ClassDB::bind_method(D_METHOD("get_player_input_storage_size"), &NetworkedController::get_player_input_storage_size); - ClassDB::bind_method(D_METHOD("set_max_redundant_inputs", "max_redundand_inputs"), &NetworkedController::set_max_redundant_inputs); + ClassDB::bind_method(D_METHOD("set_max_redundant_inputs", "max_redundant_inputs"), &NetworkedController::set_max_redundant_inputs); ClassDB::bind_method(D_METHOD("get_max_redundant_inputs"), &NetworkedController::get_max_redundant_inputs); ClassDB::bind_method(D_METHOD("set_tick_speedup_notification_delay", "tick_speedup_notification_delay"), &NetworkedController::set_tick_speedup_notification_delay); From f41be5130c3f20235c0658af365d7559888d9884 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Thu, 29 Jul 2021 09:28:00 +0300 Subject: [PATCH 2/2] Update to the latest master --- doc/classes/DataBuffer.xml | 324 ++++++++++++++++++ doc/classes/Interpolator.xml | 62 ++++ doc/classes/NetworkedController.xml | 160 +++++++++ doc/classes/SceneDiff.xml | 13 + doc/classes/SceneSynchronizer.xml | 278 +++++++++++++++ modules/network_synchronizer/interpolator.cpp | 8 +- .../networked_controller.cpp | 104 +++--- .../networked_controller.h | 14 - .../network_synchronizer/register_types.cpp | 39 +-- .../scene_synchronizer.cpp | 82 ++--- 10 files changed, 932 insertions(+), 152 deletions(-) create mode 100644 doc/classes/DataBuffer.xml create mode 100644 doc/classes/Interpolator.xml create mode 100644 doc/classes/NetworkedController.xml create mode 100644 doc/classes/SceneDiff.xml create mode 100644 doc/classes/SceneSynchronizer.xml diff --git a/doc/classes/DataBuffer.xml b/doc/classes/DataBuffer.xml new file mode 100644 index 000000000000..554564cdf402 --- /dev/null +++ b/doc/classes/DataBuffer.xml @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/Interpolator.xml b/doc/classes/Interpolator.xml new file mode 100644 index 000000000000..5020ff0b0e69 --- /dev/null +++ b/doc/classes/Interpolator.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/NetworkedController.xml b/doc/classes/NetworkedController.xml new file mode 100644 index 000000000000..67a075a401c3 --- /dev/null +++ b/doc/classes/NetworkedController.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/SceneDiff.xml b/doc/classes/SceneDiff.xml new file mode 100644 index 000000000000..877c08a6b26a --- /dev/null +++ b/doc/classes/SceneDiff.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/doc/classes/SceneSynchronizer.xml b/doc/classes/SceneSynchronizer.xml new file mode 100644 index 000000000000..353f89ec1117 --- /dev/null +++ b/doc/classes/SceneSynchronizer.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/network_synchronizer/interpolator.cpp b/modules/network_synchronizer/interpolator.cpp index d49b0ec078d1..eee1c58e99cd 100644 --- a/modules/network_synchronizer/interpolator.cpp +++ b/modules/network_synchronizer/interpolator.cpp @@ -403,12 +403,12 @@ Variant Interpolator::interpolate(const Variant &p_v1, const Variant &p_v2, real int(Math::round(Math::lerp(p_v1.operator Vector3i()[0], p_v2.operator Vector3i()[0], p_delta))), int(Math::round(Math::lerp(p_v1.operator Vector3i()[1], p_v2.operator Vector3i()[1], p_delta))), int(Math::round(Math::lerp(p_v1.operator Vector3i()[2], p_v2.operator Vector3i()[2], p_delta)))); - case Variant::Type::QUAT: - return p_v1.operator Quat().slerp(p_v2.operator Quat(), p_delta); + case Variant::Type::QUATERNION: + return p_v1.operator Quaternion().slerp(p_v2.operator Quaternion(), p_delta); case Variant::Type::BASIS: return p_v1.operator Basis().slerp(p_v2.operator Basis(), p_delta); - case Variant::Type::TRANSFORM: - return p_v1.operator Transform().interpolate_with(p_v2.operator Transform(), p_delta); + case Variant::Type::TRANSFORM3D: + return p_v1.operator Transform3D().interpolate_with(p_v2.operator Transform3D(), p_delta); default: return p_delta > 0.5 ? p_v2 : p_v1; } diff --git a/modules/network_synchronizer/networked_controller.cpp b/modules/network_synchronizer/networked_controller.cpp index a646eabeb036..6c477696c230 100644 --- a/modules/network_synchronizer/networked_controller.cpp +++ b/modules/network_synchronizer/networked_controller.cpp @@ -46,20 +46,6 @@ // 2% #define TICK_SPEED_CHANGE_NOTIF_THRESHOLD 4 -StringName NetworkedController::sn_rpc_server_send_inputs; -StringName NetworkedController::sn_rpc_send_tick_additional_speed; -StringName NetworkedController::sn_rpc_doll_notify_sync_pause; -StringName NetworkedController::sn_rpc_doll_send_epoch_batch; - -StringName NetworkedController::sn_controller_process; -StringName NetworkedController::sn_count_input_size; -StringName NetworkedController::sn_are_inputs_different; -StringName NetworkedController::sn_collect_epoch_data; -StringName NetworkedController::sn_collect_inputs; -StringName NetworkedController::sn_setup_interpolator; -StringName NetworkedController::sn_parse_epoch_data; -StringName NetworkedController::sn_apply_epoch; - void NetworkedController::_bind_methods() { ClassDB::bind_method(D_METHOD("set_player_input_storage_size", "size"), &NetworkedController::set_player_input_storage_size); ClassDB::bind_method(D_METHOD("get_player_input_storage_size"), &NetworkedController::get_player_input_storage_size); @@ -131,14 +117,14 @@ void NetworkedController::_bind_methods() { ClassDB::bind_method(D_METHOD("__on_sync_paused"), &NetworkedController::__on_sync_paused); - BIND_VMETHOD(MethodInfo("collect_inputs", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo("controller_process", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "are_inputs_different", PropertyInfo(Variant::OBJECT, "inputs_A", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"), PropertyInfo(Variant::OBJECT, "inputs_B", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "count_input_size", PropertyInfo(Variant::OBJECT, "inputs", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo("collect_epoch_data", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo("setup_interpolator", PropertyInfo(Variant::OBJECT, "interpolator", PROPERTY_HINT_RESOURCE_TYPE, "Interpolator"))); - BIND_VMETHOD(MethodInfo("parse_epoch_data", PropertyInfo(Variant::OBJECT, "interpolator", PROPERTY_HINT_RESOURCE_TYPE, "Interpolator"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); - BIND_VMETHOD(MethodInfo("apply_epoch", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::ARRAY, "interpolated_data"))); + BIND_VMETHOD(MethodInfo("_collect_inputs", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo("_controller_process", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_are_inputs_different", PropertyInfo(Variant::OBJECT, "inputs_A", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"), PropertyInfo(Variant::OBJECT, "inputs_B", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo(Variant::INT, "_count_input_size", PropertyInfo(Variant::OBJECT, "inputs", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo("_collect_epoch_data", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo("_setup_interpolator", PropertyInfo(Variant::OBJECT, "interpolator", PROPERTY_HINT_RESOURCE_TYPE, "Interpolator"))); + BIND_VMETHOD(MethodInfo("_parse_epoch_data", PropertyInfo(Variant::OBJECT, "interpolator", PROPERTY_HINT_RESOURCE_TYPE, "Interpolator"), PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "DataBuffer"))); + BIND_VMETHOD(MethodInfo("_apply_epoch", PropertyInfo(Variant::FLOAT, "delta"), PropertyInfo(Variant::ARRAY, "interpolated_data"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "input_storage_size", PROPERTY_HINT_RANGE, "5,2000,1"), "set_player_input_storage_size", "get_player_input_storage_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redundant_inputs", PROPERTY_HINT_RANGE, "0,1000,1"), "set_max_redundant_inputs", "get_max_redundant_inputs"); @@ -162,10 +148,10 @@ void NetworkedController::_bind_methods() { } NetworkedController::NetworkedController() { - rpc_config(sn_rpc_server_send_inputs, MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config(sn_rpc_send_tick_additional_speed, MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config(sn_rpc_doll_notify_sync_pause, MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config(sn_rpc_doll_send_epoch_batch, MultiplayerAPI::RPC_MODE_REMOTE); + rpc_config(SNAME("_rpc_server_send_inputs"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_UNRELIABLE); + rpc_config(SNAME("_rpc_send_tick_additional_speed"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_UNRELIABLE); + rpc_config(SNAME("_rpc_doll_notify_sync_pause"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_RELIABLE); + rpc_config(SNAME("_rpc_doll_send_epoch_batch"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_UNRELIABLE); } void NetworkedController::set_player_input_storage_size(int p_size) { @@ -343,7 +329,7 @@ void NetworkedController::set_doll_peer_active(int p_peer_id, bool p_active) { if (p_active == false) { // Notify the doll only for deactivations. The activations are automatically // handled when the first epoch is received. - rpc_id(p_peer_id, sn_rpc_doll_notify_sync_pause, server_controller->epoch); + rpc_id(p_peer_id, SNAME("_rpc_doll_notify_sync_pause"), server_controller->epoch); } } @@ -355,7 +341,7 @@ void NetworkedController::pause_notify_dolls() { for (uint32_t i = 0; i < server_controller->peers.size(); i += 1) { if (server_controller->peers[i].active) { // Notify this actor is no more active. - rpc_id(server_controller->peers[i].peer, sn_rpc_doll_notify_sync_pause, server_controller->epoch); + rpc_id(server_controller->peers[i].peer, SNAME("_rpc_doll_notify_sync_pause"), server_controller->epoch); } } } @@ -428,13 +414,13 @@ void NetworkedController::set_inputs_buffer(const BitArray &p_new_buffer, uint32 void NetworkedController::set_scene_synchronizer(SceneSynchronizer *p_synchronizer) { if (scene_synchronizer) { - scene_synchronizer->disconnect("sync_paused", Callable(this, "__on_sync_paused")); + scene_synchronizer->disconnect(SNAME("sync_paused"), Callable(this, SNAME("__on_sync_paused"))); } scene_synchronizer = p_synchronizer; if (scene_synchronizer) { - scene_synchronizer->connect("sync_paused", Callable(this, "__on_sync_paused")); + scene_synchronizer->connect(SNAME("sync_paused"), Callable(this, SNAME("__on_sync_paused"))); } } @@ -510,14 +496,14 @@ void NetworkedController::_notification(int p_what) { return; } - ERR_FAIL_COND_MSG(has_method("collect_inputs") == false, "In your script you must inherit the virtual method `collect_inputs` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("controller_process") == false, "In your script you must inherit the virtual method `controller_process` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("are_inputs_different") == false, "In your script you must inherit the virtual method `are_inputs_different` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("count_input_size") == false, "In your script you must inherit the virtual method `count_input_size` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("collect_epoch_data") == false, "In your script you must inherit the virtual method `collect_epoch_data` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("setup_interpolator") == false, "In your script you must inherit the virtual method `setup_interpolator` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("parse_epoch_data") == false, "In your script you must inherit the virtual method `parse_epoch_data` to correctly use the `NetworkedController`."); - ERR_FAIL_COND_MSG(has_method("apply_epoch") == false, "In your script you must inherit the virtual method `apply_epoch` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_collect_inputs") == false, "In your script you must inherit the virtual method `_collect_inputs` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_controller_process") == false, "In your script you must inherit the virtual method `_controller_process` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_are_inputs_different") == false, "In your script you must inherit the virtual method `_are_inputs_different` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_count_input_size") == false, "In your script you must inherit the virtual method `_count_input_size` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_collect_epoch_data") == false, "In your script you must inherit the virtual method `_collect_epoch_data` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_setup_interpolator") == false, "In your script you must inherit the virtual method `_setup_interpolator` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_parse_epoch_data") == false, "In your script you must inherit the virtual method `_parse_epoch_data` to correctly use the `NetworkedController`."); + ERR_FAIL_COND_MSG(has_method("_apply_epoch") == false, "In your script you must inherit the virtual method `_apply_epoch` to correctly use the `NetworkedController`."); } break; #endif @@ -547,7 +533,7 @@ void ServerController::process(real_t p_delta) { node->get_inputs_buffer_mut().begin_read(); node->get_inputs_buffer_mut().seek(METADATA_SIZE); node->call( - NetworkedController::sn_controller_process, + SNAME("_controller_process"), p_delta, &node->get_inputs_buffer_mut()); @@ -607,7 +593,7 @@ void ServerController::activate_peer(int p_peer) { #ifdef DEBUG_ENABLED // Unreachable because this is the server controller. - CRASH_COND(node->get_tree()->is_network_server() == false); + CRASH_COND(node->get_tree()->get_multiplayer()->is_network_server() == false); #endif if (p_peer == node->get_network_master()) { // This is self, so not a doll. @@ -673,7 +659,7 @@ void ServerController::receive_inputs(const Vector &p_data) { // Read metadata const bool has_data = pir.read_bool(); - const int input_size_in_bits = (has_data ? int(node->call(NetworkedController::sn_count_input_size, &pir)) : 0) + METADATA_SIZE; + const int input_size_in_bits = (has_data ? int(node->call(SNAME("_count_input_size"), &pir)) : 0) + METADATA_SIZE; // Pad to 8 bits. const int input_size_padded = Math::ceil((static_cast(input_size_in_bits)) / 8.0); @@ -856,7 +842,7 @@ bool ServerController::fetch_next_input() { pir_B.begin_read(); pir_B.seek(METADATA_SIZE); - const bool is_meaningful = node->call(NetworkedController::sn_are_inputs_different, &pir_A, &pir_B); + const bool is_meaningful = node->call(SNAME("_are_inputs_different"), &pir_A, &pir_B); if (is_meaningful) { break; } @@ -924,7 +910,7 @@ void ServerController::doll_sync(real_t p_delta) { if (epoch_state_collected == false) { epoch_state_data_cache.begin_write(0); epoch_state_data_cache.add_int(epoch, DataBuffer::COMPRESSION_LEVEL_1); - node->call(NetworkedController::sn_collect_epoch_data, &epoch_state_data_cache); + node->call(SNAME("_collect_epoch_data"), &epoch_state_data_cache); epoch_state_data_cache.dry(); epoch_state_collected = true; } @@ -984,9 +970,9 @@ void ServerController::doll_sync(real_t p_delta) { peers[i].batch_size = 0; // Send the data - node->rpc_unreliable_id( + node->rpc_id( peers[i].peer, - NetworkedController::sn_rpc_doll_send_epoch_batch, + SNAME("_rpc_doll_send_epoch_batch"), data); } } @@ -1051,9 +1037,9 @@ void ServerController::adjust_player_tick_rate(real_t p_delta) { Vector packet_data; packet_data.push_back(new_speed); - node->rpc_unreliable_id( + node->rpc_id( node->get_network_master(), - NetworkedController::sn_rpc_send_tick_additional_speed, + SNAME("_rpc_send_tick_additional_speed"), packet_data); } } @@ -1088,7 +1074,7 @@ void PlayerController::process(real_t p_delta) { node->get_inputs_buffer_mut().begin_write(METADATA_SIZE); node->get_inputs_buffer_mut().seek(1); - node->call(NetworkedController::sn_collect_inputs, p_delta, &node->get_inputs_buffer_mut()); + node->call(SNAME("_collect_inputs"), p_delta, &node->get_inputs_buffer_mut()); // Set metadata data. node->get_inputs_buffer_mut().seek(0); @@ -1108,7 +1094,7 @@ void PlayerController::process(real_t p_delta) { // The physics process is always emitted, because we still need to simulate // the character motion even if we don't store the player inputs. - node->call(NetworkedController::sn_controller_process, p_delta, &node->get_inputs_buffer()); + node->call(SNAME("_controller_process"), p_delta, &node->get_inputs_buffer()); node->player_set_has_new_input(false); if (accept_new_inputs) { @@ -1193,7 +1179,7 @@ bool PlayerController::process_instant(int p_i, real_t p_delta) { ib.shrink_to(METADATA_SIZE, frames_snapshot[i].buffer_size_bit - METADATA_SIZE); ib.begin_read(); ib.seek(METADATA_SIZE); - node->call(NetworkedController::sn_controller_process, p_delta, &ib); + node->call(SNAME("_controller_process"), p_delta, &ib); return (i + 1) < frames_snapshot.size(); } else { return false; @@ -1268,7 +1254,7 @@ void PlayerController::send_frame_input_buffer_to_server() { pir_B.begin_read(); pir_B.seek(METADATA_SIZE); - const bool are_different = node->call(NetworkedController::sn_are_inputs_different, &pir_A, &pir_B); + const bool are_different = node->call(SNAME("_are_inputs_different"), &pir_A, &pir_B); is_similar = are_different == false; } else if (frames_snapshot[i].similarity == previous_input_similarity) { @@ -1342,9 +1328,9 @@ void PlayerController::send_frame_input_buffer_to_server() { ofs); const int server_peer_id = 1; - node->rpc_unreliable_id( + node->rpc_id( server_peer_id, - NetworkedController::sn_rpc_server_send_inputs, + SNAME("_rpc_server_send_inputs"), packet_data); } @@ -1360,7 +1346,7 @@ DollController::DollController(NetworkedController *p_node) : void DollController::ready() { interpolator.reset(); node->call( - NetworkedController::sn_setup_interpolator, + SNAME("_setup_interpolator"), &interpolator); interpolator.terminate_init(); } @@ -1375,7 +1361,7 @@ void DollController::process(real_t p_delta) { const real_t fractional_part = advancing_epoch; node->call( - NetworkedController::sn_apply_epoch, + SNAME("_apply_epoch"), p_delta, interpolator.pop_epoch(frame_epoch, fractional_part)); } @@ -1453,7 +1439,7 @@ void DollController::receive_batch(const Vector &p_data) { net_poorness); // TODO cache this? - const double frames_per_batch = node->get_doll_epoch_batch_sync_rate() * real_t(Engine::get_singleton()->get_iterations_per_second()); + const double frames_per_batch = node->get_doll_epoch_batch_sync_rate() * real_t(Engine::get_singleton()->get_physics_ticks_per_second()); const double next_batch_arrives_in = Math::ceil(double(next_collect_rate) / frames_per_batch) * frames_per_batch; const real_t doll_interpolation_max_speedup = node->get_doll_interpolation_max_speedup(); @@ -1480,7 +1466,7 @@ uint32_t DollController::receive_epoch(const Vector &p_data) { } interpolator.begin_write(epoch); - node->call(NetworkedController::sn_parse_epoch_data, &interpolator, &buffer); + node->call(SNAME("_parse_epoch_data"), &interpolator, &buffer); interpolator.end_write(); return epoch; @@ -1573,10 +1559,10 @@ NoNetController::NoNetController(NetworkedController *p_node) : void NoNetController::process(real_t p_delta) { node->get_inputs_buffer_mut().begin_write(0); // No need of meta in this case. - node->call(NetworkedController::sn_collect_inputs, p_delta, &node->get_inputs_buffer_mut()); + node->call(SNAME("_collect_inputs"), p_delta, &node->get_inputs_buffer_mut()); node->get_inputs_buffer_mut().dry(); node->get_inputs_buffer_mut().begin_read(); - node->call(NetworkedController::sn_controller_process, p_delta, &node->get_inputs_buffer_mut()); + node->call(SNAME("_controller_process"), p_delta, &node->get_inputs_buffer_mut()); frame_id += 1; } diff --git a/modules/network_synchronizer/networked_controller.h b/modules/network_synchronizer/networked_controller.h index 7cb268b7d0e4..f14bd454c28f 100644 --- a/modules/network_synchronizer/networked_controller.h +++ b/modules/network_synchronizer/networked_controller.h @@ -81,20 +81,6 @@ class NetworkedController : public Node { CONTROLLER_TYPE_DOLL }; - static StringName sn_rpc_server_send_inputs; - static StringName sn_rpc_send_tick_additional_speed; - static StringName sn_rpc_doll_notify_sync_pause; - static StringName sn_rpc_doll_send_epoch_batch; - - static StringName sn_controller_process; - static StringName sn_count_input_size; - static StringName sn_are_inputs_different; - static StringName sn_collect_epoch_data; - static StringName sn_collect_inputs; - static StringName sn_setup_interpolator; - static StringName sn_parse_epoch_data; - static StringName sn_apply_epoch; - private: /// The input storage size is used to cap the amount of inputs collected by /// the `PlayerController`. diff --git a/modules/network_synchronizer/register_types.cpp b/modules/network_synchronizer/register_types.cpp index 7237a3e68fe6..1b591b440c9d 100644 --- a/modules/network_synchronizer/register_types.cpp +++ b/modules/network_synchronizer/register_types.cpp @@ -41,44 +41,15 @@ #include "scene_synchronizer.h" void register_network_synchronizer_types() { - NetworkedController::sn_rpc_server_send_inputs = "_rpc_server_send_inputs"; - NetworkedController::sn_rpc_send_tick_additional_speed = "_rpc_send_tick_additional_speed"; - NetworkedController::sn_rpc_doll_notify_sync_pause = "_rpc_doll_notify_sync_pause"; - NetworkedController::sn_rpc_doll_send_epoch_batch = "_rpc_doll_send_epoch_batch"; - - NetworkedController::sn_controller_process = "controller_process"; - NetworkedController::sn_count_input_size = "count_input_size"; - NetworkedController::sn_are_inputs_different = "are_inputs_different"; - NetworkedController::sn_collect_epoch_data = "collect_epoch_data"; - NetworkedController::sn_collect_inputs = "collect_inputs"; - NetworkedController::sn_setup_interpolator = "setup_interpolator"; - NetworkedController::sn_parse_epoch_data = "parse_epoch_data"; - NetworkedController::sn_apply_epoch = "apply_epoch"; - - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); + GDREGISTER_CLASS(DataBuffer); + GDREGISTER_CLASS(SceneDiff); + GDREGISTER_CLASS(Interpolator); + GDREGISTER_CLASS(NetworkedController); + GDREGISTER_CLASS(SceneSynchronizer); GLOBAL_DEF("NetworkSynchronizer/debug_server_speedup", false); GLOBAL_DEF("NetworkSynchronizer/debug_doll_speedup", false); } void unregister_network_synchronizer_types() { - // Cleanup the used `StringName` here so to avoid that the destructor is - // called too late. - NetworkedController::sn_rpc_server_send_inputs = StringName(); - NetworkedController::sn_rpc_send_tick_additional_speed = StringName(); - NetworkedController::sn_rpc_doll_notify_sync_pause = StringName(); - NetworkedController::sn_rpc_doll_send_epoch_batch = StringName(); - - NetworkedController::sn_controller_process = StringName(); - NetworkedController::sn_count_input_size = StringName(); - NetworkedController::sn_are_inputs_different = StringName(); - NetworkedController::sn_collect_epoch_data = StringName(); - NetworkedController::sn_collect_inputs = StringName(); - NetworkedController::sn_setup_interpolator = StringName(); - NetworkedController::sn_parse_epoch_data = StringName(); - NetworkedController::sn_apply_epoch = StringName(); } diff --git a/modules/network_synchronizer/scene_synchronizer.cpp b/modules/network_synchronizer/scene_synchronizer.cpp index 1d079073b91b..6433757b9835 100644 --- a/modules/network_synchronizer/scene_synchronizer.cpp +++ b/modules/network_synchronizer/scene_synchronizer.cpp @@ -39,14 +39,14 @@ #include "scene_diff.h" void SceneSynchronizer::_bind_methods() { - BIND_CONSTANT(CHANGE) - BIND_CONSTANT(SYNC_RECOVER) - BIND_CONSTANT(SYNC_RESET) - BIND_CONSTANT(SYNC_REWIND) - BIND_CONSTANT(END_SYNC) - BIND_CONSTANT(DEFAULT) - BIND_CONSTANT(SYNC) - BIND_CONSTANT(ALWAYS) + BIND_ENUM_CONSTANT(CHANGE) + BIND_ENUM_CONSTANT(SYNC_RECOVER) + BIND_ENUM_CONSTANT(SYNC_RESET) + BIND_ENUM_CONSTANT(SYNC_REWIND) + BIND_ENUM_CONSTANT(END_SYNC) + BIND_ENUM_CONSTANT(DEFAULT) + BIND_ENUM_CONSTANT(SYNC) + BIND_ENUM_CONSTANT(ALWAYS) ClassDB::bind_method(D_METHOD("reset_synchronizer_mode"), &SceneSynchronizer::reset_synchronizer_mode); ClassDB::bind_method(D_METHOD("clear"), &SceneSynchronizer::clear); @@ -145,17 +145,17 @@ void SceneSynchronizer::_notification(int p_what) { clear(); reset_synchronizer_mode(); - get_multiplayer()->connect("network_peer_connected", Callable(this, "_on_peer_connected")); - get_multiplayer()->connect("network_peer_disconnected", Callable(this, "_on_peer_disconnected")); + get_multiplayer()->connect(SNAME("network_peer_connected"), Callable(this, SNAME("_on_peer_connected"))); + get_multiplayer()->connect(SNAME("network_peer_disconnected"), Callable(this, SNAME("_on_peer_disconnected"))); - get_tree()->connect("node_removed", Callable(this, "_on_node_removed")); + get_tree()->connect(SNAME("node_removed"), Callable(this, SNAME("_on_node_removed"))); // Make sure to reset all the assigned controllers. reset_controllers(); // Init the peers already connected. - if (get_tree()->get_network_peer().is_valid()) { - const Vector peer_ids = get_tree()->get_network_connected_peers(); + if (get_tree()->get_multiplayer()->get_network_peer().is_valid()) { + const Vector peer_ids = get_tree()->get_multiplayer()->get_network_connected_peers(); const int *peer_ids_ptr = peer_ids.ptr(); for (int i = 0; i < peer_ids.size(); i += 1) { _on_peer_connected(peer_ids_ptr[i]); @@ -169,10 +169,10 @@ void SceneSynchronizer::_notification(int p_what) { clear_peers(); - get_multiplayer()->disconnect("network_peer_connected", Callable(this, "_on_peer_connected")); - get_multiplayer()->disconnect("network_peer_disconnected", Callable(this, "_on_peer_disconnected")); + get_multiplayer()->disconnect(SNAME("network_peer_connected"), Callable(this, SNAME("_on_peer_connected"))); + get_multiplayer()->disconnect(SNAME("network_peer_disconnected"), Callable(this, SNAME("_on_peer_disconnected"))); - get_tree()->disconnect("node_removed", Callable(this, "_on_node_removed")); + get_tree()->disconnect(SNAME("node_removed"), Callable(this, SNAME("_on_node_removed"))); clear(); @@ -191,10 +191,10 @@ void SceneSynchronizer::_notification(int p_what) { } SceneSynchronizer::SceneSynchronizer() { - rpc_config("_rpc_send_state", MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config("_rpc_notify_need_full_snapshot", MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config("_rpc_set_network_enabled", MultiplayerAPI::RPC_MODE_REMOTE); - rpc_config("_rpc_notify_peer_status", MultiplayerAPI::RPC_MODE_REMOTE); + rpc_config(SNAME("_rpc_send_state"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_RELIABLE); + rpc_config(SNAME("_rpc_notify_need_full_snapshot"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_RELIABLE); + rpc_config(SNAME("_rpc_set_network_enabled"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_RELIABLE); + rpc_config(SNAME("_rpc_notify_peer_status"), MultiplayerAPI::RPC_MODE_REMOTE, MultiplayerPeer::TRANSFER_MODE_RELIABLE); // Avoid too much useless re-allocations. event_listener.reserve(100); @@ -638,7 +638,7 @@ void SceneSynchronizer::unregister_process(Node *p_node, const StringName &p_fun } void SceneSynchronizer::start_tracking_scene_changes(Object *p_diff_handle) const { - ERR_FAIL_COND_MSG(get_tree()->is_network_server() == false, "This function is supposed to be called only on server."); + ERR_FAIL_COND_MSG(get_tree()->get_multiplayer()->is_network_server() == false, "This function is supposed to be called only on server."); SceneDiff *diff = Object::cast_to(p_diff_handle); ERR_FAIL_COND_MSG(diff == nullptr, "The object is not a SceneDiff class."); @@ -646,7 +646,7 @@ void SceneSynchronizer::start_tracking_scene_changes(Object *p_diff_handle) cons } void SceneSynchronizer::stop_tracking_scene_changes(Object *p_diff_handle) const { - ERR_FAIL_COND_MSG(get_tree()->is_network_server() == false, "This function is supposed to be called only on server."); + ERR_FAIL_COND_MSG(get_tree()->get_multiplayer()->is_network_server() == false, "This function is supposed to be called only on server."); SceneDiff *diff = Object::cast_to(p_diff_handle); ERR_FAIL_COND_MSG(diff == nullptr, "The object is not a SceneDiff class."); @@ -781,7 +781,7 @@ void SceneSynchronizer::dirty_peers() { void SceneSynchronizer::set_enabled(bool p_enable) { ERR_FAIL_COND_MSG(synchronizer_type == SYNCHRONIZER_TYPE_SERVER, "The server is always enabled."); if (synchronizer_type == SYNCHRONIZER_TYPE_CLIENT) { - rpc_id(1, "_rpc_set_network_enabled", p_enable); + rpc_id(1, SNAME("_rpc_set_network_enabled"), p_enable); if (p_enable == false) { // If the peer want to disable, we can disable it locally // immediately. When it wants to enable the networking, the server @@ -825,7 +825,7 @@ void SceneSynchronizer::set_peer_networking_enable(int p_peer, bool p_enable) { dirty_peers(); // Just notify the peer status. - rpc_id(p_peer, "_rpc_notify_peer_status", p_enable); + rpc_id(p_peer, SNAME("_rpc_notify_peer_status"), p_enable); } else { ERR_FAIL_COND_MSG(synchronizer_type != SYNCHRONIZER_TYPE_NONETWORK, "At this point no network is expected."); static_cast(synchronizer)->set_enabled(p_enable); @@ -880,12 +880,12 @@ void SceneSynchronizer::reset_synchronizer_mode() { peer_ptr = get_multiplayer() == nullptr ? nullptr : get_multiplayer()->get_network_peer().ptr(); - if (get_tree() == nullptr || get_tree()->get_network_peer().is_null()) { + if (get_tree() == nullptr || get_tree()->get_multiplayer()->get_network_peer().is_null()) { synchronizer_type = SYNCHRONIZER_TYPE_NONETWORK; synchronizer = memnew(NoNetSynchronizer(this)); generate_id = true; - } else if (get_tree()->is_network_server()) { + } else if (get_tree()->get_multiplayer()->is_network_server()) { synchronizer_type = SYNCHRONIZER_TYPE_SERVER; synchronizer = memnew(ServerSynchronizer(this)); generate_id = true; @@ -1338,10 +1338,10 @@ bool SceneSynchronizer::compare(const Variant &p_first, const Variant &p_second, case Variant::VECTOR3: { return compare(Vector3(p_first), Vector3(p_second), p_tolerance); } - case Variant::QUAT: { - const Quat a = p_first; - const Quat b = p_second; - const Quat r(a - b); // Element wise subtraction. + case Variant::QUATERNION: { + const Quaternion a = p_first; + const Quaternion b = p_second; + const Quaternion r(a - b); // Element wise subtraction. return (r.x * r.x + r.y * r.y + r.z * r.z + r.w * r.w) <= (p_tolerance * p_tolerance); } case Variant::PLANE: { @@ -1376,9 +1376,9 @@ bool SceneSynchronizer::compare(const Variant &p_first, const Variant &p_second, } return false; } - case Variant::TRANSFORM: { - const Transform a = p_first; - const Transform b = p_second; + case Variant::TRANSFORM3D: { + const Transform3D a = p_first; + const Transform3D b = p_second; if (compare(a.origin, b.origin, p_tolerance)) { if (compare(a.basis.elements[0], b.basis.elements[0], p_tolerance)) { if (compare(a.basis.elements[1], b.basis.elements[1], p_tolerance)) { @@ -1572,10 +1572,10 @@ void SceneSynchronizer::reset_controller(NetUtility::NodeData *p_controller_nd) return; } - if (get_tree()->get_network_peer().is_null()) { + if (get_tree()->get_multiplayer()->get_network_peer().is_null()) { controller->controller_type = NetworkedController::CONTROLLER_TYPE_NONETWORK; controller->controller = memnew(NoNetController(controller)); - } else if (get_tree()->is_network_server()) { + } else if (get_tree()->get_multiplayer()->is_network_server()) { controller->controller_type = NetworkedController::CONTROLLER_TYPE_SERVER; controller->controller = memnew(ServerController(controller, controller->get_network_traced_frames())); } else if (controller->is_network_master()) { @@ -1832,7 +1832,7 @@ void ServerSynchronizer::process_snapshot_notificator(real_t p_delta) { } controller->get_server_controller()->notify_send_state(); - scene_synchronizer->rpc_id(*peer_it.key, "_rpc_send_state", snap); + scene_synchronizer->rpc_id(*peer_it.key, SNAME("_rpc_send_state"), snap); } if (notify_state) { @@ -2001,11 +2001,11 @@ void ClientSynchronizer::process() { } const real_t delta = scene_synchronizer->get_physics_process_delta_time(); - const real_t iteration_per_second = Engine::get_singleton()->get_iterations_per_second(); + const real_t physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second(); #ifdef DEBUG_ENABLED - if (unlikely(Engine::get_singleton()->get_frames_per_second() < iteration_per_second)) { - WARN_PRINT("Current FPS is " + itos(Engine::get_singleton()->get_frames_per_second()) + ", but the minimum required FPS is " + itos(iteration_per_second) + ", the client is unable to generate enough inputs for the server."); + if (unlikely(Engine::get_singleton()->get_frames_per_second() < physics_ticks_per_second)) { + WARN_PRINT("Current FPS is " + itos(Engine::get_singleton()->get_frames_per_second()) + ", but the minimum required FPS is " + itos(physics_ticks_per_second) + ", the client is unable to generate enough inputs for the server."); } #endif @@ -2026,7 +2026,7 @@ void ClientSynchronizer::process() { // // The dolls may want to speed up too, so to consume the inputs faster // and get back in time with the server. - int sub_ticks = player_controller->calculates_sub_ticks(delta, iteration_per_second); + int sub_ticks = player_controller->calculates_sub_ticks(delta, physics_ticks_per_second); while (sub_ticks > 0) { // Process the scene. @@ -3048,5 +3048,5 @@ void ClientSynchronizer::notify_server_full_snapshot_is_needed() { // Notify the server that a full snapshot is needed. need_full_snapshot_notified = true; - scene_synchronizer->rpc_id(1, "_rpc_notify_need_full_snapshot"); + scene_synchronizer->rpc_id(1, SNAME("_rpc_notify_need_full_snapshot")); }