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<T> versions
This commit is contained in:
@@ -4,6 +4,7 @@ using Robust.Client.Animations;
|
|||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared.Animations;
|
using Robust.Shared.Animations;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Client.Orbit;
|
namespace Content.Client.Orbit;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ public sealed class OrbitVisualsSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
[Dependency] private readonly AnimationPlayerSystem _animations = default!;
|
[Dependency] private readonly AnimationPlayerSystem _animations = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
|
||||||
private readonly string _orbitAnimationKey = "orbiting";
|
|
||||||
private readonly string _orbitStopKey = "orbiting_stop";
|
private readonly string _orbitStopKey = "orbiting_stop";
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -21,11 +22,11 @@ public sealed class OrbitVisualsSystem : EntitySystem
|
|||||||
|
|
||||||
SubscribeLocalEvent<OrbitVisualsComponent, ComponentInit>(OnComponentInit);
|
SubscribeLocalEvent<OrbitVisualsComponent, ComponentInit>(OnComponentInit);
|
||||||
SubscribeLocalEvent<OrbitVisualsComponent, ComponentRemove>(OnComponentRemove);
|
SubscribeLocalEvent<OrbitVisualsComponent, ComponentRemove>(OnComponentRemove);
|
||||||
SubscribeLocalEvent<OrbitVisualsComponent, AnimationCompletedEvent>(OnAnimationCompleted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnComponentInit(EntityUid uid, OrbitVisualsComponent component, ComponentInit args)
|
private void OnComponentInit(EntityUid uid, OrbitVisualsComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
|
_robustRandom.SetSeed((int)_timing.CurTime.TotalMilliseconds);
|
||||||
component.OrbitDistance =
|
component.OrbitDistance =
|
||||||
_robustRandom.NextFloat(0.75f * component.OrbitDistance, 1.25f * 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);
|
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
||||||
if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
|
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)
|
private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args)
|
||||||
@@ -57,14 +53,9 @@ public sealed class OrbitVisualsSystem : EntitySystem
|
|||||||
sprite.EnableDirectionOverride = false;
|
sprite.EnableDirectionOverride = false;
|
||||||
|
|
||||||
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
||||||
if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
|
|
||||||
{
|
|
||||||
_animations.Stop(uid, animationPlayer, _orbitAnimationKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
|
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>())
|
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));
|
var vec = angle.RotateVec(new Vector2(orbit.OrbitDistance, 0));
|
||||||
|
|
||||||
sprite.Rotation = angle;
|
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)
|
private Animation GetStopAnimation(OrbitVisualsComponent component, SpriteComponent sprite)
|
||||||
{
|
{
|
||||||
var length = component.OrbitStopLength;
|
var length = component.OrbitStopLength;
|
||||||
|
|||||||
@@ -21,10 +21,4 @@ public sealed partial class OrbitVisualsComponent : Component
|
|||||||
/// How long should the orbit stop animation last in seconds?
|
/// How long should the orbit stop animation last in seconds?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float OrbitStopLength = 1.0f;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user