From 09093013a7a0a639198741788906afaaff1e8b15 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 7 Oct 2017 15:42:10 +0800 Subject: [PATCH] Move spm calculation into counter. --- .../Objects/Drawables/DrawableSpinner.cs | 4 +- .../Objects/Drawables/Pieces/SpinnerDisc.cs | 20 ---------- .../Drawables/Pieces/SpinnerSpmCounter.cs | 37 +++++++++++++++++-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs index 97c2594f69..0fded6ec1a 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSpinner.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -14,7 +13,6 @@ using osu.Framework.Allocation; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Screens.Ranking; -using osu.Game.Graphics.Sprites; namespace osu.Game.Rulesets.Osu.Objects.Drawables { @@ -184,7 +182,7 @@ protected override void UpdateAfterChildren() circle.Rotation = disc.Rotation; ticks.Rotation = disc.Rotation; - spmText.Text = Math.Truncate(disc.SpinsPerMinute).ToString(@"#0"); + spmCounter.SetRotation(disc.RotationAbsolute); float relativeCircleScale = spinner.Scale * circle.DrawHeight / mainContainer.DrawHeight; disc.ScaleTo(relativeCircleScale + (1 - relativeCircleScale) * Progress, 200, Easing.OutQuint); diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs index 8af7de88e4..ca75a61738 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerDisc.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; -using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Input; @@ -78,17 +77,6 @@ protected override bool OnMouseMove(InputState state) private float lastAngle; private float currentRotation; public float RotationAbsolute; - public double SpinsPerMinute; - - private struct RotationRecord - { - public float Rotation; - public double Time; - } - - private readonly Queue records = new Queue(); - private const double spm_count_duration = 595; // not using hundreds to avoid frame rounding issues - private int completeTick; private bool updateCompleteTick() => completeTick != (completeTick = (int)(RotationAbsolute / 360)); @@ -121,14 +109,6 @@ protected override void Update() } lastAngle = thisAngle; - if (records.Count > 0) - { - var record = records.Peek(); - while (Time.Current - records.Peek().Time > spm_count_duration) - record = records.Dequeue(); - SpinsPerMinute = (RotationAbsolute - record.Rotation) / (Time.Current - record.Time) * 1000 * 60 / 360; - } - records.Enqueue(new RotationRecord { Rotation = RotationAbsolute, Time = Time.Current }); if (Complete && updateCompleteTick()) { diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerSpmCounter.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerSpmCounter.cs index 17b2a813a5..57ec516484 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerSpmCounter.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/SpinnerSpmCounter.cs @@ -3,9 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -38,5 +35,39 @@ public SpinnerSpmCounter() } }; } + + private double spm; + public double SpinsPerMinute + { + get { return spm; } + private set + { + if (value == spm) return; + spm = value; + spmText.Text = Math.Truncate(value).ToString(@"#0"); + } + } + + private struct RotationRecord + { + public float Rotation; + public double Time; + } + + private readonly Queue records = new Queue(); + private const double spm_count_duration = 595; // not using hundreds to avoid frame rounding issues + + + public void SetRotation(float currentRotation) + { + if (records.Count > 0) + { + var record = records.Peek(); + while (Time.Current - records.Peek().Time > spm_count_duration) + record = records.Dequeue(); + SpinsPerMinute = (currentRotation - record.Rotation) / (Time.Current - record.Time) * 1000 * 60 / 360; + } + records.Enqueue(new RotationRecord { Rotation = currentRotation, Time = Time.Current }); + } } }