From 973f29b7653a5e57e17be02b268f9ac07c8076c9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 8 Mar 2019 15:14:57 +0900 Subject: [PATCH] Apply review --- osu.Game.Rulesets.Osu/Objects/Slider.cs | 3 +- .../Beatmaps/Formats/SliderEventGenerator.cs | 115 ------------------ .../Rulesets/Objects/SliderEventGenerator.cs | 109 +++++++++++++++++ 3 files changed, 110 insertions(+), 117 deletions(-) delete mode 100644 osu.Game/Beatmaps/Formats/SliderEventGenerator.cs create mode 100644 osu.Game/Rulesets/Objects/SliderEventGenerator.cs diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index b23be96b93..9638d5e6f0 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -11,7 +11,6 @@ using osu.Framework.Caching; using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Formats; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Osu.Judgements; @@ -210,7 +209,7 @@ namespace osu.Game.Rulesets.Osu.Objects RepeatIndex = e.SpanIndex, SpanDuration = SpanDuration, StartTime = StartTime + (e.SpanIndex + 1) * SpanDuration, - Position = Position + Path.PositionAt((e.SpanIndex + 1) % 2), + Position = Position + Path.PositionAt(e.PathProgress), StackHeight = StackHeight, Scale = Scale, Samples = getNodeSamples(1 + e.SpanIndex) diff --git a/osu.Game/Beatmaps/Formats/SliderEventGenerator.cs b/osu.Game/Beatmaps/Formats/SliderEventGenerator.cs deleted file mode 100644 index afe46f42f3..0000000000 --- a/osu.Game/Beatmaps/Formats/SliderEventGenerator.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using osuTK; - -namespace osu.Game.Beatmaps.Formats -{ - public static class SliderEventGenerator - { - public static IEnumerable Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount, double? legacyLastTickOffset) - { - List events = new List(); - - // 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. - const double max_length = 100000; - - var length = Math.Min(max_length, totalDistance); - tickDistance = MathHelper.Clamp(tickDistance, 0, length); - - { - var minDistanceFromEnd = velocity * 10; - - events.Add(new SliderEventDescriptor - { - Type = SliderEventType.Head, - SpanIndex = 0, - SpanStartTime = startTime, - StartTime = startTime, - PathProgress = 0, - }); - - if (tickDistance != 0) - { - for (var span = 0; span < spanCount; span++) - { - var spanStartTime = startTime + span * spanDuration; - var reversed = span % 2 == 1; - - for (var d = tickDistance; d <= length; d += tickDistance) - { - if (d > length - minDistanceFromEnd) - break; - - var pathProgress = d / length; - var timeProgress = reversed ? 1 - pathProgress : pathProgress; - - events.Add(new SliderEventDescriptor - { - Type = SliderEventType.Tick, - SpanIndex = span, - SpanStartTime = spanStartTime, - StartTime = spanStartTime + timeProgress * spanDuration, - PathProgress = pathProgress, - }); - } - - if (span < spanCount - 1) - { - events.Add(new SliderEventDescriptor - { - Type = SliderEventType.Repeat, - SpanIndex = span, - SpanStartTime = startTime + span * spanDuration, - StartTime = spanStartTime + (span + 1) * spanDuration, - PathProgress = 1, - }); - } - } - } - - double totalDuration = spanCount * spanDuration; - - var tail = new SliderEventDescriptor - { - Type = SliderEventType.Tail, - SpanIndex = spanCount - 1, - SpanStartTime = startTime + (spanCount - 1) * spanDuration, - StartTime = startTime + totalDuration, - PathProgress = 1, - }; - - if (legacyLastTickOffset != null) - tail.StartTime = Math.Max(startTime + totalDuration / 2, tail.StartTime - legacyLastTickOffset.Value); - - events.Add(tail); - - return events; - } - } - } - - public class SliderEventDescriptor - { - public SliderEventType Type; - - public int SpanIndex; - - public double SpanStartTime; - - public double StartTime; - - public double PathProgress; - } - - public enum SliderEventType - { - Tick, - Head, - Tail, - Repeat - } -} diff --git a/osu.Game/Rulesets/Objects/SliderEventGenerator.cs b/osu.Game/Rulesets/Objects/SliderEventGenerator.cs new file mode 100644 index 0000000000..39827ef532 --- /dev/null +++ b/osu.Game/Rulesets/Objects/SliderEventGenerator.cs @@ -0,0 +1,109 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osuTK; + +namespace osu.Game.Rulesets.Objects +{ + public static class SliderEventGenerator + { + public static IEnumerable Generate(double startTime, double spanDuration, double velocity, double tickDistance, double totalDistance, int spanCount, double? legacyLastTickOffset) + { + // 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. + const double max_length = 100000; + + var length = Math.Min(max_length, totalDistance); + tickDistance = MathHelper.Clamp(tickDistance, 0, length); + + var minDistanceFromEnd = velocity * 10; + + yield return new SliderEventDescriptor + { + Type = SliderEventType.Head, + SpanIndex = 0, + SpanStartTime = startTime, + StartTime = startTime, + PathProgress = 0, + }; + + if (tickDistance != 0) + { + for (var span = 0; span < spanCount; span++) + { + var spanStartTime = startTime + span * spanDuration; + var reversed = span % 2 == 1; + + for (var d = tickDistance; d <= length; d += tickDistance) + { + if (d > length - minDistanceFromEnd) + break; + + var pathProgress = d / length; + var timeProgress = reversed ? 1 - pathProgress : pathProgress; + + yield return new SliderEventDescriptor + { + Type = SliderEventType.Tick, + SpanIndex = span, + SpanStartTime = spanStartTime, + StartTime = spanStartTime + timeProgress * spanDuration, + PathProgress = pathProgress, + }; + } + + if (span < spanCount - 1) + { + yield return new SliderEventDescriptor + { + Type = SliderEventType.Repeat, + SpanIndex = span, + SpanStartTime = startTime + span * spanDuration, + StartTime = spanStartTime + (span + 1) * spanDuration, + PathProgress = (span + 1) % 2, + }; + } + } + } + + double totalDuration = spanCount * spanDuration; + + var tail = new SliderEventDescriptor + { + Type = SliderEventType.Tail, + SpanIndex = spanCount - 1, + SpanStartTime = startTime + (spanCount - 1) * spanDuration, + StartTime = startTime + totalDuration, + PathProgress = 1, + }; + + if (legacyLastTickOffset != null) + tail.StartTime = Math.Max(startTime + totalDuration / 2, tail.StartTime - legacyLastTickOffset.Value); + + yield return tail; + } + } + + public struct SliderEventDescriptor + { + public SliderEventType Type; + + public int SpanIndex; + + public double SpanStartTime; + + public double StartTime; + + public double PathProgress; + } + + public enum SliderEventType + { + Tick, + Head, + Tail, + Repeat + } +}