From e180d49304356b0d54fe0003467ecd43b70d24e3 Mon Sep 17 00:00:00 2001 From: LastExceed Date: Sat, 23 Jun 2018 16:37:58 +0200 Subject: [PATCH 01/23] preload BASS --- .vscode/launch.json | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ed67fa92cc..2c781363af 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,12 @@ ], "cwd": "${workspaceRoot}", "preLaunchTask": "Build tests (Debug)", - "env": {}, + "linux": { + "env": { + "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", + "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", + }, + }, "console": "internalConsole" }, { @@ -24,7 +29,12 @@ ], "cwd": "${workspaceRoot}", "preLaunchTask": "Build tests (Release)", - "env": {}, + "linux": { + "env": { + "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", + "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", + }, + }, "console": "internalConsole" }, { @@ -37,7 +47,12 @@ ], "cwd": "${workspaceRoot}", "preLaunchTask": "Build osu! (Debug)", - "env": {}, + "linux": { + "env": { + "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", + "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", + }, + }, "console": "internalConsole" }, { @@ -50,7 +65,12 @@ ], "cwd": "${workspaceRoot}", "preLaunchTask": "Build osu! (Release)", - "env": {}, + "linux": { + "env": { + "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Release/netcoreapp2.1/libbass.so", + "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Release/netcoreapp2.1/", + }, + }, "console": "internalConsole" } ] From 2882981f9c2494a84ddf8f055f860434437d0608 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 18:08:46 +0900 Subject: [PATCH 02/23] Implement and use equality comparers for ControlPoint --- .../Beatmaps/ControlPoints/ControlPoint.cs | 8 +- .../ControlPoints/DifficultyControlPoint.cs | 5 ++ .../ControlPoints/EffectControlPoint.cs | 6 ++ .../ControlPoints/SampleControlPoint.cs | 6 ++ .../ControlPoints/TimingControlPoint.cs | 6 ++ .../Beatmaps/Formats/LegacyBeatmapDecoder.cs | 81 ++++++++++++------- 6 files changed, 82 insertions(+), 30 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index db9e712d86..e1e5affc78 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -14,6 +14,12 @@ namespace osu.Game.Beatmaps.ControlPoints public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); - public bool Equals(ControlPoint other) => Time.Equals(other?.Time); + public virtual bool Equals(ControlPoint other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return Time.Equals(other.Time); + } } } diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs index 9f717d21e3..9c6735a36a 100644 --- a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -17,5 +17,10 @@ namespace osu.Game.Beatmaps.ControlPoints } private double speedMultiplier = 1; + + public override bool Equals(ControlPoint other) + => base.Equals(other) + && other is DifficultyControlPoint difficulty + && SpeedMultiplier == difficulty.SpeedMultiplier; } } diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs index 73d5232f44..6fdddc44bb 100644 --- a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -14,5 +14,11 @@ namespace osu.Game.Beatmaps.ControlPoints /// Whether the first bar line of this control point is ignored. /// public bool OmitFirstBarLine; + + public override bool Equals(ControlPoint other) + => base.Equals(other) + && other is EffectControlPoint effect + && KiaiMode == effect.KiaiMode + && OmitFirstBarLine == effect.OmitFirstBarLine; } } diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index 5d801a1163..69c00e463c 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -30,5 +30,11 @@ namespace osu.Game.Beatmaps.ControlPoints Name = sampleName, Volume = SampleVolume, }; + + public override bool Equals(ControlPoint other) + => base.Equals(other) + && other is SampleControlPoint sample + && SampleBank == sample.SampleBank + && SampleVolume == sample.SampleVolume; } } diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs index d20b1b87a6..cc1546675b 100644 --- a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -23,5 +23,11 @@ namespace osu.Game.Beatmaps.ControlPoints } private double beatLength = 1000; + + public override bool Equals(ControlPoint other) + => base.Equals(other) + && other is TimingControlPoint timing + && TimeSignature == timing.TimeSignature + && BeatLength == timing.beatLength; } } diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index 581207607a..603de5949e 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -314,13 +314,9 @@ namespace osu.Game.Beatmaps.Formats if (stringSampleSet == @"none") stringSampleSet = @"normal"; - DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time); - SampleControlPoint samplePoint = beatmap.ControlPointInfo.SamplePointAt(time); - EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time); - if (timingChange) { - beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint + handleTimingControlPoint(new TimingControlPoint { Time = time, BeatLength = beatLength, @@ -328,41 +324,68 @@ namespace osu.Game.Beatmaps.Formats }); } - if (speedMultiplier != difficultyPoint.SpeedMultiplier) + handleDifficultyControlPoint(new DifficultyControlPoint { - beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time); - beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint - { - Time = time, - SpeedMultiplier = speedMultiplier - }); - } + Time = time, + SpeedMultiplier = speedMultiplier + }); - if (stringSampleSet != samplePoint.SampleBank || sampleVolume != samplePoint.SampleVolume) + handleEffectControlPoint(new EffectControlPoint { - beatmap.ControlPointInfo.SamplePoints.Add(new SampleControlPoint - { - Time = time, - SampleBank = stringSampleSet, - SampleVolume = sampleVolume - }); - } + Time = time, + KiaiMode = kiaiMode, + OmitFirstBarLine = omitFirstBarSignature + }); - if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine) + handleSampleControlPoint(new LegacySampleControlPoint { - beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint - { - Time = time, - KiaiMode = kiaiMode, - OmitFirstBarLine = omitFirstBarSignature - }); - } + Time = time, + SampleBank = stringSampleSet, + SampleVolume = sampleVolume, + CustomSampleBank = customSampleBank + }); } catch (FormatException e) { } } + private void handleTimingControlPoint(TimingControlPoint newPoint) + { + beatmap.ControlPointInfo.TimingPoints.Add(newPoint); + } + + private void handleDifficultyControlPoint(DifficultyControlPoint newPoint) + { + var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time); + + if (newPoint.Equals(existing)) + return; + + beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == newPoint.Time); + beatmap.ControlPointInfo.DifficultyPoints.Add(newPoint); + } + + private void handleEffectControlPoint(EffectControlPoint newPoint) + { + var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time); + + if (newPoint.Equals(existing)) + return; + + beatmap.ControlPointInfo.EffectPoints.Add(newPoint); + } + + private void handleSampleControlPoint(SampleControlPoint newPoint) + { + var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time); + + if (newPoint.Equals(existing)) + return; + + beatmap.ControlPointInfo.SamplePoints.Add(newPoint); + } + private void handleHitObject(string line) { // If the ruleset wasn't specified, assume the osu!standard ruleset. From 781095b96bd781bc930ed65a571cadc42467fc64 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 18:20:29 +0900 Subject: [PATCH 03/23] Encapsulate the method to apply SampleControlPoints to SampleInfos --- .../Beatmaps/ControlPoints/SampleControlPoint.cs | 12 ++++++++++++ .../Rulesets/Objects/Drawables/DrawableHitObject.cs | 13 ++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index 69c00e463c..ae65e7ea42 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -31,6 +31,18 @@ namespace osu.Game.Beatmaps.ControlPoints Volume = SampleVolume, }; + /// + /// Applies and to a if necessary, returning the modified . + /// + /// The . This will not be modified. + /// The modified . This does not share a reference with . + public virtual SampleInfo ApplyTo(SampleInfo sampleInfo) => new SampleInfo + { + Bank = sampleInfo.Bank ?? SampleBank, + Name = sampleInfo.Name, + Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume + }; + public override bool Equals(ControlPoint other) => base.Equals(other) && other is SampleControlPoint sample diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 88990d435c..4892e20814 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -90,13 +90,12 @@ namespace osu.Game.Rulesets.Objects.Drawables if (HitObject.SampleControlPoint == null) throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}." + $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}."); - AddInternal(Samples = new SkinnableSound(samples.Select(s => new SampleInfo - { - Bank = s.Bank ?? HitObject.SampleControlPoint.SampleBank, - Name = s.Name, - Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume, - Namespace = SampleNamespace - }).ToArray())); + + samples = samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)).ToArray(); + foreach (var s in samples) + s.Namespace = SampleNamespace; + + AddInternal(Samples = new SkinnableSound(samples)); } } From 3a9a82c80c5c2d6a2843fa5cb64432d2d0ce455b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 18:20:43 +0900 Subject: [PATCH 04/23] Add back legacy custom sample banks --- .../Formats/LegacyBeatmapDecoderTest.cs | 17 ++++++++++++++ osu.Game.Tests/Resources/custom-samples.osu | 16 ++++++++++++++ .../Beatmaps/Formats/LegacyBeatmapDecoder.cs | 6 ++--- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 22 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 osu.Game.Tests/Resources/custom-samples.osu diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 1628423fe8..a77730c453 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -8,6 +8,7 @@ using OpenTK.Graphics; using osu.Game.Tests.Resources; using System.Linq; using osu.Game.Audio; +using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects.Types; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Timing; @@ -211,5 +212,21 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.IsTrue(hitObjects[1].Samples.Any(s => s.Name == SampleInfo.HIT_CLAP)); } } + + [Test] + public void TestDecodeCustomSamples() + { + var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; + using (var resStream = Resource.OpenResource("custom-samples.osu")) + using (var stream = new StreamReader(resStream)) + { + var hitObjects = decoder.Decode(stream).HitObjects; + + Assert.AreEqual(0, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[0].SampleControlPoint).CustomSampleBank); + Assert.AreEqual(1, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[1].SampleControlPoint).CustomSampleBank); + Assert.AreEqual(2, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[2].SampleControlPoint).CustomSampleBank); + Assert.AreEqual(0, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[3].SampleControlPoint).CustomSampleBank); + } + } } } diff --git a/osu.Game.Tests/Resources/custom-samples.osu b/osu.Game.Tests/Resources/custom-samples.osu new file mode 100644 index 0000000000..1e0e6f558e --- /dev/null +++ b/osu.Game.Tests/Resources/custom-samples.osu @@ -0,0 +1,16 @@ +osu file format v14 + +[General] +SampleSet: Normal + +[TimingPoints] +2170,468.75,4,1,0,40,1,0 +2638,-100,4,1,1,40,0,0 +3107,-100,4,1,2,40,0,0 +3576,-100,4,1,0,40,0,0 + +[HitObjects] +255,193,2170,1,0,0:0:0:0: +256,191,2638,5,0,0:0:0:0: +255,193,3107,1,0,0:0:0:0: +256,191,3576,1,0,0:0:0:0: diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index 603de5949e..f33e963f08 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -289,9 +289,9 @@ namespace osu.Game.Beatmaps.Formats if (split.Length >= 4) sampleSet = (LegacySampleBank)int.Parse(split[3]); - //SampleBank sampleBank = SampleBank.Default; - //if (split.Length >= 5) - // sampleBank = (SampleBank)int.Parse(split[4]); + int customSampleBank = 0; + if (split.Length >= 5) + customSampleBank = int.Parse(split[4]); int sampleVolume = defaultSampleVolume; if (split.Length >= 6) diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index e77efd8508..c207761866 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.IO; using osu.Framework.Logging; +using osu.Game.Audio; +using osu.Game.Beatmaps.ControlPoints; using OpenTK.Graphics; namespace osu.Game.Beatmaps.Formats @@ -167,5 +169,25 @@ namespace osu.Game.Beatmaps.Formats Pass = 2, Foreground = 3 } + + internal class LegacySampleControlPoint : SampleControlPoint + { + public int CustomSampleBank; + + public override SampleInfo ApplyTo(SampleInfo sampleInfo) + { + var baseInfo = base.ApplyTo(sampleInfo); + + if (CustomSampleBank > 0) + baseInfo.Name += CustomSampleBank; + + return baseInfo; + } + + public override bool Equals(ControlPoint other) + => base.Equals(other) + && other is LegacySampleControlPoint legacy + && CustomSampleBank == legacy.CustomSampleBank; + } } } From 94f1b2eeb867d2ff457b66a6a4b26f1ca8a8ff72 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 18:27:33 +0900 Subject: [PATCH 05/23] Only custom sample banks > 1 modify the filename --- .../Beatmaps/Formats/LegacyBeatmapDecoderTest.cs | 11 +++++++---- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index a77730c453..4be6eeef0d 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -12,6 +12,7 @@ using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects.Types; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Timing; +using osu.Game.Rulesets.Objects; using osu.Game.Skinning; namespace osu.Game.Tests.Beatmaps.Formats @@ -222,11 +223,13 @@ namespace osu.Game.Tests.Beatmaps.Formats { var hitObjects = decoder.Decode(stream).HitObjects; - Assert.AreEqual(0, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[0].SampleControlPoint).CustomSampleBank); - Assert.AreEqual(1, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[1].SampleControlPoint).CustomSampleBank); - Assert.AreEqual(2, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[2].SampleControlPoint).CustomSampleBank); - Assert.AreEqual(0, ((LegacyDecoder.LegacySampleControlPoint)hitObjects[3].SampleControlPoint).CustomSampleBank); + Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[0]).Name); + Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[1]).Name); + Assert.AreEqual("hitnormal2", getTestableSampleInfo(hitObjects[2]).Name); + Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[3]).Name); } + + SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); } } } diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index c207761866..60fff4bd7f 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -178,7 +178,7 @@ namespace osu.Game.Beatmaps.Formats { var baseInfo = base.ApplyTo(sampleInfo); - if (CustomSampleBank > 0) + if (CustomSampleBank > 1) baseInfo.Name += CustomSampleBank; return baseInfo; From 9fd9af22f0f2a2370177fe93568340a0d7e1fd49 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 18:40:12 +0900 Subject: [PATCH 06/23] Remove unused using --- osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index 4be6eeef0d..d3c61960bb 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -8,7 +8,6 @@ using OpenTK.Graphics; using osu.Game.Tests.Resources; using System.Linq; using osu.Game.Audio; -using osu.Game.Beatmaps; using osu.Game.Rulesets.Objects.Types; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.Timing; From aea50e770b6a58f4e196cbf33bb2db1701248862 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 13:23:59 +0900 Subject: [PATCH 07/23] Use .Equals everywhere --- osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs | 2 +- osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs | 4 ++-- osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs | 4 ++-- osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs index 9c6735a36a..296dcf66b1 100644 --- a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -21,6 +21,6 @@ namespace osu.Game.Beatmaps.ControlPoints public override bool Equals(ControlPoint other) => base.Equals(other) && other is DifficultyControlPoint difficulty - && SpeedMultiplier == difficulty.SpeedMultiplier; + && SpeedMultiplier.Equals(difficulty.SpeedMultiplier); } } diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs index 6fdddc44bb..e41fb3a1d3 100644 --- a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -18,7 +18,7 @@ namespace osu.Game.Beatmaps.ControlPoints public override bool Equals(ControlPoint other) => base.Equals(other) && other is EffectControlPoint effect - && KiaiMode == effect.KiaiMode - && OmitFirstBarLine == effect.OmitFirstBarLine; + && KiaiMode.Equals(effect.KiaiMode) + && OmitFirstBarLine.Equals(effect.OmitFirstBarLine); } } diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index ae65e7ea42..c4d6ad24a0 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -46,7 +46,7 @@ namespace osu.Game.Beatmaps.ControlPoints public override bool Equals(ControlPoint other) => base.Equals(other) && other is SampleControlPoint sample - && SampleBank == sample.SampleBank - && SampleVolume == sample.SampleVolume; + && SampleBank.Equals(sample.SampleBank) + && SampleVolume.Equals(sample.SampleVolume); } } diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs index cc1546675b..3e4e2a0bb1 100644 --- a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -27,7 +27,7 @@ namespace osu.Game.Beatmaps.ControlPoints public override bool Equals(ControlPoint other) => base.Equals(other) && other is TimingControlPoint timing - && TimeSignature == timing.TimeSignature - && BeatLength == timing.beatLength; + && TimeSignature.Equals(timing.TimeSignature) + && BeatLength.Equals(timing.BeatLength); } } From c78bfbfa55f9d49f0a20d1184820ede77259c964 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 13:24:09 +0900 Subject: [PATCH 08/23] Fix failing json conversion testcases --- osu.Game.Tests/Beatmaps/Formats/OsuJsonDecoderTest.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/OsuJsonDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/OsuJsonDecoderTest.cs index b834be71f1..64bd563897 100644 --- a/osu.Game.Tests/Beatmaps/Formats/OsuJsonDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/OsuJsonDecoderTest.cs @@ -118,7 +118,11 @@ namespace osu.Game.Tests.Beatmaps.Formats public void TestParity(string beatmap) { var legacy = decode(beatmap, out Beatmap json); - json.WithDeepEqual(legacy).IgnoreProperty(r => r.DeclaringType == typeof(HitWindows)).Assert(); + json.WithDeepEqual(legacy) + .IgnoreProperty(r => r.DeclaringType == typeof(HitWindows) + // Todo: CustomSampleBank shouldn't exist going forward, we need a conversion mechanism + || r.Name == nameof(LegacyDecoder.LegacySampleControlPoint.CustomSampleBank)) + .Assert(); } /// From b664d3ef8176662bfe44855394fcba78a268955b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 13:33:59 +0900 Subject: [PATCH 09/23] Fix time being a part of controlpoint change comparisons --- osu.Game/Beatmaps/ControlPoints/ControlPoint.cs | 15 +++++++++------ .../ControlPoints/DifficultyControlPoint.cs | 4 ++-- .../Beatmaps/ControlPoints/EffectControlPoint.cs | 4 ++-- .../Beatmaps/ControlPoints/SampleControlPoint.cs | 4 ++-- .../Beatmaps/ControlPoints/TimingControlPoint.cs | 4 ++-- osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs | 6 +++--- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 4 ++-- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index e1e5affc78..cf6d9a3ccd 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -14,12 +14,15 @@ namespace osu.Game.Beatmaps.ControlPoints public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); - public virtual bool Equals(ControlPoint other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; + /// + /// Whether this provides the same changes to gameplay as another . + /// + /// The to compare to. + /// Whether this provides the same changes to gameplay as . + public virtual bool ChangeEquals(ControlPoint other) => !ReferenceEquals(null, other); - return Time.Equals(other.Time); - } + public bool Equals(ControlPoint other) + => ChangeEquals(other) + && Time.Equals(other.Time); } } diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs index 296dcf66b1..f821ff11f4 100644 --- a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -18,8 +18,8 @@ namespace osu.Game.Beatmaps.ControlPoints private double speedMultiplier = 1; - public override bool Equals(ControlPoint other) - => base.Equals(other) + public override bool ChangeEquals(ControlPoint other) + => base.ChangeEquals(other) && other is DifficultyControlPoint difficulty && SpeedMultiplier.Equals(difficulty.SpeedMultiplier); } diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs index e41fb3a1d3..0cbdf7fdf2 100644 --- a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -15,8 +15,8 @@ namespace osu.Game.Beatmaps.ControlPoints /// public bool OmitFirstBarLine; - public override bool Equals(ControlPoint other) - => base.Equals(other) + public override bool ChangeEquals(ControlPoint other) + => base.ChangeEquals(other) && other is EffectControlPoint effect && KiaiMode.Equals(effect.KiaiMode) && OmitFirstBarLine.Equals(effect.OmitFirstBarLine); diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index c4d6ad24a0..11de392d14 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -43,8 +43,8 @@ namespace osu.Game.Beatmaps.ControlPoints Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume }; - public override bool Equals(ControlPoint other) - => base.Equals(other) + public override bool ChangeEquals(ControlPoint other) + => base.ChangeEquals(other) && other is SampleControlPoint sample && SampleBank.Equals(sample.SampleBank) && SampleVolume.Equals(sample.SampleVolume); diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs index 3e4e2a0bb1..8fe3257786 100644 --- a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -24,8 +24,8 @@ namespace osu.Game.Beatmaps.ControlPoints private double beatLength = 1000; - public override bool Equals(ControlPoint other) - => base.Equals(other) + public override bool ChangeEquals(ControlPoint other) + => base.ChangeEquals(other) && other is TimingControlPoint timing && TimeSignature.Equals(timing.TimeSignature) && BeatLength.Equals(timing.BeatLength); diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index f33e963f08..fe55d19908 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -359,7 +359,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time); - if (newPoint.Equals(existing)) + if (newPoint.ChangeEquals(existing)) return; beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == newPoint.Time); @@ -370,7 +370,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time); - if (newPoint.Equals(existing)) + if (newPoint.ChangeEquals(existing)) return; beatmap.ControlPointInfo.EffectPoints.Add(newPoint); @@ -380,7 +380,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time); - if (newPoint.Equals(existing)) + if (newPoint.ChangeEquals(existing)) return; beatmap.ControlPointInfo.SamplePoints.Add(newPoint); diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 60fff4bd7f..f5e3a34462 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -184,8 +184,8 @@ namespace osu.Game.Beatmaps.Formats return baseInfo; } - public override bool Equals(ControlPoint other) - => base.Equals(other) + public override bool ChangeEquals(ControlPoint other) + => base.ChangeEquals(other) && other is LegacySampleControlPoint legacy && CustomSampleBank == legacy.CustomSampleBank; } From 37495c34faa7a02852934d2d9db0dab9e2492a66 Mon Sep 17 00:00:00 2001 From: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com> Date: Mon, 2 Jul 2018 13:51:47 +0900 Subject: [PATCH 10/23] Fix possible nullreference --- osu.Game/Beatmaps/ControlPoints/ControlPoint.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index cf6d9a3ccd..90c0ded38f 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -23,6 +23,7 @@ namespace osu.Game.Beatmaps.ControlPoints public bool Equals(ControlPoint other) => ChangeEquals(other) + && !ReferenceEquals(null, other) && Time.Equals(other.Time); } } From 8b0c6a4c855509aa3de33ddd97e33b70525ab5d8 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:17:19 +0900 Subject: [PATCH 11/23] Make SampleControlPoint clone the existing SampleInfo --- osu.Game/Audio/SampleInfo.cs | 2 ++ .../Beatmaps/ControlPoints/SampleControlPoint.cs | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index f635b74030..53b6e439f5 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -32,5 +32,7 @@ namespace osu.Game.Audio /// The sample volume. /// public int Volume; + + public SampleInfo Clone() => (SampleInfo)MemberwiseClone(); } } diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index 11de392d14..77d42551c6 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -36,12 +36,14 @@ namespace osu.Game.Beatmaps.ControlPoints /// /// The . This will not be modified. /// The modified . This does not share a reference with . - public virtual SampleInfo ApplyTo(SampleInfo sampleInfo) => new SampleInfo + public virtual SampleInfo ApplyTo(SampleInfo sampleInfo) { - Bank = sampleInfo.Bank ?? SampleBank, - Name = sampleInfo.Name, - Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume - }; + var newSampleInfo = sampleInfo.Clone(); + newSampleInfo.Bank = sampleInfo.Bank ?? SampleBank; + newSampleInfo.Name = sampleInfo.Name; + newSampleInfo.Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume; + return newSampleInfo; + } public override bool ChangeEquals(ControlPoint other) => base.ChangeEquals(other) From 310c4a7d6c04213b93a38082a3a225533a3cdc0d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:18:41 +0900 Subject: [PATCH 12/23] Make SampleInfo choose its own lookup name --- osu.Game/Audio/SampleInfo.cs | 7 +++++++ osu.Game/Skinning/SkinnableSound.cs | 18 ++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 53b6e439f5..7906a6012f 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; namespace osu.Game.Audio { @@ -33,6 +34,12 @@ namespace osu.Game.Audio /// public int Volume; + public virtual IEnumerable LookupNames => new[] + { + $"{Namespace}/{Bank}-{Name}", + $"{Bank}-{Name}" // Without namespace as a fallback + }; + public SampleInfo Clone() => (SampleInfo)MemberwiseClone(); } } diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 1a11b0c03e..2fc9cff463 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -44,19 +44,17 @@ namespace osu.Game.Skinning private SampleChannel loadChannel(SampleInfo info, Func getSampleFunction) { - SampleChannel ch = null; + foreach (var lookup in info.LookupNames) + { + var ch = getSampleFunction($"Gameplay/{lookup}"); + if (ch == null) + continue; - if (info.Namespace != null) - ch = getSampleFunction($"Gameplay/{info.Namespace}/{info.Bank}-{info.Name}"); - - // try without namespace as a fallback. - if (ch == null) - ch = getSampleFunction($"Gameplay/{info.Bank}-{info.Name}"); - - if (ch != null) ch.Volume.Value = info.Volume / 100.0; + return ch; + } - return ch; + return null; } } } From 73fac2115a286570e8673d0be0194a45037c8e61 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:20:35 +0900 Subject: [PATCH 13/23] Implement hitobject sample files --- .../Objects/Legacy/ConvertHitObjectParser.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 9edd0f1f34..8a996cfe30 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -6,6 +6,7 @@ using osu.Game.Rulesets.Objects.Types; using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using osu.Game.Beatmaps.Formats; using osu.Game.Audio; using System.Linq; @@ -196,8 +197,7 @@ namespace osu.Game.Rulesets.Objects.Legacy var bank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[0]); var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[1]); - // Let's not implement this for now, because this doesn't fit nicely into the bank structure - //string sampleFile = split2.Length > 4 ? split2[4] : string.Empty; + bankInfo.Filename = split.Length > 4 ? split[4] : null; string stringBank = bank.ToString().ToLower(); if (stringBank == @"none") @@ -252,6 +252,10 @@ namespace osu.Game.Rulesets.Objects.Legacy private List convertSoundType(LegacySoundType type, SampleBankInfo bankInfo) { + // Todo: This should return the normal SampleInfos if the specified sample file isn't found, but that's a pretty edge-case scenario + if (!string.IsNullOrEmpty(bankInfo.Filename)) + return new List { new FileSampleInfo { Filename = bankInfo.Filename } }; + var soundTypes = new List { new SampleInfo @@ -297,14 +301,24 @@ namespace osu.Game.Rulesets.Objects.Legacy private class SampleBankInfo { + public string Filename; + public string Normal; public string Add; public int Volume; - public SampleBankInfo Clone() + public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone(); + } + + private class FileSampleInfo : SampleInfo + { + public string Filename; + + public override IEnumerable LookupNames => new[] { - return (SampleBankInfo)MemberwiseClone(); - } + Filename, + Path.ChangeExtension(Filename, null) + }; } [Flags] From 7f832e34c05fab9975b83f8b4f7a8e175510fd60 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:29:18 +0900 Subject: [PATCH 14/23] Reorder sample bank property setters --- osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs index 8a996cfe30..95589d8953 100644 --- a/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs +++ b/osu.Game/Rulesets/Objects/Legacy/ConvertHitObjectParser.cs @@ -197,8 +197,6 @@ namespace osu.Game.Rulesets.Objects.Legacy var bank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[0]); var addbank = (LegacyBeatmapDecoder.LegacySampleBank)Convert.ToInt32(split[1]); - bankInfo.Filename = split.Length > 4 ? split[4] : null; - string stringBank = bank.ToString().ToLower(); if (stringBank == @"none") stringBank = null; @@ -211,6 +209,8 @@ namespace osu.Game.Rulesets.Objects.Legacy if (split.Length > 3) bankInfo.Volume = int.Parse(split[3]); + + bankInfo.Filename = split.Length > 4 ? split[4] : null; } /// From 189194ee8d3e36261152760dc66a7437ec8adf49 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:35:03 +0900 Subject: [PATCH 15/23] Don't include empty namespace in sample lookup --- osu.Game/Audio/SampleInfo.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 7906a6012f..3d76184e09 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -34,11 +34,16 @@ namespace osu.Game.Audio /// public int Volume; - public virtual IEnumerable LookupNames => new[] + public virtual IEnumerable LookupNames { - $"{Namespace}/{Bank}-{Name}", - $"{Bank}-{Name}" // Without namespace as a fallback - }; + get + { + if (!string.IsNullOrEmpty(Namespace)) + yield return $"{Namespace}/{Bank}-{Name}"; + + yield return $"{Bank}-{Name}"; // Without namespace as a fallback even when we have a namespace + } + } public SampleInfo Clone() => (SampleInfo)MemberwiseClone(); } From c1b8799253e4ab2f4789306308925b9b20be326a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 14:40:43 +0900 Subject: [PATCH 16/23] Add simple testcase --- .../Formats/LegacyBeatmapDecoderTest.cs | 18 ++++++++++++++++++ .../Resources/custom-hitobject-samples.osu | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 osu.Game.Tests/Resources/custom-hitobject-samples.osu diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index d3c61960bb..ad203d2107 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -230,5 +230,23 @@ namespace osu.Game.Tests.Beatmaps.Formats SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); } + + [Test] + public void TestDecodeCustomHitObjectSamples() + { + var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false }; + using (var resStream = Resource.OpenResource("custom-hitobject-samples.osu")) + using (var stream = new StreamReader(resStream)) + { + var hitObjects = decoder.Decode(stream).HitObjects; + + Assert.AreEqual("hit_1.wav", hitObjects[0].Samples[0].LookupNames.First()); + Assert.AreEqual("hit_2.wav", hitObjects[1].Samples[0].LookupNames.First()); + Assert.AreEqual("hitnormal2", getTestableSampleInfo(hitObjects[2]).Name); + Assert.AreEqual("hit_1.wav", hitObjects[3].Samples[0].LookupNames.First()); + } + + SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); + } } } diff --git a/osu.Game.Tests/Resources/custom-hitobject-samples.osu b/osu.Game.Tests/Resources/custom-hitobject-samples.osu new file mode 100644 index 0000000000..588672e2d9 --- /dev/null +++ b/osu.Game.Tests/Resources/custom-hitobject-samples.osu @@ -0,0 +1,16 @@ +osu file format v14 + +[General] +SampleSet: Normal + +[TimingPoints] +2170,468.75,4,1,0,40,1,0 +2638,-100,4,1,1,40,0,0 +3107,-100,4,1,2,40,0,0 +3576,-100,4,1,0,40,0,0 + +[HitObjects] +255,193,2170,1,0,0:0:0:0:hit_1.wav +256,191,2638,5,0,0:0:0:0:hit_2.wav +255,193,3107,1,0,0:0:0:0: +256,191,3576,1,0,0:0:0:0:hit_1.wav From 45a4187923cd18f2f2d80b683ea5e3cadb11574c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 2 Jul 2018 16:10:56 +0900 Subject: [PATCH 17/23] Tidy up lookups to NestedHitObjects --- osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs | 3 --- .../Objects/Drawables/DrawableSlider.cs | 8 ++++---- .../Rulesets/Objects/Drawables/DrawableHitObject.cs | 12 +++++------- .../Visualisers/OverlappingSpeedChangeVisualiser.cs | 9 +++------ .../Visualisers/SequentialSpeedChangeVisualiser.cs | 9 +++------ 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs index 0f70ceece2..e827fa1fdc 100644 --- a/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs +++ b/osu.Game.Rulesets.Mania.Tests/TestCaseNotes.cs @@ -153,9 +153,6 @@ namespace osu.Game.Rulesets.Mania.Tests if (!(obj.HitObject is IHasEndTime endTime)) continue; - if (!obj.HasNestedHitObjects) - continue; - foreach (var nested in obj.NestedHitObjects) { double finalPosition = (nested.HitObject.StartTime - obj.HitObject.StartTime) / endTime.Duration; diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs index c8544d9cc1..f1907a92a8 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs @@ -93,9 +93,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables base.AccentColour = value; Body.AccentColour = AccentColour; Ball.AccentColour = AccentColour; - if (HasNestedHitObjects) - foreach (var drawableHitObject in NestedHitObjects) - drawableHitObject.AccentColour = AccentColour; + + foreach (var drawableHitObject in NestedHitObjects) + drawableHitObject.AccentColour = AccentColour; } } @@ -136,7 +136,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables { if (!userTriggered && Time.Current >= slider.EndTime) { - var judgementsCount = NestedHitObjects.Count; + var judgementsCount = NestedHitObjects.Count(); var judgementsHit = NestedHitObjects.Count(h => h.IsHit); var hitFraction = (double)judgementsHit / judgementsCount; diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index 88990d435c..1f857cb7a8 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -33,8 +33,7 @@ namespace osu.Game.Rulesets.Objects.Drawables protected virtual IEnumerable GetSamples() => HitObject.Samples; private readonly Lazy> nestedHitObjects = new Lazy>(); - public bool HasNestedHitObjects => nestedHitObjects.IsValueCreated; - public IReadOnlyList NestedHitObjects => nestedHitObjects.Value; + public IEnumerable NestedHitObjects => nestedHitObjects.IsValueCreated ? nestedHitObjects.Value : Enumerable.Empty(); public event Action OnJudgement; public event Action OnJudgementRemoved; @@ -50,12 +49,12 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// Whether this and all of its nested s have been hit. /// - public bool IsHit => Judgements.Any(j => j.Final && j.IsHit) && (!HasNestedHitObjects || NestedHitObjects.All(n => n.IsHit)); + public bool IsHit => Judgements.Any(j => j.Final && j.IsHit) && NestedHitObjects.All(n => n.IsHit); /// /// Whether this and all of its nested s have been judged. /// - public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (!HasNestedHitObjects || NestedHitObjects.All(h => h.AllJudged)); + public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && NestedHitObjects.All(h => h.AllJudged); /// /// Whether this can be judged. @@ -206,9 +205,8 @@ namespace osu.Game.Rulesets.Objects.Drawables if (AllJudged) return false; - if (HasNestedHitObjects) - foreach (var d in NestedHitObjects) - judgementOccurred |= d.UpdateJudgement(userTriggered); + foreach (var d in NestedHitObjects) + judgementOccurred |= d.UpdateJudgement(userTriggered); if (!ProvidesJudgement || judgementFinalized || judgementOccurred) return judgementOccurred; diff --git a/osu.Game/Rulesets/UI/Scrolling/Visualisers/OverlappingSpeedChangeVisualiser.cs b/osu.Game/Rulesets/UI/Scrolling/Visualisers/OverlappingSpeedChangeVisualiser.cs index 35a91275a7..d2b79e2fa7 100644 --- a/osu.Game/Rulesets/UI/Scrolling/Visualisers/OverlappingSpeedChangeVisualiser.cs +++ b/osu.Game/Rulesets/UI/Scrolling/Visualisers/OverlappingSpeedChangeVisualiser.cs @@ -47,13 +47,10 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers } } - if (obj.HasNestedHitObjects) - { - ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length); + ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length); - // Nested hitobjects don't need to scroll, but they do need accurate positions - UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length); - } + // Nested hitobjects don't need to scroll, but they do need accurate positions + UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length); } } diff --git a/osu.Game/Rulesets/UI/Scrolling/Visualisers/SequentialSpeedChangeVisualiser.cs b/osu.Game/Rulesets/UI/Scrolling/Visualisers/SequentialSpeedChangeVisualiser.cs index 745352a4d3..25dea8dfbf 100644 --- a/osu.Game/Rulesets/UI/Scrolling/Visualisers/SequentialSpeedChangeVisualiser.cs +++ b/osu.Game/Rulesets/UI/Scrolling/Visualisers/SequentialSpeedChangeVisualiser.cs @@ -48,13 +48,10 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers } } - if (obj.HasNestedHitObjects) - { - ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length); + ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length); - // Nested hitobjects don't need to scroll, but they do need accurate positions - UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length); - } + // Nested hitobjects don't need to scroll, but they do need accurate positions + UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length); } } From d476842c4462e04a9dcdad598c13a7938c1c1384 Mon Sep 17 00:00:00 2001 From: Joehu Date: Mon, 2 Jul 2018 22:03:17 -0700 Subject: [PATCH 18/23] Fix FooterButton clicking area --- osu.Game/Screens/Select/FooterButton.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Select/FooterButton.cs b/osu.Game/Screens/Select/FooterButton.cs index 602b03380c..3fa12283b5 100644 --- a/osu.Game/Screens/Select/FooterButton.cs +++ b/osu.Game/Screens/Select/FooterButton.cs @@ -55,6 +55,8 @@ namespace osu.Game.Screens.Select private readonly Box box; private readonly Box light; + public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => box.ReceiveMouseInputAt(screenSpacePos); + public FooterButton() { Children = new Drawable[] From 73851fb1945a847b0e2108901c8845f4bcb439ca Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 3 Jul 2018 15:57:05 +0900 Subject: [PATCH 19/23] Fix beatmap details not working for unranked beatmaps --- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index 3b6bb565b0..bbaaa0c756 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -49,7 +49,7 @@ namespace osu.Game.Online.API.Requests.Responses private DateTimeOffset submitted { get; set; } [JsonProperty(@"ranked_date")] - private DateTimeOffset ranked { get; set; } + private DateTimeOffset? ranked { get; set; } [JsonProperty(@"last_updated")] private DateTimeOffset lastUpdated { get; set; } From b33206c212b185ba5e79bccb013c3713a284f8bf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Jul 2018 18:35:09 +0900 Subject: [PATCH 20/23] Fix selecting a button on a dialog causing both that button and exit to animate --- osu.Game/Overlays/Dialog/PopupDialog.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Dialog/PopupDialog.cs b/osu.Game/Overlays/Dialog/PopupDialog.cs index d90a850f4a..cd0913a25e 100644 --- a/osu.Game/Overlays/Dialog/PopupDialog.cs +++ b/osu.Game/Overlays/Dialog/PopupDialog.cs @@ -69,10 +69,10 @@ namespace osu.Game.Overlays.Dialog { if (actionInvoked) return; - Hide(); - actionInvoked = true; action?.Invoke(); + + Hide(); }; } } From 44aecdc3a0ebd60873058cbb25922c6bc69ef1c3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 5 Jul 2018 15:00:02 +0900 Subject: [PATCH 21/23] Rename method to EquivalentTo --- osu.Game/Beatmaps/ControlPoints/ControlPoint.cs | 11 +++++------ .../Beatmaps/ControlPoints/DifficultyControlPoint.cs | 4 ++-- osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs | 4 ++-- osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs | 4 ++-- osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs | 4 ++-- osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs | 6 +++--- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 4 ++-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index 90c0ded38f..9ed476d97c 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -15,15 +15,14 @@ namespace osu.Game.Beatmaps.ControlPoints public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); /// - /// Whether this provides the same changes to gameplay as another . + /// Whether this provides the same parametric changes as another . + /// Basically an equality check without considering the . /// /// The to compare to. - /// Whether this provides the same changes to gameplay as . - public virtual bool ChangeEquals(ControlPoint other) => !ReferenceEquals(null, other); + /// Whether this is equivalent to . + public virtual bool EquivalentTo(ControlPoint other) => true; public bool Equals(ControlPoint other) - => ChangeEquals(other) - && !ReferenceEquals(null, other) - && Time.Equals(other.Time); + => EquivalentTo(other) && Time.Equals(other?.Time); } } diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs index f821ff11f4..526bddf51a 100644 --- a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -18,8 +18,8 @@ namespace osu.Game.Beatmaps.ControlPoints private double speedMultiplier = 1; - public override bool ChangeEquals(ControlPoint other) - => base.ChangeEquals(other) + public override bool EquivalentTo(ControlPoint other) + => base.EquivalentTo(other) && other is DifficultyControlPoint difficulty && SpeedMultiplier.Equals(difficulty.SpeedMultiplier); } diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs index 0cbdf7fdf2..dd9d568133 100644 --- a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -15,8 +15,8 @@ namespace osu.Game.Beatmaps.ControlPoints /// public bool OmitFirstBarLine; - public override bool ChangeEquals(ControlPoint other) - => base.ChangeEquals(other) + public override bool EquivalentTo(ControlPoint other) + => base.EquivalentTo(other) && other is EffectControlPoint effect && KiaiMode.Equals(effect.KiaiMode) && OmitFirstBarLine.Equals(effect.OmitFirstBarLine); diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index 77d42551c6..acccbcde46 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -45,8 +45,8 @@ namespace osu.Game.Beatmaps.ControlPoints return newSampleInfo; } - public override bool ChangeEquals(ControlPoint other) - => base.ChangeEquals(other) + public override bool EquivalentTo(ControlPoint other) + => base.EquivalentTo(other) && other is SampleControlPoint sample && SampleBank.Equals(sample.SampleBank) && SampleVolume.Equals(sample.SampleVolume); diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs index 8fe3257786..eb60133fed 100644 --- a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -24,8 +24,8 @@ namespace osu.Game.Beatmaps.ControlPoints private double beatLength = 1000; - public override bool ChangeEquals(ControlPoint other) - => base.ChangeEquals(other) + public override bool EquivalentTo(ControlPoint other) + => base.EquivalentTo(other) && other is TimingControlPoint timing && TimeSignature.Equals(timing.TimeSignature) && BeatLength.Equals(timing.BeatLength); diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index fe55d19908..c79938e613 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -359,7 +359,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time); - if (newPoint.ChangeEquals(existing)) + if (newPoint.EquivalentTo(existing)) return; beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == newPoint.Time); @@ -370,7 +370,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time); - if (newPoint.ChangeEquals(existing)) + if (newPoint.EquivalentTo(existing)) return; beatmap.ControlPointInfo.EffectPoints.Add(newPoint); @@ -380,7 +380,7 @@ namespace osu.Game.Beatmaps.Formats { var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time); - if (newPoint.ChangeEquals(existing)) + if (newPoint.EquivalentTo(existing)) return; beatmap.ControlPointInfo.SamplePoints.Add(newPoint); diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index f5e3a34462..22a6acf459 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -184,8 +184,8 @@ namespace osu.Game.Beatmaps.Formats return baseInfo; } - public override bool ChangeEquals(ControlPoint other) - => base.ChangeEquals(other) + public override bool EquivalentTo(ControlPoint other) + => base.EquivalentTo(other) && other is LegacySampleControlPoint legacy && CustomSampleBank == legacy.CustomSampleBank; } From 7328121ef5ab766f6ce75c35cc8b788b5199a07e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 5 Jul 2018 19:29:49 +0900 Subject: [PATCH 22/23] Remove LD_PRELOAD as it is now unnecessary --- .vscode/launch.json | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 2c781363af..12bb5b7734 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,9 +13,8 @@ "preLaunchTask": "Build tests (Debug)", "linux": { "env": { - "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", - "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", - }, + "LD_LIBRARY_PATH": "${workspaceRoot}/osu.Game.Tests/bin/Debug/netcoreapp2.1:${env:LD_LIBRARY_PATH}" + } }, "console": "internalConsole" }, @@ -31,9 +30,8 @@ "preLaunchTask": "Build tests (Release)", "linux": { "env": { - "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", - "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", - }, + "LD_LIBRARY_PATH": "${workspaceRoot}/osu.Game.Tests/bin/Release/netcoreapp2.1:${env:LD_LIBRARY_PATH}" + } }, "console": "internalConsole" }, @@ -49,9 +47,8 @@ "preLaunchTask": "Build osu! (Debug)", "linux": { "env": { - "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/libbass.so", - "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1/", - }, + "LD_LIBRARY_PATH": "${workspaceRoot}/osu.Desktop/bin/Debug/netcoreapp2.1:${env:LD_LIBRARY_PATH}" + } }, "console": "internalConsole" }, @@ -67,9 +64,8 @@ "preLaunchTask": "Build osu! (Release)", "linux": { "env": { - "LD_PRELOAD": "${workspaceRoot}/osu.Desktop/bin/Release/netcoreapp2.1/libbass.so", - "LD_LIBRARY_PATH" : "${workspaceRoot}/osu.Desktop/bin/Release/netcoreapp2.1/", - }, + "LD_LIBRARY_PATH": "${workspaceRoot}/osu.Desktop/bin/Release/netcoreapp2.1:${env:LD_LIBRARY_PATH}" + } }, "console": "internalConsole" } From 8f04acc506bf5ae4474897f0f420d43583e4fcee Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 5 Jul 2018 20:16:55 +0900 Subject: [PATCH 23/23] Add missing xmldoc --- osu.Game/Audio/SampleInfo.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 3d76184e09..7e329ac651 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -34,6 +34,9 @@ namespace osu.Game.Audio /// public int Volume; + /// + /// Retrieve all possible filenames that can be used as a source, returned in order of preference (highest first). + /// public virtual IEnumerable LookupNames { get