From f0caa1006631c08c9f15e665e865b3108543a64c Mon Sep 17 00:00:00 2001 From: Tollii Date: Fri, 5 Nov 2021 23:53:48 +0100 Subject: [PATCH] Add support for a provided cancellation token for GetPlayableBeatmap() --- osu.Game/Beatmaps/IWorkingBeatmap.cs | 4 +++- osu.Game/Beatmaps/WorkingBeatmap.cs | 7 ++++--- osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/IWorkingBeatmap.cs b/osu.Game/Beatmaps/IWorkingBeatmap.cs index a916b37b85..6f0f408060 100644 --- a/osu.Game/Beatmaps/IWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/IWorkingBeatmap.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; using osu.Framework.Audio.Track; using osu.Framework.Graphics.Textures; using osu.Game.Rulesets; @@ -57,9 +58,10 @@ public interface IWorkingBeatmap /// The to create a playable for. /// The s to apply to the . /// The maximum length in milliseconds to wait for load to complete. Defaults to 10,000ms. + /// Externally provided cancellation token. /// The converted . /// If could not be converted to . - IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null); + IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default); /// /// Load a new audio track instance for this beatmap. This should be called once before accessing . diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index d2c0f7de0f..affc19c700 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -81,7 +81,7 @@ protected virtual Track GetVirtualTrack(double emptyLength = 0) /// The applicable . protected virtual IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap, Ruleset ruleset) => ruleset.CreateBeatmapConverter(beatmap); - public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) + public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default) { using (var cancellationSource = createCancellationTokenSource(timeout)) { @@ -105,7 +105,7 @@ public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList()) @@ -143,7 +143,7 @@ public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList()) { cancellationSource.Token.ThrowIfCancellationRequested(); + cancellationToken.ThrowIfCancellationRequested(); mod.ApplyToBeatmap(converted); } diff --git a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs index ef289c2a20..922d1e6bbe 100644 --- a/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs +++ b/osu.Game/Screens/Play/HUD/PerformancePointsCounter.cs @@ -210,7 +210,7 @@ public GameplayWorkingBeatmap(IBeatmap gameplayBeatmap) this.gameplayBeatmap = gameplayBeatmap; } - public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null) + public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default) => gameplayBeatmap; protected override IBeatmap GetBeatmap() => gameplayBeatmap;