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:
parent
fb9d2cb05c
commit
4d743f64f5
@ -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>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user