1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 19:03:08 +08:00

Merge pull request #15972 from peppy/cancellation-woes

Fix `GetPlayableBeatmap` timeout not being applied when no `CancellationToken` is provided to difficulty calculations
This commit is contained in:
Dan Balasescu 2021-12-07 14:31:56 +09:00 committed by GitHub
commit 9f77529e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,14 +120,14 @@ namespace osu.Game.Rulesets.Difficulty
/// Calculates the difficulty of the beatmap using all mod combinations applicable to the beatmap.
/// </summary>
/// <returns>A collection of structures describing the difficulty of the beatmap for each mod combination.</returns>
public IEnumerable<DifficultyAttributes> CalculateAll()
public IEnumerable<DifficultyAttributes> CalculateAll(CancellationToken cancellationToken = default)
{
foreach (var combination in CreateDifficultyAdjustmentModCombinations())
{
if (combination is MultiMod multi)
yield return Calculate(multi.Mods);
yield return Calculate(multi.Mods, cancellationToken);
else
yield return Calculate(combination.Yield());
yield return Calculate(combination.Yield(), cancellationToken);
}
}
@ -145,7 +145,11 @@ namespace osu.Game.Rulesets.Difficulty
{
playableMods = mods.Select(m => m.DeepClone()).ToArray();
Beatmap = beatmap.GetPlayableBeatmap(ruleset, playableMods, cancellationToken);
// 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);
var track = new TrackVirtual(10000);
playableMods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));