mirror of
https://github.com/ppy/osu
synced 2025-03-04 18:40:24 +00:00
Fix PR comments.
Nitpick, more cancellation token checks.
This commit is contained in:
parent
eb7d04bc77
commit
cf0b757b16
@ -408,7 +408,7 @@ namespace osu.Game.Beatmaps
|
||||
beatmap.BeatmapInfo.Ruleset = ruleset;
|
||||
|
||||
// TODO: this should be done in a better place once we actually need to dynamically update it.
|
||||
beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate(null).StarRating ?? 0;
|
||||
beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance().CreateDifficultyCalculator(new DummyConversionBeatmap(beatmap)).Calculate().StarRating ?? 0;
|
||||
beatmap.BeatmapInfo.Length = calculateLength(beatmap);
|
||||
beatmap.BeatmapInfo.BPM = 60000 / beatmap.GetMostCommonBeatLength();
|
||||
|
||||
|
@ -58,10 +58,10 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="ruleset">The <see cref="RulesetInfo"/> to create a playable <see cref="IBeatmap"/> for.</param>
|
||||
/// <param name="mods">The <see cref="Mod"/>s to apply to the <see cref="IBeatmap"/>.</param>
|
||||
/// <param name="timeout">The maximum length in milliseconds to wait for load to complete. Defaults to 10,000ms.</param>
|
||||
/// <param name="cancellationToken">Externally provided cancellation token.</param>
|
||||
/// <param name="timeoutToken">Cancellation token that cancels the beatmap loading process.</param>
|
||||
/// <returns>The converted <see cref="IBeatmap"/>.</returns>
|
||||
/// <exception cref="BeatmapInvalidForRulesetException">If <see cref="Beatmap"/> could not be converted to <paramref name="ruleset"/>.</exception>
|
||||
IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default);
|
||||
IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken timeoutToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Load a new audio track instance for this beatmap. This should be called once before accessing <see cref="Track"/>.
|
||||
|
@ -81,9 +81,10 @@ namespace osu.Game.Beatmaps
|
||||
/// <returns>The applicable <see cref="IBeatmapConverter"/>.</returns>
|
||||
protected virtual IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap, Ruleset ruleset) => ruleset.CreateBeatmapConverter(beatmap);
|
||||
|
||||
public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
|
||||
public virtual IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken timeoutToken = default)
|
||||
{
|
||||
using (var cancellationSource = createCancellationTokenSource(timeout))
|
||||
using (var timeoutSource = createTimeoutTokenSource(timeout))
|
||||
using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutToken, timeoutSource.Token))
|
||||
{
|
||||
mods ??= Array.Empty<Mod>();
|
||||
|
||||
@ -98,19 +99,19 @@ namespace osu.Game.Beatmaps
|
||||
// Apply conversion mods
|
||||
foreach (var mod in mods.OfType<IApplicableToBeatmapConverter>())
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
if (linkedTokenSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
mod.ApplyToBeatmapConverter(converter);
|
||||
}
|
||||
|
||||
// Convert
|
||||
IBeatmap converted = converter.Convert(cancellationToken != CancellationToken.None ? cancellationToken : cancellationSource.Token);
|
||||
IBeatmap converted = converter.Convert(linkedTokenSource.Token);
|
||||
|
||||
// Apply conversion mods to the result
|
||||
foreach (var mod in mods.OfType<IApplicableAfterBeatmapConversion>())
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
if (linkedTokenSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
mod.ApplyToBeatmap(converted);
|
||||
@ -121,7 +122,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
if (linkedTokenSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
mod.ApplyToDifficulty(converted.Difficulty);
|
||||
@ -140,10 +141,10 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
foreach (var obj in converted.HitObjects)
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
if (linkedTokenSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, cancellationToken != CancellationToken.None ? cancellationToken : cancellationSource.Token);
|
||||
obj.ApplyDefaults(converted.ControlPointInfo, converted.Difficulty, linkedTokenSource.Token);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@ -155,7 +156,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
foreach (var obj in converted.HitObjects)
|
||||
{
|
||||
if (cancellationSource.IsCancellationRequested)
|
||||
if (linkedTokenSource.IsCancellationRequested)
|
||||
throw new BeatmapLoadTimeoutException(BeatmapInfo);
|
||||
|
||||
mod.ApplyToHitObject(obj);
|
||||
@ -166,8 +167,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
foreach (var mod in mods.OfType<IApplicableToBeatmap>())
|
||||
{
|
||||
cancellationSource.Token.ThrowIfCancellationRequested();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
linkedTokenSource.Token.ThrowIfCancellationRequested();
|
||||
mod.ApplyToBeatmap(converted);
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
private CancellationTokenSource createCancellationTokenSource(TimeSpan? timeout)
|
||||
private CancellationTokenSource createTimeoutTokenSource(TimeSpan? timeout)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
// ignore timeout when debugger is attached (may be breakpointing / debugging).
|
||||
|
@ -42,8 +42,9 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
/// <param name="mods">The mods that should be applied to the beatmap.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>A structure describing the difficulty of the beatmap.</returns>
|
||||
public DifficultyAttributes Calculate(IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
|
||||
public DifficultyAttributes Calculate(IEnumerable<Mod> mods = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
preProcess(mods, cancellationToken);
|
||||
|
||||
var skills = CreateSkills(Beatmap, playableMods, clockRate);
|
||||
@ -54,7 +55,10 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
foreach (var hitObject in getDifficultyHitObjects())
|
||||
{
|
||||
foreach (var skill in skills)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
skill.ProcessInternal(hitObject);
|
||||
}
|
||||
}
|
||||
|
||||
return CreateDifficultyAttributes(Beatmap, playableMods, skills, clockRate);
|
||||
@ -68,6 +72,7 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
/// <returns>The set of <see cref="TimedDifficultyAttributes"/>.</returns>
|
||||
public List<TimedDifficultyAttributes> CalculateTimed(IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
preProcess(mods, cancellationToken);
|
||||
|
||||
var attribs = new List<TimedDifficultyAttributes>();
|
||||
@ -83,7 +88,10 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
progressiveBeatmap.HitObjects.Add(hitObject.BaseObject);
|
||||
|
||||
foreach (var skill in skills)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
skill.ProcessInternal(hitObject);
|
||||
}
|
||||
|
||||
attribs.Add(new TimedDifficultyAttributes(hitObject.EndTime * clockRate, CreateDifficultyAttributes(progressiveBeatmap, playableMods, skills, clockRate)));
|
||||
}
|
||||
@ -102,7 +110,7 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
if (combination is MultiMod multi)
|
||||
yield return Calculate(multi.Mods);
|
||||
else
|
||||
yield return Calculate(new[] { combination });
|
||||
yield return Calculate(combination.Yield());
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,12 +123,12 @@ namespace osu.Game.Rulesets.Difficulty
|
||||
/// Performs required tasks before every calculation.
|
||||
/// </summary>
|
||||
/// <param name="mods">The original list of <see cref="Mod"/>s.</param>
|
||||
/// <param name="cancellationToken">The cancellation cancellationToken.</param>
|
||||
private void preProcess(IEnumerable<Mod> mods, CancellationToken cancellationToken = default)
|
||||
/// <param name="cancellationToken">The cancellation timeoutToken.</param>
|
||||
private void preProcess(IEnumerable<Mod> mods = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
playableMods = mods.Select(m => m.DeepClone()).ToArray();
|
||||
|
||||
Beatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, playableMods, cancellationToken: cancellationToken);
|
||||
Beatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, playableMods, timeoutToken: cancellationToken);
|
||||
|
||||
var track = new TrackVirtual(10000);
|
||||
playableMods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
|
||||
|
@ -210,7 +210,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
this.gameplayBeatmap = gameplayBeatmap;
|
||||
}
|
||||
|
||||
public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
|
||||
public override IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods = null, TimeSpan? timeout = null, CancellationToken timeoutToken = default)
|
||||
=> gameplayBeatmap;
|
||||
|
||||
protected override IBeatmap GetBeatmap() => gameplayBeatmap;
|
||||
|
@ -284,7 +284,7 @@ namespace osu.Game.Stores
|
||||
decoded.BeatmapInfo.Ruleset = rulesetInstance.RulesetInfo;
|
||||
|
||||
// TODO: this should be done in a better place once we actually need to dynamically update it.
|
||||
beatmap.StarRating = rulesetInstance.CreateDifficultyCalculator(new DummyConversionBeatmap(decoded)).Calculate(null).StarRating;
|
||||
beatmap.StarRating = rulesetInstance.CreateDifficultyCalculator(new DummyConversionBeatmap(decoded)).Calculate().StarRating;
|
||||
beatmap.Length = calculateLength(decoded);
|
||||
beatmap.BPM = 60000 / decoded.GetMostCommonBeatLength();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user