mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:43:19 +08:00
Remove blocking calls and add back Task.WhenAll
This commit is contained in:
parent
261fae6873
commit
42d904acee
@ -5,7 +5,6 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Extensions;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
@ -29,21 +28,30 @@ namespace osu.Game.Rulesets.Difficulty
|
|||||||
[ItemCanBeNull]
|
[ItemCanBeNull]
|
||||||
public async Task<PerformanceBreakdown> CalculateAsync(ScoreInfo score, CancellationToken cancellationToken = default)
|
public async Task<PerformanceBreakdown> CalculateAsync(ScoreInfo score, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
PerformanceAttributes performance = await performanceCache.CalculatePerformanceAsync(score, cancellationToken).ConfigureAwait(false);
|
PerformanceAttributes[] performanceArray = await Task.WhenAll(
|
||||||
|
// compute actual performance
|
||||||
|
performanceCache.CalculatePerformanceAsync(score, cancellationToken),
|
||||||
|
// compute performance for perfect play
|
||||||
|
getPerfectPerformance(score, cancellationToken)
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return new PerformanceBreakdown { Performance = performanceArray[0], PerfectPerformance = performanceArray[1] };
|
||||||
|
}
|
||||||
|
|
||||||
|
[ItemCanBeNull]
|
||||||
|
private async Task<PerformanceAttributes> getPerfectPerformance(ScoreInfo score, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
ScoreInfo perfectScore = await getPerfectScore(score, cancellationToken).ConfigureAwait(false);
|
ScoreInfo perfectScore = await getPerfectScore(score, cancellationToken).ConfigureAwait(false);
|
||||||
if (perfectScore == null)
|
if (perfectScore == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
PerformanceAttributes perfectPerformance = await performanceCache.CalculatePerformanceAsync(perfectScore, cancellationToken).ConfigureAwait(false);
|
return await performanceCache.CalculatePerformanceAsync(perfectScore, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return new PerformanceBreakdown { Performance = performance, PerfectPerformance = perfectPerformance };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ItemCanBeNull]
|
[ItemCanBeNull]
|
||||||
private Task<ScoreInfo> getPerfectScore(ScoreInfo score, CancellationToken cancellationToken = default)
|
private Task<ScoreInfo> getPerfectScore(ScoreInfo score, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return Task.Factory.StartNew(() =>
|
return Task.Run(async () =>
|
||||||
{
|
{
|
||||||
IBeatmap beatmap = beatmapManager.GetWorkingBeatmap(score.BeatmapInfo).GetPlayableBeatmap(score.Ruleset, score.Mods);
|
IBeatmap beatmap = beatmapManager.GetWorkingBeatmap(score.BeatmapInfo).GetPlayableBeatmap(score.Ruleset, score.Mods);
|
||||||
ScoreInfo perfectPlay = score.DeepClone();
|
ScoreInfo perfectPlay = score.DeepClone();
|
||||||
@ -51,12 +59,12 @@ namespace osu.Game.Rulesets.Difficulty
|
|||||||
perfectPlay.Passed = true;
|
perfectPlay.Passed = true;
|
||||||
|
|
||||||
// calculate max combo
|
// calculate max combo
|
||||||
var difficulty = difficultyCache.GetDifficultyAsync(
|
var difficulty = await difficultyCache.GetDifficultyAsync(
|
||||||
beatmap.BeatmapInfo,
|
beatmap.BeatmapInfo,
|
||||||
score.Ruleset,
|
score.Ruleset,
|
||||||
score.Mods,
|
score.Mods,
|
||||||
cancellationToken
|
cancellationToken
|
||||||
).GetResultSafely();
|
).ConfigureAwait(false);
|
||||||
|
|
||||||
if (difficulty == null)
|
if (difficulty == null)
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user