1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Use single queue for spinning record.

This commit is contained in:
Huo Yaoyuan 2017-10-06 18:35:51 +08:00
parent 54a98a74bc
commit 404c4917dc

View File

@ -79,8 +79,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
private float currentRotation; private float currentRotation;
public float RotationAbsolute; public float RotationAbsolute;
public double SpinsPerMinute; public double SpinsPerMinute;
private readonly Queue<float> rotations = new Queue<float>();
private readonly Queue<double> times = new Queue<double>(); private struct RotationRecord
{
public float Rotation;
public double Time;
}
private readonly Queue<RotationRecord> records = new Queue<RotationRecord>();
private const double spm_count_duration = 595; // not using hundreds to avoid frame rounding issues private const double spm_count_duration = 595; // not using hundreds to avoid frame rounding issues
private int completeTick; private int completeTick;
@ -115,19 +121,14 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
} }
lastAngle = thisAngle; lastAngle = thisAngle;
if (rotations.Count > 0) if (records.Count > 0)
{ {
float rotationFrom = rotations.Peek(); var record = records.Peek();
double timeFrom = times.Peek(); while (Time.Current - records.Peek().Time > spm_count_duration)
while (Time.Current - times.Peek() > spm_count_duration) record = records.Dequeue();
{ SpinsPerMinute = (RotationAbsolute - record.Rotation) / (Time.Current - record.Time) * 1000 * 60 / 360;
rotationFrom = rotations.Dequeue();
timeFrom = times.Dequeue();
}
SpinsPerMinute = (RotationAbsolute - rotationFrom) / (Time.Current - timeFrom) * 1000 * 60 / 360;
} }
rotations.Enqueue(RotationAbsolute); records.Enqueue(new RotationRecord { Rotation = RotationAbsolute, Time = Time.Current });
times.Enqueue(Time.Current);
if (Complete && updateCompleteTick()) if (Complete && updateCompleteTick())
{ {