1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 22:47:24 +08:00

Make CalculatePerformanceAsync() nullable.

This commit is contained in:
Lucas A 2020-10-10 19:16:21 +02:00
parent 6459ce28a3
commit de522d53ea
2 changed files with 12 additions and 8 deletions

View File

@ -24,7 +24,7 @@ namespace osu.Game.Scoring
/// </summary>
/// <param name="score">The score to do the calculation on. </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))
return perf;
@ -39,21 +39,21 @@ namespace osu.Game.Scoring
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);
// Performance calculation requires the beatmap and ruleset to be locally available. If not, return a default value.
if (attributes.Attributes == null)
return default;
return null;
if (token.IsCancellationRequested)
return default;
token.ThrowIfCancellationRequested();
var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(attributes.Attributes, score);
var total = calculator?.Calculate() ?? default;
var total = calculator?.Calculate();
performanceCache[lookupKey] = total;
if (total.HasValue)
performanceCache[lookupKey] = total.Value;
return total;
}

View File

@ -32,7 +32,11 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
else
{
performanceManager.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => performance.Value = (int)t.Result), cancellationTokenSource.Token);
.ContinueWith(t => Schedule(() =>
{
if (t.Result.HasValue)
performance.Value = (int)t.Result.Value;
}), cancellationTokenSource.Token);
}
}