]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Ghost orbit jitter fix (#34797)
authorTayrtahn <tayrtahn@gmail.com>
Sun, 2 Feb 2025 01:38:02 +0000 (20:38 -0500)
committerGitHub <noreply@github.com>
Sun, 2 Feb 2025 01:38:02 +0000 (02:38 +0100)
* Only randomize orbit parameters once

* Revert "Only randomize orbit parameters once"

This reverts commit e828c51e66600bf11b66308169da1d1daf7501e3.

* Derive orbit properties from current time

* Derive orbit progress from current time

* Remove now-unused orbit animation

* Remove OrbitVisualsComponent.Orbit as it is no longer used

* Update AnimationPlayerSystem method calls to Entity<T> versions

Content.Client/Orbit/OrbitVisualsSystem.cs
Content.Shared/Follower/Components/OrbitVisualsComponent.cs

index 1799e8ecc897a294dad8fb778e03f379c96722c5..1bcebd07b7debbc420b939279ffdd204130699d5 100644 (file)
@@ -4,6 +4,7 @@ using Robust.Client.Animations;
 using Robust.Client.GameObjects;
 using Robust.Shared.Animations;
 using Robust.Shared.Random;
+using Robust.Shared.Timing;
 
 namespace Content.Client.Orbit;
 
@@ -11,8 +12,8 @@ public sealed class OrbitVisualsSystem : EntitySystem
 {
     [Dependency] private readonly IRobustRandom _robustRandom = default!;
     [Dependency] private readonly AnimationPlayerSystem _animations = default!;
+    [Dependency] private readonly IGameTiming _timing = default!;
 
-    private readonly string _orbitAnimationKey = "orbiting";
     private readonly string _orbitStopKey = "orbiting_stop";
 
     public override void Initialize()
@@ -21,11 +22,11 @@ public sealed class OrbitVisualsSystem : EntitySystem
 
         SubscribeLocalEvent<OrbitVisualsComponent, ComponentInit>(OnComponentInit);
         SubscribeLocalEvent<OrbitVisualsComponent, ComponentRemove>(OnComponentRemove);
-        SubscribeLocalEvent<OrbitVisualsComponent, AnimationCompletedEvent>(OnAnimationCompleted);
     }
 
     private void OnComponentInit(EntityUid uid, OrbitVisualsComponent component, ComponentInit args)
     {
+        _robustRandom.SetSeed((int)_timing.CurTime.TotalMilliseconds);
         component.OrbitDistance =
             _robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * component.OrbitDistance);
 
@@ -38,15 +39,10 @@ public sealed class OrbitVisualsSystem : EntitySystem
         }
 
         var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
-        if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
-            return;
-
         if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
         {
-            _animations.Stop(uid, animationPlayer, _orbitStopKey);
+            _animations.Stop((uid, animationPlayer), _orbitStopKey);
         }
-
-        _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey);
     }
 
     private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args)
@@ -57,14 +53,9 @@ public sealed class OrbitVisualsSystem : EntitySystem
         sprite.EnableDirectionOverride = false;
 
         var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
-        if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
-        {
-            _animations.Stop(uid, animationPlayer, _orbitAnimationKey);
-        }
-
         if (!_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
         {
-            _animations.Play(uid, animationPlayer, GetStopAnimation(component, sprite), _orbitStopKey);
+            _animations.Play((uid, animationPlayer), GetStopAnimation(component, sprite), _orbitStopKey);
         }
     }
 
@@ -74,7 +65,8 @@ public sealed class OrbitVisualsSystem : EntitySystem
 
         foreach (var (orbit, sprite) in EntityManager.EntityQuery<OrbitVisualsComponent, SpriteComponent>())
         {
-            var angle = new Angle(Math.PI * 2 * orbit.Orbit);
+            var progress = (float)(_timing.CurTime.TotalSeconds / orbit.OrbitLength) % 1;
+            var angle = new Angle(Math.PI * 2 * progress);
             var vec = angle.RotateVec(new Vector2(orbit.OrbitDistance, 0));
 
             sprite.Rotation = angle;
@@ -82,38 +74,6 @@ public sealed class OrbitVisualsSystem : EntitySystem
         }
     }
 
-    private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args)
-    {
-        if (args.Key == _orbitAnimationKey && TryComp(uid, out AnimationPlayerComponent? animationPlayer))
-        {
-            _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey);
-        }
-    }
-
-    private Animation GetOrbitAnimation(OrbitVisualsComponent component)
-    {
-        var length = component.OrbitLength;
-
-        return new Animation()
-        {
-            Length = TimeSpan.FromSeconds(length),
-            AnimationTracks =
-            {
-                new AnimationTrackComponentProperty()
-                {
-                    ComponentType = typeof(OrbitVisualsComponent),
-                    Property = nameof(OrbitVisualsComponent.Orbit),
-                    KeyFrames =
-                    {
-                        new AnimationTrackProperty.KeyFrame(0.0f, 0f),
-                        new AnimationTrackProperty.KeyFrame(1.0f, length),
-                    },
-                    InterpolationMode = AnimationInterpolationMode.Linear
-                }
-            }
-        };
-    }
-
     private Animation GetStopAnimation(OrbitVisualsComponent component, SpriteComponent sprite)
     {
         var length = component.OrbitStopLength;
index a1ee17c27fc925559e84eb602941f4fc374a0aa6..47ea0a523f57e5e0d55ce5c87f93202b2e6eff4d 100644 (file)
@@ -21,10 +21,4 @@ public sealed partial class OrbitVisualsComponent : Component
     ///     How long should the orbit stop animation last in seconds?
     /// </summary>
     public float OrbitStopLength = 1.0f;
-
-    /// <summary>
-    ///     How far along in the orbit, from 0 to 1, is this entity?
-    /// </summary>
-    [Animatable]
-    public float Orbit { get; set; } = 0.0f;
 }