1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Fix large instantaneous delta on first frame

Happens when the first update frame comes in before any mouse input.
This commit is contained in:
Dan Balasescu 2023-09-30 02:19:11 +09:00 committed by Dean Herbert
parent 9cd33d9bb2
commit 84be714d6b
No known key found for this signature in database

View File

@ -22,11 +22,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
private readonly DrawableSpinner drawableSpinner;
private Vector2 mousePosition;
private Vector2? mousePosition;
private float? lastAngle;
private float lastAngle;
private float currentRotation;
private bool rotationTransferred;
[Resolved(canBeNull: true)]
@ -63,17 +62,19 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
protected override void Update()
{
base.Update();
float thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(mousePosition.X - DrawSize.X / 2, mousePosition.Y - DrawSize.Y / 2));
float delta = thisAngle - lastAngle;
if (mousePosition is Vector2 pos)
{
float thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(pos.X - DrawSize.X / 2, pos.Y - DrawSize.Y / 2));
float delta = lastAngle == null ? 0 : thisAngle - lastAngle.Value;
if (Tracking)
AddRotation(delta);
if (Tracking)
AddRotation(delta);
lastAngle = thisAngle;
lastAngle = thisAngle;
}
IsSpinning.Value = isSpinnableTime && Math.Abs(currentRotation - Rotation) > 10f;
Rotation = (float)Interpolation.Damp(Rotation, currentRotation, 0.99, Math.Abs(Time.Elapsed));
}
@ -116,8 +117,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
{
Tracking = false;
IsSpinning.Value = false;
mousePosition = default;
lastAngle = currentRotation = Rotation = 0;
mousePosition = null;
lastAngle = null;
currentRotation = 0;
Rotation = 0;
rotationTransferred = false;
}