Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Movement Overhaul #2073

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ resharper_wrap_object_and_collection_initializer_style = chop_if_long
[*.{proj, csproj, targets}]
indent_size = 4
insert_final_newline = true
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_code_quality_unused_parameters = all:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent

[App.config]
indent_size = 4
Expand All @@ -21,6 +53,54 @@ insert_final_newline = true
indent_size = 4
insert_final_newline = true
charset = utf-8
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_indent_labels = one_less_than_current
csharp_style_throw_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
csharp_prefer_static_local_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:silent
csharp_space_around_binary_operators = before_and_after

[*.g.cs]
generated_code = true
Expand Down
2 changes: 1 addition & 1 deletion Nitrox.Analyzers/Diagnostics/EnumeratorUsageAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
Expand Down
12 changes: 2 additions & 10 deletions Nitrox.Test/Client/Communication/DeferredPacketReceiverTest.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nitrox.Test.Client.Communication;
using NitroxClient.Map;
using NitroxModel.DataStructures.GameLogic;
using NitroxModel.DataStructures.Unity;
using NitroxModel.Packets;

namespace NitroxClient.Communication;

[TestClass]
public class DeferredPacketReceiverTest
{
private readonly VisibleCells visibleCells = new();
private PacketReceiver packetReceiver;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private PacketReceiver packetReceiver;
private readonly PacketReceiver packetReceiver = new();


// Test Data
private const ushort PLAYER_ID = 1;
private const int CELL_LEVEL = 3;
private readonly NitroxVector3 loadedActionPosition = new(50, 50, 50);
private AbsoluteEntityCell loadedCell;

[TestInitialize]
public void TestInitialize()
{
packetReceiver = new PacketReceiver();
loadedCell = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
visibleCells.Add(loadedCell);
ClientAutoFacRegistrar registrar = new ClientAutoFacRegistrar();
}
Comment on lines 15 to 20
Copy link
Member

@Jannify Jannify Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method can be completely removed.


[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -13,7 +13,7 @@ namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
public class DisconnectedStateTests
{
[TestMethod]
public void NegotiateShouldStartTheClientOnTheContext()
public async Task NegotiateShouldStartTheClientOnTheContext()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -29,14 +29,14 @@ public void NegotiateShouldStartTheClientOnTheContext()
Disconnected connectionState = new Disconnected();
killzoms marked this conversation as resolved.
Show resolved Hide resolved

// Act
connectionState.NegotiateReservationAsync(connectionContext);
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
serverClient.IsConnected.Should().BeTrue();
}

[TestMethod]
public void NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
public async Task NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -52,14 +52,14 @@ public void NegotiateShouldSendMultiplayerSessionPolicyRequestPacketToClient()
Disconnected connectionState = new Disconnected();

// Act
connectionState.NegotiateReservationAsync(connectionContext);
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
serverClient.Received().Send(Arg.Any<MultiplayerSessionPolicyRequest>());
}

[TestMethod]
public void NegotiateShouldTransitionToEstablishingSessionPolicyState()
public async Task NegotiateShouldTransitionToEstablishingSessionPolicyState()
{
// Arrange
IClient serverClient = Substitute.For<IClient>();
Expand All @@ -75,7 +75,7 @@ public void NegotiateShouldTransitionToEstablishingSessionPolicyState()
Disconnected connectionState = new Disconnected();

// Act
connectionState.NegotiateReservationAsync(connectionContext);
await connectionState.NegotiateReservationAsync(connectionContext);

// Assert
connectionContext.Received().UpdateConnectionState(Arg.Any<EstablishingSessionPolicy>());
Expand Down
1 change: 0 additions & 1 deletion Nitrox.Test/Helper/Faker/NitroxAutoFaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using BinaryPack.Attributes;
using NitroxModel.Logger;

namespace Nitrox.Test.Helper.Faker;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Linq;
using FluentAssertions;
using HarmonyLib;
Expand Down
1 change: 0 additions & 1 deletion Nitrox.Test/Server/Serialization/WorldPersistenceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nitrox.Test;
using Nitrox.Test.Helper;
using Nitrox.Test.Helper.Faker;
using NitroxModel.Core;
using NitroxModel.DataStructures.GameLogic;
Expand Down
14 changes: 6 additions & 8 deletions NitroxClient/ClientAutoFacRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using NitroxClient.Communication.MultiplayerSession;
using NitroxClient.Communication.NetworkingLayer.LiteNetLib;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.Debuggers;
using NitroxClient.Debuggers.Drawer;
killzoms marked this conversation as resolved.
Show resolved Hide resolved
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.ChatUI;
using NitroxClient.GameLogic.FMOD;
Expand Down Expand Up @@ -58,20 +56,20 @@ private static void RegisterCoreDependencies(ContainerBuilder containerBuilder)
{
#if DEBUG
containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<BaseDebugger>()
.As<BaseDebugger>()
.AssignableTo<Debuggers.BaseDebugger>()
.As<Debuggers.BaseDebugger>()
.AsImplementedInterfaces()
.AsSelf()
.SingleInstance();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<IDrawer>()
.As<IDrawer>()
.AssignableTo<Debuggers.Drawer.IDrawer>()
.As<Debuggers.Drawer.IDrawer>()
.SingleInstance();

containerBuilder.RegisterAssemblyTypes(currentAssembly)
.AssignableTo<IStructDrawer>()
.As<IStructDrawer>()
.AssignableTo<Debuggers.Drawer.IStructDrawer>()
.As<Debuggers.Drawer.IStructDrawer>()
.SingleInstance();
#endif
containerBuilder.Register(c => new NitroxProtobufSerializer($"{nameof(NitroxModel)}.dll"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.MultiplayerSession.ConnectionState;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.MonoBehaviours;
using NitroxModel.Packets;
using NitroxModel_Subnautica.DataStructures;
using UnityEngine;

namespace NitroxClient.Communication.Packets.Processors;

public class BasicMovementProcessor : ClientPacketProcessor<BasicMovement>
{
public override void Process(BasicMovement movement)
{
if (!MultiplayerMovementController.TryGetMovementControllerFrom(movement.Id, out MultiplayerMovementController mc) &&
NitroxEntity.TryGetObjectFrom(movement.Id, out GameObject gameObject))
{
mc = gameObject.EnsureComponent<MultiplayerMovementController>();
}

if (mc)
{
mc.TargetPosition = movement.Position.ToUnity();
mc.TargetRotation = movement.Rotation.ToUnity();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures.Util;
using NitroxModel.Packets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
using NitroxClient.Unity.Helper;
using NitroxModel_Subnautica.DataStructures;
using NitroxModel.DataStructures.Util;
using NitroxModel.Packets;
Expand All @@ -20,21 +17,14 @@ public PlayerMovementProcessor(PlayerManager remotePlayerManager)

public override void Process(PlayerMovement movement)
{
Optional<RemotePlayer> remotePlayer = remotePlayerManager.Find(movement.PlayerId);
Optional<RemotePlayer> remotePlayer = remotePlayerManager.Find(movement.Id);
if (!remotePlayer.HasValue)
{
return;
}

Multiplayer.Main.StartCoroutine(QueueForFixedUpdate(remotePlayer.Value, movement));
}

private IEnumerator QueueForFixedUpdate(RemotePlayer player, PlayerMovement movement)
{
yield return Yielders.WaitForFixedUpdate;
player.UpdatePosition(movement.Position.ToUnity(),
movement.Velocity.ToUnity(),
movement.BodyRotation.ToUnity(),
remotePlayer.Value.UpdatePosition(movement.Position.ToUnity(),
movement.Rotation.ToUnity(),
movement.AimingRotation.ToUnity());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxClient.MonoBehaviours;
using NitroxModel.DataStructures;
using NitroxModel.DataStructures.Util;
using NitroxModel.Packets;
using UnityEngine;

Expand Down Expand Up @@ -37,17 +36,27 @@ public override void Process(SimulationOwnershipResponse response)
{
RemoveRemoteController(response.Id);
}

SwapMovementController(response.Id, response.LockAcquired);
}

private void RemoveRemoteController(NitroxId id)
{
Optional<GameObject> gameObject = NitroxEntity.GetObjectFrom(id);

if (gameObject.HasValue)
if (NitroxEntity.TryGetObjectFrom(id, out GameObject gameObject))
{
RemotelyControlled remotelyControlled = gameObject.Value.GetComponent<RemotelyControlled>();
RemotelyControlled remotelyControlled = gameObject.GetComponent<RemotelyControlled>();
Object.Destroy(remotelyControlled);
}
}

private void SwapMovementController(NitroxId id, bool lockAcquired)
{
if (NitroxEntity.TryGetObjectFrom(id, out GameObject gameObject))
{
MultiplayerMovementController movementController = gameObject.EnsureComponent<MultiplayerMovementController>();
movementController.SetBroadcasting(lockAcquired);
movementController.SetReceiving(!lockAcquired);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using NitroxClient.Communication.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
Expand Down Expand Up @@ -32,7 +32,7 @@ public override void Process(VehicleDocking packet)
using (PacketSuppressor<VehicleDocking>.Suppress())
{
Log.Debug($"Set vehicle docked for {vehicleDockingBay.gameObject.name}");
vehicle.GetComponent<MultiplayerVehicleControl>().SetPositionVelocityRotation(vehicle.transform.position, Vector3.zero, vehicle.transform.rotation, Vector3.zero);
vehicle.GetComponent<MultiplayerVehicleControl>().SetPositionRotation(vehicle.transform.position, vehicle.transform.rotation);
vehicle.GetComponent<MultiplayerVehicleControl>().Exit();
}
vehicle.StartCoroutine(DelayAnimationAndDisablePiloting(vehicle, vehicleDockingBay, packet.VehicleId, packet.PlayerId));
Expand Down
Loading