From 1508f513bf883ad8047dd952a0571258c539b9a1 Mon Sep 17 00:00:00 2001 From: Psychpsyo <60073468+Psychpsyo@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:57:09 +0200 Subject: [PATCH] Jittering System Fix + Cleanup (#20921) --- Content.Client/Jittering/JitteringSystem.cs | 21 ++++++++----------- .../Jittering/SharedJitteringSystem.cs | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Content.Client/Jittering/JitteringSystem.cs b/Content.Client/Jittering/JitteringSystem.cs index 032eb3e18f..41f20634ab 100644 --- a/Content.Client/Jittering/JitteringSystem.cs +++ b/Content.Client/Jittering/JitteringSystem.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Immutable; using System.Numerics; using Content.Shared.Jittering; using Robust.Client.Animations; using Robust.Client.GameObjects; -using Robust.Shared.Animations; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Maths; using Robust.Shared.Random; namespace Content.Client.Jittering @@ -15,6 +9,7 @@ namespace Content.Client.Jittering public sealed class JitteringSystem : SharedJitteringSystem { [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!; private readonly float[] _sign = { -1, 1 }; private readonly string _jitterAnimationKey = "jittering"; @@ -35,13 +30,13 @@ namespace Content.Client.Jittering var animationPlayer = EntityManager.EnsureComponent(uid); - animationPlayer.Play(GetAnimation(jittering, sprite), _jitterAnimationKey); + _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey); } private void OnShutdown(EntityUid uid, JitteringComponent jittering, ComponentShutdown args) { if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer)) - animationPlayer.Stop(_jitterAnimationKey); + _animationPlayer.Stop(animationPlayer, _jitterAnimationKey); if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) sprite.Offset = Vector2.Zero; @@ -52,9 +47,9 @@ namespace Content.Client.Jittering if(args.Key != _jitterAnimationKey) return; - if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer) + if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer) && EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) - animationPlayer.Play(GetAnimation(jittering, sprite), _jitterAnimationKey); + _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey); } private Animation GetAnimation(JitteringComponent jittering, SpriteComponent sprite) @@ -77,8 +72,10 @@ namespace Content.Client.Jittering offset.Y *= -1; } - // Animation length shouldn't be too high so we will cap it at 2 seconds... - var length = Math.Min((1f/jittering.Frequency), 2f); + var length = 0f; + // avoid dividing by 0 so animations don't try to be infinitely long + if (jittering.Frequency > 0) + length = 1f / jittering.Frequency; jittering.LastJitter = offset; diff --git a/Content.Shared/Jittering/SharedJitteringSystem.cs b/Content.Shared/Jittering/SharedJitteringSystem.cs index 327a452175..1ac8413375 100644 --- a/Content.Shared/Jittering/SharedJitteringSystem.cs +++ b/Content.Shared/Jittering/SharedJitteringSystem.cs @@ -72,7 +72,7 @@ namespace Content.Shared.Jittering var jitter = EnsureComp(uid); jitter.Amplitude = amplitude; jitter.Frequency = frequency; - Dirty(jitter); + Dirty(uid, jitter); } } } -- 2.51.2