From af0f934e1a1b47080aefb8f4353a411c3e20c732 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 31 May 2022 17:37:48 +0900 Subject: [PATCH] Move raw ScoreProcessor values into ScoringValues struct --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 111 +++++++++++++------- osu.Game/Scoring/ScoringValues.cs | 38 +++++++ 2 files changed, 111 insertions(+), 38 deletions(-) create mode 100644 osu.Game/Scoring/ScoringValues.cs diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 1403a3f243..493da763cb 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -88,17 +88,20 @@ namespace osu.Game.Rulesets.Scoring private readonly double accuracyPortion; private readonly double comboPortion; - private int maxAchievableCombo; + /// + /// Maximum achievable scoring values. + /// + private ScoringValues maximumScoringValues; /// - /// The maximum achievable base score. + /// Maximum achievable scoring values up to the current point in time. /// - private double maxBaseScore; + private ScoringValues rollingMaximumScoringValues; /// - /// The maximum number of basic (non-tick and non-bonus) hitobjects. + /// Scoring values for the current play. /// - private int maxBasicHitObjects; + private ScoringValues currentScoringValues; /// /// The maximum of a basic (non-tick and non-bonus) hitobject. @@ -106,9 +109,6 @@ namespace osu.Game.Rulesets.Scoring /// private HitResult? maxBasicResult; - private double rollingMaxBaseScore; - private double baseScore; - private int basicHitObjects; private bool beatmapApplied; private readonly Dictionary scoreResultCounts = new Dictionary(); @@ -164,23 +164,42 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) + 1; if (!result.Type.IsScorable()) - return; + { + // The inverse of non-scorable (ignore) judgements may be bonus judgements. + if (result.Judgement.MaxResult.IsBonus()) + rollingMaximumScoringValues.BonusScore += result.Judgement.MaxNumericResult; + return; + } + + // Update rolling combo. if (result.Type.IncreasesCombo()) Combo.Value++; else if (result.Type.BreaksCombo()) Combo.Value = 0; - double scoreIncrease = result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; + // Update maximum combo. + currentScoringValues.MaxCombo = HighestCombo.Value; + rollingMaximumScoringValues.MaxCombo += result.Judgement.MaxResult.AffectsCombo() ? 1 : 0; - if (!result.Type.IsBonus()) + // Update base/bonus score. + if (result.Type.IsBonus()) { - baseScore += scoreIncrease; - rollingMaxBaseScore += result.Judgement.MaxNumericResult; + currentScoringValues.BonusScore += result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; + rollingMaximumScoringValues.BonusScore += result.Judgement.MaxNumericResult; + } + else + { + currentScoringValues.BaseScore += result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; + rollingMaximumScoringValues.BaseScore += result.Judgement.MaxNumericResult; } + // Update hitobject count. if (result.Type.IsBasic()) - basicHitObjects++; + { + currentScoringValues.HitObjects++; + rollingMaximumScoringValues.HitObjects++; + } hitEvents.Add(CreateHitEvent(result)); lastHitObject = result.HitObject; @@ -207,18 +226,36 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) - 1; if (!result.Type.IsScorable()) - return; - - double scoreIncrease = result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; - - if (!result.Type.IsBonus()) { - baseScore -= scoreIncrease; - rollingMaxBaseScore -= result.Judgement.MaxNumericResult; + // The inverse of non-scorable (ignore) judgements may be bonus judgements. + if (result.Judgement.MaxResult.IsBonus()) + rollingMaximumScoringValues.BonusScore -= result.Judgement.MaxNumericResult; + + return; } + // Update maximum combo. + currentScoringValues.MaxCombo = HighestCombo.Value; + rollingMaximumScoringValues.MaxCombo -= result.Judgement.MaxResult.AffectsCombo() ? 1 : 0; + + // Update base/bonus score. + if (result.Type.IsBonus()) + { + currentScoringValues.BonusScore -= result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; + rollingMaximumScoringValues.BonusScore -= result.Judgement.MaxNumericResult; + } + else + { + currentScoringValues.BaseScore -= result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0; + rollingMaximumScoringValues.BaseScore -= result.Judgement.MaxNumericResult; + } + + // Update hitobject count. if (result.Type.IsBasic()) - basicHitObjects--; + { + currentScoringValues.HitObjects--; + rollingMaximumScoringValues.HitObjects--; + } Debug.Assert(hitEvents.Count > 0); lastHitObject = hitEvents[^1].LastHitObject; @@ -229,12 +266,12 @@ namespace osu.Game.Rulesets.Scoring private void updateScore() { - double rollingAccuracyRatio = rollingMaxBaseScore > 0 ? baseScore / rollingMaxBaseScore : 1; - double accuracyRatio = maxBaseScore > 0 ? baseScore / maxBaseScore : 1; - double comboRatio = maxAchievableCombo > 0 ? (double)HighestCombo.Value / maxAchievableCombo : 1; + double rollingAccuracyRatio = rollingMaximumScoringValues.BaseScore > 0 ? currentScoringValues.BaseScore / rollingMaximumScoringValues.BaseScore : 1; + double accuracyRatio = maximumScoringValues.BaseScore > 0 ? currentScoringValues.BaseScore / maximumScoringValues.BaseScore : 1; + double comboRatio = maximumScoringValues.MaxCombo > 0 ? currentScoringValues.MaxCombo / maximumScoringValues.MaxCombo : 1; Accuracy.Value = rollingAccuracyRatio; - TotalScore.Value = ComputeScore(Mode.Value, accuracyRatio, comboRatio, getBonusScore(scoreResultCounts), maxBasicHitObjects); + TotalScore.Value = ComputeScore(Mode.Value, accuracyRatio, comboRatio, getBonusScore(scoreResultCounts), maximumScoringValues.HitObjects); } /// @@ -286,10 +323,10 @@ namespace osu.Game.Rulesets.Scoring out _, out _); - double accuracyRatio = maxBaseScore > 0 ? extractedBaseScore / maxBaseScore : 1; - double comboRatio = maxAchievableCombo > 0 ? (double)scoreInfo.MaxCombo / maxAchievableCombo : 1; + double accuracyRatio = maximumScoringValues.BaseScore > 0 ? extractedBaseScore / maximumScoringValues.BaseScore : 1; + double comboRatio = maximumScoringValues.MaxCombo > 0 ? (double)scoreInfo.MaxCombo / maximumScoringValues.MaxCombo : 1; - return ComputeScore(mode, accuracyRatio, comboRatio, getBonusScore(scoreInfo.Statistics), maxBasicHitObjects); + return ComputeScore(mode, accuracyRatio, comboRatio, getBonusScore(scoreInfo.Statistics), maximumScoringValues.HitObjects); } /// @@ -398,15 +435,10 @@ namespace osu.Game.Rulesets.Scoring lastHitObject = null; if (storeResults) - { - maxAchievableCombo = HighestCombo.Value; - maxBaseScore = baseScore; - maxBasicHitObjects = basicHitObjects; - } + maximumScoringValues = currentScoringValues; - baseScore = 0; - rollingMaxBaseScore = 0; - basicHitObjects = 0; + currentScoringValues = default; + rollingMaximumScoringValues = default; TotalScore.Value = 0; Accuracy.Value = 1; @@ -440,7 +472,10 @@ namespace osu.Game.Rulesets.Scoring if (frame.Header == null) return; - extractFromStatistics(frame.Header.Statistics, out baseScore, out rollingMaxBaseScore, out _, out _); + extractFromStatistics(frame.Header.Statistics, out double baseScore, out double rollingMaxBaseScore, out _, out _); + currentScoringValues.BaseScore = baseScore; + rollingMaximumScoringValues.BaseScore = rollingMaxBaseScore; + HighestCombo.Value = frame.Header.MaxCombo; scoreResultCounts.Clear(); diff --git a/osu.Game/Scoring/ScoringValues.cs b/osu.Game/Scoring/ScoringValues.cs new file mode 100644 index 0000000000..4b562c20e4 --- /dev/null +++ b/osu.Game/Scoring/ScoringValues.cs @@ -0,0 +1,38 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using MessagePack; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Scoring; + +namespace osu.Game.Scoring +{ + [MessagePackObject] + public struct ScoringValues + { + /// + /// The sum of all "basic" scoring values. See: and . + /// + [Key(0)] + public double BaseScore; + + /// + /// The sum of all "bonus" scoring values. See: and . + /// + [Key(1)] + public double BonusScore; + + /// + /// The highest achieved combo. + /// + [Key(2)] + public int MaxCombo; + + /// + /// The count of "basic" s. See: . + /// + [Key(3)] + public int HitObjects; + } +}