From 1f6939f57bc7443abbb73d9c775e6dfab311bd01 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 18 May 2017 17:39:03 +0900 Subject: [PATCH 1/5] Add IHasEndTime object pattern generation. --- .../Beatmaps/LegacyBeatmapConverter.cs | 14 +-- .../Legacy/EndTimeObjectPatternGenerator.cs | 100 ++++++++++++++++++ osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 6 ++ .../osu.Game.Rulesets.Mania.csproj | 1 + 4 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs diff --git a/osu.Game.Rulesets.Mania/Beatmaps/LegacyBeatmapConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/LegacyBeatmapConverter.cs index e3045df185..3fd5b3900b 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/LegacyBeatmapConverter.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/LegacyBeatmapConverter.cs @@ -9,6 +9,7 @@ using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Mania.Beatmaps.Patterns; using osu.Game.Rulesets.Mania.MathUtils; +using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy; namespace osu.Game.Rulesets.Mania.Beatmaps { @@ -74,9 +75,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps var distanceData = original as IHasDistance; var positionData = original as IHasPosition; - // Following lines currently commented out to appease resharper - - //PatternGenerator conversion = null; + Patterns.PatternGenerator conversion = null; if (distanceData != null) { @@ -84,6 +83,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps } else if (endTimeData != null) { + conversion = new EndTimeObjectPatternGenerator(random, original, beatmap); // Spinner } else if (positionData != null) @@ -91,13 +91,13 @@ namespace osu.Game.Rulesets.Mania.Beatmaps // Circle } - //if (conversion == null) + if (conversion == null) return null; - //Pattern newPattern = conversion.Generate(); - //lastPattern = newPattern; + Pattern newPattern = conversion.Generate(); + lastPattern = newPattern; - //return newPattern.HitObjects; + return newPattern.HitObjects; } /// diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs new file mode 100644 index 0000000000..cd04418ac5 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -0,0 +1,100 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Mania.MathUtils; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Types; +using System.Linq; +using osu.Game.Audio; +using osu.Game.Rulesets.Mania.Objects; + +namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy +{ + internal class EndTimeObjectPatternGenerator : PatternGenerator + { + private readonly double endTime; + + public EndTimeObjectPatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap) + : base(random, hitObject, beatmap, new Pattern()) + { + var endtimeData = HitObject as IHasEndTime; + + endTime = endtimeData?.EndTime ?? 0; + } + + public override Pattern Generate() + { + var pattern = new Pattern(); + + bool generateHold = endTime - HitObject.StartTime >= 100; + + if (AvailableColumns == 8) + { + if (HitObject.Samples.Any(s => s.Name == SampleInfo.HIT_FINISH) && endTime - HitObject.StartTime < 1000) + addToPattern(pattern, 0, generateHold); + else + addToPattern(pattern, getNextRandomColumn(RandomStart), generateHold); + } + else + addToPattern(pattern, getNextRandomColumn(0), generateHold); + + return pattern; + } + + /// + /// Picks a random column after a column. + /// + /// The starting column. + /// A random column after . + private int getNextRandomColumn(int start) + { + int nextColumn = Random.Next(start, AvailableColumns); + + while (PreviousPattern.IsFilled(nextColumn)) + nextColumn = Random.Next(start, AvailableColumns); + + return nextColumn; + } + + /// + /// Constructs and adds a note to a pattern. + /// + /// The pattern to add to. + /// The column to add the note to. + /// Whether to add a hold note. + private void addToPattern(Pattern pattern, int column, bool holdNote) + { + ManiaHitObject newObject; + + if (holdNote) + { + newObject = new HoldNote + { + StartTime = HitObject.StartTime, + EndSamples = HitObject.Samples, + Column = column, + Duration = endTime - HitObject.StartTime, + Siblings = 1 + }; + + newObject.Samples.Add(new SampleInfo + { + Name = SampleInfo.HIT_NORMAL + }); + } + else + { + newObject = new Note + { + StartTime = HitObject.StartTime, + Samples = HitObject.Samples, + Column = column, + Siblings = 1 + }; + } + + pattern.Add(newObject); + } + } +} diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index a25b8fbf2a..701947c381 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Audio; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Mania.Judgements; @@ -22,6 +23,11 @@ namespace osu.Game.Rulesets.Mania.Objects public double Duration { get; set; } public double EndTime => StartTime + Duration; + /// + /// The samples to be played when this hold note is released. + /// + public SampleInfoList EndSamples = new SampleInfoList(); + /// /// The key-release hit windows for this hold note. /// diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index ea65588a81..9e8d300328 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -47,6 +47,7 @@ + From e76cb4cc3153bdc4e716f60a2a68c81bdf804bb4 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 19 May 2017 17:51:59 +0900 Subject: [PATCH 2/5] Update to match base branch. --- .../Beatmaps/ManiaBeatmapConverter.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs index 933fe0787c..9a93815ce3 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/ManiaBeatmapConverter.cs @@ -11,6 +11,7 @@ using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Mania.Beatmaps.Patterns; using osu.Game.Rulesets.Mania.MathUtils; using osu.Game.Database; +using osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy; namespace osu.Game.Rulesets.Mania.Beatmaps { @@ -83,28 +84,26 @@ namespace osu.Game.Rulesets.Mania.Beatmaps // Following lines currently commented out to appease resharper - //Patterns.PatternGenerator conversion = null; + Patterns.PatternGenerator conversion = null; if (distanceData != null) { // Slider } else if (endTimeData != null) - { - // Spinner - } + conversion = new EndTimeObjectPatternGenerator(random, original, beatmap); else if (positionData != null) { // Circle } - //if (conversion == null) - return null; + if (conversion == null) + return null; - //Pattern newPattern = conversion.Generate(); - //lastPattern = newPattern; + Pattern newPattern = conversion.Generate(); + lastPattern = newPattern; - //return newPattern.HitObjects; + return newPattern.HitObjects; } /// From 9f2ca1acbf87c53aff1088c81d196395e5b23440 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 09:57:03 +0900 Subject: [PATCH 3/5] Remove siblings. --- .../Patterns/Legacy/EndTimeObjectPatternGenerator.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs index cd04418ac5..e84802617c 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -74,8 +74,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy StartTime = HitObject.StartTime, EndSamples = HitObject.Samples, Column = column, - Duration = endTime - HitObject.StartTime, - Siblings = 1 + Duration = endTime - HitObject.StartTime }; newObject.Samples.Add(new SampleInfo @@ -89,8 +88,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy { StartTime = HitObject.StartTime, Samples = HitObject.Samples, - Column = column, - Siblings = 1 + Column = column }; } From 2d11a8bdf0588a9fece729f38c8b20b59eb5159f Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 10:20:42 +0900 Subject: [PATCH 4/5] Update with pattern changes. --- .../Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs index e84802617c..1956361f5c 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -51,7 +51,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy { int nextColumn = Random.Next(start, AvailableColumns); - while (PreviousPattern.IsFilled(nextColumn)) + while (PreviousPattern.ColumnHasObject(nextColumn)) nextColumn = Random.Next(start, AvailableColumns); return nextColumn; From 6714a244e83f6a43c462dc47ad7f1373b16323af Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 10:23:08 +0900 Subject: [PATCH 5/5] Add check before possibly going into endless loop. --- .../Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs index 1956361f5c..8f438f9ff4 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/EndTimeObjectPatternGenerator.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy else addToPattern(pattern, getNextRandomColumn(RandomStart), generateHold); } - else + else if (AvailableColumns > 0) addToPattern(pattern, getNextRandomColumn(0), generateHold); return pattern;