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

Excellently improve player movements in Cyclops #2154

Merged
Merged
Show file tree
Hide file tree
Changes from 14 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using HarmonyLib;
using NitroxTest.Patcher;

namespace NitroxPatcher.Patches.Dynamic;

[TestClass]
public class CyclopsSonarDisplay_NewEntityOnSonar_PatchTest
{
[TestMethod]
public void Sanity()
{
IEnumerable<CodeInstruction> originalIl = PatchTestHelper.GetInstructionsFromMethod(CyclopsSonarDisplay_NewEntityOnSonar_Patch.TARGET_METHOD);
IEnumerable<CodeInstruction> transformedIl = CyclopsSonarDisplay_NewEntityOnSonar_Patch.Transpiler(originalIl);
transformedIl.Count().Should().Be(originalIl.Count() + 3);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.HUD;
using NitroxModel.DataStructures.Util;
Expand Down Expand Up @@ -26,6 +26,7 @@ public override void Process(Disconnect disconnect)
Optional<RemotePlayer> remotePlayer = remotePlayerManager.Find(disconnect.PlayerId);
if (remotePlayer.HasValue)
{
remotePlayer.Value.PlayerDisconnectEvent.Trigger(remotePlayer.Value);
remotePlayerManager.RemovePlayer(disconnect.PlayerId);
Log.Info($"{remotePlayer.Value.PlayerName} disconnected");
Log.InGame(Language.main.Get("Nitrox_PlayerDisconnected").Replace("{PLAYER}", remotePlayer.Value.PlayerName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NitroxClient.Communication.Packets.Processors.Abstract;
using NitroxClient.GameLogic;
using NitroxModel.Packets;
using NitroxModel_Subnautica.DataStructures;

namespace NitroxClient.Communication.Packets.Processors;

public class PlayerInCyclopsMovementProcessor : ClientPacketProcessor<PlayerInCyclopsMovement>
{
private readonly PlayerManager remotePlayerManager;

public PlayerInCyclopsMovementProcessor(PlayerManager remotePlayerManager)
{
this.remotePlayerManager = remotePlayerManager;
}

public override void Process(PlayerInCyclopsMovement movement)
{
if (remotePlayerManager.TryFind(movement.PlayerId, out RemotePlayer remotePlayer) && remotePlayer.Pawn != null)
{
remotePlayer.UpdatePositionInCyclops(movement.LocalPosition.ToUnity(), movement.LocalRotation.ToUnity());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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;
using NitroxModel_Subnautica.DataStructures;

namespace NitroxClient.Communication.Packets.Processors;

Expand All @@ -20,21 +16,12 @@ public PlayerMovementProcessor(PlayerManager remotePlayerManager)

public override void Process(PlayerMovement movement)
{
Optional<RemotePlayer> remotePlayer = remotePlayerManager.Find(movement.PlayerId);
if (!remotePlayer.HasValue)
if (remotePlayerManager.TryFind(movement.PlayerId, out RemotePlayer remotePlayer))
{
return;
remotePlayer.UpdatePosition(movement.Position.ToUnity(),
movement.Velocity.ToUnity(),
movement.BodyRotation.ToUnity(),
movement.AimingRotation.ToUnity());
}

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

private IEnumerator QueueForFixedUpdate(RemotePlayer player, PlayerMovement movement)
dartasen marked this conversation as resolved.
Show resolved Hide resolved
{
yield return Yielders.WaitForFixedUpdate;
player.UpdatePosition(movement.Position.ToUnity(),
movement.Velocity.ToUnity(),
movement.BodyRotation.ToUnity(),
movement.AimingRotation.ToUnity());
}
}
1 change: 1 addition & 0 deletions NitroxClient/Debuggers/Drawer/DrawerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public DrawerManager(SceneDebugger sceneDebugger)
AddDrawer<UnityEventDrawer, UnityEvent>(unityEventDrawer);
AddDrawer<UnityEventDrawer, UnityEvent<bool>>(unityEventDrawer);
AddDrawer<AnimatorDrawer, Animator>();
AddDrawer<CharacterControllerDrawer, CharacterController>(new(vectorDrawer));

AddEditor<VectorDrawer, Vector2>(vectorDrawer);
AddEditor<VectorDrawer, Vector3>(vectorDrawer);
Expand Down
119 changes: 119 additions & 0 deletions NitroxClient/Debuggers/Drawer/Unity/CharacterControllerDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxClient.Debuggers.Drawer.Unity;

/// <summary>
/// Draws a <see cref="CharacterController"/> component on the gameobjects in the <see cref="SceneDebugger"/>
/// </summary>
public class CharacterControllerDrawer : IDrawer<CharacterController>
{
private readonly VectorDrawer vectorDrawer;
private const float LABEL_WIDTH = 120;
private const float VALUE_MAX_WIDTH = 405;

public CharacterControllerDrawer(VectorDrawer vectorDrawer)
{
Validate.NotNull(vectorDrawer);

this.vectorDrawer = vectorDrawer;
}

public void Draw(CharacterController cc)
{
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Slope Limit (°)", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.slopeLimit = NitroxGUILayout.FloatField(cc.slopeLimit, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Step Offset", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.stepOffset = NitroxGUILayout.FloatField(cc.stepOffset, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Skin Width", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.skinWidth = NitroxGUILayout.FloatField(cc.skinWidth, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Min Move Distance", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.minMoveDistance = NitroxGUILayout.FloatField(cc.minMoveDistance, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Center", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.center = vectorDrawer.Draw(cc.center);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Radius", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.radius = NitroxGUILayout.FloatField(cc.radius, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Height", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.height = NitroxGUILayout.FloatField(cc.height, VALUE_MAX_WIDTH);
}

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Velocity", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
vectorDrawer.Draw(cc.velocity);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Is Grounded", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
NitroxGUILayout.BoolField(cc.isGrounded, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Detect Collisions", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
cc.detectCollisions = NitroxGUILayout.BoolField(cc.detectCollisions, VALUE_MAX_WIDTH);
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Enable Overlap Recovery", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH + 30));
NitroxGUILayout.Separator();
cc.enableOverlapRecovery = NitroxGUILayout.BoolField(cc.enableOverlapRecovery, VALUE_MAX_WIDTH);
}
}
}
11 changes: 10 additions & 1 deletion NitroxClient/Debuggers/Drawer/Unity/RigidbodyDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NitroxModel.Helper;
using NitroxModel.Helper;
using UnityEngine;

namespace NitroxClient.Debuggers.Drawer.Unity;
Expand Down Expand Up @@ -105,5 +105,14 @@ public void Draw(Rigidbody rb)
NitroxGUILayout.Separator();
vectorDrawer.Draw(rb.angularVelocity, new VectorDrawer.DrawOptions(VALUE_MAX_WIDTH));
}

GUILayout.Space(10);

using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Detect Collisions", NitroxGUILayout.DrawerLabel, GUILayout.Width(LABEL_WIDTH));
NitroxGUILayout.Separator();
rb.detectCollisions = NitroxGUILayout.BoolField(rb.detectCollisions, NitroxGUILayout.VALUE_WIDTH);
}
}
}
2 changes: 1 addition & 1 deletion NitroxClient/Debuggers/NetworkDebugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class NetworkDebugger : BaseDebugger, INetworkDebugger
{
nameof(PlayerMovement), nameof(EntityTransformUpdates), nameof(PlayerStats), nameof(SpawnEntities), nameof(VehicleMovement), nameof(PlayerCinematicControllerCall),
nameof(FMODAssetPacket), nameof(FMODEventInstancePacket), nameof(FMODCustomEmitterPacket), nameof(FMODStudioEmitterPacket), nameof(FMODCustomLoopingEmitterPacket),
nameof(SimulationOwnershipChange), nameof(CellVisibilityChanged)
nameof(SimulationOwnershipChange), nameof(CellVisibilityChanged), nameof(PlayerInCyclopsMovement)
};
private readonly List<PacketDebugWrapper> packets = new List<PacketDebugWrapper>(PACKET_STORED_COUNT);

Expand Down
Loading