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

Actually use the cancellation token

This commit is contained in:
smoogipoo 2020-05-15 18:17:39 +09:00
parent 4079642d58
commit 4719fcc291
5 changed files with 26 additions and 11 deletions

View File

@ -59,7 +59,7 @@ namespace osu.Game.Rulesets.Catch.Objects
SliderEventDescriptor? lastEvent = null; SliderEventDescriptor? lastEvent = null;
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset)) foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken))
{ {
// generate tiny droplets since the last point // generate tiny droplets since the last point
if (lastEvent != null) if (lastEvent != null)
@ -74,6 +74,8 @@ namespace osu.Game.Rulesets.Catch.Objects
for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny) for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
{ {
cancellationToken.ThrowIfCancellationRequested();
AddNested(new TinyDroplet AddNested(new TinyDroplet
{ {
StartTime = t + lastEvent.Value.Time, StartTime = t + lastEvent.Value.Time,

View File

@ -96,7 +96,7 @@ namespace osu.Game.Rulesets.Mania.Objects
{ {
base.CreateNestedHitObjects(cancellationToken); base.CreateNestedHitObjects(cancellationToken);
createTicks(); createTicks(cancellationToken);
AddNested(Head = new Note AddNested(Head = new Note
{ {
@ -113,13 +113,15 @@ namespace osu.Game.Rulesets.Mania.Objects
}); });
} }
private void createTicks() private void createTicks(CancellationToken cancellationToken)
{ {
if (tickSpacing == 0) if (tickSpacing == 0)
return; return;
for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing) for (double t = StartTime + tickSpacing; t <= EndTime - tickSpacing; t += tickSpacing)
{ {
cancellationToken.ThrowIfCancellationRequested();
AddNested(new HoldNoteTick AddNested(new HoldNoteTick
{ {
StartTime = t, StartTime = t,

View File

@ -139,7 +139,7 @@ namespace osu.Game.Rulesets.Osu.Objects
base.CreateNestedHitObjects(cancellationToken); base.CreateNestedHitObjects(cancellationToken);
foreach (var e in foreach (var e in
SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset)) SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset, cancellationToken))
{ {
switch (e.Type) switch (e.Type)
{ {

View File

@ -129,12 +129,19 @@ namespace osu.Game.Beatmaps
processor?.PreProcess(); processor?.PreProcess();
// Compute default values for hitobjects, including creating nested hitobjects in-case they're needed // Compute default values for hitobjects, including creating nested hitobjects in-case they're needed
foreach (var obj in converted.HitObjects) try
{ {
if (cancellationSource.IsCancellationRequested) foreach (var obj in converted.HitObjects)
throw new BeatmapLoadTimeoutException(BeatmapInfo); {
if (cancellationSource.IsCancellationRequested)
throw new BeatmapLoadTimeoutException(BeatmapInfo);
obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty, cancellationSource.Token); obj.ApplyDefaults(converted.ControlPointInfo, converted.BeatmapInfo.BaseDifficulty, cancellationSource.Token);
}
}
catch (OperationCanceledException)
{
throw new BeatmapLoadTimeoutException(BeatmapInfo);
} }
foreach (var mod in mods.OfType<IApplicableToHitObject>()) foreach (var mod in mods.OfType<IApplicableToHitObject>())

View File

@ -4,13 +4,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
namespace osu.Game.Rulesets.Objects namespace osu.Game.Rulesets.Objects
{ {
public static class SliderEventGenerator public static class SliderEventGenerator
{ {
public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount, public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount,
double? legacyLastTickOffset) double? legacyLastTickOffset, CancellationToken cancellationToken = default)
{ {
// A very lenient maximum length of a slider for ticks to be generated. // A very lenient maximum length of a slider for ticks to be generated.
// This exists for edge cases such as /b/1573664 where the beatmap has been edited by the user, and should never be reached in normal usage. // This exists for edge cases such as /b/1573664 where the beatmap has been edited by the user, and should never be reached in normal usage.
@ -37,7 +38,7 @@ namespace osu.Game.Rulesets.Objects
var spanStartTime = startTime + span * spanDuration; var spanStartTime = startTime + span * spanDuration;
var reversed = span % 2 == 1; var reversed = span % 2 == 1;
var ticks = generateTicks(span, spanStartTime, spanDuration, reversed, length, tickDistance, minDistanceFromEnd); var ticks = generateTicks(span, spanStartTime, spanDuration, reversed, length, tickDistance, minDistanceFromEnd, cancellationToken);
if (reversed) if (reversed)
{ {
@ -108,12 +109,15 @@ namespace osu.Game.Rulesets.Objects
/// <param name="length">The length of the path.</param> /// <param name="length">The length of the path.</param>
/// <param name="tickDistance">The distance between each tick.</param> /// <param name="tickDistance">The distance between each tick.</param>
/// <param name="minDistanceFromEnd">The distance from the end of the path at which ticks are not allowed to be added.</param> /// <param name="minDistanceFromEnd">The distance from the end of the path at which ticks are not allowed to be added.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A <see cref="SliderEventDescriptor"/> for each tick. If <paramref name="reversed"/> is true, the ticks will be returned in reverse-StartTime order.</returns> /// <returns>A <see cref="SliderEventDescriptor"/> for each tick. If <paramref name="reversed"/> is true, the ticks will be returned in reverse-StartTime order.</returns>
private static IEnumerable<SliderEventDescriptor> generateTicks(int spanIndex, double spanStartTime, double spanDuration, bool reversed, double length, double tickDistance, private static IEnumerable<SliderEventDescriptor> generateTicks(int spanIndex, double spanStartTime, double spanDuration, bool reversed, double length, double tickDistance,
double minDistanceFromEnd) double minDistanceFromEnd, CancellationToken cancellationToken = default)
{ {
for (var d = tickDistance; d <= length; d += tickDistance) for (var d = tickDistance; d <= length; d += tickDistance)
{ {
cancellationToken.ThrowIfCancellationRequested();
if (d >= length - minDistanceFromEnd) if (d >= length - minDistanceFromEnd)
break; break;