From 947a727920c8171c29ecd14e4e7747b05bfee5fb Mon Sep 17 00:00:00 2001 From: Roman Vasilyev Date: Sat, 11 Feb 2023 16:06:52 -0800 Subject: [PATCH 1/2] 4.0 current fixes --- networked_controller.gd | 28 ++++++++++++++-------------- world.gd | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/networked_controller.gd b/networked_controller.gd index e1da4c6..cec8b54 100644 --- a/networked_controller.gd +++ b/networked_controller.gd @@ -118,21 +118,21 @@ func _collect_epoch_data(buffer: DataBuffer): buffer.add_vector3(get_parent().mesh_container.rotation, DataBuffer.COMPRESSION_LEVEL_2) -func _setup_interpolator(interpolator: Interpolator): - # Called only on client doll to initialize the `Intepolator`. - _position_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST) - _rotation_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST) +#func _setup_interpolator(interpolator: Interpolator): +# # Called only on client doll to initialize the `Intepolator`. +# _position_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST) +# _rotation_id = interpolator.register_variable(Vector3(), Interpolator.FALLBACK_NEW_OR_NEAREST) -func _parse_epoch_data(interpolator: Interpolator, buffer: DataBuffer): - # Called locally to parse the `DataBuffer` and store the data into the `Interpolator`. - var position := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_0) - var rotation := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_2) - interpolator.epoch_insert(_position_id, position) - interpolator.epoch_insert(_rotation_id, rotation) +#func _parse_epoch_data(interpolator: Interpolator, buffer: DataBuffer): +# # Called locally to parse the `DataBuffer` and store the data into the `Interpolator`. +# var position := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_0) +# var rotation := buffer.read_vector3(DataBuffer.COMPRESSION_LEVEL_2) +# interpolator.epoch_insert(_position_id, position) +# interpolator.epoch_insert(_rotation_id, rotation) -func _apply_epoch(_delta: float, interpolated_data: Array): - # Happens only on doll client each frame. Here is necessary to apply the _already interpolated_ values. - get_parent().global_transform.origin = interpolated_data[_position_id] - get_parent().mesh_container.rotation = interpolated_data[_rotation_id] +#func _apply_epoch(_delta: float, _interpolation_alpha: float, past_buffer: DataBuffer, future_buffer: DataBuffer): +# # Happens only on doll client each frame. Here is necessary to apply the _already interpolated_ values. +# get_parent().global_transform.origin = future_buffer[_position_id] +# get_parent().mesh_container.rotation = future_buffer[_rotation_id] diff --git a/world.gd b/world.gd index f6f80cc..40550d0 100644 --- a/world.gd +++ b/world.gd @@ -80,7 +80,7 @@ func _on_client_disconnected(peer_id): rpc_id(_players[player_id][&"peer_id"], &"_remove_player", disconnected_player_id) -@rpc(call_remote, any_peer, reliable) +@rpc("call_remote", "any_peer", "reliable") func _spawn_new_player(player_id, peer_id): print("Spawn player id: ", player_id, ", Peer_id: ", peer_id) print("While my peer id is: ", get_tree().get_multiplayer().multiplayer_peer.get_unique_id()) @@ -92,7 +92,7 @@ func _spawn_new_player(player_id, peer_id): player.set_color(COLORS_LIST[player_id]) -@rpc(call_remote, any_peer, reliable) +@rpc("call_remote", "any_peer", "reliable") func _remove_player(player_id): var player_node = get_tree().get_current_scene().get_node("player_" + str(player_id)) if player_node != null: From 926d3315438499c5a2718a30cc3801a25bd17326 Mon Sep 17 00:00:00 2001 From: Roman Vasilyev Date: Sun, 12 Feb 2023 14:47:41 -0800 Subject: [PATCH 2/2] godot 4.0 current fixes --- networked_controller.gd | 5 +++-- world.tscn | 45 +++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/networked_controller.gd b/networked_controller.gd index cec8b54..d32fad9 100644 --- a/networked_controller.gd +++ b/networked_controller.gd @@ -11,7 +11,7 @@ var _rotation_id := -1 func _ready(): # Notify the NetworkSync who is controlling parent nodes. NetworkSync.set_node_as_controlled_by(get_parent(), self) - NetworkSync.register_variable(get_parent(), "translation") + NetworkSync.register_variable(get_parent(), "position") NetworkSync.register_variable(get_parent(), "velocity") NetworkSync.register_variable(get_parent(), "on_floor") if not get_tree().get_multiplayer().is_server(): @@ -132,7 +132,8 @@ func _collect_epoch_data(buffer: DataBuffer): # interpolator.epoch_insert(_rotation_id, rotation) -#func _apply_epoch(_delta: float, _interpolation_alpha: float, past_buffer: DataBuffer, future_buffer: DataBuffer): +func _apply_epoch(_delta: float, _interpolation_alpha: float, past_buffer: DataBuffer, future_buffer: DataBuffer): + pass # # Happens only on doll client each frame. Here is necessary to apply the _already interpolated_ values. # get_parent().global_transform.origin = future_buffer[_position_id] # get_parent().mesh_container.rotation = future_buffer[_rotation_id] diff --git a/world.tscn b/world.tscn index 1402e39..22e4cdb 100644 --- a/world.tscn +++ b/world.tscn @@ -29,7 +29,7 @@ volumetric_fog_density = 0.1293 [sub_resource type="BoxShape3D" id="6"] [node name="World" type="Node"] -script = ExtResource( "2" ) +script = ExtResource("2") [node name="DirectionalLight" type="DirectionalLight3D" parent="."] transform = Transform3D(-0.0134716, -0.995255, 0.0963678, -0.13779, 0.0973049, 0.98567, -0.99037, 3.38571e-08, -0.138447, 0, -5.26483, 0) @@ -41,92 +41,93 @@ collision_mask = 3 [node name="CollisionShape" type="CollisionShape3D" parent="StaticBody"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0) -shape = SubResource( "1" ) +shape = SubResource("1") disabled = true [node name="MeshInstance" type="MeshInstance3D" parent="StaticBody/CollisionShape"] -mesh = SubResource( "2" ) +mesh = SubResource("2") [node name="StaticBody" type="StaticBody3D" parent="StaticBody/CollisionShape/MeshInstance"] [node name="CollisionShape" type="CollisionShape3D" parent="StaticBody/CollisionShape/MeshInstance/StaticBody"] -shape = SubResource( "3" ) +shape = SubResource("3") [node name="ServerCamera" type="Camera3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 0, 10.6518, 37.3083) current = true [node name="Menu" type="Control" parent="."] +layout_mode = 3 +anchors_preset = 10 anchor_right = 1.0 +grow_horizontal = 2 [node name="VBoxContainer" type="VBoxContainer" parent="Menu"] +layout_mode = 0 anchor_left = 0.5 anchor_right = 0.5 [node name="ServerButton" type="Button" parent="Menu/VBoxContainer"] -offset_right = 107.0 -offset_bottom = 31.0 +layout_mode = 2 text = "Start Server" [node name="ClientButton" type="Button" parent="Menu/VBoxContainer"] -offset_top = 35.0 -offset_right = 107.0 -offset_bottom = 66.0 +layout_mode = 2 text = "Client Server" -[node name="SyncMesh" parent="." instance=ExtResource( "3" )] +[node name="SyncMesh" parent="." instance=ExtResource("3")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.12977, 0.11825, 0.354554) -[node name="SyncMesh2" parent="." instance=ExtResource( "3" )] +[node name="SyncMesh2" parent="." instance=ExtResource("3")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.21811, 0.11825, 0.46023) [node name="WorldEnvironment" type="WorldEnvironment" parent="."] -environment = SubResource( "4" ) +environment = SubResource("4") [node name="StaticBody2" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6) [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody2"] -mesh = SubResource( "5" ) +mesh = SubResource("5") [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody2"] -shape = SubResource( "6" ) +shape = SubResource("6") [node name="StaticBody3" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 11) [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody3"] -mesh = SubResource( "5" ) +mesh = SubResource("5") [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3"] -shape = SubResource( "6" ) +shape = SubResource("6") [node name="StaticBody4" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7, 0, 11) [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody4"] -mesh = SubResource( "5" ) +mesh = SubResource("5") [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody4"] -shape = SubResource( "6" ) +shape = SubResource("6") [node name="StaticBody6" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -8.57699) [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody6"] -mesh = SubResource( "5" ) +mesh = SubResource("5") [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody6"] -shape = SubResource( "6" ) +shape = SubResource("6") [node name="StaticBody5" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6, 0, 11) [node name="MeshInstance3D" type="MeshInstance3D" parent="StaticBody5"] -mesh = SubResource( "5" ) +mesh = SubResource("5") [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody5"] -shape = SubResource( "6" ) +shape = SubResource("6") [connection signal="button_up" from="Menu/VBoxContainer/ServerButton" to="." method="_start_server"] [connection signal="button_up" from="Menu/VBoxContainer/ClientButton" to="." method="_start_client"]