]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix MouseRotator on rotated grids (#29663)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Tue, 2 Jul 2024 13:04:15 +0000 (15:04 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Jul 2024 13:04:15 +0000 (23:04 +1000)
* fix harm mode rotation

* cleanup

* -pi to pi

Content.Client/MouseRotator/MouseRotatorSystem.cs
Content.Shared/MouseRotator/MouseRotatorComponent.cs
Content.Shared/MouseRotator/SharedMouseRotatorSystem.cs

index ce174c6144c59647b950724e9c43aa7ca9d430d4..18d60d9a7b9d0515a2e9764b5770bf1992a63214 100644 (file)
@@ -2,7 +2,6 @@
 using Robust.Client.Graphics;
 using Robust.Client.Input;
 using Robust.Client.Player;
-using Robust.Client.Replays.Loading;
 using Robust.Shared.Map;
 using Robust.Shared.Timing;
 
@@ -46,13 +45,19 @@ public sealed class MouseRotatorSystem : SharedMouseRotatorSystem
         // only raise event if the cardinal direction has changed
         if (rotator.Simple4DirMode)
         {
-            var angleDir = angle.GetCardinalDir();
-            if (angleDir == curRot.GetCardinalDir())
+            var eyeRot = _eye.CurrentEye.Rotation; // camera rotation
+            var angleDir = (angle + eyeRot).GetCardinalDir(); // apply GetCardinalDir in the camera frame, not in the world frame
+            if (angleDir == (curRot + eyeRot).GetCardinalDir())
                 return;
 
-            RaisePredictiveEvent(new RequestMouseRotatorRotationSimpleEvent()
+            var rotation = angleDir.ToAngle() - eyeRot; // convert back to world frame
+            if (rotation >= Math.PI) // convert to [-PI, +PI)
+                rotation -= 2 * Math.PI;
+            else if (rotation < -Math.PI)
+                rotation += 2 * Math.PI;
+            RaisePredictiveEvent(new RequestMouseRotatorRotationEvent
             {
-                Direction = angleDir,
+                Rotation = rotation
             });
 
             return;
index a35dfe0a288f3982f6bb5697d4387951d4af5a97..2844b3cb8b56d971f3ed8f71aac632507c4a4a46 100644 (file)
@@ -30,8 +30,7 @@ public sealed partial class MouseRotatorComponent : Component
     public double RotationSpeed = float.MaxValue;
 
     /// <summary>
-    ///     This one is important. If this is true, <see cref="AngleTolerance"/> does not apply, and the system will
-    ///     use <see cref="RequestMouseRotatorRotationSimpleEvent"/> instead. In this mode, the client will only send
+    ///     This one is important. If this is true, <see cref="AngleTolerance"/> does not apply. In this mode, the client will only send
     ///     events when an entity should snap to a different cardinal direction, rather than for every angle change.
     ///
     ///     This is useful for cases like humans, where what really matters is the visual sprite direction, as opposed to something
@@ -50,13 +49,3 @@ public sealed class RequestMouseRotatorRotationEvent : EntityEventArgs
 {
     public Angle Rotation;
 }
-
-/// <summary>
-///     Simpler version of <see cref="RequestMouseRotatorRotationEvent"/> for implementations
-///     that only require snapping to 4-dir and not full angle rotation.
-/// </summary>
-[Serializable, NetSerializable]
-public sealed class RequestMouseRotatorRotationSimpleEvent : EntityEventArgs
-{
-    public Direction Direction;
-}
index c57d477bd2fd46873313d1273297b1c1b2a4b7cc..9663b3363d1cba82859a30657abd4149c1dc1b8f 100644 (file)
@@ -1,5 +1,4 @@
 using Content.Shared.Interaction;
-using Robust.Shared.Timing;
 
 namespace Content.Shared.MouseRotator;
 
@@ -16,7 +15,6 @@ public abstract class SharedMouseRotatorSystem : EntitySystem
         base.Initialize();
 
         SubscribeAllEvent<RequestMouseRotatorRotationEvent>(OnRequestRotation);
-        SubscribeAllEvent<RequestMouseRotatorRotationSimpleEvent>(OnRequestSimpleRotation);
     }
 
     public override void Update(float frameTime)
@@ -50,7 +48,7 @@ public abstract class SharedMouseRotatorSystem : EntitySystem
     private void OnRequestRotation(RequestMouseRotatorRotationEvent msg, EntitySessionEventArgs args)
     {
         if (args.SenderSession.AttachedEntity is not { } ent
-            || !TryComp<MouseRotatorComponent>(ent, out var rotator) || rotator.Simple4DirMode)
+            || !TryComp<MouseRotatorComponent>(ent, out var rotator))
         {
             Log.Error($"User {args.SenderSession.Name} ({args.SenderSession.UserId}) tried setting local rotation directly without a valid mouse rotator component attached!");
             return;
@@ -59,17 +57,4 @@ public abstract class SharedMouseRotatorSystem : EntitySystem
         rotator.GoalRotation = msg.Rotation;
         Dirty(ent, rotator);
     }
-
-    private void OnRequestSimpleRotation(RequestMouseRotatorRotationSimpleEvent ev, EntitySessionEventArgs args)
-    {
-        if (args.SenderSession.AttachedEntity is not { } ent
-            || !TryComp<MouseRotatorComponent>(ent, out var rotator) || !rotator.Simple4DirMode)
-        {
-            Log.Error($"User {args.SenderSession.Name} ({args.SenderSession.UserId}) tried setting 4-dir rotation directly without a valid mouse rotator component attached!");
-            return;
-        }
-
-        rotator.GoalRotation = ev.Direction.ToAngle();
-        Dirty(ent, rotator);
-    }
 }