From: Tayrtahn Date: Sun, 2 Feb 2025 01:38:02 +0000 (-0500) Subject: Ghost orbit jitter fix (#34797) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=a238f71540c0a509cd26b6bdb76857fd846317e7;p=space-station-14.git Ghost orbit jitter fix (#34797) * 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 versions --- diff --git a/Content.Client/Orbit/OrbitVisualsSystem.cs b/Content.Client/Orbit/OrbitVisualsSystem.cs index 1799e8ecc8..1bcebd07b7 100644 --- a/Content.Client/Orbit/OrbitVisualsSystem.cs +++ b/Content.Client/Orbit/OrbitVisualsSystem.cs @@ -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(OnComponentInit); SubscribeLocalEvent(OnComponentRemove); - SubscribeLocalEvent(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(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(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()) { - 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; diff --git a/Content.Shared/Follower/Components/OrbitVisualsComponent.cs b/Content.Shared/Follower/Components/OrbitVisualsComponent.cs index a1ee17c27f..47ea0a523f 100644 --- a/Content.Shared/Follower/Components/OrbitVisualsComponent.cs +++ b/Content.Shared/Follower/Components/OrbitVisualsComponent.cs @@ -21,10 +21,4 @@ public sealed partial class OrbitVisualsComponent : Component /// How long should the orbit stop animation last in seconds? /// public float OrbitStopLength = 1.0f; - - /// - /// How far along in the orbit, from 0 to 1, is this entity? - /// - [Animatable] - public float Orbit { get; set; } = 0.0f; }