// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps; namespace osu.Game.Scoring { public class ScorePerformanceManager : Component { [Resolved] private BeatmapManager beatmapManager { get; set; } /// /// Calculates performance for the given . /// /// The score to do the calculation on. /// An optional to cancel the operation. public async Task CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default) { return await Task.Factory.StartNew(() => { if (token.IsCancellationRequested) return default; var beatmap = beatmapManager.GetWorkingBeatmap(score.Beatmap); var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(beatmap, score); var total = calculator.Calculate(); return total; }, token); } } }