From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Wed, 3 Jul 2024 05:16:18 +0000 (-0700) Subject: Make camera recoil system only refresh offset when its values change (#29673) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=347bed8be55d1536860d04f2e6d6cf297b4e6710;p=space-station-14.git Make camera recoil system only refresh offset when its values change (#29673) --- diff --git a/Content.Shared/Camera/CameraRecoilComponent.cs b/Content.Shared/Camera/CameraRecoilComponent.cs index 5d615f87be..8b8b290845 100644 --- a/Content.Shared/Camera/CameraRecoilComponent.cs +++ b/Content.Shared/Camera/CameraRecoilComponent.cs @@ -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; } /// diff --git a/Content.Shared/Camera/SharedCameraRecoilSystem.cs b/Content.Shared/Camera/SharedCameraRecoilSystem.cs index d42fe9dcee..5ba97dabe2 100644 --- a/Content.Shared/Camera/SharedCameraRecoilSystem.cs +++ b/Content.Shared/Camera/SharedCameraRecoilSystem.cs @@ -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 /// 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); } }