]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make camera recoil system only refresh offset when its values change (#29673)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Wed, 3 Jul 2024 05:16:18 +0000 (22:16 -0700)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 05:16:18 +0000 (15:16 +1000)
Content.Shared/Camera/CameraRecoilComponent.cs
Content.Shared/Camera/SharedCameraRecoilSystem.cs

index 5d615f87bef46d71ab0610cf4f7619c4a96e11e7..8b8b290845e03964d26288d32ec02a2c4d83059a 100644 (file)
@@ -8,6 +8,7 @@ namespace Content.Shared.Camera;
 public sealed partial class CameraRecoilComponent : Component
 {
     public Vector2 CurrentKick { get; set; }
+    public Vector2 LastKick { get; set; }
     public float LastKickTime { get; set; }
 
     /// <summary>
index d42fe9dceeea373122415ef699a3363a9ac17540..5ba97dabe2cb68f41e51df6bb32d07037d93427a 100644 (file)
@@ -1,5 +1,4 @@
 using System.Numerics;
-using Content.Shared.Movement.Systems;
 using JetBrains.Annotations;
 using Robust.Shared.Network;
 using Robust.Shared.Serialization;
@@ -29,7 +28,7 @@ public abstract class SharedCameraRecoilSystem : EntitySystem
     /// </summary>
     protected const float KickMagnitudeMax = 1f;
 
-    [Dependency] private readonly SharedContentEyeSystem _eye = default!;
+    [Dependency] private readonly SharedEyeSystem _eye = default!;
     [Dependency] private readonly INetManager _net = default!;
 
     public override void Initialize()
@@ -61,7 +60,6 @@ public abstract class SharedCameraRecoilSystem : EntitySystem
             if (magnitude <= 0.005f)
             {
                 recoil.CurrentKick = Vector2.Zero;
-                _eye.UpdateEyeOffset((uid, eye));
             }
             else // Continually restore camera to 0.
             {
@@ -77,8 +75,15 @@ public abstract class SharedCameraRecoilSystem : EntitySystem
                     y = 0;
 
                 recoil.CurrentKick = new Vector2(x, y);
-                _eye.UpdateEyeOffset((uid, eye));
             }
+
+            if (recoil.CurrentKick == recoil.LastKick)
+                continue;
+
+            recoil.LastKick = recoil.CurrentKick;
+            var ev = new GetEyeOffsetEvent();
+            RaiseLocalEvent(uid, ref ev);
+            _eye.SetOffset(uid, ev.Offset, eye);
         }
     }