/// <summary> /// Calculates performance for the given <see cref="ScoreInfo"/>. /// </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 Task <double?> CalculatePerformanceAsync([NotNull] ScoreInfo score, CancellationToken token = default) { var lookupKey = new PerformanceCacheLookup(score); if (performanceCache.TryGetValue(lookupKey, out double performance)) { return(Task.FromResult((double?)performance)); } return(computePerformanceAsync(score, lookupKey, token)); }
protected override async Task <PerformanceAttributes> ComputeValueAsync(PerformanceCacheLookup lookup, CancellationToken token = default) { var score = lookup.ScoreInfo; var attributes = await difficultyCache.GetDifficultyAsync(score.BeatmapInfo, score.Ruleset, score.Mods, token).ConfigureAwait(false); // Performance calculation requires the beatmap and ruleset to be locally available. If not, return a default value. if (attributes?.Attributes == null) { return(null); } token.ThrowIfCancellationRequested(); return(score.Ruleset.CreateInstance().CreatePerformanceCalculator()?.Calculate(score, attributes.Value.Attributes)); }
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(null); } token.ThrowIfCancellationRequested(); var calculator = score.Ruleset.CreateInstance().CreatePerformanceCalculator(attributes.Attributes, score); var total = calculator?.Calculate(); if (total.HasValue) { performanceCache[lookupKey] = total.Value; } return(total); }