From 347bed8be55d1536860d04f2e6d6cf297b4e6710 Mon Sep 17 00:00:00 2001 From: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com> Date: Tue, 2 Jul 2024 22:16:18 -0700 Subject: [PATCH] Make camera recoil system only refresh offset when its values change (#29673) --- Content.Shared/Camera/CameraRecoilComponent.cs | 1 + Content.Shared/Camera/SharedCameraRecoilSystem.cs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) 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); } } -- 2.51.2