From b88c4464cb7eee25ae7c6791b881df7ba192f898 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 27 Jun 2018 16:02:49 +0900 Subject: [PATCH 1/9] Make virtual beatmap tracks approximate beatmap length --- .../Beatmaps/BeatmapManager_WorkingBeatmap.cs | 2 +- osu.Game/Beatmaps/WorkingBeatmap.cs | 4 +- .../WorkingBeatmap_VirtualBeatmapTrack.cs | 46 +++++++++++++++++++ .../Timelines/Summary/Parts/MarkerPart.cs | 2 - .../Timelines/Summary/Parts/TimelinePart.cs | 3 +- .../Edit/Screens/Compose/Timeline/Timeline.cs | 10 ++-- 6 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs diff --git a/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs b/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs index 71406c6034..d086064425 100644 --- a/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs @@ -69,7 +69,7 @@ namespace osu.Game.Beatmaps } catch { - return new TrackVirtual(); + return null; } } diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 9b50aed077..1a65611a3d 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -19,7 +19,7 @@ using osu.Game.Skinning; namespace osu.Game.Beatmaps { - public abstract class WorkingBeatmap : IDisposable + public abstract partial class WorkingBeatmap : IDisposable { public readonly BeatmapInfo BeatmapInfo; @@ -145,7 +145,7 @@ namespace osu.Game.Beatmaps private Track populateTrack() { // we want to ensure that we always have a track, even if it's a fake one. - var t = GetTrack() ?? new TrackVirtual(); + var t = GetTrack() ?? new VirtualBeatmapTrack(Beatmap); applyRateAdjustments(t); return t; } diff --git a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs new file mode 100644 index 0000000000..1cadf9ee90 --- /dev/null +++ b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs @@ -0,0 +1,46 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Linq; +using osu.Framework.Audio.Track; +using osu.Game.Rulesets.Objects.Types; + +namespace osu.Game.Beatmaps +{ + public partial class WorkingBeatmap + { + private class VirtualBeatmapTrack : TrackVirtual + { + private readonly IBeatmap beatmap; + + public VirtualBeatmapTrack(IBeatmap beatmap) + { + this.beatmap = beatmap; + } + + protected override void UpdateState() + { + updateVirtualLength(); + base.UpdateState(); + } + + private void updateVirtualLength() + { + var lastObject = beatmap.HitObjects.LastOrDefault(); + + switch (lastObject) + { + case null: + Length = 1000; + break; + case IHasEndTime endTime: + Length = endTime.EndTime + 1000; + break; + default: + Length = lastObject.StartTime + 1000; + break; + } + } + } + } +} diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs index d1fc8be005..0dc110951b 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/MarkerPart.cs @@ -52,8 +52,6 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts if (Beatmap.Value == null) return; - if (Beatmap.Value.Track.Length == double.PositiveInfinity) return; - float markerPos = MathHelper.Clamp(ToLocalSpace(screenPosition).X, 0, DrawWidth); adjustableClock.Seek(markerPos / DrawWidth * Beatmap.Value.Track.Length); } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs index 07d9398d38..5628630d0e 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs @@ -47,8 +47,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts return; } - // Todo: This should be handled more gracefully - timeline.RelativeChildSize = Beatmap.Value.Track.Length == double.PositiveInfinity ? Vector2.One : new Vector2((float)Math.Max(1, Beatmap.Value.Track.Length), 1); + timeline.RelativeChildSize = new Vector2((float)Math.Max(1, Beatmap.Value.Track.Length), 1); } protected void Add(Drawable visualisation) => timeline.Add(visualisation); diff --git a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs index e6a04bf1e7..d9b827ffec 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs @@ -2,7 +2,6 @@ // 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.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -118,18 +117,15 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline private void seekTrackToCurrent() { - var track = Beatmap.Value.Track; - if (track is TrackVirtual || !track.IsLoaded) + if (!Beatmap.Value.TrackLoaded) return; - if (!(Beatmap.Value.Track is TrackVirtual)) - adjustableClock.Seek(Current / Content.DrawWidth * Beatmap.Value.Track.Length); + adjustableClock.Seek(Current / Content.DrawWidth * Beatmap.Value.Track.Length); } private void scrollToTrackTime() { - var track = Beatmap.Value.Track; - if (track is TrackVirtual || !track.IsLoaded) + if (!Beatmap.Value.TrackLoaded) return; ScrollTo((float)(adjustableClock.CurrentTime / Beatmap.Value.Track.Length) * Content.DrawWidth, false); From b4b28f8ae805bdb520420cb9ebf49909a50aa5bc Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 27 Jun 2018 16:07:18 +0900 Subject: [PATCH 2/9] Make GetWaveform() not hard bail if errors occur --- osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs b/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs index d086064425..43ae30f780 100644 --- a/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/BeatmapManager_WorkingBeatmap.cs @@ -73,7 +73,18 @@ namespace osu.Game.Beatmaps } } - protected override Waveform GetWaveform() => new Waveform(store.GetStream(getPathForFile(Metadata.AudioFile))); + protected override Waveform GetWaveform() + { + try + { + var trackData = store.GetStream(getPathForFile(Metadata.AudioFile)); + return trackData == null ? null : new Waveform(trackData); + } + catch + { + return null; + } + } protected override Storyboard GetStoryboard() { From 5640385f480c6bdbca0ba1bbb0fc030c1a552c60 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 27 Jun 2018 16:12:49 +0900 Subject: [PATCH 3/9] Update the length once during construction --- osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs index 1cadf9ee90..fb3c0027f7 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs @@ -9,6 +9,9 @@ namespace osu.Game.Beatmaps { public partial class WorkingBeatmap { + /// + /// A type of which provides a valid length based on the s of an . + /// private class VirtualBeatmapTrack : TrackVirtual { private readonly IBeatmap beatmap; @@ -16,6 +19,7 @@ namespace osu.Game.Beatmaps public VirtualBeatmapTrack(IBeatmap beatmap) { this.beatmap = beatmap; + updateVirtualLength(); } protected override void UpdateState() From c0c94e24b9e5172f693b57514b6120dd3274b641 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 11:45:48 +0900 Subject: [PATCH 4/9] Use VirtualBeatmapTrack in testcases --- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 +- .../WorkingBeatmap_VirtualBeatmapTrack.cs | 2 +- osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs | 19 +------------------ 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index 265c6832b2..25a76b52a7 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -45,7 +45,7 @@ namespace osu.Game.Beatmaps protected override Texture GetBackground() => game?.Textures.Get(@"Backgrounds/bg4"); - protected override Track GetTrack() => new TrackVirtual(); + protected override Track GetTrack() => new TrackVirtual { Length = 1000 }; private class DummyRulesetInfo : RulesetInfo { diff --git a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs index fb3c0027f7..b3b3562dc4 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps /// /// A type of which provides a valid length based on the s of an . /// - private class VirtualBeatmapTrack : TrackVirtual + protected class VirtualBeatmapTrack : TrackVirtual { private readonly IBeatmap beatmap; diff --git a/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs b/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs index 37693c99e8..2f5c887726 100644 --- a/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs +++ b/osu.Game/Tests/Beatmaps/TestWorkingBeatmap.cs @@ -1,12 +1,10 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Linq; using osu.Framework.Audio.Track; using osu.Framework.Graphics.Textures; using osu.Game.Beatmaps; using osu.Game.Rulesets; -using osu.Game.Rulesets.Objects.Types; namespace osu.Game.Tests.Beatmaps { @@ -26,21 +24,6 @@ namespace osu.Game.Tests.Beatmaps private readonly IBeatmap beatmap; protected override IBeatmap GetBeatmap() => beatmap; protected override Texture GetBackground() => null; - - protected override Track GetTrack() - { - var lastObject = beatmap.HitObjects.LastOrDefault(); - if (lastObject != null) - return new TestTrack(((lastObject as IHasEndTime)?.EndTime ?? lastObject.StartTime) + 1000); - return new TrackVirtual(); - } - - private class TestTrack : TrackVirtual - { - public TestTrack(double length) - { - Length = length; - } - } + protected override Track GetTrack() => null; } } From 87e8074cd267f9f8676fa7f7f5ecc18ae3a56029 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 11:46:56 +0900 Subject: [PATCH 5/9] Use a const for excess length --- osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs index b3b3562dc4..4c37c0c4a0 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs @@ -14,6 +14,8 @@ namespace osu.Game.Beatmaps /// protected class VirtualBeatmapTrack : TrackVirtual { + private const double excess_length = 1000; + private readonly IBeatmap beatmap; public VirtualBeatmapTrack(IBeatmap beatmap) @@ -35,13 +37,13 @@ namespace osu.Game.Beatmaps switch (lastObject) { case null: - Length = 1000; + Length = excess_length; break; case IHasEndTime endTime: - Length = endTime.EndTime + 1000; + Length = endTime.EndTime + excess_length; break; default: - Length = lastObject.StartTime + 1000; + Length = lastObject.StartTime + excess_length; break; } } From 2f2bd59844e65fa6a57ab05d81dc39907a3aeb23 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 11:47:41 +0900 Subject: [PATCH 6/9] Remove editor functionality from VirtualBeatmapTrack /shrug --- .../Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs index 4c37c0c4a0..0e0a9a3bb9 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap_VirtualBeatmapTrack.cs @@ -16,21 +16,7 @@ namespace osu.Game.Beatmaps { private const double excess_length = 1000; - private readonly IBeatmap beatmap; - public VirtualBeatmapTrack(IBeatmap beatmap) - { - this.beatmap = beatmap; - updateVirtualLength(); - } - - protected override void UpdateState() - { - updateVirtualLength(); - base.UpdateState(); - } - - private void updateVirtualLength() { var lastObject = beatmap.HitObjects.LastOrDefault(); From 01b90aaffe7affde478e989d15c0542d0fec06a7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 28 Jun 2018 11:58:06 +0900 Subject: [PATCH 7/9] Fix CI not passing --- osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs index d9b827ffec..28239533c8 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs @@ -117,7 +117,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline private void seekTrackToCurrent() { - if (!Beatmap.Value.TrackLoaded) + if (!Beatmap.Value.TrackLoaded || !Beatmap.Value.Track.IsLoaded) return; adjustableClock.Seek(Current / Content.DrawWidth * Beatmap.Value.Track.Length); @@ -125,7 +125,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline private void scrollToTrackTime() { - if (!Beatmap.Value.TrackLoaded) + if (!Beatmap.Value.TrackLoaded || !Beatmap.Value.Track.IsLoaded) return; ScrollTo((float)(adjustableClock.CurrentTime / Beatmap.Value.Track.Length) * Content.DrawWidth, false); From 3b0c4ff16b39a93b8dbe842aca781178ded7dbb9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jun 2018 14:08:15 +0900 Subject: [PATCH 8/9] Tidy code --- .../Edit/Screens/Compose/Timeline/Timeline.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs index 28239533c8..8cb0fdd908 100644 --- a/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs +++ b/osu.Game/Screens/Edit/Screens/Compose/Timeline/Timeline.cs @@ -2,6 +2,7 @@ // 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.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -51,13 +52,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline WaveformVisible.ValueChanged += visible => waveform.FadeTo(visible ? 1 : 0, 200, Easing.OutQuint); Beatmap.BindTo(beatmap); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - Beatmap.BindValueChanged(b => waveform.Waveform = b.Waveform); - waveform.Waveform = Beatmap.Value.Waveform; + Beatmap.BindValueChanged(b => + { + waveform.Waveform = b.Waveform; + track = b.Track; + }, true); } /// @@ -80,6 +79,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline /// private bool trackWasPlaying; + private Track track; + protected override void Update() { base.Update(); @@ -117,18 +118,18 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline private void seekTrackToCurrent() { - if (!Beatmap.Value.TrackLoaded || !Beatmap.Value.Track.IsLoaded) + if (!track.IsLoaded) return; - adjustableClock.Seek(Current / Content.DrawWidth * Beatmap.Value.Track.Length); + adjustableClock.Seek(Current / Content.DrawWidth * track.Length); } private void scrollToTrackTime() { - if (!Beatmap.Value.TrackLoaded || !Beatmap.Value.Track.IsLoaded) + if (!track.IsLoaded) return; - ScrollTo((float)(adjustableClock.CurrentTime / Beatmap.Value.Track.Length) * Content.DrawWidth, false); + ScrollTo((float)(adjustableClock.CurrentTime / track.Length) * Content.DrawWidth, false); } protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) From b1a3f012125a57be44cf3cd3ae2e096a6cab8458 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 28 Jun 2018 16:36:42 +0900 Subject: [PATCH 9/9] Fix mania maps not being treated as mania maps in release builds --- osu.Game/Rulesets/RulesetStore.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/RulesetStore.cs b/osu.Game/Rulesets/RulesetStore.cs index 8d267f48e9..a7a9fea5f2 100644 --- a/osu.Game/Rulesets/RulesetStore.cs +++ b/osu.Game/Rulesets/RulesetStore.cs @@ -84,10 +84,11 @@ namespace osu.Game.Rulesets { try { - var instance = r.CreateInstance(); + var instanceInfo = ((Ruleset)Activator.CreateInstance(Type.GetType(r.InstantiationInfo), (RulesetInfo)null)).RulesetInfo; - r.Name = instance.Description; - r.ShortName = instance.ShortName; + r.Name = instanceInfo.Name; + r.ShortName = instanceInfo.ShortName; + r.InstantiationInfo = instanceInfo.InstantiationInfo; r.Available = true; }