mirror of
https://github.com/ppy/osu.git
synced 2024-11-08 02:52:50 +08:00
Merge pull request #18506 from smoogipoo/scoreprocessor-cleanup
Refactor ScoreProcessor for use in more external scenarios
This commit is contained in:
commit
11f6190091
@ -61,13 +61,13 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
||||||
|
|
||||||
// No header shouldn't cause any change
|
// No header shouldn't cause any change
|
||||||
scoreProcessor.ResetFromReplayFrame(new OsuRuleset(), new OsuReplayFrame());
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame());
|
||||||
|
|
||||||
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(1_000_000));
|
Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(1_000_000));
|
||||||
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
||||||
|
|
||||||
// Reset with a miss instead.
|
// Reset with a miss instead.
|
||||||
scoreProcessor.ResetFromReplayFrame(new OsuRuleset(), new OsuReplayFrame
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame
|
||||||
{
|
{
|
||||||
Header = new FrameHeader(0, 0, 0, new Dictionary<HitResult, int> { { HitResult.Miss, 1 } }, DateTimeOffset.Now)
|
Header = new FrameHeader(0, 0, 0, new Dictionary<HitResult, int> { { HitResult.Miss, 1 } }, DateTimeOffset.Now)
|
||||||
});
|
});
|
||||||
@ -76,7 +76,7 @@ namespace osu.Game.Tests.Gameplay
|
|||||||
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1));
|
||||||
|
|
||||||
// Reset with no judged hit.
|
// Reset with no judged hit.
|
||||||
scoreProcessor.ResetFromReplayFrame(new OsuRuleset(), new OsuReplayFrame
|
scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame
|
||||||
{
|
{
|
||||||
Header = new FrameHeader(0, 0, 0, new Dictionary<HitResult, int>(), DateTimeOffset.Now)
|
Header = new FrameHeader(0, 0, 0, new Dictionary<HitResult, int>(), DateTimeOffset.Now)
|
||||||
});
|
});
|
||||||
|
@ -117,9 +117,8 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// If the provided replay frame does not have any header information, this will be a noop.
|
/// If the provided replay frame does not have any header information, this will be a noop.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="ruleset">The ruleset to be used for retrieving statistics.</param>
|
|
||||||
/// <param name="frame">The replay frame to read header statistics from.</param>
|
/// <param name="frame">The replay frame to read header statistics from.</param>
|
||||||
public virtual void ResetFromReplayFrame(Ruleset ruleset, ReplayFrame frame)
|
public virtual void ResetFromReplayFrame(ReplayFrame frame)
|
||||||
{
|
{
|
||||||
if (frame.Header == null)
|
if (frame.Header == null)
|
||||||
return;
|
return;
|
||||||
|
@ -6,11 +6,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
|
using osu.Game.Online.Spectator;
|
||||||
using osu.Game.Rulesets.Judgements;
|
using osu.Game.Rulesets.Judgements;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -88,17 +90,34 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
private readonly double accuracyPortion;
|
private readonly double accuracyPortion;
|
||||||
private readonly double comboPortion;
|
private readonly double comboPortion;
|
||||||
|
|
||||||
private int maxAchievableCombo;
|
/// <summary>
|
||||||
|
/// Scoring values for a perfect play.
|
||||||
|
/// </summary>
|
||||||
|
public ScoringValues MaximumScoringValues
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!beatmapApplied)
|
||||||
|
throw new InvalidOperationException($"Cannot access maximum scoring values before calling {nameof(ApplyBeatmap)}.");
|
||||||
|
|
||||||
|
return maximumScoringValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoringValues maximumScoringValues;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum achievable base score.
|
/// Scoring values for the current play assuming all perfect hits.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private double maxBaseScore;
|
/// <remarks>
|
||||||
|
/// This is only used to determine the accuracy with respect to the current point in time for an ongoing play session.
|
||||||
|
/// </remarks>
|
||||||
|
private ScoringValues currentMaximumScoringValues;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum number of basic (non-tick and non-bonus) hitobjects.
|
/// Scoring values for the current play.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int maxBasicHitObjects;
|
private ScoringValues currentScoringValues;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum <see cref="HitResult"/> of a basic (non-tick and non-bonus) hitobject.
|
/// The maximum <see cref="HitResult"/> of a basic (non-tick and non-bonus) hitobject.
|
||||||
@ -106,9 +125,6 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private HitResult? maxBasicResult;
|
private HitResult? maxBasicResult;
|
||||||
|
|
||||||
private double rollingMaxBaseScore;
|
|
||||||
private double baseScore;
|
|
||||||
private int basicHitObjects;
|
|
||||||
private bool beatmapApplied;
|
private bool beatmapApplied;
|
||||||
|
|
||||||
private readonly Dictionary<HitResult, int> scoreResultCounts = new Dictionary<HitResult, int>();
|
private readonly Dictionary<HitResult, int> scoreResultCounts = new Dictionary<HitResult, int>();
|
||||||
@ -163,6 +179,10 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
|
|
||||||
scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) + 1;
|
scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) + 1;
|
||||||
|
|
||||||
|
// Always update the maximum scoring values.
|
||||||
|
applyResult(result.Judgement.MaxResult, ref currentMaximumScoringValues);
|
||||||
|
currentMaximumScoringValues.MaxCombo += result.Judgement.MaxResult.IncreasesCombo() ? 1 : 0;
|
||||||
|
|
||||||
if (!result.Type.IsScorable())
|
if (!result.Type.IsScorable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -171,16 +191,8 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
else if (result.Type.BreaksCombo())
|
else if (result.Type.BreaksCombo())
|
||||||
Combo.Value = 0;
|
Combo.Value = 0;
|
||||||
|
|
||||||
double scoreIncrease = result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0;
|
applyResult(result.Type, ref currentScoringValues);
|
||||||
|
currentScoringValues.MaxCombo = HighestCombo.Value;
|
||||||
if (!result.Type.IsBonus())
|
|
||||||
{
|
|
||||||
baseScore += scoreIncrease;
|
|
||||||
rollingMaxBaseScore += result.Judgement.MaxNumericResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.Type.IsBasic())
|
|
||||||
basicHitObjects++;
|
|
||||||
|
|
||||||
hitEvents.Add(CreateHitEvent(result));
|
hitEvents.Add(CreateHitEvent(result));
|
||||||
lastHitObject = result.HitObject;
|
lastHitObject = result.HitObject;
|
||||||
@ -188,6 +200,20 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
updateScore();
|
updateScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void applyResult(HitResult result, ref ScoringValues scoringValues)
|
||||||
|
{
|
||||||
|
if (!result.IsScorable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (result.IsBonus())
|
||||||
|
scoringValues.BonusScore += result.IsHit() ? Judgement.ToNumericResult(result) : 0;
|
||||||
|
else
|
||||||
|
scoringValues.BaseScore += result.IsHit() ? Judgement.ToNumericResult(result) : 0;
|
||||||
|
|
||||||
|
if (result.IsBasic())
|
||||||
|
scoringValues.CountBasicHitObjects++;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the <see cref="HitEvent"/> that describes a <see cref="JudgementResult"/>.
|
/// Creates the <see cref="HitEvent"/> that describes a <see cref="JudgementResult"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -206,19 +232,15 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
|
|
||||||
scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) - 1;
|
scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) - 1;
|
||||||
|
|
||||||
|
// Always update the maximum scoring values.
|
||||||
|
revertResult(result.Judgement.MaxResult, ref currentMaximumScoringValues);
|
||||||
|
currentMaximumScoringValues.MaxCombo -= result.Judgement.MaxResult.IncreasesCombo() ? 1 : 0;
|
||||||
|
|
||||||
if (!result.Type.IsScorable())
|
if (!result.Type.IsScorable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
double scoreIncrease = result.Type.IsHit() ? result.Judgement.NumericResultFor(result) : 0;
|
revertResult(result.Type, ref currentScoringValues);
|
||||||
|
currentScoringValues.MaxCombo = HighestCombo.Value;
|
||||||
if (!result.Type.IsBonus())
|
|
||||||
{
|
|
||||||
baseScore -= scoreIncrease;
|
|
||||||
rollingMaxBaseScore -= result.Judgement.MaxNumericResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.Type.IsBasic())
|
|
||||||
basicHitObjects--;
|
|
||||||
|
|
||||||
Debug.Assert(hitEvents.Count > 0);
|
Debug.Assert(hitEvents.Count > 0);
|
||||||
lastHitObject = hitEvents[^1].LastHitObject;
|
lastHitObject = hitEvents[^1].LastHitObject;
|
||||||
@ -227,14 +249,24 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
updateScore();
|
updateScore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void revertResult(HitResult result, ref ScoringValues scoringValues)
|
||||||
|
{
|
||||||
|
if (!result.IsScorable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (result.IsBonus())
|
||||||
|
scoringValues.BonusScore -= result.IsHit() ? Judgement.ToNumericResult(result) : 0;
|
||||||
|
else
|
||||||
|
scoringValues.BaseScore -= result.IsHit() ? Judgement.ToNumericResult(result) : 0;
|
||||||
|
|
||||||
|
if (result.IsBasic())
|
||||||
|
scoringValues.CountBasicHitObjects--;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateScore()
|
private void updateScore()
|
||||||
{
|
{
|
||||||
double rollingAccuracyRatio = rollingMaxBaseScore > 0 ? baseScore / rollingMaxBaseScore : 1;
|
Accuracy.Value = currentMaximumScoringValues.BaseScore > 0 ? currentScoringValues.BaseScore / currentMaximumScoringValues.BaseScore : 1;
|
||||||
double accuracyRatio = maxBaseScore > 0 ? baseScore / maxBaseScore : 1;
|
TotalScore.Value = ComputeScore(Mode.Value, currentScoringValues, maximumScoringValues);
|
||||||
double comboRatio = maxAchievableCombo > 0 ? (double)HighestCombo.Value / maxAchievableCombo : 1;
|
|
||||||
|
|
||||||
Accuracy.Value = rollingAccuracyRatio;
|
|
||||||
TotalScore.Value = ComputeScore(Mode.Value, accuracyRatio, comboRatio, getBonusScore(scoreResultCounts), maxBasicHitObjects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -246,22 +278,15 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
|
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
|
||||||
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
||||||
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
||||||
|
[Pure]
|
||||||
public double ComputeFinalScore(ScoringMode mode, ScoreInfo scoreInfo)
|
public double ComputeFinalScore(ScoringMode mode, ScoreInfo scoreInfo)
|
||||||
{
|
{
|
||||||
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
||||||
throw new ArgumentException($"Unexpected score ruleset. Expected \"{ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\".");
|
throw new ArgumentException($"Unexpected score ruleset. Expected \"{ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\".");
|
||||||
|
|
||||||
extractFromStatistics(ruleset,
|
ExtractScoringValues(scoreInfo, out var current, out var maximum);
|
||||||
scoreInfo.Statistics,
|
|
||||||
out double extractedBaseScore,
|
|
||||||
out double extractedMaxBaseScore,
|
|
||||||
out int extractedMaxCombo,
|
|
||||||
out int extractedBasicHitObjects);
|
|
||||||
|
|
||||||
double accuracyRatio = extractedMaxBaseScore > 0 ? extractedBaseScore / extractedMaxBaseScore : 1;
|
return ComputeScore(mode, current, maximum);
|
||||||
double comboRatio = extractedMaxCombo > 0 ? (double)scoreInfo.MaxCombo / extractedMaxCombo : 1;
|
|
||||||
|
|
||||||
return ComputeScore(mode, accuracyRatio, comboRatio, getBonusScore(scoreInfo.Statistics), extractedBasicHitObjects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -273,6 +298,7 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
|
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
|
||||||
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
||||||
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
||||||
|
[Pure]
|
||||||
public double ComputePartialScore(ScoringMode mode, ScoreInfo scoreInfo)
|
public double ComputePartialScore(ScoringMode mode, ScoreInfo scoreInfo)
|
||||||
{
|
{
|
||||||
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
||||||
@ -281,17 +307,9 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
if (!beatmapApplied)
|
if (!beatmapApplied)
|
||||||
throw new InvalidOperationException($"Cannot compute partial score without calling {nameof(ApplyBeatmap)}.");
|
throw new InvalidOperationException($"Cannot compute partial score without calling {nameof(ApplyBeatmap)}.");
|
||||||
|
|
||||||
extractFromStatistics(ruleset,
|
ExtractScoringValues(scoreInfo, out var current, out _);
|
||||||
scoreInfo.Statistics,
|
|
||||||
out double extractedBaseScore,
|
|
||||||
out _,
|
|
||||||
out _,
|
|
||||||
out _);
|
|
||||||
|
|
||||||
double accuracyRatio = maxBaseScore > 0 ? extractedBaseScore / maxBaseScore : 1;
|
return ComputeScore(mode, current, MaximumScoringValues);
|
||||||
double comboRatio = maxAchievableCombo > 0 ? (double)scoreInfo.MaxCombo / maxAchievableCombo : 1;
|
|
||||||
|
|
||||||
return ComputeScore(mode, accuracyRatio, comboRatio, getBonusScore(scoreInfo.Statistics), maxBasicHitObjects);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -305,6 +323,7 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
/// <param name="scoreInfo">The <see cref="ScoreInfo"/> to compute the total score of.</param>
|
||||||
/// <param name="maxAchievableCombo">The maximum achievable combo for the provided beatmap.</param>
|
/// <param name="maxAchievableCombo">The maximum achievable combo for the provided beatmap.</param>
|
||||||
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
/// <returns>The total score in the given <see cref="ScoringMode"/>.</returns>
|
||||||
|
[Pure]
|
||||||
public double ComputeFinalLegacyScore(ScoringMode mode, ScoreInfo scoreInfo, int maxAchievableCombo)
|
public double ComputeFinalLegacyScore(ScoringMode mode, ScoreInfo scoreInfo, int maxAchievableCombo)
|
||||||
{
|
{
|
||||||
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
if (!ruleset.RulesetInfo.Equals(scoreInfo.Ruleset))
|
||||||
@ -313,26 +332,30 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
double accuracyRatio = scoreInfo.Accuracy;
|
double accuracyRatio = scoreInfo.Accuracy;
|
||||||
double comboRatio = maxAchievableCombo > 0 ? (double)scoreInfo.MaxCombo / maxAchievableCombo : 1;
|
double comboRatio = maxAchievableCombo > 0 ? (double)scoreInfo.MaxCombo / maxAchievableCombo : 1;
|
||||||
|
|
||||||
|
ExtractScoringValues(scoreInfo, out var current, out var maximum);
|
||||||
|
|
||||||
// For legacy osu!mania scores, a full-GREAT score has 100% accuracy. If combined with a full-combo, the score becomes indistinguishable from a full-PERFECT score.
|
// For legacy osu!mania scores, a full-GREAT score has 100% accuracy. If combined with a full-combo, the score becomes indistinguishable from a full-PERFECT score.
|
||||||
// To get around this, the accuracy ratio is always recalculated based on the hit statistics rather than trusting the score.
|
// To get around this, the accuracy ratio is always recalculated based on the hit statistics rather than trusting the score.
|
||||||
// Note: This cannot be applied universally to all legacy scores, as some rulesets (e.g. catch) group multiple judgements together.
|
// Note: This cannot be applied universally to all legacy scores, as some rulesets (e.g. catch) group multiple judgements together.
|
||||||
if (scoreInfo.IsLegacyScore && scoreInfo.Ruleset.OnlineID == 3)
|
if (scoreInfo.IsLegacyScore && scoreInfo.Ruleset.OnlineID == 3 && maximum.BaseScore > 0)
|
||||||
{
|
accuracyRatio = current.BaseScore / maximum.BaseScore;
|
||||||
extractFromStatistics(
|
|
||||||
ruleset,
|
|
||||||
scoreInfo.Statistics,
|
|
||||||
out double computedBaseScore,
|
|
||||||
out double computedMaxBaseScore,
|
|
||||||
out _,
|
|
||||||
out _);
|
|
||||||
|
|
||||||
if (computedMaxBaseScore > 0)
|
return ComputeScore(mode, accuracyRatio, comboRatio, current.BonusScore, maximum.CountBasicHitObjects);
|
||||||
accuracyRatio = computedBaseScore / computedMaxBaseScore;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int computedBasicHitObjects = scoreInfo.Statistics.Where(kvp => kvp.Key.IsBasic()).Select(kvp => kvp.Value).Sum();
|
/// <summary>
|
||||||
|
/// Computes the total score from scoring values.
|
||||||
return ComputeScore(mode, accuracyRatio, comboRatio, getBonusScore(scoreInfo.Statistics), computedBasicHitObjects);
|
/// </summary>
|
||||||
|
/// <param name="mode">The <see cref="ScoringMode"/> to represent the score as.</param>
|
||||||
|
/// <param name="current">The current scoring values.</param>
|
||||||
|
/// <param name="maximum">The maximum scoring values.</param>
|
||||||
|
/// <returns>The total score computed from the given scoring values.</returns>
|
||||||
|
[Pure]
|
||||||
|
public double ComputeScore(ScoringMode mode, ScoringValues current, ScoringValues maximum)
|
||||||
|
{
|
||||||
|
double accuracyRatio = maximum.BaseScore > 0 ? current.BaseScore / maximum.BaseScore : 1;
|
||||||
|
double comboRatio = maximum.MaxCombo > 0 ? (double)current.MaxCombo / maximum.MaxCombo : 1;
|
||||||
|
return ComputeScore(mode, accuracyRatio, comboRatio, current.BonusScore, maximum.CountBasicHitObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -344,6 +367,7 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
/// <param name="bonusScore">The total bonus score.</param>
|
/// <param name="bonusScore">The total bonus score.</param>
|
||||||
/// <param name="totalBasicHitObjects">The total number of basic (non-tick and non-bonus) hitobjects in the beatmap.</param>
|
/// <param name="totalBasicHitObjects">The total number of basic (non-tick and non-bonus) hitobjects in the beatmap.</param>
|
||||||
/// <returns>The total score computed from the given scoring component ratios.</returns>
|
/// <returns>The total score computed from the given scoring component ratios.</returns>
|
||||||
|
[Pure]
|
||||||
public double ComputeScore(ScoringMode mode, double accuracyRatio, double comboRatio, double bonusScore, int totalBasicHitObjects)
|
public double ComputeScore(ScoringMode mode, double accuracyRatio, double comboRatio, double bonusScore, int totalBasicHitObjects)
|
||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
@ -362,15 +386,6 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates the total bonus score from score statistics.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="statistics">The score statistics.</param>
|
|
||||||
/// <returns>The total bonus score.</returns>
|
|
||||||
private double getBonusScore(IReadOnlyDictionary<HitResult, int> statistics)
|
|
||||||
=> statistics.GetValueOrDefault(HitResult.SmallBonus) * Judgement.SMALL_BONUS_SCORE
|
|
||||||
+ statistics.GetValueOrDefault(HitResult.LargeBonus) * Judgement.LARGE_BONUS_SCORE;
|
|
||||||
|
|
||||||
private ScoreRank rankFrom(double acc)
|
private ScoreRank rankFrom(double acc)
|
||||||
{
|
{
|
||||||
if (acc == 1)
|
if (acc == 1)
|
||||||
@ -402,15 +417,10 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
lastHitObject = null;
|
lastHitObject = null;
|
||||||
|
|
||||||
if (storeResults)
|
if (storeResults)
|
||||||
{
|
maximumScoringValues = currentScoringValues;
|
||||||
maxAchievableCombo = HighestCombo.Value;
|
|
||||||
maxBaseScore = baseScore;
|
|
||||||
maxBasicHitObjects = basicHitObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
baseScore = 0;
|
currentScoringValues = default;
|
||||||
rollingMaxBaseScore = 0;
|
currentMaximumScoringValues = default;
|
||||||
basicHitObjects = 0;
|
|
||||||
|
|
||||||
TotalScore.Value = 0;
|
TotalScore.Value = 0;
|
||||||
Accuracy.Value = 1;
|
Accuracy.Value = 1;
|
||||||
@ -437,14 +447,19 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
score.TotalScore = (long)Math.Round(ComputeFinalScore(ScoringMode.Standardised, score));
|
score.TotalScore = (long)Math.Round(ComputeFinalScore(ScoringMode.Standardised, score));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ResetFromReplayFrame(Ruleset ruleset, ReplayFrame frame)
|
public override void ResetFromReplayFrame(ReplayFrame frame)
|
||||||
{
|
{
|
||||||
base.ResetFromReplayFrame(ruleset, frame);
|
base.ResetFromReplayFrame(frame);
|
||||||
|
|
||||||
if (frame.Header == null)
|
if (frame.Header == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
extractFromStatistics(ruleset, frame.Header.Statistics, out baseScore, out rollingMaxBaseScore, out _, out _);
|
extractScoringValues(frame.Header.Statistics, out var current, out var maximum);
|
||||||
|
currentScoringValues.BaseScore = current.BaseScore;
|
||||||
|
currentScoringValues.MaxCombo = frame.Header.MaxCombo;
|
||||||
|
currentMaximumScoringValues.BaseScore = maximum.BaseScore;
|
||||||
|
currentMaximumScoringValues.MaxCombo = maximum.MaxCombo;
|
||||||
|
|
||||||
HighestCombo.Value = frame.Header.MaxCombo;
|
HighestCombo.Value = frame.Header.MaxCombo;
|
||||||
|
|
||||||
scoreResultCounts.Clear();
|
scoreResultCounts.Clear();
|
||||||
@ -455,52 +470,126 @@ namespace osu.Game.Rulesets.Scoring
|
|||||||
OnResetFromReplayFrame?.Invoke();
|
OnResetFromReplayFrame?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractFromStatistics(Ruleset ruleset, IReadOnlyDictionary<HitResult, int> statistics, out double baseScore, out double maxBaseScore, out int maxCombo,
|
#region ScoringValue extraction
|
||||||
out int basicHitObjects)
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies a best-effort extraction of hit statistics into <see cref="ScoringValues"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method is useful in a variety of situations, with a few drawbacks that need to be considered:
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item>The maximum <see cref="ScoringValues.BonusScore"/> will always be 0.</item>
|
||||||
|
/// <item>The current and maximum <see cref="ScoringValues.CountBasicHitObjects"/> will always be the same value.</item>
|
||||||
|
/// </list>
|
||||||
|
/// Consumers are expected to more accurately fill in the above values through external means.
|
||||||
|
/// <para>
|
||||||
|
/// <b>Ensure</b> to fill in the maximum <see cref="ScoringValues.CountBasicHitObjects"/> for use in
|
||||||
|
/// <see cref="ComputeScore(osu.Game.Rulesets.Scoring.ScoringMode,osu.Game.Scoring.ScoringValues,osu.Game.Scoring.ScoringValues)"/>.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="scoreInfo">The score to extract scoring values from.</param>
|
||||||
|
/// <param name="current">The "current" scoring values, representing the hit statistics as they appear.</param>
|
||||||
|
/// <param name="maximum">The "maximum" scoring values, representing the hit statistics as if the maximum hit result was attained each time.</param>
|
||||||
|
[Pure]
|
||||||
|
internal void ExtractScoringValues(ScoreInfo scoreInfo, out ScoringValues current, out ScoringValues maximum)
|
||||||
{
|
{
|
||||||
baseScore = 0;
|
extractScoringValues(scoreInfo.Statistics, out current, out maximum);
|
||||||
maxBaseScore = 0;
|
current.MaxCombo = scoreInfo.MaxCombo;
|
||||||
maxCombo = 0;
|
}
|
||||||
basicHitObjects = 0;
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies a best-effort extraction of hit statistics into <see cref="ScoringValues"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method is useful in a variety of situations, with a few drawbacks that need to be considered:
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item>The maximum <see cref="ScoringValues.BonusScore"/> will always be 0.</item>
|
||||||
|
/// <item>The current and maximum <see cref="ScoringValues.CountBasicHitObjects"/> will always be the same value.</item>
|
||||||
|
/// </list>
|
||||||
|
/// Consumers are expected to more accurately fill in the above values through external means.
|
||||||
|
/// <para>
|
||||||
|
/// <b>Ensure</b> to fill in the maximum <see cref="ScoringValues.CountBasicHitObjects"/> for use in
|
||||||
|
/// <see cref="ComputeScore(osu.Game.Rulesets.Scoring.ScoringMode,osu.Game.Scoring.ScoringValues,osu.Game.Scoring.ScoringValues)"/>.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="header">The replay frame header to extract scoring values from.</param>
|
||||||
|
/// <param name="current">The "current" scoring values, representing the hit statistics as they appear.</param>
|
||||||
|
/// <param name="maximum">The "maximum" scoring values, representing the hit statistics as if the maximum hit result was attained each time.</param>
|
||||||
|
[Pure]
|
||||||
|
internal void ExtractScoringValues(FrameHeader header, out ScoringValues current, out ScoringValues maximum)
|
||||||
|
{
|
||||||
|
extractScoringValues(header.Statistics, out current, out maximum);
|
||||||
|
current.MaxCombo = header.MaxCombo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies a best-effort extraction of hit statistics into <see cref="ScoringValues"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method is useful in a variety of situations, with a few drawbacks that need to be considered:
|
||||||
|
/// <list type="bullet">
|
||||||
|
/// <item>The current <see cref="ScoringValues.MaxCombo"/> will always be 0.</item>
|
||||||
|
/// <item>The maximum <see cref="ScoringValues.BonusScore"/> will always be 0.</item>
|
||||||
|
/// <item>The current and maximum <see cref="ScoringValues.CountBasicHitObjects"/> will always be the same value.</item>
|
||||||
|
/// </list>
|
||||||
|
/// Consumers are expected to more accurately fill in the above values (especially the current <see cref="ScoringValues.MaxCombo"/>) via external means (e.g. <see cref="ScoreInfo"/>).
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="statistics">The hit statistics to extract scoring values from.</param>
|
||||||
|
/// <param name="current">The "current" scoring values, representing the hit statistics as they appear.</param>
|
||||||
|
/// <param name="maximum">The "maximum" scoring values, representing the hit statistics as if the maximum hit result was attained each time.</param>
|
||||||
|
[Pure]
|
||||||
|
private void extractScoringValues(IReadOnlyDictionary<HitResult, int> statistics, out ScoringValues current, out ScoringValues maximum)
|
||||||
|
{
|
||||||
|
current = default;
|
||||||
|
maximum = default;
|
||||||
|
|
||||||
foreach ((HitResult result, int count) in statistics)
|
foreach ((HitResult result, int count) in statistics)
|
||||||
{
|
{
|
||||||
// Bonus scores are counted separately directly from the statistics dictionary later on.
|
if (!result.IsScorable())
|
||||||
if (!result.IsScorable() || result.IsBonus())
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// The maximum result of this judgement if it wasn't a miss.
|
if (result.IsBonus())
|
||||||
// E.g. For a GOOD judgement, the max result is either GREAT/PERFECT depending on which one the ruleset uses (osu!: GREAT, osu!mania: PERFECT).
|
current.BonusScore += count * Judgement.ToNumericResult(result);
|
||||||
HitResult maxResult;
|
else
|
||||||
|
|
||||||
switch (result)
|
|
||||||
{
|
{
|
||||||
case HitResult.LargeTickHit:
|
// The maximum result of this judgement if it wasn't a miss.
|
||||||
case HitResult.LargeTickMiss:
|
// E.g. For a GOOD judgement, the max result is either GREAT/PERFECT depending on which one the ruleset uses (osu!: GREAT, osu!mania: PERFECT).
|
||||||
maxResult = HitResult.LargeTickHit;
|
HitResult maxResult;
|
||||||
break;
|
|
||||||
|
|
||||||
case HitResult.SmallTickHit:
|
switch (result)
|
||||||
case HitResult.SmallTickMiss:
|
{
|
||||||
maxResult = HitResult.SmallTickHit;
|
case HitResult.LargeTickHit:
|
||||||
break;
|
case HitResult.LargeTickMiss:
|
||||||
|
maxResult = HitResult.LargeTickHit;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
case HitResult.SmallTickHit:
|
||||||
maxResult = maxBasicResult ??= ruleset.GetHitResults().OrderByDescending(kvp => Judgement.ToNumericResult(kvp.result)).First().result;
|
case HitResult.SmallTickMiss:
|
||||||
break;
|
maxResult = HitResult.SmallTickHit;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
maxResult = maxBasicResult ??= ruleset.GetHitResults().OrderByDescending(kvp => Judgement.ToNumericResult(kvp.result)).First().result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
current.BaseScore += count * Judgement.ToNumericResult(result);
|
||||||
|
maximum.BaseScore += count * Judgement.ToNumericResult(maxResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
baseScore += count * Judgement.ToNumericResult(result);
|
|
||||||
maxBaseScore += count * Judgement.ToNumericResult(maxResult);
|
|
||||||
|
|
||||||
if (result.AffectsCombo())
|
if (result.AffectsCombo())
|
||||||
maxCombo += count;
|
maximum.MaxCombo += count;
|
||||||
|
|
||||||
if (result.IsBasic())
|
if (result.IsBasic())
|
||||||
basicHitObjects += count;
|
{
|
||||||
|
current.CountBasicHitObjects += count;
|
||||||
|
maximum.CountBasicHitObjects += count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
@ -27,8 +27,6 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
public readonly KeyBindingContainer<T> KeyBindingContainer;
|
public readonly KeyBindingContainer<T> KeyBindingContainer;
|
||||||
|
|
||||||
private readonly Ruleset ruleset;
|
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private ScoreProcessor scoreProcessor { get; set; }
|
private ScoreProcessor scoreProcessor { get; set; }
|
||||||
|
|
||||||
@ -57,8 +55,6 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
|
||||||
{
|
{
|
||||||
this.ruleset = ruleset.CreateInstance();
|
|
||||||
|
|
||||||
InternalChild = KeyBindingContainer =
|
InternalChild = KeyBindingContainer =
|
||||||
CreateKeyBindingContainer(ruleset, variant, unique)
|
CreateKeyBindingContainer(ruleset, variant, unique)
|
||||||
.WithChild(content = new Container { RelativeSizeAxes = Axes.Both });
|
.WithChild(content = new Container { RelativeSizeAxes = Axes.Both });
|
||||||
@ -85,7 +81,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ReplayStatisticsFrameEvent statisticsStateChangeEvent:
|
case ReplayStatisticsFrameEvent statisticsStateChangeEvent:
|
||||||
scoreProcessor?.ResetFromReplayFrame(ruleset, statisticsStateChangeEvent.Frame);
|
scoreProcessor?.ResetFromReplayFrame(statisticsStateChangeEvent.Frame);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
41
osu.Game/Scoring/ScoringValues.cs
Normal file
41
osu.Game/Scoring/ScoringValues.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the required scoring data that fulfils the minimum requirements for a <see cref="ScoreProcessor"/> to calculate score.
|
||||||
|
/// </summary>
|
||||||
|
[MessagePackObject]
|
||||||
|
public struct ScoringValues
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The sum of all "basic" <see cref="HitObject"/> scoring values. See: <see cref="HitResultExtensions.IsBasic"/> and <see cref="Judgement.ToNumericResult"/>.
|
||||||
|
/// </summary>
|
||||||
|
[Key(0)]
|
||||||
|
public double BaseScore;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sum of all "bonus" <see cref="HitObject"/> scoring values. See: <see cref="HitResultExtensions.IsBonus"/> and <see cref="Judgement.ToNumericResult"/>.
|
||||||
|
/// </summary>
|
||||||
|
[Key(1)]
|
||||||
|
public double BonusScore;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The highest achieved combo.
|
||||||
|
/// </summary>
|
||||||
|
[Key(2)]
|
||||||
|
public int MaxCombo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The count of "basic" <see cref="HitObject"/>s. See: <see cref="HitResultExtensions.IsBasic"/>.
|
||||||
|
/// </summary>
|
||||||
|
[Key(3)]
|
||||||
|
public int CountBasicHitObjects;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user