1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-10 21:40:34 +08:00

Cancel difficulty calculation after 10 seconds by default

This commit is contained in:
Dan Balasescu 2025-03-04 11:22:47 +09:00
parent c30f334cf9
commit 550ff85550
No known key found for this signature in database

View File

@ -62,6 +62,11 @@ namespace osu.Game.Rulesets.Difficulty
/// <returns>A structure describing the difficulty of the beatmap.</returns>
public DifficultyAttributes Calculate([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
{
using var timedCancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
if (!cancellationToken.CanBeCanceled)
cancellationToken = timedCancellationSource.Token;
cancellationToken.ThrowIfCancellationRequested();
preProcess(mods, cancellationToken);
@ -98,6 +103,11 @@ namespace osu.Game.Rulesets.Difficulty
/// <returns>The set of <see cref="TimedDifficultyAttributes"/>.</returns>
public List<TimedDifficultyAttributes> CalculateTimed([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
{
using var timedCancellationSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
if (!cancellationToken.CanBeCanceled)
cancellationToken = timedCancellationSource.Token;
cancellationToken.ThrowIfCancellationRequested();
preProcess(mods, cancellationToken);
@ -166,15 +176,10 @@ namespace osu.Game.Rulesets.Difficulty
/// </summary>
/// <param name="mods">The original list of <see cref="Mod"/>s.</param>
/// <param name="cancellationToken">The cancellation token.</param>
private void preProcess([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
private void preProcess([NotNull] IEnumerable<Mod> mods, CancellationToken cancellationToken)
{
playableMods = mods.Select(m => m.DeepClone()).ToArray();
// Only pass through the cancellation token if it's non-default.
// This allows for the default timeout to be applied for playable beatmap construction.
Beatmap = cancellationToken == default
? beatmap.GetPlayableBeatmap(ruleset, playableMods)
: beatmap.GetPlayableBeatmap(ruleset, playableMods, cancellationToken);
Beatmap = beatmap.GetPlayableBeatmap(ruleset, playableMods, cancellationToken);
var track = new TrackVirtual(10000);
playableMods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));