Make camera recoil system only refresh offset when its values change (#29673)

This commit is contained in:
DrSmugleaf
2024-07-02 22:16:18 -07:00
committed by GitHub
parent c6d718d126
commit 347bed8be5
2 changed files with 10 additions and 4 deletions

View 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>

View 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);
}
}