1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:03:08 +08:00

Add a method to calculate asynchronously performance on a beatmap.

This commit is contained in:
Lucas A 2020-09-23 21:15:41 +02:00
parent fb9d2cb05c
commit 4d743f64f5

View File

@ -16,6 +16,7 @@ using osu.Framework.Lists;
using osu.Framework.Threading;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
namespace osu.Game.Beatmaps
{
@ -114,6 +115,28 @@ namespace osu.Game.Beatmaps
return computeDifficulty(key, beatmapInfo, rulesetInfo);
}
/// <summary>
/// Calculates performance for the given <see cref="ScoreInfo"/> on a given <see cref="WorkingBeatmap"/>.
/// </summary>
/// <param name="beatmap">The <see cref="WorkingBeatmap"/> to do the calculation on. </param>
/// <param name="score">The score to do the calculation on. </param>
/// <param name="token">An optional <see cref="CancellationToken"/> to cancel the operation.</param>
/// <returns></returns>
public async Task<double> CalculateScorePerformance([NotNull] WorkingBeatmap beatmap, [NotNull] ScoreInfo score, CancellationToken token = default)
{
return await Task.Factory.StartNew(() =>
{
if (token.IsCancellationRequested)
return default;
var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(beatmap, score);
var total = calculator.Calculate(null);
return total;
}, token, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
}
private CancellationTokenSource trackedUpdateCancellationSource;
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();