From 0801a211da226bcb7cc3f802cfcac829f984cdc6 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Wed, 17 May 2017 01:14:04 -0500 Subject: [PATCH 01/36] Add a base container with beat syncing logic --- .../Containers/BeatSyncedContainer.cs | 64 +++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 2 files changed, 65 insertions(+) create mode 100644 osu.Game/Graphics/Containers/BeatSyncedContainer.cs diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs new file mode 100644 index 0000000000..1438ccf002 --- /dev/null +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -0,0 +1,64 @@ +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Timing; + +namespace osu.Game.Graphics.Containers +{ + public class BeatSyncedContainer : Container + { + private Bindable beatmap; + private int beat; + private double timingPointStart; + //This is to avoid sending new beats when not at the very start of the beat + private const int seek_tolerance = 20; + private const double min_beat_length = 1E-100; + + public BeatSyncedContainer() + { + } + + protected override void Update() + { + if (beatmap.Value != null) + { + double currentTime = beatmap.Value.Track.CurrentTime; + ControlPoint kiaiControlPoint; + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTime, out kiaiControlPoint); + + if (controlPoint != null) + { + double oldTimingPointStart = timingPointStart; + double beatLenght = double.MinValue; + int oldBeat = beat; + bool kiai = false; + + beatLenght = controlPoint.BeatLength; + timingPointStart = controlPoint.Time; + kiai = kiaiControlPoint?.KiaiMode ?? false; + + beat = beatLenght > min_beat_length ? (int)((currentTime - timingPointStart) / beatLenght) : 0; + + //should we handle negative beats? (before the start of the controlPoint) + //The beats before the start of the first control point are off by 1, this should do the trick + if (currentTime <= timingPointStart) + beat--; + + if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % (beatLenght)) <= seek_tolerance) + OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + } + } + } + + protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) + { + } + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + beatmap = game.Beatmap; + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 63acdb1914..18c483fe40 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -74,6 +74,7 @@ + From 5f192cae7bb6042e5c1ac8131d4bda557d92673e Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Wed, 17 May 2017 01:18:56 -0500 Subject: [PATCH 02/36] Add missing licence header --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 1438ccf002..9d279ebb44 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -1,4 +1,7 @@ -using osu.Framework.Allocation; +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; From 387d26a5769790142a9ac16f558758d968ad66ed Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Wed, 17 May 2017 01:26:34 -0500 Subject: [PATCH 03/36] CI Fixes --- .../Graphics/Containers/BeatSyncedContainer.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 9d279ebb44..ba25cc1d1a 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -18,10 +18,6 @@ namespace osu.Game.Graphics.Containers private const int seek_tolerance = 20; private const double min_beat_length = 1E-100; - public BeatSyncedContainer() - { - } - protected override void Update() { if (beatmap.Value != null) @@ -33,23 +29,23 @@ namespace osu.Game.Graphics.Containers if (controlPoint != null) { double oldTimingPointStart = timingPointStart; - double beatLenght = double.MinValue; + double beatLength; int oldBeat = beat; - bool kiai = false; + bool kiai; - beatLenght = controlPoint.BeatLength; + beatLength = controlPoint.BeatLength; timingPointStart = controlPoint.Time; kiai = kiaiControlPoint?.KiaiMode ?? false; - beat = beatLenght > min_beat_length ? (int)((currentTime - timingPointStart) / beatLenght) : 0; + beat = beatLength > min_beat_length ? (int)((currentTime - timingPointStart) / beatLength) : 0; //should we handle negative beats? (before the start of the controlPoint) //The beats before the start of the first control point are off by 1, this should do the trick if (currentTime <= timingPointStart) beat--; - if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % (beatLenght)) <= seek_tolerance) - OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (currentTime - timingPointStart) % (beatLength) <= seek_tolerance) + OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); } } } From 198542465b81e9deb6735ff39cf594bd2d36f952 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Wed, 17 May 2017 01:37:31 -0500 Subject: [PATCH 04/36] More CI fixes --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index ba25cc1d1a..2fc7731ef5 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -29,13 +29,10 @@ namespace osu.Game.Graphics.Containers if (controlPoint != null) { double oldTimingPointStart = timingPointStart; - double beatLength; + double beatLength = controlPoint.BeatLength; int oldBeat = beat; - bool kiai; - - beatLength = controlPoint.BeatLength; + bool kiai = kiaiControlPoint?.KiaiMode ?? false; timingPointStart = controlPoint.Time; - kiai = kiaiControlPoint?.KiaiMode ?? false; beat = beatLength > min_beat_length ? (int)((currentTime - timingPointStart) / beatLength) : 0; @@ -44,7 +41,7 @@ namespace osu.Game.Graphics.Containers if (currentTime <= timingPointStart) beat--; - if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (currentTime - timingPointStart) % (beatLength) <= seek_tolerance) + if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % beatLength) <= seek_tolerance) OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); } } From f4c7a02a6f06acb13d8ed6c20ef434863fa0c57e Mon Sep 17 00:00:00 2001 From: Javier Flores Date: Wed, 17 May 2017 09:23:04 -0500 Subject: [PATCH 05/36] Fix having negative beat when it should be 0 --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 2fc7731ef5..3b10e96398 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -38,7 +38,7 @@ namespace osu.Game.Graphics.Containers //should we handle negative beats? (before the start of the controlPoint) //The beats before the start of the first control point are off by 1, this should do the trick - if (currentTime <= timingPointStart) + if (currentTime < timingPointStart) beat--; if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % beatLength) <= seek_tolerance) @@ -57,4 +57,4 @@ namespace osu.Game.Graphics.Containers beatmap = game.Beatmap; } } -} \ No newline at end of file +} From 793b760ff2244f0cfc6b424bffc84764b1986b1f Mon Sep 17 00:00:00 2001 From: Javier Flores Date: Thu, 18 May 2017 20:19:00 -0500 Subject: [PATCH 06/36] Cleanup logic --- .../Containers/BeatSyncedContainer.cs | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 3b10e96398..d7f5d6c112 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . +// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; @@ -12,8 +12,8 @@ namespace osu.Game.Graphics.Containers public class BeatSyncedContainer : Container { private Bindable beatmap; - private int beat; - private double timingPointStart; + private int lastBeat; + private double lastTimingPointStart; //This is to avoid sending new beats when not at the very start of the beat private const int seek_tolerance = 20; private const double min_beat_length = 1E-100; @@ -22,27 +22,25 @@ namespace osu.Game.Graphics.Containers { if (beatmap.Value != null) { - double currentTime = beatmap.Value.Track.CurrentTime; + double trackCurrentTime = beatmap.Value.Track.CurrentTime; ControlPoint kiaiControlPoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTime, out kiaiControlPoint); + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out kiaiControlPoint); if (controlPoint != null) { - double oldTimingPointStart = timingPointStart; double beatLength = controlPoint.BeatLength; - int oldBeat = beat; bool kiai = kiaiControlPoint?.KiaiMode ?? false; - timingPointStart = controlPoint.Time; + double timingPointStart = controlPoint.Time; + int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; - beat = beatLength > min_beat_length ? (int)((currentTime - timingPointStart) / beatLength) : 0; - - //should we handle negative beats? (before the start of the controlPoint) //The beats before the start of the first control point are off by 1, this should do the trick - if (currentTime < timingPointStart) + if (trackCurrentTime < timingPointStart) beat--; - if ((timingPointStart != oldTimingPointStart || beat != oldBeat) && (int)((currentTime - timingPointStart) % beatLength) <= seek_tolerance) + if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance) OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); + lastBeat = beat; + lastTimingPointStart = timingPointStart; } } } From f9eb448f162915e1d7293652635a417a2dbed825 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 15:29:17 +0900 Subject: [PATCH 07/36] Implement DrawableNote hits. --- .../Objects/Drawables/DrawableNote.cs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs index d0519c61a8..48cfcd66cd 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs @@ -1,10 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Input; +using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces; using osu.Game.Rulesets.Objects.Drawables; @@ -40,14 +43,50 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables } } - protected override void Update() + protected override void CheckJudgement(bool userTriggered) { - if (Time.Current > HitObject.StartTime) - Colour = Color4.Green; + if (!userTriggered) + { + if (Judgement.TimeOffset > HitObject.HitWindows.Bad / 2) + Judgement.Result = HitResult.Miss; + return; + } + + double offset = Math.Abs(Judgement.TimeOffset); + + if (offset > HitObject.HitWindows.Miss / 2) + return; + + ManiaHitResult? tmpResult = HitObject.HitWindows.ResultFor(offset); + + if (tmpResult.HasValue) + { + Judgement.Result = HitResult.Hit; + Judgement.ManiaResult = tmpResult.Value; + } + else + Judgement.Result = HitResult.Miss; } protected override void UpdateState(ArmedState state) { + switch (State) + { + case ArmedState.Hit: + Colour = Color4.Green; + break; + } + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (Judgement.Result != HitResult.None) + return false; + + if (args.Key != Key) + return false; + + return UpdateJudgement(true); } } } From 4200e05fe702acb5673cc3c99db7f773f3a94660 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 16:42:14 +0900 Subject: [PATCH 08/36] Don't handle repeat keys. --- osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs index 48cfcd66cd..42bb371975 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableNote.cs @@ -86,6 +86,9 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables if (args.Key != Key) return false; + if (args.Repeat) + return false; + return UpdateJudgement(true); } } From abe9c464a82cc672699075417cfb3419fb901757 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 16:56:40 +0900 Subject: [PATCH 09/36] Invert if statements. --- .../Containers/BeatSyncedContainer.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index d7f5d6c112..4a2e8b6262 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -20,29 +20,29 @@ namespace osu.Game.Graphics.Containers protected override void Update() { - if (beatmap.Value != null) - { - double trackCurrentTime = beatmap.Value.Track.CurrentTime; - ControlPoint kiaiControlPoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out kiaiControlPoint); + if (beatmap.Value == null) + return; - if (controlPoint != null) - { - double beatLength = controlPoint.BeatLength; - bool kiai = kiaiControlPoint?.KiaiMode ?? false; - double timingPointStart = controlPoint.Time; - int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; + double trackCurrentTime = beatmap.Value.Track.CurrentTime; + ControlPoint kiaiControlPoint; + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out kiaiControlPoint); - //The beats before the start of the first control point are off by 1, this should do the trick - if (trackCurrentTime < timingPointStart) - beat--; + if (controlPoint == null) + return; - if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance) - OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); - lastBeat = beat; - lastTimingPointStart = timingPointStart; - } - } + double beatLength = controlPoint.BeatLength; + bool kiai = kiaiControlPoint?.KiaiMode ?? false; + double timingPointStart = controlPoint.Time; + int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; + + //The beats before the start of the first control point are off by 1, this should do the trick + if (trackCurrentTime < timingPointStart) + beat--; + + if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance) + OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); + lastBeat = beat; + lastTimingPointStart = timingPointStart; } protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) From b241140496813ee12431c2a876ca81841c4a2e1b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 16:59:44 +0900 Subject: [PATCH 10/36] Proper kiai mode detection. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 4a2e8b6262..5f6f0b76b5 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -30,8 +30,9 @@ namespace osu.Game.Graphics.Containers if (controlPoint == null) return; + bool kiai = (controlPoint ?? controlPoint).KiaiMode; + double beatLength = controlPoint.BeatLength; - bool kiai = kiaiControlPoint?.KiaiMode ?? false; double timingPointStart = controlPoint.Time; int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; From 609aac6453a1fd48d8a3a872f3dcefd79f30a110 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 17:00:53 +0900 Subject: [PATCH 11/36] Better kiai mode detection. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 5f6f0b76b5..521d9650d9 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -24,13 +24,13 @@ namespace osu.Game.Graphics.Containers return; double trackCurrentTime = beatmap.Value.Track.CurrentTime; - ControlPoint kiaiControlPoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out kiaiControlPoint); + ControlPoint overridePoint; + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out overridePoint); if (controlPoint == null) return; - bool kiai = (controlPoint ?? controlPoint).KiaiMode; + bool kiai = (overridePoint ?? controlPoint).KiaiMode; double beatLength = controlPoint.BeatLength; double timingPointStart = controlPoint.Time; From f81ffa636dc1770284c3d88c9f9514bdc4a30f22 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 17:01:43 +0900 Subject: [PATCH 12/36] Use BindTo instead of taking the game's beatmap bindable. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 521d9650d9..666d0e3f77 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -11,7 +11,8 @@ namespace osu.Game.Graphics.Containers { public class BeatSyncedContainer : Container { - private Bindable beatmap; + private Bindable beatmap = new Bindable(); + private int lastBeat; private double lastTimingPointStart; //This is to avoid sending new beats when not at the very start of the beat @@ -20,7 +21,7 @@ namespace osu.Game.Graphics.Containers protected override void Update() { - if (beatmap.Value == null) + if (beatmap.Value?.Track == null) return; double trackCurrentTime = beatmap.Value.Track.CurrentTime; @@ -53,7 +54,7 @@ namespace osu.Game.Graphics.Containers [BackgroundDependencyLoader] private void load(OsuGameBase game) { - beatmap = game.Beatmap; + beatmap.BindTo(game.Beatmap); } } } From 70d7f61f7cf38314f2f68390b9924daf526dc9b7 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 17:15:23 +0900 Subject: [PATCH 13/36] More inversion for logic simplification. --- .../Containers/BeatSyncedContainer.cs | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 666d0e3f77..8b38547037 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -11,40 +11,42 @@ namespace osu.Game.Graphics.Containers { public class BeatSyncedContainer : Container { + /// + /// A new beat will not be sent if the time since the beat is larger than this tolerance. + /// + private const int seek_tolerance = 20; + private Bindable beatmap = new Bindable(); private int lastBeat; - private double lastTimingPointStart; - //This is to avoid sending new beats when not at the very start of the beat - private const int seek_tolerance = 20; - private const double min_beat_length = 1E-100; + private ControlPoint lastControlPoint; protected override void Update() { if (beatmap.Value?.Track == null) return; - double trackCurrentTime = beatmap.Value.Track.CurrentTime; + double currentTrackTime = beatmap.Value.Track.CurrentTime; ControlPoint overridePoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(trackCurrentTime, out overridePoint); - - if (controlPoint == null) - return; + ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTrackTime, out overridePoint); bool kiai = (overridePoint ?? controlPoint).KiaiMode; + int beat = controlPoint.BeatLength > 0 ? (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength) : 0; - double beatLength = controlPoint.BeatLength; - double timingPointStart = controlPoint.Time; - int beat = beatLength > min_beat_length ? (int)((trackCurrentTime - timingPointStart) / beatLength) : 0; - - //The beats before the start of the first control point are off by 1, this should do the trick - if (trackCurrentTime < timingPointStart) + // The beats before the start of the first control point are off by 1, this should do the trick + if (currentTrackTime < controlPoint.Time) beat--; - if ((timingPointStart != lastTimingPointStart || beat != lastBeat) && (int)((trackCurrentTime - timingPointStart) % beatLength) <= seek_tolerance) - OnNewBeat(beat, beatLength, controlPoint.TimeSignature, kiai); + if (controlPoint == lastControlPoint && beat == lastBeat) + return; + + if ((currentTrackTime - controlPoint.Time) % controlPoint.BeatLength > seek_tolerance) + return; + + OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + lastBeat = beat; - lastTimingPointStart = timingPointStart; + lastControlPoint = controlPoint; } protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) From 3235e280a9a64554e56e618ee4ff27322955a4d9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 17:31:53 +0900 Subject: [PATCH 14/36] Add to csproj. --- osu.Game/osu.Game.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 1631311ef6..b94c19e1f8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -292,6 +292,7 @@ + From fc90cfa604d37e1b063f7f5bffbb9f2d5a3cb015 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 22 May 2017 17:50:05 +0900 Subject: [PATCH 15/36] Update BeatSyncedContainer.cs --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 8b38547037..945de822a3 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Containers /// private const int seek_tolerance = 20; - private Bindable beatmap = new Bindable(); + private readonly Bindable beatmap = new Bindable(); private int lastBeat; private ControlPoint lastControlPoint; From 95c4704a9e679381274c414d69dc9a5f5a5b908a Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 20:01:28 +0900 Subject: [PATCH 16/36] Delay backwards instead of using a millisecond tolerance. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 945de822a3..d4b042c34c 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -11,11 +11,6 @@ namespace osu.Game.Graphics.Containers { public class BeatSyncedContainer : Container { - /// - /// A new beat will not be sent if the time since the beat is larger than this tolerance. - /// - private const int seek_tolerance = 20; - private readonly Bindable beatmap = new Bindable(); private int lastBeat; @@ -40,10 +35,10 @@ namespace osu.Game.Graphics.Containers if (controlPoint == lastControlPoint && beat == lastBeat) return; - if ((currentTrackTime - controlPoint.Time) % controlPoint.BeatLength > seek_tolerance) - return; + double offsetFromBeat = (controlPoint.Time - currentTrackTime) % controlPoint.BeatLength; - OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + using (BeginDelayedSequence(offsetFromBeat, true)) + OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); lastBeat = beat; lastControlPoint = controlPoint; From de575b3867fb2b91db85494d935db9c99dd934bc Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 20:02:02 +0900 Subject: [PATCH 17/36] Early return if beatLength = 0. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index d4b042c34c..12ed015c92 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -25,8 +25,11 @@ namespace osu.Game.Graphics.Containers ControlPoint overridePoint; ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTrackTime, out overridePoint); + if (controlPoint.BeatLength == 0) + return; + bool kiai = (overridePoint ?? controlPoint).KiaiMode; - int beat = controlPoint.BeatLength > 0 ? (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength) : 0; + int beat = (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength); // The beats before the start of the first control point are off by 1, this should do the trick if (currentTrackTime < controlPoint.Time) From adf8bb853e16da48f1bc6d9bb06312e963249353 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 20:06:37 +0900 Subject: [PATCH 18/36] Move load() to be directly below ctor. --- osu.Game/Graphics/Containers/BeatSyncedContainer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 12ed015c92..dfb742f7d1 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -47,14 +47,14 @@ namespace osu.Game.Graphics.Containers lastControlPoint = controlPoint; } - protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) - { - } - [BackgroundDependencyLoader] private void load(OsuGameBase game) { beatmap.BindTo(game.Beatmap); } + + protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) + { + } } } From 3cdfd2eef5ca0af577503b8859d1de1792fe1362 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 13:55:18 +0900 Subject: [PATCH 19/36] Split ControlPoint into different types. # Conflicts: # osu.Game.Rulesets.Mania/UI/Column.cs --- osu-framework | 2 +- .../Tests/TestCaseGamefield.cs | 7 +- .../Tests/TestCaseManiaPlayfield.cs | 6 +- .../Legacy/DistanceObjectPatternGenerator.cs | 12 ++- osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 5 +- osu.Game.Rulesets.Mania/Objects/Note.cs | 5 +- .../Timing/ControlPointContainer.cs | 9 ++- .../Timing/TimingChange.cs | 23 ++++++ osu.Game.Rulesets.Mania/UI/Column.cs | 3 +- .../UI/ManiaHitRenderer.cs | 31 ++++--- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 3 +- .../osu.Game.Rulesets.Mania.csproj | 1 + osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs | 5 +- osu.Game.Rulesets.Osu/Objects/Slider.cs | 12 ++- osu.Game.Rulesets.Osu/Objects/Spinner.cs | 5 +- .../Beatmaps/TaikoBeatmapConverter.cs | 8 +- osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs | 9 ++- osu.Game.Rulesets.Taiko/Objects/Hit.cs | 5 +- .../Objects/TaikoHitObject.cs | 15 ++-- .../UI/TaikoHitRenderer.cs | 6 +- osu.Game/Beatmaps/Beatmap.cs | 5 +- .../Beatmaps/ControlPoints/ControlPoint.cs | 10 +++ .../ControlPoints/ControlPointInfo.cs | 63 +++++++++++++++ .../ControlPoints/DifficultyControlPoint.cs | 7 ++ .../ControlPoints/EffectControlPoint.cs | 8 ++ .../ControlPoints/SoundControlPoint.cs | 8 ++ .../ControlPoints/TimingControlPoint.cs | 10 +++ osu.Game/Beatmaps/DifficultyCalculator.cs | 2 +- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 56 ++++++++++--- osu.Game/Beatmaps/Timing/ControlPoint.cs | 20 ----- osu.Game/Beatmaps/Timing/TimingInfo.cs | 80 ------------------- .../Containers/BeatSyncedContainer.cs | 31 +++---- .../Rulesets/Beatmaps/BeatmapConverter.cs | 2 +- osu.Game/Rulesets/Objects/HitObject.cs | 20 +++-- osu.Game/Rulesets/UI/HitRenderer.cs | 2 +- osu.Game/Screens/Play/Player.cs | 2 +- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 6 +- osu.Game/osu.Game.csproj | 8 +- 38 files changed, 307 insertions(+), 205 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Timing/TimingChange.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/ControlPoint.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs create mode 100644 osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs delete mode 100644 osu.Game/Beatmaps/Timing/ControlPoint.cs delete mode 100644 osu.Game/Beatmaps/Timing/TimingInfo.cs diff --git a/osu-framework b/osu-framework index 42e26d49b9..773d60eb6b 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 42e26d49b9046fcb96c123b0dfb48e06d741e162 +Subproject commit 773d60eb6b811f395e32a22dc66bb4d2e63a6dbc diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index 6bd9d35b80..fb5bd8cde4 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using osu.Desktop.VisualTests.Beatmaps; using osu.Framework.Allocation; using osu.Game.Beatmaps.Timing; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Desktop.VisualTests.Tests { @@ -53,8 +54,8 @@ namespace osu.Desktop.VisualTests.Tests time += RNG.Next(50, 500); } - TimingInfo timing = new TimingInfo(); - timing.ControlPoints.Add(new ControlPoint + var controlPointInfo = new ControlPointInfo(); + controlPointInfo.ControlPoints.Add(new TimingControlPoint { BeatLength = 200 }); @@ -73,7 +74,7 @@ namespace osu.Desktop.VisualTests.Tests Author = @"peppy", }, }, - TimingInfo = timing + ControlPointInfo = controlPointInfo }); Add(new Drawable[] diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 04fcd8e94a..88f90fc333 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -11,6 +11,8 @@ using osu.Game.Beatmaps.Timing; using OpenTK; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Mania.Timing; namespace osu.Desktop.VisualTests.Tests { @@ -27,7 +29,7 @@ namespace osu.Desktop.VisualTests.Tests Action createPlayfield = (cols, pos) => { Clear(); - Add(new ManiaPlayfield(cols, new List()) + Add(new ManiaPlayfield(cols, new List()) { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -41,7 +43,7 @@ namespace osu.Desktop.VisualTests.Tests Clear(); ManiaPlayfield playField; - Add(playField = new ManiaPlayfield(cols, new List { new ControlPoint { BeatLength = 200 } }) + Add(playField = new ManiaPlayfield(cols, new List()) { Anchor = Anchor.Centre, Origin = Anchor.Centre, diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs index 0cad23304e..1209a5c879 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs @@ -10,6 +10,7 @@ using osu.Game.Rulesets.Mania.MathUtils; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy { @@ -32,11 +33,8 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy public DistanceObjectPatternGenerator(FastRandom random, HitObject hitObject, Beatmap beatmap, Pattern previousPattern) : base(random, hitObject, beatmap, previousPattern) { - ControlPoint overridePoint; - ControlPoint controlPoint = Beatmap.TimingInfo.TimingPointAt(hitObject.StartTime, out overridePoint); - convertType = PatternType.None; - if ((overridePoint ?? controlPoint)?.KiaiMode == false) + if (Beatmap.ControlPointInfo.EffectPointAt(hitObject.StartTime).KiaiMode) convertType = PatternType.LowProbability; var distanceData = hitObject as IHasDistance; @@ -44,13 +42,13 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy repeatCount = repeatsData?.RepeatCount ?? 1; - double speedAdjustment = beatmap.TimingInfo.SpeedMultiplierAt(hitObject.StartTime); - double speedAdjustedBeatLength = beatmap.TimingInfo.BeatLengthAt(hitObject.StartTime) * speedAdjustment; + TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(hitObject.StartTime); + DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(hitObject.StartTime); // The true distance, accounting for any repeats double distance = (distanceData?.Distance ?? 0) * repeatCount; // The velocity of the osu! hit object - calculated as the velocity of a slider - double osuVelocity = osu_base_scoring_distance * beatmap.BeatmapInfo.Difficulty.SliderMultiplier / speedAdjustedBeatLength; + double osuVelocity = osu_base_scoring_distance * beatmap.BeatmapInfo.Difficulty.SliderMultiplier / (timingPoint.BeatLength * difficultyPoint.SpeedMultiplier); // The duration of the osu! hit object double osuDuration = distance / osuVelocity; diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index 41bbe08d56..b0a0ed10b8 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Audio; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Mania.Judgements; @@ -33,9 +34,9 @@ namespace osu.Game.Rulesets.Mania.Objects /// public HitWindows ReleaseHitWindows { get; protected set; } = new HitWindows(); - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); ReleaseHitWindows = HitWindows * release_window_lenience; } diff --git a/osu.Game.Rulesets.Mania/Objects/Note.cs b/osu.Game.Rulesets.Mania/Objects/Note.cs index e955f6658b..e91c00c145 100644 --- a/osu.Game.Rulesets.Mania/Objects/Note.cs +++ b/osu.Game.Rulesets.Mania/Objects/Note.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.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Mania.Judgements; @@ -17,9 +18,9 @@ namespace osu.Game.Rulesets.Mania.Objects /// public HitWindows HitWindows { get; protected set; } = new HitWindows(); - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); HitWindows = new HitWindows(difficulty.OverallDifficulty); } diff --git a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs index 2ff97047c0..38e975f468 100644 --- a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK; using osu.Game.Beatmaps.Timing; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Mania.Timing { @@ -26,9 +27,9 @@ namespace osu.Game.Rulesets.Mania.Timing /// public double TimeSpan { get; set; } - private readonly List drawableControlPoints; + private readonly List drawableControlPoints = new List(); - public ControlPointContainer(IEnumerable timingChanges) + public ControlPointContainer(IEnumerable timingChanges) { drawableControlPoints = timingChanges.Select(t => new DrawableControlPoint(t)).ToList(); Children = drawableControlPoints; @@ -64,7 +65,7 @@ namespace osu.Game.Rulesets.Mania.Timing /// private class DrawableControlPoint : Container { - private readonly ControlPoint timingChange; + private readonly TimingChange timingChange; protected override Container Content => content; private readonly Container content; @@ -76,7 +77,7 @@ namespace osu.Game.Rulesets.Mania.Timing /// the content container will scroll at twice the normal rate. /// /// The control point to create the drawable control point for. - public DrawableControlPoint(ControlPoint timingChange) + public DrawableControlPoint(TimingChange timingChange) { this.timingChange = timingChange; diff --git a/osu.Game.Rulesets.Mania/Timing/TimingChange.cs b/osu.Game.Rulesets.Mania/Timing/TimingChange.cs new file mode 100644 index 0000000000..fb6f1d2db1 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Timing/TimingChange.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Timing +{ + public class TimingChange + { + /// + /// The time at which this timing change happened. + /// + public double Time; + + /// + /// The beat length. + /// + public double BeatLength = 500; + + /// + /// The speed multiplier. + /// + public double SpeedMultiplier = 1; + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 72c60b28c9..12c4cea58c 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -18,6 +18,7 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Beatmaps.Timing; +using osu.Game.Beatmaps.ControlPoints; using System; using osu.Framework.Configuration; @@ -46,7 +47,7 @@ namespace osu.Game.Rulesets.Mania.UI public readonly ControlPointContainer ControlPointContainer; - public Column(IEnumerable timingChanges) + public Column(IEnumerable timingChanges) { RelativeSizeAxes = Axes.Y; Width = column_width; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 4d734d231f..8d5e22933c 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -8,6 +8,7 @@ using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; @@ -15,6 +16,7 @@ using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Scoring; +using osu.Game.Rulesets.Mania.Timing; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Scoring; @@ -33,22 +35,29 @@ namespace osu.Game.Rulesets.Mania.UI protected override Playfield CreatePlayfield() { - ControlPoint firstTimingChange = Beatmap.TimingInfo.ControlPoints.FirstOrDefault(t => t.TimingChange); - - if (firstTimingChange == null) - throw new InvalidOperationException("The Beatmap contains no timing points!"); + double lastSpeedMultiplier = 1; + double lastBeatLength = 500; // Generate the timing points, making non-timing changes use the previous timing change - var timingChanges = Beatmap.TimingInfo.ControlPoints.Select(c => + var timingChanges = Beatmap.ControlPointInfo.ControlPoints.Where(c => c is TimingControlPoint || c is DifficultyControlPoint).Select(c => { - ControlPoint t = c.Clone(); + var change = new TimingChange(); - if (c.TimingChange) - firstTimingChange = c; - else - t.BeatLength = firstTimingChange.BeatLength; + var timingPoint = c as TimingControlPoint; + var difficultyPoint = c as DifficultyControlPoint; - return t; + if (timingPoint != null) + lastBeatLength = timingPoint.BeatLength; + + if (difficultyPoint != null) + lastSpeedMultiplier = difficultyPoint.SpeedMultiplier; + + return new TimingChange + { + Time = c.Time, + BeatLength = lastBeatLength, + SpeedMultiplier = lastSpeedMultiplier + }; }); double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 70bdd3b13c..c0915c5d82 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -22,6 +22,7 @@ using osu.Framework.Input; using osu.Game.Beatmaps.Timing; using osu.Framework.Graphics.Transforms; using osu.Framework.MathUtils; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Mania.UI { @@ -65,7 +66,7 @@ namespace osu.Game.Rulesets.Mania.UI private readonly int columnCount; - public ManiaPlayfield(int columnCount, IEnumerable timingChanges) + public ManiaPlayfield(int columnCount, IEnumerable timingChanges) { this.columnCount = columnCount; diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index a3f30acae0..9442d7cf8f 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -78,6 +78,7 @@ + diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs index 723a37ed7b..c4b4e3fc4a 100644 --- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs @@ -8,6 +8,7 @@ using osu.Game.Rulesets.Objects.Types; using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Database; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Osu.Objects { @@ -68,9 +69,9 @@ namespace osu.Game.Rulesets.Osu.Objects return OsuScoreResult.Miss; } - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2; } diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index 6c0147a3de..1a5065d17d 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -10,6 +10,7 @@ using osu.Game.Rulesets.Objects; using osu.Game.Database; using System.Linq; using osu.Game.Audio; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Osu.Objects { @@ -62,13 +63,16 @@ namespace osu.Game.Rulesets.Osu.Objects public double Velocity; public double TickDistance; - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); - double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier / timing.SpeedMultiplierAt(StartTime); + TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); + DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); - Velocity = scoringDistance / timing.BeatLengthAt(StartTime); + double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier / difficultyPoint.SpeedMultiplier; + + Velocity = scoringDistance / timingPoint.BeatLength; TickDistance = scoringDistance / difficulty.SliderTickRate; } diff --git a/osu.Game.Rulesets.Osu/Objects/Spinner.cs b/osu.Game.Rulesets.Osu/Objects/Spinner.cs index 3761b62b65..8c0a218108 100644 --- a/osu.Game.Rulesets.Osu/Objects/Spinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Spinner.cs @@ -4,6 +4,7 @@ using osu.Game.Rulesets.Objects.Types; using osu.Game.Beatmaps.Timing; using osu.Game.Database; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Osu.Objects { @@ -19,9 +20,9 @@ namespace osu.Game.Rulesets.Osu.Objects public override bool NewCombo => true; - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); SpinsRequired = (int)(Duration / 1000 * BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 3, 5, 7.5)); } diff --git a/osu.Game.Rulesets.Taiko/Beatmaps/TaikoBeatmapConverter.cs b/osu.Game.Rulesets.Taiko/Beatmaps/TaikoBeatmapConverter.cs index a2dea3731e..5d44da78f9 100644 --- a/osu.Game.Rulesets.Taiko/Beatmaps/TaikoBeatmapConverter.cs +++ b/osu.Game.Rulesets.Taiko/Beatmaps/TaikoBeatmapConverter.cs @@ -12,6 +12,7 @@ using osu.Game.Database; using osu.Game.IO.Serialization; using osu.Game.Audio; using osu.Game.Rulesets.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Taiko.Beatmaps { @@ -77,8 +78,11 @@ namespace osu.Game.Rulesets.Taiko.Beatmaps { int repeats = repeatsData?.RepeatCount ?? 1; - double speedAdjustment = beatmap.TimingInfo.SpeedMultiplierAt(obj.StartTime); - double speedAdjustedBeatLength = beatmap.TimingInfo.BeatLengthAt(obj.StartTime) * speedAdjustment; + TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(obj.StartTime); + DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(obj.StartTime); + + double speedAdjustment = difficultyPoint.SpeedMultiplier; + double speedAdjustedBeatLength = timingPoint.BeatLength * speedAdjustment; // The true distance, accounting for any repeats. This ends up being the drum roll distance later double distance = distanceData.Distance * repeats * legacy_velocity_multiplier; diff --git a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs index f79c01b643..857dd8d3a5 100644 --- a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs @@ -8,6 +8,7 @@ using System.Linq; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Audio; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Taiko.Objects { @@ -55,11 +56,13 @@ namespace osu.Game.Rulesets.Taiko.Objects /// private double tickSpacing = 100; - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); - tickSpacing = timing.BeatLengthAt(StartTime) / TickRate; + TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); + + tickSpacing = timingPoint.BeatLength / TickRate; RequiredGoodHits = TotalTicks * Math.Min(0.15, 0.05 + 0.10 / 6 * difficulty.OverallDifficulty); RequiredGreatHits = TotalTicks * Math.Min(0.30, 0.10 + 0.20 / 6 * difficulty.OverallDifficulty); diff --git a/osu.Game.Rulesets.Taiko/Objects/Hit.cs b/osu.Game.Rulesets.Taiko/Objects/Hit.cs index 136e89124c..cc15b5ab98 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Hit.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Hit.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.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Database; @@ -23,9 +24,9 @@ namespace osu.Game.Rulesets.Taiko.Objects /// public double HitWindowMiss = 95; - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); HitWindowGreat = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 50, 35, 20); HitWindowGood = BeatmapDifficulty.DifficultyRange(difficulty.OverallDifficulty, 120, 80, 50); diff --git a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs index 6a6353fde2..a294a13521 100644 --- a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.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.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Objects; @@ -51,17 +52,17 @@ namespace osu.Game.Rulesets.Taiko.Objects /// public bool Kiai { get; protected set; } - public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - base.ApplyDefaults(timing, difficulty); + base.ApplyDefaults(controlPointInfo, difficulty); - ScrollTime = scroll_time * (timing.BeatLengthAt(StartTime) * timing.SpeedMultiplierAt(StartTime) / 1000) / difficulty.SliderMultiplier; + TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime); + DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime); + EffectControlPoint effectPoint = controlPointInfo.EffectPointAt(StartTime); - ControlPoint overridePoint; - Kiai = timing.TimingPointAt(StartTime, out overridePoint).KiaiMode; + ScrollTime = scroll_time * (timingPoint.BeatLength * difficultyPoint.SpeedMultiplier / 1000) / difficulty.SliderMultiplier; - if (overridePoint != null) - Kiai |= overridePoint.KiaiMode; + Kiai |= effectPoint.KiaiMode; } } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs index 73450d576d..7b0a0b085d 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs @@ -17,6 +17,8 @@ using osu.Game.Rulesets.UI; using osu.Game.Rulesets.Taiko.Replays; using OpenTK; using osu.Game.Rulesets.Beatmaps; +using System.Linq; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Taiko.UI { @@ -43,7 +45,7 @@ namespace osu.Game.Rulesets.Taiko.UI TaikoHitObject lastObject = Beatmap.HitObjects[Beatmap.HitObjects.Count - 1]; double lastHitTime = 1 + (lastObject as IHasEndTime)?.EndTime ?? lastObject.StartTime; - var timingPoints = Beatmap.TimingInfo.ControlPoints.FindAll(cp => cp.TimingChange); + var timingPoints = Beatmap.ControlPointInfo.ControlPoints.OfType().ToList(); if (timingPoints.Count == 0) return; @@ -68,7 +70,7 @@ namespace osu.Game.Rulesets.Taiko.UI StartTime = time, }; - barLine.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.Difficulty); + barLine.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.Difficulty); bool isMajor = currentBeat % (int)currentPoint.TimeSignature == 0; taikoPlayfield.AddBarLine(isMajor ? new DrawableBarLineMajor(barLine) : new DrawableBarLine(barLine)); diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 608b2fcd19..0368455b92 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -7,6 +7,7 @@ using osu.Game.Database; using osu.Game.Rulesets.Objects; using System.Collections.Generic; using System.Linq; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Beatmaps { @@ -17,7 +18,7 @@ namespace osu.Game.Beatmaps where T : HitObject { public BeatmapInfo BeatmapInfo; - public TimingInfo TimingInfo = new TimingInfo(); + public ControlPointInfo ControlPointInfo = new ControlPointInfo(); public List Breaks = new List(); public readonly List ComboColors = new List { @@ -46,7 +47,7 @@ namespace osu.Game.Beatmaps public Beatmap(Beatmap original = null) { BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo; - TimingInfo = original?.TimingInfo ?? TimingInfo; + ControlPointInfo = original?.ControlPointInfo ?? ControlPointInfo; Breaks = original?.Breaks ?? Breaks; ComboColors = original?.ComboColors ?? ComboColors; } diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs new file mode 100644 index 0000000000..5c31259de1 --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -0,0 +1,10 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Beatmaps.ControlPoints +{ + public class ControlPoint + { + public double Time; + } +} diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs new file mode 100644 index 0000000000..90c50a3e05 --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Beatmaps.ControlPoints +{ + public class ControlPointInfo + { + /// + /// All the control points. + /// + public readonly List ControlPoints = new List(); + + /// + /// Finds the difficulty control point that is active at . + /// + /// The time to find the difficulty control point at. + /// The difficulty control point. + public DifficultyControlPoint DifficultyPointAt(double time) => + ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new DifficultyControlPoint(); + + /// + /// Finds the effect control point that is active at . + /// + /// The time to find the effect control point at. + /// The effect control point. + public EffectControlPoint EffectPointAt(double time) => + ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new EffectControlPoint(); + + /// + /// Finds the sound control point that is active at . + /// + /// The time to find the sound control point at. + /// The sound control point. + public SoundControlPoint SoundPointAt(double time) => + ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new SoundControlPoint(); + + /// + /// Finds the timing control point that is active at . + /// + /// The time to find the timing control point at. + /// The timing control point. + public TimingControlPoint TimingPointAt(double time) => + ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new TimingControlPoint(); + + /// + /// Finds the maximum BPM represented by any timing control point. + /// + public double BPMMaximum => + 60000 / (ControlPoints.OfType().OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + + /// + /// Finds the minimum BPM represented by any timing control point. + /// + public double BPMMinimum => + 60000 / (ControlPoints.OfType().OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + + /// + /// Finds the mode BPM (most common BPM) represented by the control points. + /// + public double BPMMode => + 60000 / (ControlPoints.OfType().GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs new file mode 100644 index 0000000000..abd9d05971 --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -0,0 +1,7 @@ +namespace osu.Game.Beatmaps.ControlPoints +{ + public class DifficultyControlPoint : ControlPoint + { + public double SpeedMultiplier = 1; + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs new file mode 100644 index 0000000000..2f6003f57c --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -0,0 +1,8 @@ +namespace osu.Game.Beatmaps.ControlPoints +{ + public class EffectControlPoint : ControlPoint + { + public bool KiaiMode; + public bool OmitFirstBarLine; + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs new file mode 100644 index 0000000000..696e684a3d --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs @@ -0,0 +1,8 @@ +namespace osu.Game.Beatmaps.ControlPoints +{ + public class SoundControlPoint : ControlPoint + { + public string SampleBank; + public int SampleVolume; + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs new file mode 100644 index 0000000000..57c21f110b --- /dev/null +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -0,0 +1,10 @@ +using osu.Game.Beatmaps.Timing; + +namespace osu.Game.Beatmaps.ControlPoints +{ + public class TimingControlPoint : ControlPoint + { + public TimeSignatures TimeSignature = TimeSignatures.SimpleQuadruple; + public double BeatLength = 500; + } +} \ No newline at end of file diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index f483d1e6e3..474d38aa1b 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -37,7 +37,7 @@ namespace osu.Game.Beatmaps Objects = CreateBeatmapConverter().Convert(beatmap, true).HitObjects; foreach (var h in Objects) - h.ApplyDefaults(beatmap.TimingInfo, beatmap.BeatmapInfo.Difficulty); + h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.Difficulty); PreprocessHitObjects(); } diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 04208337c7..e140e2282c 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -8,6 +8,8 @@ using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets.Objects.Legacy; +using System.Linq; +using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Beatmaps.Formats { @@ -241,6 +243,7 @@ namespace osu.Game.Beatmaps.Formats double time = double.Parse(split[0].Trim(), NumberFormatInfo.InvariantInfo); double beatLength = double.Parse(split[1].Trim(), NumberFormatInfo.InvariantInfo); + double speedMultiplier = beatLength < 0 ? -beatLength / 100.0 : 1; TimeSignatures timeSignature = TimeSignatures.SimpleQuadruple; if (split.Length >= 3) @@ -275,18 +278,49 @@ namespace osu.Game.Beatmaps.Formats if (stringSampleSet == @"none") stringSampleSet = @"normal"; - beatmap.TimingInfo.ControlPoints.Add(new ControlPoint + TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(time); + DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time); + SoundControlPoint soundPoint = beatmap.ControlPointInfo.SoundPointAt(time); + EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time); + + if (timingChange && (beatLength != timingPoint.BeatLength || timeSignature != timingPoint.TimeSignature)) { - Time = time, - BeatLength = beatLength, - SpeedMultiplier = beatLength < 0 ? -beatLength / 100.0 : 1, - TimingChange = timingChange, - TimeSignature = timeSignature, - SampleBank = stringSampleSet, - SampleVolume = sampleVolume, - KiaiMode = kiaiMode, - OmitFirstBarLine = omitFirstBarSignature - }); + beatmap.ControlPointInfo.ControlPoints.Add(new TimingControlPoint + { + Time = time, + BeatLength = beatLength, + TimeSignature = timeSignature + }); + } + + if (speedMultiplier != difficultyPoint.SpeedMultiplier) + { + beatmap.ControlPointInfo.ControlPoints.Add(new DifficultyControlPoint + { + Time = time, + SpeedMultiplier = speedMultiplier + }); + } + + if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume) + { + beatmap.ControlPointInfo.ControlPoints.Add(new SoundControlPoint + { + Time = time, + SampleBank = stringSampleSet, + SampleVolume = sampleVolume + }); + } + + if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine) + { + beatmap.ControlPointInfo.ControlPoints.Add(new EffectControlPoint + { + Time = time, + KiaiMode = kiaiMode, + OmitFirstBarLine = omitFirstBarSignature + }); + } } private void handleColours(Beatmap beatmap, string key, string val, ref bool hasCustomColours) diff --git a/osu.Game/Beatmaps/Timing/ControlPoint.cs b/osu.Game/Beatmaps/Timing/ControlPoint.cs deleted file mode 100644 index fbae7d9614..0000000000 --- a/osu.Game/Beatmaps/Timing/ControlPoint.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Beatmaps.Timing -{ - public class ControlPoint - { - public string SampleBank; - public int SampleVolume; - public TimeSignatures TimeSignature = TimeSignatures.SimpleQuadruple; - public double Time; - public double BeatLength = 500; - public double SpeedMultiplier = 1; - public bool TimingChange = true; - public bool KiaiMode; - public bool OmitFirstBarLine; - - public ControlPoint Clone() => (ControlPoint)MemberwiseClone(); - } -} diff --git a/osu.Game/Beatmaps/Timing/TimingInfo.cs b/osu.Game/Beatmaps/Timing/TimingInfo.cs deleted file mode 100644 index 19cb0816ba..0000000000 --- a/osu.Game/Beatmaps/Timing/TimingInfo.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Collections.Generic; -using System.Linq; - -namespace osu.Game.Beatmaps.Timing -{ - public class TimingInfo - { - public readonly List ControlPoints = new List(); - - public double BPMMaximum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).FirstOrDefault() ?? new ControlPoint()).BeatLength; - public double BPMMinimum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new ControlPoint()).BeatLength; - public double BPMMode => BPMAt(ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time); - - public double BPMAt(double time) - { - return 60000 / BeatLengthAt(time); - } - - /// - /// Finds the speed multiplier at a time. - /// - /// The time to find the speed multiplier at. - /// The speed multiplier. - public double SpeedMultiplierAt(double time) - { - ControlPoint overridePoint; - ControlPoint timingPoint = TimingPointAt(time, out overridePoint); - - return overridePoint?.SpeedMultiplier ?? timingPoint?.SpeedMultiplier ?? 1; - } - - /// - /// Finds the beat length at a time. This is expressed in milliseconds. - /// - /// The time to find the beat length at. - /// The beat length. - public double BeatLengthAt(double time) - { - ControlPoint overridePoint; - ControlPoint timingPoint = TimingPointAt(time, out overridePoint); - - return timingPoint.BeatLength; - } - - /// - /// Finds the timing point at a time. - /// - /// The time to find the timing point at. - /// The timing point containing the velocity change of the returned timing point. - /// The timing point. - public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint) - { - overridePoint = null; - - ControlPoint timingPoint = null; - foreach (var controlPoint in ControlPoints) - { - // Some beatmaps have the first timingPoint (accidentally) start after the first HitObject(s). - // This null check makes it so that the first ControlPoint that makes a timing change is used as - // the timingPoint for those HitObject(s). - if (controlPoint.Time <= time || timingPoint == null) - { - if (controlPoint.TimingChange) - { - timingPoint = controlPoint; - overridePoint = null; - } - else - overridePoint = controlPoint; - } - else break; - } - - return timingPoint ?? new ControlPoint(); - } - } -} \ No newline at end of file diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index dfb742f7d1..3489a1550b 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -2,9 +2,11 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; +using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; namespace osu.Game.Graphics.Containers @@ -14,7 +16,8 @@ namespace osu.Game.Graphics.Containers private readonly Bindable beatmap = new Bindable(); private int lastBeat; - private ControlPoint lastControlPoint; + private TimingControlPoint lastTimingPoint; + private EffectControlPoint lastEffectPoint; protected override void Update() { @@ -22,29 +25,29 @@ namespace osu.Game.Graphics.Containers return; double currentTrackTime = beatmap.Value.Track.CurrentTime; - ControlPoint overridePoint; - ControlPoint controlPoint = beatmap.Value.Beatmap.TimingInfo.TimingPointAt(currentTrackTime, out overridePoint); - if (controlPoint.BeatLength == 0) + TimingControlPoint timingPoint = beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(currentTrackTime); + EffectControlPoint effectPoint = beatmap.Value.Beatmap.ControlPointInfo.EffectPointAt(currentTrackTime); + + if (timingPoint.BeatLength == 0) return; - bool kiai = (overridePoint ?? controlPoint).KiaiMode; - int beat = (int)((currentTrackTime - controlPoint.Time) / controlPoint.BeatLength); + int beatIndex = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength); // The beats before the start of the first control point are off by 1, this should do the trick - if (currentTrackTime < controlPoint.Time) - beat--; + if (currentTrackTime < timingPoint.Time) + beatIndex--; - if (controlPoint == lastControlPoint && beat == lastBeat) + if (timingPoint == lastTimingPoint && beatIndex == lastBeat) return; - double offsetFromBeat = (controlPoint.Time - currentTrackTime) % controlPoint.BeatLength; + double offsetFromBeat = (timingPoint.Time - currentTrackTime) % timingPoint.BeatLength; using (BeginDelayedSequence(offsetFromBeat, true)) - OnNewBeat(beat, controlPoint.BeatLength, controlPoint.TimeSignature, kiai); + OnNewBeat(beatIndex, timingPoint, effectPoint, beatmap.Value.Track.CurrentAmplitudes); - lastBeat = beat; - lastControlPoint = controlPoint; + lastBeat = beatIndex; + lastTimingPoint = timingPoint; } [BackgroundDependencyLoader] @@ -53,7 +56,7 @@ namespace osu.Game.Graphics.Containers beatmap.BindTo(game.Beatmap); } - protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) + protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) { } } diff --git a/osu.Game/Rulesets/Beatmaps/BeatmapConverter.cs b/osu.Game/Rulesets/Beatmaps/BeatmapConverter.cs index 5342686c3f..aafa576d4b 100644 --- a/osu.Game/Rulesets/Beatmaps/BeatmapConverter.cs +++ b/osu.Game/Rulesets/Beatmaps/BeatmapConverter.cs @@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Beatmaps return new Beatmap { BeatmapInfo = original.BeatmapInfo, - TimingInfo = original.TimingInfo, + ControlPointInfo = original.ControlPointInfo, HitObjects = original.HitObjects.SelectMany(h => convert(h, original)).ToList() }; } diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 46fb5fcf70..6028464a46 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Audio; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Objects.Types; @@ -33,31 +34,28 @@ namespace osu.Game.Rulesets.Objects /// /// Applies default values to this HitObject. /// + /// The control points. /// The difficulty settings to use. - /// The timing settings to use. - public virtual void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) + public virtual void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) { - ControlPoint overridePoint; - ControlPoint timingPoint = timing.TimingPointAt(StartTime, out overridePoint); - - ControlPoint samplePoint = overridePoint ?? timingPoint; + SoundControlPoint soundPoint = controlPointInfo.SoundPointAt(StartTime); // Initialize first sample - Samples.ForEach(s => initializeSampleInfo(s, samplePoint)); + Samples.ForEach(s => initializeSampleInfo(s, soundPoint)); // Initialize any repeat samples var repeatData = this as IHasRepeats; - repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => initializeSampleInfo(s, samplePoint))); + repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => initializeSampleInfo(s, soundPoint))); } - private void initializeSampleInfo(SampleInfo sample, ControlPoint controlPoint) + private void initializeSampleInfo(SampleInfo sample, SoundControlPoint soundPoint) { if (sample.Volume == 0) - sample.Volume = controlPoint?.SampleVolume ?? 0; + sample.Volume = soundPoint?.SampleVolume ?? 0; // If the bank is not assigned a name, assign it from the control point if (string.IsNullOrEmpty(sample.Bank)) - sample.Bank = controlPoint?.SampleBank ?? @"normal"; + sample.Bank = soundPoint?.SampleBank ?? @"normal"; } } } diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index d0cce87e43..f0dc143668 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -143,7 +143,7 @@ namespace osu.Game.Rulesets.UI // Apply defaults foreach (var h in Beatmap.HitObjects) - h.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.Difficulty); + h.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.Difficulty); // Post-process the beatmap processor.PostProcess(Beatmap); diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 3efc85d743..a39e7dbab2 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -123,7 +123,7 @@ namespace osu.Game.Screens.Play decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; var firstObjectTime = HitRenderer.Objects.First().StartTime; - decoupledClock.Seek(Math.Min(0, firstObjectTime - Math.Max(Beatmap.Beatmap.TimingInfo.BeatLengthAt(firstObjectTime) * 4, Beatmap.BeatmapInfo.AudioLeadIn))); + decoupledClock.Seek(Math.Min(0, firstObjectTime - Math.Max(Beatmap.Beatmap.ControlPointInfo.TimingPointAt(firstObjectTime).BeatLength * 4, Beatmap.BeatmapInfo.AudioLeadIn))); decoupledClock.ProcessFrame(); offsetClock = new FramedOffsetClock(decoupledClock); diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index 2f5b35f92a..2d002597ab 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -238,12 +238,12 @@ namespace osu.Game.Screens.Select private string getBPMRange(Beatmap beatmap) { - double bpmMax = beatmap.TimingInfo.BPMMaximum; - double bpmMin = beatmap.TimingInfo.BPMMinimum; + double bpmMax = beatmap.ControlPointInfo.BPMMaximum; + double bpmMin = beatmap.ControlPointInfo.BPMMinimum; if (Precision.AlmostEquals(bpmMin, bpmMax)) return Math.Round(bpmMin) + "bpm"; - return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.TimingInfo.BPMMode) + "bpm)"; + return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.ControlPointInfo.BPMMode) + "bpm)"; } public class InfoLabel : Container diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 6946462e81..cde7a51ef4 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -87,10 +87,15 @@ + + + + + + - @@ -202,7 +207,6 @@ - From ea4a28532960466c4e8e3c05c80df002275f0ec5 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 14:08:15 +0900 Subject: [PATCH 20/36] Fix compile errors. --- .../Patterns/Legacy/HitObjectPatternGenerator.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs index d044ee8893..4547c3d4a3 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs @@ -6,6 +6,7 @@ using System.Linq; using OpenTK; using osu.Game.Audio; using osu.Game.Beatmaps; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Mania.MathUtils; using osu.Game.Rulesets.Mania.Objects; @@ -25,17 +26,14 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy { StairType = lastStair; - ControlPoint overridePoint; - ControlPoint controlPoint = beatmap.TimingInfo.TimingPointAt(hitObject.StartTime, out overridePoint); + TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(hitObject.StartTime); + EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(hitObject.StartTime); var positionData = hitObject as IHasPosition; float positionSeparation = ((positionData?.Position ?? Vector2.Zero) - previousPosition).Length; double timeSeparation = hitObject.StartTime - previousTime; - double beatLength = controlPoint.BeatLength; - bool kiai = (overridePoint ?? controlPoint).KiaiMode; - if (timeSeparation <= 125) { // More than 120 BPM @@ -72,12 +70,12 @@ namespace osu.Game.Rulesets.Mania.Beatmaps.Patterns.Legacy // More than 100 BPM stream convertType |= PatternType.ForceStack | PatternType.LowProbability; } - else if (positionSeparation < 20 && density >= beatLength / 2.5) + else if (positionSeparation < 20 && density >= timingPoint.BeatLength / 2.5) { // Low density stream convertType |= PatternType.Reverse | PatternType.LowProbability; } - else if (density < beatLength / 2.5 || kiai) + else if (density < timingPoint.BeatLength / 2.5 || effectPoint.KiaiMode) { // High density } From 6bfd7e0fb0b44a0cd9660211b063416a06a38d9c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 14:11:37 +0900 Subject: [PATCH 21/36] xmldocs. --- osu.Game/Beatmaps/ControlPoints/ControlPoint.cs | 3 +++ osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs | 10 ++++++++++ osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs | 10 ++++++++++ osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs | 10 ++++++++++ 4 files changed, 33 insertions(+) diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index 5c31259de1..5707caa235 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -5,6 +5,9 @@ namespace osu.Game.Beatmaps.ControlPoints { public class ControlPoint { + /// + /// The time at which the control point takes effect. + /// public double Time; } } diff --git a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs index 2f6003f57c..7671739cd9 100644 --- a/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/EffectControlPoint.cs @@ -1,8 +1,18 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + namespace osu.Game.Beatmaps.ControlPoints { public class EffectControlPoint : ControlPoint { + /// + /// Whether this control point enables Kiai mode. + /// public bool KiaiMode; + + /// + /// Whether the first bar line of this control point is ignored. + /// public bool OmitFirstBarLine; } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs index 696e684a3d..8084229382 100644 --- a/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SoundControlPoint.cs @@ -1,8 +1,18 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + namespace osu.Game.Beatmaps.ControlPoints { public class SoundControlPoint : ControlPoint { + /// + /// The default sample bank at this control point. + /// public string SampleBank; + + /// + /// The default sample volume at this control point. + /// public int SampleVolume; } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs index 57c21f110b..6f7e38c163 100644 --- a/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/TimingControlPoint.cs @@ -1,10 +1,20 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + using osu.Game.Beatmaps.Timing; namespace osu.Game.Beatmaps.ControlPoints { public class TimingControlPoint : ControlPoint { + /// + /// The time signature at this control point. + /// public TimeSignatures TimeSignature = TimeSignatures.SimpleQuadruple; + + /// + /// The beat length at this control point. + /// public double BeatLength = 500; } } \ No newline at end of file From 002a0e99a2ca7452b815df396e6b9705640f7d34 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 15:20:32 +0900 Subject: [PATCH 22/36] Use SortedList + BinarySearch to find control points at time values. --- .../Tests/TestCaseGamefield.cs | 2 +- .../UI/ManiaHitRenderer.cs | 13 +++-- .../UI/TaikoHitRenderer.cs | 2 +- .../Beatmaps/ControlPoints/ControlPoint.cs | 6 ++- .../ControlPoints/ControlPointInfo.cs | 49 +++++++++++++------ osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 8 +-- 6 files changed, 54 insertions(+), 26 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index fb5bd8cde4..a44780d673 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -55,7 +55,7 @@ namespace osu.Desktop.VisualTests.Tests } var controlPointInfo = new ControlPointInfo(); - controlPointInfo.ControlPoints.Add(new TimingControlPoint + controlPointInfo.TimingPoints.Add(new TimingControlPoint { BeatLength = 200 }); diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 8d5e22933c..8b3623cbab 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -2,11 +2,13 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using System.Linq; using OpenTK; using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.Timing; @@ -38,11 +40,14 @@ namespace osu.Game.Rulesets.Mania.UI double lastSpeedMultiplier = 1; double lastBeatLength = 500; - // Generate the timing points, making non-timing changes use the previous timing change - var timingChanges = Beatmap.ControlPointInfo.ControlPoints.Where(c => c is TimingControlPoint || c is DifficultyControlPoint).Select(c => - { - var change = new TimingChange(); + // Merge timing + difficulty points + var allPoints = new SortedList(Comparer.Default); + allPoints.AddRange(Beatmap.ControlPointInfo.TimingPoints); + allPoints.AddRange(Beatmap.ControlPointInfo.DifficultyPoints); + // Generate the timing points, making non-timing changes use the previous timing change + var timingChanges = allPoints.Select(c => + { var timingPoint = c as TimingControlPoint; var difficultyPoint = c as DifficultyControlPoint; diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs index 7b0a0b085d..f4d411e15f 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs @@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Taiko.UI TaikoHitObject lastObject = Beatmap.HitObjects[Beatmap.HitObjects.Count - 1]; double lastHitTime = 1 + (lastObject as IHasEndTime)?.EndTime ?? lastObject.StartTime; - var timingPoints = Beatmap.ControlPointInfo.ControlPoints.OfType().ToList(); + var timingPoints = Beatmap.ControlPointInfo.TimingPoints.ToList(); if (timingPoints.Count == 0) return; diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs index 5707caa235..0d1dc21e96 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPoint.cs @@ -1,13 +1,17 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; + namespace osu.Game.Beatmaps.ControlPoints { - public class ControlPoint + public class ControlPoint : IComparable { /// /// The time at which the control point takes effect. /// public double Time; + + public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time); } } diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 90c50a3e05..84b6dcfc20 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -1,63 +1,82 @@ using System.Collections.Generic; using System.Linq; +using osu.Framework.Lists; namespace osu.Game.Beatmaps.ControlPoints { public class ControlPointInfo { - /// - /// All the control points. - /// - public readonly List ControlPoints = new List(); + public readonly SortedList TimingPoints = new SortedList(Comparer.Default); + public readonly SortedList DifficultyPoints = new SortedList(Comparer.Default); + public readonly SortedList SoundPoints = new SortedList(Comparer.Default); + public readonly SortedList EffectPoints = new SortedList(Comparer.Default); /// /// Finds the difficulty control point that is active at . /// /// The time to find the difficulty control point at. /// The difficulty control point. - public DifficultyControlPoint DifficultyPointAt(double time) => - ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new DifficultyControlPoint(); + public DifficultyControlPoint DifficultyPointAt(double time) => binarySearch(DifficultyPoints, time); /// /// Finds the effect control point that is active at . /// /// The time to find the effect control point at. /// The effect control point. - public EffectControlPoint EffectPointAt(double time) => - ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new EffectControlPoint(); + public EffectControlPoint EffectPointAt(double time) => binarySearch(EffectPoints, time); /// /// Finds the sound control point that is active at . /// /// The time to find the sound control point at. /// The sound control point. - public SoundControlPoint SoundPointAt(double time) => - ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new SoundControlPoint(); + public SoundControlPoint SoundPointAt(double time) => binarySearch(SoundPoints, time); /// /// Finds the timing control point that is active at . /// /// The time to find the timing control point at. /// The timing control point. - public TimingControlPoint TimingPointAt(double time) => - ControlPoints.OfType().LastOrDefault(t => t.Time <= time) ?? new TimingControlPoint(); + public TimingControlPoint TimingPointAt(double time) => binarySearch(TimingPoints, time); /// /// Finds the maximum BPM represented by any timing control point. /// public double BPMMaximum => - 60000 / (ControlPoints.OfType().OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + 60000 / (TimingPoints.OrderBy(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; /// /// Finds the minimum BPM represented by any timing control point. /// public double BPMMinimum => - 60000 / (ControlPoints.OfType().OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + 60000 / (TimingPoints.OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? new TimingControlPoint()).BeatLength; /// /// Finds the mode BPM (most common BPM) represented by the control points. /// public double BPMMode => - 60000 / (ControlPoints.OfType().GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + 60000 / (TimingPoints.GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).FirstOrDefault()?.FirstOrDefault() ?? new TimingControlPoint()).BeatLength; + + private T binarySearch(SortedList list, double time) + where T : ControlPoint, new() + { + if (list.Count == 0) + return new T(); + + if (time < list[0].Time) + return new T(); + + int index = list.BinarySearch(new T() { Time = time }); + + // Check if we've found an exact match (t == time) + if (index >= 0) + return list[index]; + + index = ~index; + + if (index == list.Count) + return list[list.Count - 1]; + return list[index - 1]; + } } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index e140e2282c..875efab5f9 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -285,7 +285,7 @@ namespace osu.Game.Beatmaps.Formats if (timingChange && (beatLength != timingPoint.BeatLength || timeSignature != timingPoint.TimeSignature)) { - beatmap.ControlPointInfo.ControlPoints.Add(new TimingControlPoint + beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { Time = time, BeatLength = beatLength, @@ -295,7 +295,7 @@ namespace osu.Game.Beatmaps.Formats if (speedMultiplier != difficultyPoint.SpeedMultiplier) { - beatmap.ControlPointInfo.ControlPoints.Add(new DifficultyControlPoint + beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint { Time = time, SpeedMultiplier = speedMultiplier @@ -304,7 +304,7 @@ namespace osu.Game.Beatmaps.Formats if (stringSampleSet != soundPoint.SampleBank || sampleVolume != soundPoint.SampleVolume) { - beatmap.ControlPointInfo.ControlPoints.Add(new SoundControlPoint + beatmap.ControlPointInfo.SoundPoints.Add(new SoundControlPoint { Time = time, SampleBank = stringSampleSet, @@ -314,7 +314,7 @@ namespace osu.Game.Beatmaps.Formats if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine) { - beatmap.ControlPointInfo.ControlPoints.Add(new EffectControlPoint + beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint { Time = time, KiaiMode = kiaiMode, From 2344f37a3c337f0b6d2f071c7c6eadc38f05e766 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 15:26:07 +0900 Subject: [PATCH 23/36] Always add TimingChange control points. --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 875efab5f9..448b6b6b98 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -278,12 +278,11 @@ namespace osu.Game.Beatmaps.Formats if (stringSampleSet == @"none") stringSampleSet = @"normal"; - TimingControlPoint timingPoint = beatmap.ControlPointInfo.TimingPointAt(time); DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time); SoundControlPoint soundPoint = beatmap.ControlPointInfo.SoundPointAt(time); EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time); - if (timingChange && (beatLength != timingPoint.BeatLength || timeSignature != timingPoint.TimeSignature)) + if (timingChange) { beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint { From 836bf930a0be6e473578d0ead265b3f4f0cfe0a1 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 15:29:38 +0900 Subject: [PATCH 24/36] More cleanups. --- .../Tests/TestCaseGamefield.cs | 1 - .../Tests/TestCaseManiaPlayfield.cs | 2 -- .../Legacy/DistanceObjectPatternGenerator.cs | 1 - .../Legacy/HitObjectPatternGenerator.cs | 1 - osu.Game.Rulesets.Mania/Objects/HoldNote.cs | 1 - osu.Game.Rulesets.Mania/Objects/Note.cs | 1 - .../Timing/ControlPointContainer.cs | 1 - osu.Game.Rulesets.Mania/UI/Column.cs | 2 -- osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs | 1 - osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 2 -- osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs | 1 - osu.Game.Rulesets.Osu/Objects/Slider.cs | 1 - osu.Game.Rulesets.Osu/Objects/Spinner.cs | 1 - osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs | 1 - osu.Game.Rulesets.Taiko/Objects/Hit.cs | 1 - .../Objects/TaikoHitObject.cs | 1 - osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs | 1 - .../Beatmaps/ControlPoints/ControlPointInfo.cs | 18 ++++++++++++++++++ .../ControlPoints/DifficultyControlPoint.cs | 6 ++++++ osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 1 - .../Graphics/Containers/BeatSyncedContainer.cs | 1 - osu.Game/Rulesets/Objects/HitObject.cs | 1 - 22 files changed, 24 insertions(+), 23 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs index a44780d673..e2cd2bf67b 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseGamefield.cs @@ -18,7 +18,6 @@ using osu.Game.Rulesets.Taiko.UI; using System.Collections.Generic; using osu.Desktop.VisualTests.Beatmaps; using osu.Framework.Allocation; -using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.ControlPoints; namespace osu.Desktop.VisualTests.Tests diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 88f90fc333..ec50f19f98 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -7,11 +7,9 @@ using osu.Framework.Graphics; using osu.Game.Rulesets.Mania.UI; using System; using System.Collections.Generic; -using osu.Game.Beatmaps.Timing; using OpenTK; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; -using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Mania.Timing; namespace osu.Desktop.VisualTests.Tests diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs index 1209a5c879..718e0967da 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/DistanceObjectPatternGenerator.cs @@ -5,7 +5,6 @@ using System; using System.Linq; using osu.Game.Audio; using osu.Game.Beatmaps; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Mania.MathUtils; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Types; diff --git a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs index 4547c3d4a3..b1ba99d98b 100644 --- a/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs +++ b/osu.Game.Rulesets.Mania/Beatmaps/Patterns/Legacy/HitObjectPatternGenerator.cs @@ -7,7 +7,6 @@ using OpenTK; using osu.Game.Audio; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Mania.MathUtils; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Objects; diff --git a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs index b0a0ed10b8..30e71aeb5d 100644 --- a/osu.Game.Rulesets.Mania/Objects/HoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/HoldNote.cs @@ -3,7 +3,6 @@ using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Objects.Types; diff --git a/osu.Game.Rulesets.Mania/Objects/Note.cs b/osu.Game.Rulesets.Mania/Objects/Note.cs index e91c00c145..6c0cacd277 100644 --- a/osu.Game.Rulesets.Mania/Objects/Note.cs +++ b/osu.Game.Rulesets.Mania/Objects/Note.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Mania.Judgements; diff --git a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs index 38e975f468..6d390464fe 100644 --- a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs @@ -7,7 +7,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK; -using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Mania.Timing diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 12c4cea58c..c8cb5f6387 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -17,8 +17,6 @@ using System.Collections.Generic; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Judgements; -using osu.Game.Beatmaps.Timing; -using osu.Game.Beatmaps.ControlPoints; using System; using osu.Framework.Configuration; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 8b3623cbab..95b7979e43 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics; using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Judgements; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index c0915c5d82..ff763f87c4 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -19,10 +19,8 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Mania.Timing; using osu.Framework.Input; -using osu.Game.Beatmaps.Timing; using osu.Framework.Graphics.Transforms; using osu.Framework.MathUtils; -using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Mania.UI { diff --git a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs index c4b4e3fc4a..e6fd82e6c8 100644 --- a/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Rulesets.Osu/Objects/OsuHitObject.cs @@ -6,7 +6,6 @@ using OpenTK; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Objects.Types; using OpenTK.Graphics; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Beatmaps.ControlPoints; diff --git a/osu.Game.Rulesets.Osu/Objects/Slider.cs b/osu.Game.Rulesets.Osu/Objects/Slider.cs index 1a5065d17d..3b44e38d5e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Slider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Slider.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK; -using osu.Game.Beatmaps.Timing; using osu.Game.Rulesets.Objects.Types; using System; using System.Collections.Generic; diff --git a/osu.Game.Rulesets.Osu/Objects/Spinner.cs b/osu.Game.Rulesets.Osu/Objects/Spinner.cs index 8c0a218108..eff60ba935 100644 --- a/osu.Game.Rulesets.Osu/Objects/Spinner.cs +++ b/osu.Game.Rulesets.Osu/Objects/Spinner.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Rulesets.Objects.Types; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Beatmaps.ControlPoints; diff --git a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs index 857dd8d3a5..18e3016fc3 100644 --- a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs @@ -5,7 +5,6 @@ using osu.Game.Rulesets.Objects.Types; using System; using System.Collections.Generic; using System.Linq; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; diff --git a/osu.Game.Rulesets.Taiko/Objects/Hit.cs b/osu.Game.Rulesets.Taiko/Objects/Hit.cs index cc15b5ab98..f31472d0fd 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Hit.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Hit.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; namespace osu.Game.Rulesets.Taiko.Objects diff --git a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs index a294a13521..4f87467706 100644 --- a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Taiko.UI; diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs index f4d411e15f..662cace511 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoHitRenderer.cs @@ -18,7 +18,6 @@ using osu.Game.Rulesets.Taiko.Replays; using OpenTK; using osu.Game.Rulesets.Beatmaps; using System.Linq; -using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Rulesets.Taiko.UI { diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index 84b6dcfc20..5740c961b1 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -1,3 +1,6 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + using System.Collections.Generic; using System.Linq; using osu.Framework.Lists; @@ -6,9 +9,24 @@ namespace osu.Game.Beatmaps.ControlPoints { public class ControlPointInfo { + /// + /// All timing points. + /// public readonly SortedList TimingPoints = new SortedList(Comparer.Default); + + /// + /// All difficulty points. + /// public readonly SortedList DifficultyPoints = new SortedList(Comparer.Default); + + /// + /// All sound points. + /// public readonly SortedList SoundPoints = new SortedList(Comparer.Default); + + /// + /// All effect points. + /// public readonly SortedList EffectPoints = new SortedList(Comparer.Default); /// diff --git a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs index abd9d05971..30c7884334 100644 --- a/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/DifficultyControlPoint.cs @@ -1,7 +1,13 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + namespace osu.Game.Beatmaps.ControlPoints { public class DifficultyControlPoint : ControlPoint { + /// + /// The speed multiplier at this control point. + /// public double SpeedMultiplier = 1; } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 448b6b6b98..cb1d9d2fcd 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -8,7 +8,6 @@ using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets.Objects.Legacy; -using System.Linq; using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Beatmaps.Formats diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 3489a1550b..429a794a03 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -7,7 +7,6 @@ using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; namespace osu.Game.Graphics.Containers { diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index 6028464a46..5592681cab 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -3,7 +3,6 @@ using osu.Game.Audio; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Rulesets.Objects.Types; From 1867cbb3817439813c8d33c1e5680b8175d86026 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 16:05:58 +0900 Subject: [PATCH 25/36] Revert a bit of BeatSyncedContainer for smaller changeset. --- osu-framework | 2 +- .../Graphics/Containers/BeatSyncedContainer.cs | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/osu-framework b/osu-framework index 773d60eb6b..c6f030d6f1 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 773d60eb6b811f395e32a22dc66bb4d2e63a6dbc +Subproject commit c6f030d6f1ab65a48de9ff1d0c424acb686e0149 diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 429a794a03..5895eabde4 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -2,11 +2,11 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; -using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Beatmaps.Timing; namespace osu.Game.Graphics.Containers { @@ -16,7 +16,6 @@ namespace osu.Game.Graphics.Containers private int lastBeat; private TimingControlPoint lastTimingPoint; - private EffectControlPoint lastEffectPoint; protected override void Update() { @@ -31,21 +30,21 @@ namespace osu.Game.Graphics.Containers if (timingPoint.BeatLength == 0) return; - int beatIndex = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength); + int beat = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength); // The beats before the start of the first control point are off by 1, this should do the trick if (currentTrackTime < timingPoint.Time) - beatIndex--; + beat--; - if (timingPoint == lastTimingPoint && beatIndex == lastBeat) + if (timingPoint == lastTimingPoint && beat == lastBeat) return; double offsetFromBeat = (timingPoint.Time - currentTrackTime) % timingPoint.BeatLength; using (BeginDelayedSequence(offsetFromBeat, true)) - OnNewBeat(beatIndex, timingPoint, effectPoint, beatmap.Value.Track.CurrentAmplitudes); + OnNewBeat(beat, timingPoint.BeatLength, timingPoint.TimeSignature, effectPoint.KiaiMode); - lastBeat = beatIndex; + lastBeat = beat; lastTimingPoint = timingPoint; } @@ -55,7 +54,7 @@ namespace osu.Game.Graphics.Containers beatmap.BindTo(game.Beatmap); } - protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) + protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) { } } From aad6f8f5d61f05f752f06932643ce186099db155 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 16:11:46 +0900 Subject: [PATCH 26/36] Refactoring of BeatSyncedContainer. --- osu-framework | 2 +- .../Graphics/Containers/BeatSyncedContainer.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osu-framework b/osu-framework index c6f030d6f1..773d60eb6b 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit c6f030d6f1ab65a48de9ff1d0c424acb686e0149 +Subproject commit 773d60eb6b811f395e32a22dc66bb4d2e63a6dbc diff --git a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs index 5895eabde4..3d08431bea 100644 --- a/osu.Game/Graphics/Containers/BeatSyncedContainer.cs +++ b/osu.Game/Graphics/Containers/BeatSyncedContainer.cs @@ -2,11 +2,11 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; +using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; -using osu.Game.Beatmaps.Timing; namespace osu.Game.Graphics.Containers { @@ -30,21 +30,21 @@ namespace osu.Game.Graphics.Containers if (timingPoint.BeatLength == 0) return; - int beat = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength); + int beatIndex = (int)((currentTrackTime - timingPoint.Time) / timingPoint.BeatLength); // The beats before the start of the first control point are off by 1, this should do the trick if (currentTrackTime < timingPoint.Time) - beat--; + beatIndex--; - if (timingPoint == lastTimingPoint && beat == lastBeat) + if (timingPoint == lastTimingPoint && beatIndex == lastBeat) return; double offsetFromBeat = (timingPoint.Time - currentTrackTime) % timingPoint.BeatLength; using (BeginDelayedSequence(offsetFromBeat, true)) - OnNewBeat(beat, timingPoint.BeatLength, timingPoint.TimeSignature, effectPoint.KiaiMode); + OnNewBeat(beatIndex, timingPoint, effectPoint, beatmap.Value.Track.CurrentAmplitudes); - lastBeat = beat; + lastBeat = beatIndex; lastTimingPoint = timingPoint; } @@ -54,7 +54,7 @@ namespace osu.Game.Graphics.Containers beatmap.BindTo(game.Beatmap); } - protected virtual void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) + protected virtual void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes) { } } From 7e5bb61a44daf7ce3e57de1bf5d476830b560d52 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 16:13:51 +0900 Subject: [PATCH 27/36] Fix line endings. --- .../Timing/TimingChange.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Timing/TimingChange.cs b/osu.Game.Rulesets.Mania/Timing/TimingChange.cs index fb6f1d2db1..9153ba6991 100644 --- a/osu.Game.Rulesets.Mania/Timing/TimingChange.cs +++ b/osu.Game.Rulesets.Mania/Timing/TimingChange.cs @@ -1,23 +1,23 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Rulesets.Mania.Timing -{ - public class TimingChange - { - /// - /// The time at which this timing change happened. - /// - public double Time; - - /// - /// The beat length. - /// - public double BeatLength = 500; - - /// - /// The speed multiplier. - /// - public double SpeedMultiplier = 1; - } +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Mania.Timing +{ + public class TimingChange + { + /// + /// The time at which this timing change happened. + /// + public double Time; + + /// + /// The beat length. + /// + public double BeatLength = 500; + + /// + /// The speed multiplier. + /// + public double SpeedMultiplier = 1; + } } \ No newline at end of file From fe7ac20e292cbd014a1d6d15a41f3756da83c008 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 May 2017 16:26:51 +0900 Subject: [PATCH 28/36] Read menu music from osz resource --- osu-resources | 2 +- .../Beatmaps/IO/LegacyFilesystemReader.cs | 2 + osu.Game/Beatmaps/IO/ArchiveReader.cs | 2 + osu.Game/Beatmaps/IO/OszArchiveReader.cs | 2 + osu.Game/Database/BeatmapDatabase.cs | 113 +++++++++--------- osu.Game/OsuGame.cs | 2 +- osu.Game/Screens/Menu/Intro.cs | 49 +++++++- osu.Game/Screens/Menu/MainMenu.cs | 32 +---- 8 files changed, 111 insertions(+), 93 deletions(-) diff --git a/osu-resources b/osu-resources index ffccbeb98d..9f46a456dc 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit ffccbeb98dc9e8f0965520270b5885e63f244c83 +Subproject commit 9f46a456dc3a56dcbff09671a3f588b16a464106 diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index 8c896646bf..8772fc9f28 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -37,5 +37,7 @@ namespace osu.Desktop.Beatmaps.IO { // no-op } + + public override Stream GetUnderlyingStream() => null; } } diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 9d7d67007e..7ff5668b6f 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -63,5 +63,7 @@ namespace osu.Game.Beatmaps.IO return buffer; } } + + public abstract Stream GetUnderlyingStream(); } } \ No newline at end of file diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index 6c550def8d..eb9e740779 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -49,5 +49,7 @@ namespace osu.Game.Beatmaps.IO archive.Dispose(); archiveStream.Dispose(); } + + public override Stream GetUnderlyingStream() => archiveStream; } } \ No newline at end of file diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index bd25ebe8a9..efd5631077 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -12,6 +12,7 @@ using osu.Game.Beatmaps; using osu.Game.Beatmaps.Formats; using osu.Game.Beatmaps.IO; using osu.Game.IPC; +using osu.Game.Screens.Menu; using SQLite.Net; using SQLiteNetExtensions.Extensions; @@ -38,6 +39,10 @@ namespace osu.Game.Database { foreach (var b in GetAllWithChildren(b => b.DeletePending)) { + if (b.Hash == Intro.MENU_MUSIC_BEATMAP_HASH) + // this is a bit hacky, but will do for now. + continue; + try { Storage.Delete(b.Path); @@ -97,50 +102,49 @@ namespace osu.Game.Database typeof(BeatmapDifficulty), }; + public void Import(string path) + { + try + { + Import(ArchiveReader.GetReader(Storage, path)); + + // We may or may not want to delete the file depending on where it is stored. + // e.g. reconstructing/repairing database with beatmaps from default storage. + // Also, not always a single file, i.e. for LegacyFilesystemReader + // TODO: Add a check to prevent files from storage to be deleted. + try + { + File.Delete(path); + } + catch (Exception e) + { + Logger.Error(e, $@"Could not delete file at {path}"); + } + } + catch (Exception e) + { + e = e.InnerException ?? e; + Logger.Error(e, @"Could not import beatmap set"); + } + } + + public void Import(ArchiveReader archiveReader) + { + BeatmapSetInfo set = getBeatmapSet(archiveReader); + + //If we have an ID then we already exist in the database. + if (set.ID == 0) + Import(new[] { set }); + } + /// /// Import multiple from . /// /// Multiple locations on disk - public void Import(IEnumerable paths) + public void Import(params string[] paths) { foreach (string p in paths) - { - try - { - BeatmapSetInfo set = getBeatmapSet(p); - - //If we have an ID then we already exist in the database. - if (set.ID == 0) - Import(new[] { set }); - - // We may or may not want to delete the file depending on where it is stored. - // e.g. reconstructing/repairing database with beatmaps from default storage. - // Also, not always a single file, i.e. for LegacyFilesystemReader - // TODO: Add a check to prevent files from storage to be deleted. - try - { - File.Delete(p); - } - catch (Exception e) - { - Logger.Error(e, $@"Could not delete file at {p}"); - } - } - catch (Exception e) - { - e = e.InnerException ?? e; - Logger.Error(e, @"Could not import beatmap set"); - } - } - } - - /// - /// Import from . - /// - /// Location on disk - public void Import(string path) - { - Import(new[] { path }); + Import(p); } /// @@ -148,29 +152,26 @@ namespace osu.Game.Database /// /// Content location /// - private BeatmapSetInfo getBeatmapSet(string path) - { - string hash = null; + private BeatmapSetInfo getBeatmapSet(string path) => getBeatmapSet(ArchiveReader.GetReader(Storage, path)); + private BeatmapSetInfo getBeatmapSet(ArchiveReader archiveReader) + { BeatmapMetadata metadata; - using (var reader = ArchiveReader.GetReader(Storage, path)) - { - using (var stream = new StreamReader(reader.GetStream(reader.BeatmapFilenames[0]))) - metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; - } + using (var stream = new StreamReader(archiveReader.GetStream(archiveReader.BeatmapFilenames[0]))) + metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata; - if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader + string hash; + string path; + + using (var input = archiveReader.GetUnderlyingStream()) { - using (var input = Storage.GetStream(path)) - { - hash = input.GetMd5Hash(); - input.Seek(0, SeekOrigin.Begin); - path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); - if (!Storage.Exists(path)) - using (var output = Storage.GetStream(path, FileAccess.Write)) - input.CopyTo(output); - } + hash = input.GetMd5Hash(); + input.Seek(0, SeekOrigin.Begin); + path = Path.Combine(@"beatmaps", hash.Remove(1), hash.Remove(2), hash); + if (!Storage.Exists(path)) + using (var output = Storage.GetStream(path, FileAccess.Write)) + input.CopyTo(output); } var existing = Connection.Table().FirstOrDefault(b => b.Hash == hash); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4cf436a8e4..f13043a745 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -82,7 +82,7 @@ namespace osu.Game if (args?.Length > 0) { var paths = args.Where(a => !a.StartsWith(@"-")); - Task.Run(() => BeatmapDatabase.Import(paths)); + Task.Run(() => BeatmapDatabase.Import(paths.ToArray())); } Dependencies.Cache(this); diff --git a/osu.Game/Screens/Menu/Intro.cs b/osu.Game/Screens/Menu/Intro.cs index 01659edd72..5791b7f196 100644 --- a/osu.Game/Screens/Menu/Intro.cs +++ b/osu.Game/Screens/Menu/Intro.cs @@ -8,7 +8,10 @@ using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Screens; using osu.Framework.Graphics; +using osu.Framework.MathUtils; +using osu.Game.Beatmaps.IO; using osu.Game.Configuration; +using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Screens.Backgrounds; using OpenTK.Graphics; @@ -19,6 +22,8 @@ namespace osu.Game.Screens.Menu { private readonly OsuLogo logo; + public const string MENU_MUSIC_BEATMAP_HASH = "21c1271b91234385978b5418881fdd88"; + /// /// Whether we have loaded the menu previously. /// @@ -27,7 +32,6 @@ namespace osu.Game.Screens.Menu private MainMenu mainMenu; private SampleChannel welcome; private SampleChannel seeya; - private Track bgm; internal override bool HasLocalCursorDisplayed => true; @@ -60,15 +64,49 @@ namespace osu.Game.Screens.Menu private Bindable menuVoice; private Bindable menuMusic; + private Track track; [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager config) + private void load(AudioManager audio, OsuConfigManager config, BeatmapDatabase beatmaps, Framework.Game game) { menuVoice = config.GetBindable(OsuSetting.MenuVoice); menuMusic = config.GetBindable(OsuSetting.MenuMusic); - bgm = audio.Track.Get(@"circles"); - bgm.Looping = true; + var trackManager = audio.Track; + + BeatmapSetInfo setInfo = null; + + if (!menuMusic) + { + var query = beatmaps.Query().Where(b => !b.DeletePending); + int count = query.Count(); + if (count > 0) + setInfo = query.ElementAt(RNG.Next(0, count - 1)); + } + + if (setInfo == null) + { + var query = beatmaps.Query().Where(b => b.Hash == MENU_MUSIC_BEATMAP_HASH); + + setInfo = query.FirstOrDefault(); + + if (setInfo == null) + { + // we need to import the default menu background beatmap + beatmaps.Import(new OszArchiveReader(game.Resources.GetStream(@"Tracks/circles.osz"))); + + setInfo = query.First(); + + setInfo.DeletePending = true; + beatmaps.Update(setInfo, false); + } + } + + beatmaps.GetChildren(setInfo); + Beatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); + + track = Beatmap.Track; + trackManager.SetExclusive(track); welcome = audio.Sample.Get(@"welcome"); seeya = audio.Sample.Get(@"seeya"); @@ -83,8 +121,7 @@ namespace osu.Game.Screens.Menu Scheduler.AddDelayed(delegate { - if (menuMusic) - bgm.Start(); + track.Start(); LoadComponentAsync(mainMenu = new MainMenu()); diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 71d020b0f2..b74ee52f9c 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -1,18 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Threading.Tasks; using OpenTK; using OpenTK.Input; using osu.Framework.Allocation; -using osu.Framework.Audio.Track; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Input; -using osu.Framework.MathUtils; using osu.Framework.Screens; -using osu.Game.Configuration; -using osu.Game.Database; using osu.Game.Graphics.Containers; using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Charts; @@ -60,30 +54,11 @@ namespace osu.Game.Screens.Menu }; } - private Bindable menuMusic; - private TrackManager trackManager; - [BackgroundDependencyLoader] - private void load(OsuGame game, OsuConfigManager config, BeatmapDatabase beatmaps) + private void load(OsuGame game) { - menuMusic = config.GetBindable(OsuSetting.MenuMusic); LoadComponentAsync(background); - if (!menuMusic) - { - trackManager = game.Audio.Track; - - var query = beatmaps.Query().Where(b => !b.DeletePending); - int count = query.Count(); - - if (count > 0) - { - var beatmap = query.ElementAt(RNG.Next(0, count - 1)); - beatmaps.GetChildren(beatmap); - Beatmap = beatmaps.GetWorkingBeatmap(beatmap.Beatmaps[0]); - } - } - buttons.OnSettings = game.ToggleSettings; preloadSongSelect(); @@ -108,14 +83,13 @@ namespace osu.Game.Screens.Menu buttons.FadeInFromZero(500); if (last is Intro && Beatmap != null) { - Task.Run(() => + if (!Beatmap.Track.IsRunning) { - trackManager.SetExclusive(Beatmap.Track); Beatmap.Track.Seek(Beatmap.Metadata.PreviewTime); if (Beatmap.Metadata.PreviewTime == -1) Beatmap.Track.Seek(Beatmap.Track.Length * 0.4f); Beatmap.Track.Start(); - }); + } } } From a4823bca91514e34b39ebd5b62e50fd096ae7980 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 16:47:47 +0900 Subject: [PATCH 29/36] CI fixes. --- osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs | 2 +- osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs index 6d390464fe..cc8897840e 100644 --- a/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ControlPointContainer.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Mania.Timing /// public double TimeSpan { get; set; } - private readonly List drawableControlPoints = new List(); + private readonly List drawableControlPoints; public ControlPointContainer(IEnumerable timingChanges) { diff --git a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs index 4f87467706..82ceaeed1a 100644 --- a/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/TaikoHitObject.cs @@ -31,12 +31,12 @@ namespace osu.Game.Rulesets.Taiko.Objects public const float DEFAULT_STRONG_CIRCLE_DIAMETER = DEFAULT_CIRCLE_DIAMETER * STRONG_CIRCLE_DIAMETER_SCALE; /// - /// The time taken from the initial (off-screen) spawn position to the centre of the hit target for a of 1000ms. + /// The time taken from the initial (off-screen) spawn position to the centre of the hit target for a of 1000ms. /// private const double scroll_time = 6000; /// - /// Our adjusted taking into consideration local and other speed multipliers. + /// Our adjusted taking into consideration local and other speed multipliers. /// public double ScrollTime; From eafe215169b6ba92b813e280d2681e76b7d1b723 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 11:53:12 +0300 Subject: [PATCH 30/36] Simplify Hud visibility change --- osu.Game/Screens/Play/HUDOverlay.cs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 1e57c2ba2a..34522d74ef 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -30,7 +30,6 @@ namespace osu.Game.Screens.Play public readonly SongProgress Progress; public readonly ModDisplay ModDisplay; - private Bindable showKeyCounter; private Bindable showHud; private static bool hasShownNotificationOnce; @@ -46,6 +45,7 @@ namespace osu.Game.Screens.Play protected HUDOverlay() { RelativeSizeAxes = Axes.Both; + AlwaysPresent = true; Add(content = new Container { @@ -67,24 +67,8 @@ namespace osu.Game.Screens.Play [BackgroundDependencyLoader(true)] private void load(OsuConfigManager config, NotificationManager notificationManager) { - showKeyCounter = config.GetBindable(OsuSetting.KeyOverlay); - showKeyCounter.ValueChanged += keyCounterVisibility => - { - if (keyCounterVisibility) - KeyCounter.FadeIn(duration); - else - KeyCounter.FadeOut(duration); - }; - showKeyCounter.TriggerChange(); - showHud = config.GetBindable(OsuSetting.ShowInterface); - showHud.ValueChanged += hudVisibility => - { - if (hudVisibility) - content.FadeIn(duration); - else - content.FadeOut(duration); - }; + showHud.ValueChanged += hudVisibility => FadeTo(hudVisibility ? 1 : 0, duration); showHud.TriggerChange(); if (!showHud && !hasShownNotificationOnce) From 4b23cc47eae4d81a2a2a6d4072d5498b9de836ed Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 11:53:42 +0300 Subject: [PATCH 31/36] Moved KeyCounter visibility logic to it's own class --- osu.Game/Screens/Play/KeyCounterCollection.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index 4a561e6036..e53a1dcd99 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -6,14 +6,22 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using OpenTK.Graphics; using osu.Framework.Input; +using osu.Framework.Configuration; +using osu.Framework.Allocation; +using osu.Game.Configuration; namespace osu.Game.Screens.Play { public class KeyCounterCollection : FillFlowContainer { + private const int duration = 100; + + private Bindable showKeyCounter; + public KeyCounterCollection() { AlwaysReceiveInput = true; + AlwaysPresent = true; Direction = FillDirection.Horizontal; AutoSizeAxes = Axes.Both; @@ -34,6 +42,14 @@ namespace osu.Game.Screens.Play counter.ResetCount(); } + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + showKeyCounter = config.GetBindable(OsuSetting.KeyOverlay); + showKeyCounter.ValueChanged += keyCounterVisibility => FadeTo(keyCounterVisibility ? 1 : 0, duration); + showKeyCounter.TriggerChange(); + } + //further: change default values here and in KeyCounter if needed, instead of passing them in every constructor private bool isCounting; public bool IsCounting From 76fe4af9a6c68650ae3ebdbdeb768b08d424638e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 23 May 2017 18:06:31 +0900 Subject: [PATCH 32/36] Fix visual test failing. --- osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index ec50f19f98..9dcba02849 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -41,7 +41,7 @@ namespace osu.Desktop.VisualTests.Tests Clear(); ManiaPlayfield playField; - Add(playField = new ManiaPlayfield(cols, new List()) + Add(playField = new ManiaPlayfield(cols, new List { new TimingChange { BeatLength = 200 } }) { Anchor = Anchor.Centre, Origin = Anchor.Centre, From c7a241246ecb912897aded1faf75203589f66614 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 12:09:32 +0300 Subject: [PATCH 33/36] Better letterbox settings transition --- .../Sections/Graphics/LayoutSettings.cs | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 9a5fd769cd..8b093c8d79 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; namespace osu.Game.Overlays.Settings.Sections.Graphics { @@ -11,11 +12,13 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics { protected override string Header => "Layout"; - private SettingsSlider letterboxPositionX; - private SettingsSlider letterboxPositionY; + private FillFlowContainer letterboxSettings; private Bindable letterboxing; + private const int letterbox_container_height = 75; + private const int duration = 200; + [BackgroundDependencyLoader] private void load(FrameworkConfigManager config) { @@ -33,34 +36,30 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics LabelText = "Letterboxing", Bindable = letterboxing, }, - letterboxPositionX = new SettingsSlider + letterboxSettings = new FillFlowContainer { - LabelText = "Horizontal position", - Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionX) - }, - letterboxPositionY = new SettingsSlider - { - LabelText = "Vertical position", - Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionY) + Direction = FillDirection.Vertical, + RelativeSizeAxes = Axes.X, + Masking = true, + + Children = new Drawable[] + { + new SettingsSlider + { + LabelText = "Horizontal position", + Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionX) + }, + new SettingsSlider + { + LabelText = "Vertical position", + Bindable = config.GetBindable(FrameworkSetting.LetterboxPositionY) + }, + } }, }; - letterboxing.ValueChanged += visibilityChanged; + letterboxing.ValueChanged += isVisible => letterboxSettings.ResizeHeightTo(isVisible ? letterbox_container_height : 0, duration, EasingTypes.OutQuint); letterboxing.TriggerChange(); } - - private void visibilityChanged(bool newVisibility) - { - if (newVisibility) - { - letterboxPositionX.Show(); - letterboxPositionY.Show(); - } - else - { - letterboxPositionX.Hide(); - letterboxPositionY.Hide(); - } - } } } From 2e28b10c3678518e496801d799b9b5f6239ad56f Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 12:24:16 +0300 Subject: [PATCH 34/36] CI fixes and removed useless property --- osu.Game/Screens/Play/HUDOverlay.cs | 3 +-- osu.Game/Screens/Play/KeyCounterCollection.cs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 34522d74ef..115611c244 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -45,7 +45,6 @@ namespace osu.Game.Screens.Play protected HUDOverlay() { RelativeSizeAxes = Axes.Both; - AlwaysPresent = true; Add(content = new Container { @@ -68,7 +67,7 @@ namespace osu.Game.Screens.Play private void load(OsuConfigManager config, NotificationManager notificationManager) { showHud = config.GetBindable(OsuSetting.ShowInterface); - showHud.ValueChanged += hudVisibility => FadeTo(hudVisibility ? 1 : 0, duration); + showHud.ValueChanged += hudVisibility => content.FadeTo(hudVisibility ? 1 : 0, duration); showHud.TriggerChange(); if (!showHud && !hasShownNotificationOnce) diff --git a/osu.Game/Screens/Play/KeyCounterCollection.cs b/osu.Game/Screens/Play/KeyCounterCollection.cs index e53a1dcd99..6e1c8a34e5 100644 --- a/osu.Game/Screens/Play/KeyCounterCollection.cs +++ b/osu.Game/Screens/Play/KeyCounterCollection.cs @@ -21,7 +21,6 @@ namespace osu.Game.Screens.Play public KeyCounterCollection() { AlwaysReceiveInput = true; - AlwaysPresent = true; Direction = FillDirection.Horizontal; AutoSizeAxes = Axes.Both; From 165d6ef1bb19e6c5079dbd95e2afced50f437adc Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 12:30:39 +0300 Subject: [PATCH 35/36] Make transition a bit smoother --- osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 8b093c8d79..8ff145823c 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -17,7 +17,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics private Bindable letterboxing; private const int letterbox_container_height = 75; - private const int duration = 200; + private const int duration = 300; [BackgroundDependencyLoader] private void load(FrameworkConfigManager config) From 564abc1a5bc171a7f62e5f0568fa17ec87efeffa Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 23 May 2017 14:32:45 +0300 Subject: [PATCH 36/36] using autosize instead of constant height --- .../Settings/Sections/Graphics/LayoutSettings.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index 8ff145823c..ea9ccd3492 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -16,8 +16,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics private Bindable letterboxing; - private const int letterbox_container_height = 75; - private const int duration = 300; + private const int transition_duration = 400; [BackgroundDependencyLoader] private void load(FrameworkConfigManager config) @@ -40,6 +39,9 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics { Direction = FillDirection.Vertical, RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + AutoSizeDuration = transition_duration, + AutoSizeEasing = EasingTypes.OutQuint, Masking = true, Children = new Drawable[] @@ -58,7 +60,14 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics }, }; - letterboxing.ValueChanged += isVisible => letterboxSettings.ResizeHeightTo(isVisible ? letterbox_container_height : 0, duration, EasingTypes.OutQuint); + letterboxing.ValueChanged += isVisible => + { + letterboxSettings.ClearTransforms(); + letterboxSettings.AutoSizeAxes = isVisible ? Axes.Y : Axes.None; + + if(!isVisible) + letterboxSettings.ResizeHeightTo(0, transition_duration, EasingTypes.OutQuint); + }; letterboxing.TriggerChange(); } }