mirror of
https://github.com/osukey/osukey.git
synced 2025-05-03 20:57:28 +09:00
Split performance calculation to its own class.
This commit is contained in:
parent
3cb9103fe0
commit
ddede85704
@ -16,7 +16,6 @@ using osu.Framework.Lists;
|
|||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Scoring;
|
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps
|
namespace osu.Game.Beatmaps
|
||||||
{
|
{
|
||||||
@ -115,26 +114,6 @@ namespace osu.Game.Beatmaps
|
|||||||
return computeDifficulty(key, beatmapInfo, rulesetInfo);
|
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>
|
|
||||||
public async Task<double> CalculatePerformance([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();
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}, token, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CancellationTokenSource trackedUpdateCancellationSource;
|
private CancellationTokenSource trackedUpdateCancellationSource;
|
||||||
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
||||||
|
|
||||||
|
@ -58,6 +58,8 @@ namespace osu.Game
|
|||||||
|
|
||||||
protected ScoreManager ScoreManager;
|
protected ScoreManager ScoreManager;
|
||||||
|
|
||||||
|
protected ScorePerformanceManager ScorePerformanceManager;
|
||||||
|
|
||||||
protected BeatmapDifficultyManager DifficultyManager;
|
protected BeatmapDifficultyManager DifficultyManager;
|
||||||
|
|
||||||
protected SkinManager SkinManager;
|
protected SkinManager SkinManager;
|
||||||
@ -226,6 +228,9 @@ namespace osu.Game
|
|||||||
dependencies.Cache(DifficultyManager = new BeatmapDifficultyManager());
|
dependencies.Cache(DifficultyManager = new BeatmapDifficultyManager());
|
||||||
AddInternal(DifficultyManager);
|
AddInternal(DifficultyManager);
|
||||||
|
|
||||||
|
dependencies.Cache(ScorePerformanceManager = new ScorePerformanceManager());
|
||||||
|
AddInternal(ScorePerformanceManager);
|
||||||
|
|
||||||
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||||
|
39
osu.Game/Scoring/ScorePerformanceManager.cs
Normal file
39
osu.Game/Scoring/ScorePerformanceManager.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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; }
|
||||||
|
|
||||||
|
/// <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 async Task<double> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,6 @@
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps;
|
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
||||||
@ -24,7 +23,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(BeatmapManager beatmapManager, BeatmapDifficultyManager difficultyManager)
|
private void load(ScorePerformanceManager performanceManager)
|
||||||
{
|
{
|
||||||
if (score.PP.HasValue)
|
if (score.PP.HasValue)
|
||||||
{
|
{
|
||||||
@ -32,9 +31,8 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var beatmap = beatmapManager.GetWorkingBeatmap(score.Beatmap);
|
performanceManager.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
|
||||||
difficultyManager.CalculatePerformance(beatmap, score, cancellationTokenSource.Token)
|
.ContinueWith(t => Schedule(() => performance.Value = (int)t.Result), cancellationTokenSource.Token);
|
||||||
.ContinueWith(t => Schedule(() => performance.Value = (int)t.Result), cancellationTokenSource.Token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user