1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Simplify implementation of CalculatePerformanceAsync

This commit is contained in:
Bartłomiej Dach 2020-10-12 22:10:02 +02:00
parent 7117fd0fba
commit d4ba9d2682

View File

@ -26,19 +26,14 @@ namespace osu.Game.Scoring
/// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param> /// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param>
public async Task<double?> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default) public async Task<double?> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default)
{ {
if (tryGetExisting(score, out var perf, out var lookupKey)) var lookupKey = new PerformanceCacheLookup(score);
return perf;
if (performanceCache.TryGetValue(lookupKey, out double performance))
return performance;
return await computePerformanceAsync(score, lookupKey, token); return await computePerformanceAsync(score, lookupKey, token);
} }
private bool tryGetExisting(ScoreInfo score, out double performance, out PerformanceCacheLookup lookupKey)
{
lookupKey = new PerformanceCacheLookup(score);
return performanceCache.TryGetValue(lookupKey, out performance);
}
private async Task<double?> computePerformanceAsync(ScoreInfo score, PerformanceCacheLookup lookupKey, CancellationToken token = default) private async Task<double?> computePerformanceAsync(ScoreInfo score, PerformanceCacheLookup lookupKey, CancellationToken token = default)
{ {
var attributes = await difficultyManager.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods, token); var attributes = await difficultyManager.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods, token);