Calculate max combo locally in `PerformanceBreakdownCalculator`

This commit is contained in:
Henry Lin 2022-02-06 10:59:53 +08:00
parent b31c1513f6
commit f78c853bc7
1 changed files with 14 additions and 12 deletions

View File

@ -51,17 +51,7 @@ private Task<PerformanceAttributes> getPerfectPerformance(ScoreInfo score, Cance
perfectPlay.Passed = true; perfectPlay.Passed = true;
// calculate max combo // calculate max combo
var difficulty = await difficultyCache.GetDifficultyAsync( perfectPlay.MaxCombo = calculateMaxCombo(playableBeatmap);
playableBeatmap.BeatmapInfo,
score.Ruleset,
score.Mods,
cancellationToken
).ConfigureAwait(false);
if (difficulty == null)
return null;
perfectPlay.MaxCombo = difficulty.Value.MaxCombo;
// create statistics assuming all hit objects have perfect hit result // create statistics assuming all hit objects have perfect hit result
var statistics = playableBeatmap.HitObjects var statistics = playableBeatmap.HitObjects
@ -86,11 +76,23 @@ private Task<PerformanceAttributes> getPerfectPerformance(ScoreInfo score, Cance
} }
// calculate performance for this perfect score // calculate performance for this perfect score
var difficulty = await difficultyCache.GetDifficultyAsync(
playableBeatmap.BeatmapInfo,
score.Ruleset,
score.Mods,
cancellationToken
).ConfigureAwait(false);
// ScorePerformanceCache is not used to avoid caching multiple copies of essentially identical perfect performance attributes // ScorePerformanceCache is not used to avoid caching multiple copies of essentially identical perfect performance attributes
return ruleset.CreatePerformanceCalculator(difficulty.Value.Attributes, perfectPlay)?.Calculate(); return difficulty == null ? null : ruleset.CreatePerformanceCalculator(difficulty.Value.Attributes, perfectPlay)?.Calculate();
}, cancellationToken); }, cancellationToken);
} }
private int calculateMaxCombo(IBeatmap beatmap)
{
return beatmap.HitObjects.SelectMany(getPerfectHitResults).Count(r => r.AffectsCombo());
}
private IEnumerable<HitResult> getPerfectHitResults(HitObject hitObject) private IEnumerable<HitResult> getPerfectHitResults(HitObject hitObject)
{ {
foreach (HitObject nested in hitObject.NestedHitObjects) foreach (HitObject nested in hitObject.NestedHitObjects)