mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge pull request #9033 from smoogipoo/applydefaults-cancellation
Add cancellation token support to CreateNestedHitObjects()
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Bindables;
|
||||
@ -99,7 +100,8 @@ namespace osu.Game.Rulesets.Objects
|
||||
/// </summary>
|
||||
/// <param name="controlPointInfo">The control points.</param>
|
||||
/// <param name="difficulty">The difficulty settings to use.</param>
|
||||
public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
public void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
||||
|
||||
@ -108,7 +110,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
|
||||
nestedHitObjects.Clear();
|
||||
|
||||
CreateNestedHitObjects();
|
||||
CreateNestedHitObjects(cancellationToken);
|
||||
|
||||
if (this is IHasComboInformation hasCombo)
|
||||
{
|
||||
@ -122,7 +124,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
nestedHitObjects.Sort((h1, h2) => h1.StartTime.CompareTo(h2.StartTime));
|
||||
|
||||
foreach (var h in nestedHitObjects)
|
||||
h.ApplyDefaults(controlPointInfo, difficulty);
|
||||
h.ApplyDefaults(controlPointInfo, difficulty, cancellationToken);
|
||||
|
||||
DefaultsApplied?.Invoke(this);
|
||||
}
|
||||
@ -136,6 +138,14 @@ namespace osu.Game.Rulesets.Objects
|
||||
HitWindows?.SetDifficulty(difficulty.OverallDifficulty);
|
||||
}
|
||||
|
||||
protected virtual void CreateNestedHitObjects(CancellationToken cancellationToken)
|
||||
{
|
||||
// ReSharper disable once MethodSupportsCancellation (https://youtrack.jetbrains.com/issue/RIDER-44520)
|
||||
#pragma warning disable 618
|
||||
CreateNestedHitObjects();
|
||||
#pragma warning restore 618
|
||||
}
|
||||
|
||||
protected virtual void CreateNestedHitObjects()
|
||||
{
|
||||
}
|
||||
|
@ -4,13 +4,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects
|
||||
{
|
||||
public static class SliderEventGenerator
|
||||
{
|
||||
[Obsolete("Use the overload with cancellation support instead.")] // can be removed 20201115
|
||||
public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount,
|
||||
double? legacyLastTickOffset)
|
||||
{
|
||||
return Generate(startTime, spanDuration, velocity, tickDistance, totalDistance, spanCount, legacyLastTickOffset, default);
|
||||
}
|
||||
|
||||
// ReSharper disable once MethodOverloadWithOptionalParameter
|
||||
public static IEnumerable<SliderEventDescriptor> Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount,
|
||||
double? legacyLastTickOffset, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 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.
|
||||
@ -37,7 +46,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
var spanStartTime = startTime + span * spanDuration;
|
||||
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)
|
||||
{
|
||||
@ -108,12 +117,15 @@ namespace osu.Game.Rulesets.Objects
|
||||
/// <param name="length">The length of the path.</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="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>
|
||||
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)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (d >= length - minDistanceFromEnd)
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user