Skip to content

Commit

Permalink
Only update unstable rate counter when an applicable hitobject is rea…
Browse files Browse the repository at this point in the history
…ched
  • Loading branch information
peppy committed Nov 25, 2024
1 parent ea68d4b commit bbe8f2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion osu.Game/Rulesets/Scoring/HitEventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Game.Rulesets.Objects;

namespace osu.Game.Rulesets.Scoring
{
Expand Down Expand Up @@ -69,7 +70,8 @@ public static class HitEventExtensions
return timeOffsets.Average();
}

public static bool AffectsUnstableRate(HitEvent e) => e.HitObject.HitWindows != HitWindows.Empty && e.Result.IsHit();
public static bool AffectsUnstableRate(HitEvent e) => AffectsUnstableRate(e.HitObject, e.Result);
public static bool AffectsUnstableRate(HitObject hitObject, HitResult result) => hitObject.HitWindows != HitWindows.Empty && result.IsHit();

public class UnstableRateCalculationResult
{
Expand Down
13 changes: 11 additions & 2 deletions osu.Game/Screens/Play/HUD/UnstableRateCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public partial class UnstableRateCounter : RollingCounter<int>, ISerialisableDra
private const float alpha_when_invalid = 0.3f;
private readonly Bindable<bool> valid = new Bindable<bool>();

private HitEventExtensions.UnstableRateCalculationResult? unstableRateResult;

[Resolved]
private ScoreProcessor scoreProcessor { get; set; } = null!;

Expand All @@ -53,13 +55,20 @@ protected override void LoadComplete()
updateDisplay();
}

private void updateDisplay(JudgementResult _) => Scheduler.AddOnce(updateDisplay);
private void updateDisplay(JudgementResult result)
{
if (HitEventExtensions.AffectsUnstableRate(result.HitObject, result.Type))
Scheduler.AddOnce(updateDisplay);
}

private void updateDisplay()
{
double? unstableRate = scoreProcessor.HitEvents.CalculateUnstableRate()?.Result;
unstableRateResult = scoreProcessor.HitEvents.CalculateUnstableRate(unstableRateResult);

double? unstableRate = unstableRateResult?.Result;

valid.Value = unstableRate != null;

if (unstableRate != null)
Current.Value = (int)Math.Round(unstableRate.Value);
}
Expand Down

0 comments on commit bbe8f2e

Please sign in to comment.