From 8de6bdf3402706fec50f785573192d141217d956 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 9 Jun 2017 02:43:48 +0900 Subject: [PATCH] Rewrite mania to use the new timing section stuff. --- .../Tests/TestCaseManiaPlayfield.cs | 23 +++------- .../Mods/ManiaModGravity.cs | 11 +++-- .../BasicScrollingHitObjectCollection.cs | 27 +++++++++++ .../DrawableManiaScrollingTimingChange.cs | 25 ---------- .../Drawables/DrawableManiaTimingChange.cs | 31 ------------- .../Drawables/DrawableManiaTimingSection.cs | 46 +++++++++++++++++++ ...=> GravityScrollingHitObjectCollection.cs} | 44 +++++++++--------- .../Timing/ScrollingAlgorithm.cs | 17 +++++++ .../UI/ManiaHitRenderer.cs | 5 +- .../osu.Game.Rulesets.Mania.csproj | 7 +-- 10 files changed, 131 insertions(+), 105 deletions(-) create mode 100644 osu.Game.Rulesets.Mania/Timing/Drawables/BasicScrollingHitObjectCollection.cs delete mode 100644 osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaScrollingTimingChange.cs delete mode 100644 osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingChange.cs create mode 100644 osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingSection.cs rename osu.Game.Rulesets.Mania/Timing/Drawables/{DrawableManiaGravityTimingChange.cs => GravityScrollingHitObjectCollection.cs} (56%) create mode 100644 osu.Game.Rulesets.Mania/Timing/ScrollingAlgorithm.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs index 6531851c17..c6aa20d63f 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseManiaPlayfield.cs @@ -13,8 +13,9 @@ using osu.Framework.Configuration; using OpenTK.Input; using osu.Framework.Timing; using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Game.Rulesets.Mania.Timing.Drawables; using System.Linq; +using osu.Game.Rulesets.Mania.Timing; +using osu.Game.Rulesets.Mania.Timing.Drawables; using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.Timing.Drawables; @@ -45,23 +46,11 @@ namespace osu.Desktop.VisualTests.Tests const double start_time = 500; const double duration = 500; - Func createTimingChange = (time, gravity) => + Func createTimingChange = (time, gravity) => new DrawableManiaTimingSection(new TimingSection { - if (gravity) - { - return new DrawableManiaGravityTimingChange(new TimingSection - { - BeatLength = 1000, - Time = time - }); - } - - return new DrawableManiaScrollingTimingChange(new TimingSection - { - BeatLength = 1000, - Time = time - }); - }; + BeatLength = 1000, + Time = time + }, gravity ? ScrollingAlgorithm.Gravity : ScrollingAlgorithm.Basic); Action createPlayfieldWithNotes = gravity => { diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs index bfd9ffbe87..3caa6cb3ab 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs @@ -6,13 +6,14 @@ using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.UI; -using osu.Game.Rulesets.Mania.Timing.Drawables; using osu.Game.Rulesets.Objects.Types; using System.Linq; using osu.Framework.Lists; using osu.Game.Beatmaps.ControlPoints; using osu.Framework.MathUtils; using osu.Game.Graphics; +using osu.Game.Rulesets.Mania.Timing; +using osu.Game.Rulesets.Mania.Timing.Drawables; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.Timing.Drawables; @@ -43,11 +44,11 @@ namespace osu.Game.Rulesets.Mania.Mods if (maniaObject == null) continue; - maniaHitRenderer.HitObjectTimingChanges[maniaObject.Column].Add(new DrawableManiaGravityTimingChange(new TimingSection + maniaHitRenderer.HitObjectTimingChanges[maniaObject.Column].Add(new DrawableManiaTimingSection(new TimingSection { Time = obj.StartTime, BeatLength = 1000 - })); + }, ScrollingAlgorithm.Gravity)); } double lastObjectTime = (maniaHitRenderer.Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? maniaHitRenderer.Objects.LastOrDefault()?.StartTime ?? double.MaxValue; @@ -62,11 +63,11 @@ namespace osu.Game.Rulesets.Mania.Mods for (double t = timingPoints[i].Time; Precision.DefinitelyBigger(endTime, t); t += point.BeatLength) { - maniaHitRenderer.BarlineTimingChanges.Add(new DrawableManiaGravityTimingChange(new TimingSection + maniaHitRenderer.BarlineTimingChanges.Add(new DrawableManiaTimingSection(new TimingSection { Time = t, BeatLength = 1000 - })); + }, ScrollingAlgorithm.Gravity)); } } } diff --git a/osu.Game.Rulesets.Mania/Timing/Drawables/BasicScrollingHitObjectCollection.cs b/osu.Game.Rulesets.Mania/Timing/Drawables/BasicScrollingHitObjectCollection.cs new file mode 100644 index 0000000000..27eec6288b --- /dev/null +++ b/osu.Game.Rulesets.Mania/Timing/Drawables/BasicScrollingHitObjectCollection.cs @@ -0,0 +1,27 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.Timing.Drawables; + +namespace osu.Game.Rulesets.Mania.Timing.Drawables +{ + internal class BasicScrollingHitObjectCollection : HitObjectCollection + { + private readonly TimingSection timingSection; + + public BasicScrollingHitObjectCollection(TimingSection timingSection) + : base(Axes.Y) + { + this.timingSection = timingSection; + } + + protected override void Update() + { + base.Update(); + + Y = (float)(timingSection.Time - Time.Current); + } + } +} diff --git a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaScrollingTimingChange.cs b/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaScrollingTimingChange.cs deleted file mode 100644 index 4f4d8825ed..0000000000 --- a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaScrollingTimingChange.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Game.Rulesets.Timing; - -namespace osu.Game.Rulesets.Mania.Timing.Drawables -{ - /// - /// A basic timing change which scrolls along with a timing change. - /// - public class DrawableManiaScrollingTimingChange : DrawableManiaTimingChange - { - public DrawableManiaScrollingTimingChange(TimingSection timingChange) - : base(timingChange) - { - } - - protected override void Update() - { - base.Update(); - - Content.Y = (float)(TimingChange.Time - Time.Current); - } - } -} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingChange.cs b/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingChange.cs deleted file mode 100644 index 3aed4264bf..0000000000 --- a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingChange.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; -using osu.Game.Rulesets.Timing; -using osu.Game.Rulesets.Timing.Drawables; - -namespace osu.Game.Rulesets.Mania.Timing.Drawables -{ - public abstract class DrawableManiaTimingChange : DrawableTimingSection - { - protected DrawableManiaTimingChange(TimingSection timingChange) - : base(timingChange, Axes.Y) - { - } - - protected override void UpdateAfterChildren() - { - base.UpdateAfterChildren(); - - var parent = Parent as TimingSectionCollection; - - if (parent == null) - return; - - // This is very naive and can be improved, but is adequate for now - LifetimeStart = TimingChange.Time - parent.TimeSpan; - LifetimeEnd = TimingChange.Time + Content.RelativeChildSize.Y * 2; - } - } -} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingSection.cs new file mode 100644 index 0000000000..772c8acca1 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaTimingSection.cs @@ -0,0 +1,46 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Graphics; +using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.Timing.Drawables; + +namespace osu.Game.Rulesets.Mania.Timing.Drawables +{ + public class DrawableManiaTimingSection : DrawableTimingSection + { + private readonly ScrollingAlgorithm scrollingAlgorithm; + + public DrawableManiaTimingSection(TimingSection timingSection, ScrollingAlgorithm scrollingAlgorithm) + : base(timingSection, Axes.Y) + { + this.scrollingAlgorithm = scrollingAlgorithm; + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + var parent = Parent as TimingSectionCollection; + + if (parent == null) + return; + + // This is very naive and can be improved, but is adequate for now + LifetimeStart = TimingSection.Time - parent.TimeSpan; + LifetimeEnd = TimingSection.Time + Content.Height * 2; + } + + protected override HitObjectCollection CreateHitObjectCollection() + { + switch (scrollingAlgorithm) + { + default: + case ScrollingAlgorithm.Basic: + return new BasicScrollingHitObjectCollection(TimingSection); + case ScrollingAlgorithm.Gravity: + return new GravityScrollingHitObjectCollection(TimingSection, () => RelativeChildSize.Y); + } + } + } +} \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaGravityTimingChange.cs b/osu.Game.Rulesets.Mania/Timing/Drawables/GravityScrollingHitObjectCollection.cs similarity index 56% rename from osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaGravityTimingChange.cs rename to osu.Game.Rulesets.Mania/Timing/Drawables/GravityScrollingHitObjectCollection.cs index d08682a171..919a1f0703 100644 --- a/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableManiaGravityTimingChange.cs +++ b/osu.Game.Rulesets.Mania/Timing/Drawables/GravityScrollingHitObjectCollection.cs @@ -1,31 +1,36 @@ -// 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 System; +using osu.Framework.Graphics; using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.Timing.Drawables; namespace osu.Game.Rulesets.Mania.Timing.Drawables { - /// - /// A timing change which scrolls with an increasing velocity, following a form of "gravity". - /// - public class DrawableManiaGravityTimingChange : DrawableManiaTimingChange + internal class GravityScrollingHitObjectCollection : HitObjectCollection { - public DrawableManiaGravityTimingChange(TimingSection timingChange) - : base(timingChange) + private readonly TimingSection timingSection; + private readonly Func timeSpan; + + public GravityScrollingHitObjectCollection(TimingSection timingSection, Func timeSpan) + : base(Axes.Y) { + this.timingSection = timingSection; + this.timeSpan = timeSpan; } - protected override void Update() + protected override void UpdateAfterChildren() { - base.Update(); + base.UpdateAfterChildren(); // The gravity-adjusted start position - float startY = (float)computeGravityTime(TimingChange.Time); + float startPos = (float)computeGravityTime(timingSection.Time); // The gravity-adjusted end position - float endY = (float)computeGravityTime(TimingChange.Time + Content.RelativeChildSize.Y); + float endPos = (float)computeGravityTime(timingSection.Time + RelativeChildSize.Y); - Content.Y = startY; - Content.Height = endY - startY; + Y = startPos; + Height = endPos - startPos; } /// @@ -40,24 +45,19 @@ namespace osu.Game.Rulesets.Mania.Timing.Drawables // The sign of the relative time, this is used to apply backwards acceleration leading into startTime double sign = relativeTime < 0 ? -1 : 1; - return timeSpan - acceleration * relativeTime * relativeTime * sign; + return timeSpan() - acceleration * relativeTime * relativeTime * sign; } - /// - /// The time spanned by this container. - /// - private double timeSpan => RelativeChildSize.Y; - /// /// The acceleration due to "gravity" of the content of this container. /// - private double acceleration => 1 / timeSpan; + private double acceleration => 1 / timeSpan(); /// /// Computes the current time relative to , accounting for . /// /// The non-offset time. /// The current time relative to - . - private double relativeTimeAt(double time) => Time.Current - time + timeSpan; + private double relativeTimeAt(double time) => Time.Current - time + timeSpan(); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Mania/Timing/ScrollingAlgorithm.cs b/osu.Game.Rulesets.Mania/Timing/ScrollingAlgorithm.cs new file mode 100644 index 0000000000..72e096f5aa --- /dev/null +++ b/osu.Game.Rulesets.Mania/Timing/ScrollingAlgorithm.cs @@ -0,0 +1,17 @@ +// 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 enum ScrollingAlgorithm + { + /// + /// Basic scrolling algorithm based on the timing section time. This is the default algorithm. + /// + Basic, + /// + /// Emulating a form of gravity where hit objects speed up over time. + /// + Gravity + } +} diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 3e266ea7af..cdc5563fc9 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -20,6 +20,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.Mania.Timing.Drawables; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Types; @@ -114,9 +115,9 @@ namespace osu.Game.Rulesets.Mania.UI timingChanges.ForEach(t => { for (int i = 0; i < PreferredColumns; i++) - HitObjectTimingChanges[i].Add(new DrawableManiaScrollingTimingChange(t)); + HitObjectTimingChanges[i].Add(new DrawableManiaTimingSection(t, ScrollingAlgorithm.Basic)); - BarlineTimingChanges.Add(new DrawableManiaScrollingTimingChange(t)); + BarlineTimingChanges.Add(new DrawableManiaTimingSection(t, ScrollingAlgorithm.Basic)); }); } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 7e92e1865c..0300061d57 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -77,6 +77,9 @@ + + + @@ -84,9 +87,7 @@ - - - +