From 0f901c99a01bcd75b6bb7904d6fd529ea6c29d0e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 4 Aug 2017 14:44:43 +0930 Subject: [PATCH 01/24] Implement SpeedAdjustedPlayfield and a new HitRenderer derivation. --- .../UI/ManiaHitRenderer.cs | 2 +- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 2 +- osu.Game/Rulesets/UI/HitRenderer.cs | 28 ++++++++++++++++++- .../Rulesets/UI/SpeedAdjustedHitRenderer.cs | 6 ++-- .../Rulesets/UI/SpeedAdjustedPlayfield.cs | 15 ++++++++++ osu.Game/osu.Game.csproj | 1 + 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index b92c0916b1..2805c129f3 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -30,7 +30,7 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaHitRenderer : SpeedAdjustedHitRenderer + public class ManiaHitRenderer : SpeedAdjustedHitRenderer { /// /// Preferred column count. This will only have an effect during the initialization of the play field. diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 03b6e18856..b81b9c44fe 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -23,7 +23,7 @@ using osu.Framework.Graphics.Shapes; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaPlayfield : Playfield + public class ManiaPlayfield : SpeedAdjustedPlayfield { public const float HIT_TARGET_POSITION = 50; diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 8fe1dd3e0a..fd43078c2b 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -221,7 +221,7 @@ namespace osu.Game.Rulesets.UI /// /// The playfield. /// - protected Playfield Playfield; + protected Playfield Playfield { get; private set; } protected override Container Content => content; private readonly Container content; @@ -319,6 +319,32 @@ namespace osu.Game.Rulesets.UI protected abstract Playfield CreatePlayfield(); } + /// + /// A derivable HitRenderer that manages the Playfield and HitObjects. + /// + /// The type of HitObject contained by this HitRenderer. + /// The type of Judgement of DrawableHitObjects contained by this HitRenderer. + public abstract class HitRenderer : HitRenderer + where TObject : HitObject + where TJudgement : Judgement + where TPlayfield : Playfield + { + /// + /// The playfield. + /// + protected new TPlayfield Playfield => (TPlayfield)base.Playfield; + + /// + /// Creates a hit renderer for a beatmap. + /// + /// The beatmap to create the hit renderer for. + /// Whether to assume the beatmap is for the current ruleset. + protected HitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(beatmap, isForCurrentRuleset) + { + } + } + public class BeatmapInvalidForRulesetException : ArgumentException { public BeatmapInvalidForRulesetException(string text) diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs index 42dadb047d..2dadbb04d0 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs @@ -16,11 +16,13 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { /// - /// A type of that supports speed adjustments in some capacity. + /// A type of that exposes s to be used + /// in s. /// - public abstract class SpeedAdjustedHitRenderer : HitRenderer + public abstract class SpeedAdjustedHitRenderer : HitRenderer where TObject : HitObject where TJudgement : Judgement + where TPlayfield : SpeedAdjustedPlayfield { protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs b/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs new file mode 100644 index 0000000000..1d1f890a6e --- /dev/null +++ b/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs @@ -0,0 +1,15 @@ +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.UI +{ + public class SpeedAdjustedPlayfield : Playfield + where TObject : HitObject + where TJudgement : Judgement + { + protected SpeedAdjustedPlayfield(float? customWidth = null) + : base(customWidth) + { + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3f475a34c8..5ec7f365f5 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -340,6 +340,7 @@ + From d42faa02df7e090362da87b4d09fb15cfc1687c6 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 4 Aug 2017 20:11:51 +0930 Subject: [PATCH 02/24] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 9ae8979ef7..c687b8b102 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 9ae8979ef7ef0968c90cdbce40a04969d43633c7 +Subproject commit c687b8b102dac1f8b7ffad7efc12939484e256c0 From 54503eef71d409ebc842fd0df028833f93e67d5b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 4 Aug 2017 20:52:53 +0930 Subject: [PATCH 03/24] Rename *ScrollingDrawableTimingSection -> *ScrollingContainer, move LinearScrollingContainer to osu.Game, make SpeedAdjustmentContainer non-abstract. --- .../Visual/TestCaseScrollingHitObjects.cs | 8 ++--- .../BasicScrollingDrawableTimingSection.cs | 27 ---------------- ...ection.cs => GravityScrollingContainer.cs} | 11 ++++--- .../Timing/ManiaSpeedAdjustmentContainer.cs | 7 ++-- .../osu.Game.Rulesets.Mania.csproj | 3 +- .../Timing/LinearScrollingContainer.cs | 32 +++++++++++++++++++ ...TimingSection.cs => ScrollingContainer.cs} | 10 +++--- .../Timing/SpeedAdjustmentContainer.cs | 26 +++++++-------- osu.Game/osu.Game.csproj | 3 +- 9 files changed, 66 insertions(+), 61 deletions(-) delete mode 100644 osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs rename osu.Game.Rulesets.Mania/Timing/{GravityScrollingDrawableTimingSection.cs => GravityScrollingContainer.cs} (80%) create mode 100644 osu.Game/Rulesets/Timing/LinearScrollingContainer.cs rename osu.Game/Rulesets/Timing/{DrawableTimingSection.cs => ScrollingContainer.cs} (93%) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs index efc129a678..056e063120 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs @@ -18,7 +18,7 @@ namespace osu.Desktop.Tests.Visual { public class TestCaseScrollingHitObjects : OsuTestCase { - public override string Description => "SpeedAdjustmentContainer/DrawableTimingSection"; + public override string Description => "SpeedAdjustmentContainer/ScrollingContainer"; private readonly BindableDouble timeRangeBindable; private readonly OsuSpriteText bottomLabel; @@ -131,13 +131,13 @@ namespace osu.Desktop.Tests.Visual { } - protected override DrawableTimingSection CreateTimingSection() => new TestDrawableTimingSection(ControlPoint); + protected override ScrollingContainer CreateScrollingContainer() => new TestScrollingContainer(ControlPoint); - private class TestDrawableTimingSection : DrawableTimingSection + private class TestScrollingContainer : ScrollingContainer { private readonly MultiplierControlPoint controlPoint; - public TestDrawableTimingSection(MultiplierControlPoint controlPoint) + public TestScrollingContainer(MultiplierControlPoint controlPoint) { this.controlPoint = controlPoint; } diff --git a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs deleted file mode 100644 index e485581d9f..0000000000 --- a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs +++ /dev/null @@ -1,27 +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 -{ - /// - /// A which scrolls relative to the control point start time. - /// - internal class BasicScrollingDrawableTimingSection : DrawableTimingSection - { - private readonly MultiplierControlPoint controlPoint; - - public BasicScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) - { - this.controlPoint = controlPoint; - } - - protected override void Update() - { - base.Update(); - - Y = (float)(controlPoint.StartTime - Time.Current); - } - } -} diff --git a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs similarity index 80% rename from osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs rename to osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs index 730daa9ffd..2cb14f224e 100644 --- a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs @@ -1,18 +1,19 @@ // 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; namespace osu.Game.Rulesets.Mania.Timing { /// - /// A that emulates a form of gravity where hit objects speed up over time. + /// A that emulates a form of gravity where hit objects speed up over time. /// - internal class GravityScrollingDrawableTimingSection : DrawableTimingSection + internal class GravityScrollingContainer : ScrollingContainer { private readonly MultiplierControlPoint controlPoint; - public GravityScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) + public GravityScrollingContainer(MultiplierControlPoint controlPoint) { this.controlPoint = controlPoint; } @@ -51,10 +52,10 @@ namespace osu.Game.Rulesets.Mania.Timing private double acceleration => 1 / VisibleTimeRange; /// - /// Computes the current time relative to , accounting for . + /// Computes the current time relative to , accounting for . /// /// The non-offset time. - /// The current time relative to - . + /// The current time relative to - . private double relativeTimeAt(double time) => Time.Current - time + VisibleTimeRange; } } diff --git a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs index ed22264d74..321b4ee92b 100644 --- a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs @@ -15,15 +15,14 @@ namespace osu.Game.Rulesets.Mania.Timing this.scrollingAlgorithm = scrollingAlgorithm; } - protected override DrawableTimingSection CreateTimingSection() + protected override ScrollingContainer CreateScrollingContainer() { switch (scrollingAlgorithm) { default: - case ScrollingAlgorithm.Basic: - return new BasicScrollingDrawableTimingSection(ControlPoint); + return base.CreateScrollingContainer(); case ScrollingAlgorithm.Gravity: - return new GravityScrollingDrawableTimingSection(ControlPoint); + return new GravityScrollingContainer(ControlPoint); } } } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 88d1ad7ad8..3832f9ace5 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -79,8 +79,7 @@ - - + diff --git a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs new file mode 100644 index 0000000000..b86165997b --- /dev/null +++ b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs @@ -0,0 +1,32 @@ +// 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; + +namespace osu.Game.Rulesets.Timing +{ + /// + /// A which scrolls relative to the control point start time. + /// This is the default returned by the base . + /// + internal class LinearScrollingContainer : ScrollingContainer + { + private readonly Axes scrollingAxes; + private readonly MultiplierControlPoint controlPoint; + + public LinearScrollingContainer(Axes scrollingAxes, MultiplierControlPoint controlPoint) + { + this.scrollingAxes = scrollingAxes; + this.controlPoint = controlPoint; + } + + protected override void Update() + { + base.Update(); + + if ((scrollingAxes & Axes.X) > 0) X = (float)(controlPoint.StartTime - Time.Current); + if ((scrollingAxes & Axes.Y) > 0) Y = (float)(controlPoint.StartTime - Time.Current); + } + } +} diff --git a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs similarity index 93% rename from osu.Game/Rulesets/Timing/DrawableTimingSection.cs rename to osu.Game/Rulesets/Timing/ScrollingContainer.cs index 6345a566c2..c412530b15 100644 --- a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Timing /// and to apply further time offsets to this collection of hit objects. /// /// - public abstract class DrawableTimingSection : Container + public abstract class ScrollingContainer : Container { private readonly BindableDouble visibleTimeRange = new BindableDouble(); /// @@ -71,9 +71,9 @@ namespace osu.Game.Rulesets.Timing } /// - /// Creates a new . + /// Creates a new . /// - protected DrawableTimingSection() + protected ScrollingContainer() { RelativeSizeAxes = Axes.Both; RelativePositionAxes = Axes.Both; @@ -128,8 +128,8 @@ namespace osu.Game.Rulesets.Timing } /// - /// The maximum duration of any one hit object inside this . This is calculated as the maximum - /// end time between all hit objects relative to this 's . + /// The maximum duration of any one hit object inside this . This is calculated as the maximum + /// end time between all hit objects relative to this 's . /// public double Duration => durationBacking.IsValid ? durationBacking : (durationBacking.Value = computeDuration()); diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index f41ef21c1e..3c0ba86db3 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -12,14 +12,14 @@ namespace osu.Game.Rulesets.Timing { /// /// A container for hit objects which applies applies the speed adjustments defined by the properties of a - /// to affect the scroll speed of the contained . + /// to affect the scroll speed of the contained . /// /// /// This container must always be relatively-sized to its parent to provide the speed adjustments. This container will provide the speed adjustments /// by modifying its size while maintaining a constant for its children /// /// - public abstract class SpeedAdjustmentContainer : Container + public class SpeedAdjustmentContainer : Container { private readonly Bindable visibleTimeRange = new Bindable(); /// @@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Timing public readonly MultiplierControlPoint ControlPoint; - private DrawableTimingSection timingSection; + private ScrollingContainer scrollingContainer; /// /// Creates a new . @@ -58,14 +58,14 @@ namespace osu.Game.Rulesets.Timing [BackgroundDependencyLoader] private void load() { - timingSection = CreateTimingSection(); + scrollingContainer = CreateScrollingContainer(); - timingSection.ScrollingAxes = ScrollingAxes; - timingSection.ControlPoint = ControlPoint; - timingSection.VisibleTimeRange.BindTo(VisibleTimeRange); - timingSection.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); + scrollingContainer.ScrollingAxes = ScrollingAxes; + scrollingContainer.ControlPoint = ControlPoint; + scrollingContainer.VisibleTimeRange.BindTo(VisibleTimeRange); + scrollingContainer.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); - AddInternal(content = timingSection); + AddInternal(content = scrollingContainer); } protected override void Update() @@ -78,7 +78,7 @@ namespace osu.Game.Rulesets.Timing } public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange; - public override double LifetimeEnd => ControlPoint.StartTime + timingSection.Duration + VisibleTimeRange; + public override double LifetimeEnd => ControlPoint.StartTime + scrollingContainer.Duration + VisibleTimeRange; public override void Add(DrawableHitObject drawable) { @@ -99,9 +99,9 @@ namespace osu.Game.Rulesets.Timing public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime; /// - /// Creates the container which handles the movement of a collection of hit objects. + /// Creates the container which contains a collection of hit objects and scrolls through this SpeedAdjustmentContainer. /// - /// The . - protected abstract DrawableTimingSection CreateTimingSection(); + /// The . + protected virtual ScrollingContainer CreateScrollingContainer() => new LinearScrollingContainer(ScrollingAxes, ControlPoint); } } \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 5ec7f365f5..075f0732f7 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -227,7 +227,8 @@ - + + From b1d25ed38815296ca64280eb08e7475a0a6d5ca8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 4 Aug 2017 23:07:08 +0900 Subject: [PATCH 04/24] Implement ScrollingPlayfield, now containing ScrollingHitObjectContainer (prev. SpeedAdjustmentCollection). Also removing a lot of mania code relating to gravity mod for now. --- .../Visual/TestCaseScrollingHitObjects.cs | 25 ++- osu.Game.Rulesets.Mania/UI/Column.cs | 37 ++-- .../UI/ManiaHitRenderer.cs | 65 +----- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 48 +---- .../Rulesets/Timing/ScrollingContainer.cs | 2 +- .../Timing/SpeedAdjustmentCollection.cs | 133 ------------ .../Timing/SpeedAdjustmentContainer.cs | 2 +- osu.Game/Rulesets/UI/Playfield.cs | 5 +- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 190 ++++++++++++++++++ .../Rulesets/UI/SpeedAdjustedHitRenderer.cs | 15 +- .../Rulesets/UI/SpeedAdjustedPlayfield.cs | 15 -- osu.Game/osu.Game.csproj | 3 +- 12 files changed, 263 insertions(+), 277 deletions(-) delete mode 100644 osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs create mode 100644 osu.Game/Rulesets/UI/ScrollingPlayfield.cs delete mode 100644 osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs index 056e063120..6b30cc4f32 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs @@ -13,6 +13,9 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Timing; using OpenTK; using OpenTK.Graphics; +using osu.Game.Rulesets.UI; +using osu.Game.Rulesets.Judgements; +using System; namespace osu.Desktop.Tests.Visual { @@ -28,7 +31,7 @@ namespace osu.Desktop.Tests.Visual public TestCaseScrollingHitObjects() { OsuSpriteText timeRangeText; - SpeedAdjustmentCollection adjustmentCollection; + ScrollingPlayfield.ScrollingHitObjectContainer scrollingHitObjectContainer; timeRangeBindable = new BindableDouble(2000) { @@ -68,7 +71,7 @@ namespace osu.Desktop.Tests.Visual RelativeSizeAxes = Axes.Both, Alpha = 0.25f }, - adjustmentCollection = new SpeedAdjustmentCollection(Axes.Y) + scrollingHitObjectContainer = new ScrollingPlayfield.ScrollingHitObjectContainer(Axes.Y) { RelativeSizeAxes = Axes.Both, VisibleTimeRange = timeRangeBindable, @@ -109,9 +112,9 @@ namespace osu.Desktop.Tests.Visual timeRangeBindable.TriggerChange(); - adjustmentCollection.Add(new TestSpeedAdjustmentContainer(new MultiplierControlPoint())); + scrollingHitObjectContainer.AddSpeedAdjustment(new TestSpeedAdjustmentContainer(new MultiplierControlPoint())); - AddStep("Add hit object", () => adjustmentCollection.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 2000 }))); + AddStep("Add hit object", () => scrollingHitObjectContainer.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 2000 }))); } protected override void Update() @@ -151,7 +154,7 @@ namespace osu.Desktop.Tests.Visual } } - private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject + private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject { private readonly Box background; private const float height = 14; @@ -204,6 +207,18 @@ namespace osu.Desktop.Tests.Visual if (Time.Current >= HitObject.StartTime) background.Colour = Color4.Red; } + + protected override Judgement CreateJudgement() => new TestJudgement(); + + protected override void UpdateState(ArmedState state) + { + } + + private class TestJudgement : Judgement + { + public override string ResultString { get { throw new NotImplementedException(); } } + public override string MaxResultString { get { throw new NotImplementedException(); } } + } } } } diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 94cf6a4337..424ed77783 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -15,10 +15,15 @@ using osu.Game.Rulesets.Objects.Drawables; using System; using osu.Framework.Configuration; using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.UI; +using osu.Game.Rulesets.Mania.Objects.Drawables; +using osu.Game.Rulesets.Mania.Objects; +using osu.Game.Rulesets.Mania.Judgements; +using osu.Framework.Allocation; namespace osu.Game.Rulesets.Mania.UI { - public class Column : Container, IHasAccentColour + public class Column : ScrollingPlayfield, IHasAccentColour { private const float key_icon_size = 10; private const float key_icon_corner_radius = 3; @@ -30,13 +35,6 @@ namespace osu.Game.Rulesets.Mania.UI private const float column_width = 45; private const float special_column_width = 70; - private readonly BindableDouble visibleTimeRange = new BindableDouble(); - public BindableDouble VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - /// /// The key that will trigger input actions for this column and hit objects contained inside it. /// @@ -46,14 +44,15 @@ namespace osu.Game.Rulesets.Mania.UI private readonly Container hitTargetBar; private readonly Container keyIcon; - private readonly SpeedAdjustmentCollection speedAdjustments; + protected override Container Content => content; + private readonly Container content; public Column() + : base(Axes.Y) { - RelativeSizeAxes = Axes.Y; Width = column_width; - Children = new Drawable[] + InternalChildren = new Drawable[] { background = new Box { @@ -97,11 +96,10 @@ namespace osu.Game.Rulesets.Mania.UI } } }, - speedAdjustments = new SpeedAdjustmentCollection(Axes.Y) + content = new Container { Name = "Hit objects", RelativeSizeAxes = Axes.Both, - VisibleTimeRange = VisibleTimeRange }, // For column lighting, we need to capture input events before the notes new InputTarget @@ -150,6 +148,8 @@ namespace osu.Game.Rulesets.Mania.UI }; } + public override Axes RelativeSizeAxes => Axes.Y; + private bool isSpecial; public bool IsSpecial { @@ -192,11 +192,16 @@ namespace osu.Game.Rulesets.Mania.UI } } - public void Add(SpeedAdjustmentContainer speedAdjustment) => speedAdjustments.Add(speedAdjustment); - public void Add(DrawableHitObject hitObject) + public void Add(SpeedAdjustmentContainer speedAdjustment) => HitObjects.AddSpeedAdjustment(speedAdjustment); + + /// + /// Adds a DrawableHitObject to this Playfield. + /// + /// The DrawableHitObject to add. + public override void Add(DrawableHitObject hitObject) { hitObject.AccentColour = AccentColour; - speedAdjustments.Add(hitObject); + HitObjects.Add(hitObject); } private bool onKeyDown(InputState state, KeyDownEventArgs args) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 2805c129f3..04185f0872 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -39,24 +39,9 @@ namespace osu.Game.Rulesets.Mania.UI public IEnumerable BarLines; - /// - /// Per-column timing changes. - /// - private readonly List[] hitObjectSpeedAdjustments; - - /// - /// Bar line timing changes. - /// - private readonly List barLineSpeedAdjustments = new List(); - public ManiaHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(beatmap, isForCurrentRuleset) { - // Generate the speed adjustment container lists - hitObjectSpeedAdjustments = new List[PreferredColumns]; - for (int i = 0; i < PreferredColumns; i++) - hitObjectSpeedAdjustments[i] = new List(); - // Generate the bar lines double lastObjectTime = (Objects.LastOrDefault() as IHasEndTime)?.EndTime ?? Objects.LastOrDefault()?.StartTime ?? double.MaxValue; @@ -83,30 +68,12 @@ namespace osu.Game.Rulesets.Mania.UI } BarLines = barLines; - - // Generate speed adjustments from mods first - bool useDefaultSpeedAdjustments = true; - - if (Mods != null) - { - foreach (var speedAdjustmentMod in Mods.OfType()) - { - useDefaultSpeedAdjustments = false; - speedAdjustmentMod.ApplyToHitRenderer(this, ref hitObjectSpeedAdjustments, ref barLineSpeedAdjustments); - } - } - - // Generate the default speed adjustments - if (useDefaultSpeedAdjustments) - generateDefaultSpeedAdjustments(); } [BackgroundDependencyLoader] private void load() { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - BarLines.ForEach(maniaPlayfield.Add); + BarLines.ForEach(Playfield.Add); } protected override void ApplyBeatmap() @@ -116,28 +83,6 @@ namespace osu.Game.Rulesets.Mania.UI PreferredColumns = (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.Difficulty.CircleSize)); } - protected override void ApplySpeedAdjustments() - { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - for (int i = 0; i < PreferredColumns; i++) - foreach (var change in hitObjectSpeedAdjustments[i]) - maniaPlayfield.Columns.ElementAt(i).Add(change); - - foreach (var change in barLineSpeedAdjustments) - maniaPlayfield.Add(change); - } - - private void generateDefaultSpeedAdjustments() - { - DefaultControlPoints.ForEach(c => - { - foreach (List t in hitObjectSpeedAdjustments) - t.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic)); - barLineSpeedAdjustments.Add(new ManiaSpeedAdjustmentContainer(c, ScrollingAlgorithm.Basic)); - }); - } - protected sealed override Playfield CreatePlayfield() => new ManiaPlayfield(PreferredColumns) { Anchor = Anchor.Centre, @@ -168,5 +113,13 @@ namespace osu.Game.Rulesets.Mania.UI } protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f); + + protected override void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) + { + base.ApplySpeedAdjustment(controlPoint); + Playfield.Columns.ForEach(c => c.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint))); + } + + protected override SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Basic); } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index b81b9c44fe..3b1dc58e4f 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -20,18 +20,14 @@ using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Timing; using osu.Framework.Configuration; using osu.Framework.Graphics.Shapes; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaPlayfield : SpeedAdjustedPlayfield + public class ManiaPlayfield : ScrollingPlayfield { public const float HIT_TARGET_POSITION = 50; - private const double time_span_default = 1500; - private const double time_span_min = 50; - private const double time_span_max = 10000; - private const double time_span_step = 50; - /// /// Default column keys, expanding outwards from the middle as more column are added. /// E.g. 2 columns use FJ, 4 columns use DFJK, 6 use SDFJKL, etc... @@ -56,13 +52,7 @@ namespace osu.Game.Rulesets.Mania.UI private readonly FlowContainer columns; public IEnumerable Columns => columns.Children; - private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) - { - MinValue = time_span_min, - MaxValue = time_span_max - }; - - private readonly SpeedAdjustmentCollection barLineContainer; + private readonly ScrollingHitObjectContainer barLineContainer; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -70,6 +60,7 @@ namespace osu.Game.Rulesets.Mania.UI private readonly int columnCount; public ManiaPlayfield(int columnCount) + : base(Axes.Y) { this.columnCount = columnCount; @@ -120,13 +111,13 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new SpeedAdjustmentCollection(Axes.Y) + barLineContainer = new ScrollingHitObjectContainer(Axes.Y) { Name = "Bar lines", Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.Y, - VisibleTimeRange = visibleTimeRange + VisibleTimeRange = VisibleTimeRange // Width is set in the Update method } } @@ -136,7 +127,7 @@ namespace osu.Game.Rulesets.Mania.UI }; for (int i = 0; i < columnCount; i++) - columns.Add(new Column { VisibleTimeRange = visibleTimeRange }); + columns.Add(new Column { VisibleTimeRange = VisibleTimeRange }); } [BackgroundDependencyLoader] @@ -211,30 +202,7 @@ namespace osu.Game.Rulesets.Mania.UI public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); public void Add(DrawableBarLine barline) => barLineContainer.Add(barline); - public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.Add(speedAdjustment); - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - if (state.Keyboard.ControlPressed) - { - switch (args.Key) - { - case Key.Minus: - transformVisibleTimeRangeTo(visibleTimeRange + time_span_step, 200, Easing.OutQuint); - break; - case Key.Plus: - transformVisibleTimeRangeTo(visibleTimeRange - time_span_step, 200, Easing.OutQuint); - break; - } - } - - return false; - } - - private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) - { - this.TransformTo(nameof(visibleTimeRange), newTimeRange, duration, easing); - } + public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.AddSpeedAdjustment(speedAdjustment); protected override void Update() { diff --git a/osu.Game/Rulesets/Timing/ScrollingContainer.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs index c412530b15..daeca5a910 100644 --- a/osu.Game/Rulesets/Timing/ScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Timing /// public abstract class ScrollingContainer : Container { - private readonly BindableDouble visibleTimeRange = new BindableDouble(); + private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; /// /// Gets or sets the range of time that is visible by the length of this container. /// diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs deleted file mode 100644 index 22213be740..0000000000 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using System.Linq; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Rulesets.Objects.Drawables; - -namespace osu.Game.Rulesets.Timing -{ - /// - /// A collection of s. - /// - /// - /// This container redirects any 's added to it to the - /// which provides the speed adjustment active at the start time of the hit object. Furthermore, this container provides the - /// necessary for the contained s. - /// - /// - public class SpeedAdjustmentCollection : Container - { - private readonly BindableDouble visibleTimeRange = new BindableDouble(); - /// - /// Gets or sets the range of time that is visible by the length of this container. - /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. - /// - public Bindable VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - - protected override int Compare(Drawable x, Drawable y) - { - var xSpeedAdjust = x as SpeedAdjustmentContainer; - var ySpeedAdjust = y as SpeedAdjustmentContainer; - - // If either of the two drawables are not hit objects, fall back to the base comparer - if (xSpeedAdjust?.ControlPoint == null || ySpeedAdjust?.ControlPoint == null) - return CompareReverseChildID(x, y); - - // Compare by start time - int i = ySpeedAdjust.ControlPoint.StartTime.CompareTo(xSpeedAdjust.ControlPoint.StartTime); - - return i != 0 ? i : CompareReverseChildID(x, y); - } - - /// - /// Hit objects that are to be re-processed on the next update. - /// - private readonly Queue queuedHitObjects = new Queue(); - - private readonly Axes scrollingAxes; - - /// - /// Creates a new . - /// - /// The axes upon which hit objects should appear to scroll inside this container. - public SpeedAdjustmentCollection(Axes scrollingAxes) - { - this.scrollingAxes = scrollingAxes; - } - - public override void Add(SpeedAdjustmentContainer speedAdjustment) - { - speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); - speedAdjustment.ScrollingAxes = scrollingAxes; - base.Add(speedAdjustment); - } - - /// - /// Adds a hit object to this . The hit objects will be kept in a queue - /// and will be processed when new s are added to this . - /// - /// The hit object to add. - public void Add(DrawableHitObject hitObject) - { - if (!(hitObject is IScrollingHitObject)) - throw new InvalidOperationException($"Hit objects added to a {nameof(SpeedAdjustmentCollection)} must implement {nameof(IScrollingHitObject)}."); - - queuedHitObjects.Enqueue(hitObject); - } - - protected override void Update() - { - base.Update(); - - // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op - // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. - - // An external count is kept because hit objects that can't be added are re-queued - int count = queuedHitObjects.Count; - while (count-- > 0) - { - var hitObject = queuedHitObjects.Dequeue(); - - var target = adjustmentContainerFor(hitObject); - if (target == null) - { - // We can't add this hit object to a speed adjustment container yet, so re-queue it - // for re-processing when the layout next invalidated - queuedHitObjects.Enqueue(hitObject); - continue; - } - - if (hitObject.RelativePositionAxes != target.ScrollingAxes) - throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes})."); - - target.Add(hitObject); - } - } - - /// - /// Finds the which provides the speed adjustment active at the start time - /// of a hit object. If there is no active at the start time of the hit object, - /// then the first (time-wise) speed adjustment is returned. - /// - /// The hit object to find the active for. - /// The active at 's start time. Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault(); - - /// - /// Finds the which provides the speed adjustment active at a time. - /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. - /// - /// The time to find the active at. - /// The active at . Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerAt(double time) => Children.FirstOrDefault(c => c.CanContain(time)) ?? Children.LastOrDefault(); - } -} diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 3c0ba86db3..6be721f6e7 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -21,7 +21,7 @@ namespace osu.Game.Rulesets.Timing /// public class SpeedAdjustmentContainer : Container { - private readonly Bindable visibleTimeRange = new Bindable(); + private readonly Bindable visibleTimeRange = new Bindable { Default = 1000 }; /// /// Gets or sets the range of time that is visible by the length of this container. /// diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index ff321a18a5..5f07df5088 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.UI /// /// The HitObjects contained in this Playfield. /// - protected HitObjectContainer> HitObjects; + public HitObjectContainer> HitObjects { get; protected set; } internal Container ScaledContent; @@ -99,7 +99,8 @@ namespace osu.Game.Rulesets.UI protected override Vector2 DrawScale => CustomWidth.HasValue ? new Vector2(DrawSize.X / CustomWidth.Value) : base.DrawScale; } - public class HitObjectContainer : Container where U : Drawable + public class HitObjectContainer : Container + where U : Drawable { } } diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs new file mode 100644 index 0000000000..b765b533a0 --- /dev/null +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Input; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Timing; + +namespace osu.Game.Rulesets.UI +{ + public class ScrollingPlayfield : Playfield + where TObject : HitObject + where TJudgement : Judgement + { + private const double time_span_default = 1500; + private const double time_span_min = 50; + private const double time_span_max = 10000; + private const double time_span_step = 50; + + /// + /// Gets or sets the range of time that is visible by the length of this playfield the scrolling axis direction. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) + { + Default = time_span_default, + MinValue = time_span_min, + MaxValue = time_span_max + }; + + public BindableDouble VisibleTimeRange + { + get { return visibleTimeRange; } + set { visibleTimeRange.BindTo(value); } + } + + public new readonly ScrollingHitObjectContainer HitObjects; + + protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) + : base(customWidth) + { + base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) + { + RelativeSizeAxes = Axes.Both, + VisibleTimeRange = VisibleTimeRange + }; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (state.Keyboard.ControlPressed) + { + switch (args.Key) + { + case Key.Minus: + transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint); + break; + case Key.Plus: + transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint); + break; + } + } + + return false; + } + + private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) + { + this.TransformTo(nameof(VisibleTimeRange), newTimeRange, duration, easing); + } + + /// + /// A collection of s. + /// + /// + /// This container redirects any 's added to it to the + /// which provides the speed adjustment active at the start time of the hit object. Furthermore, this container provides the + /// necessary for the contained s. + /// + /// + public class ScrollingHitObjectContainer : HitObjectContainer> + { + private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; + /// + /// Gets or sets the range of time that is visible by the length of this container. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + public Bindable VisibleTimeRange + { + get { return visibleTimeRange; } + set { visibleTimeRange.BindTo(value); } + } + + protected override Container> Content => content; + /// + /// The following is never used - it only exists for the purpose of being able to use AddInternal below. + /// + private Container> content; + + /// + /// Hit objects that are to be re-processed on the next update. + /// + private readonly Queue> queuedHitObjects = new Queue>(); + + private readonly Axes scrollingAxes; + + /// + /// Creates a new . + /// + /// The axes upon which hit objects should appear to scroll inside this container. + public ScrollingHitObjectContainer(Axes scrollingAxes) + { + this.scrollingAxes = scrollingAxes; + + content = new Container>(); + } + + public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment) + { + speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); + speedAdjustment.ScrollingAxes = scrollingAxes; + AddInternal(speedAdjustment); + } + + /// + /// Adds a hit object to this . The hit objects will be kept in a queue + /// and will be processed when new s are added to this . + /// + /// The hit object to add. + public override void Add(DrawableHitObject hitObject) + { + if (!(hitObject is IScrollingHitObject)) + throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); + + queuedHitObjects.Enqueue(hitObject); + } + + protected override void Update() + { + base.Update(); + + // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op + // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. + + // An external count is kept because hit objects that can't be added are re-queued + int count = queuedHitObjects.Count; + while (count-- > 0) + { + var hitObject = queuedHitObjects.Dequeue(); + + var target = adjustmentContainerFor(hitObject); + if (target == null) + { + // We can't add this hit object to a speed adjustment container yet, so re-queue it + // for re-processing when the layout next invalidated + queuedHitObjects.Enqueue(hitObject); + continue; + } + + if (hitObject.RelativePositionAxes != target.ScrollingAxes) + throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes})."); + + target.Add(hitObject); + } + } + + /// + /// Finds the which provides the speed adjustment active at the start time + /// of a hit object. If there is no active at the start time of the hit object, + /// then the first (time-wise) speed adjustment is returned. + /// + /// The hit object to find the active for. + /// The active at 's start time. Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(hitObject)) ?? InternalChildren.OfType().LastOrDefault(); + + /// + /// Finds the which provides the speed adjustment active at a time. + /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. + /// + /// The time to find the active at. + /// The active at . Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerAt(double time) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(time)) ?? InternalChildren.OfType().LastOrDefault(); + } + } +} \ No newline at end of file diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs index 2dadbb04d0..5d6293c802 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Lists; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; @@ -22,7 +23,7 @@ namespace osu.Game.Rulesets.UI public abstract class SpeedAdjustedHitRenderer : HitRenderer where TObject : HitObject where TJudgement : Judgement - where TPlayfield : SpeedAdjustedPlayfield + where TPlayfield : ScrollingPlayfield { protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); @@ -34,7 +35,7 @@ namespace osu.Game.Rulesets.UI [BackgroundDependencyLoader] private void load() { - ApplySpeedAdjustments(); + DefaultControlPoints.ForEach(c => ApplySpeedAdjustment(c)); } protected override void ApplyBeatmap() @@ -98,9 +99,11 @@ namespace osu.Game.Rulesets.UI return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone()); } - /// - /// Applies speed changes to the playfield. - /// - protected abstract void ApplySpeedAdjustments(); + protected virtual void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) + { + Playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); + } + + protected abstract SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint); } } diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs b/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs deleted file mode 100644 index 1d1f890a6e..0000000000 --- a/osu.Game/Rulesets/UI/SpeedAdjustedPlayfield.cs +++ /dev/null @@ -1,15 +0,0 @@ -using osu.Game.Rulesets.Judgements; -using osu.Game.Rulesets.Objects; - -namespace osu.Game.Rulesets.UI -{ - public class SpeedAdjustedPlayfield : Playfield - where TObject : HitObject - where TJudgement : Judgement - { - protected SpeedAdjustedPlayfield(float? customWidth = null) - : base(customWidth) - { - } - } -} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 075f0732f7..342a02ba60 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -230,7 +230,6 @@ - @@ -341,7 +340,7 @@ - + From e1dfe364b22690d5eada9900119b3efca2879a5e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 14:07:49 +0900 Subject: [PATCH 05/24] Fix lifetime performance regression. --- .../Objects/Drawables/DrawableScrollingHitObject.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index 8dc17b9542..52b8d3e12d 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -22,20 +22,22 @@ namespace osu.Game.Rulesets.Objects.Drawables { } + private double? lifetimeStart; public override double LifetimeStart { - get { return Math.Min(HitObject.StartTime - LifetimeOffset, base.LifetimeStart); } - set { base.LifetimeStart = value; } + get { return lifetimeStart ?? HitObject.StartTime - LifetimeOffset; } + set { lifetimeStart = value; } } + private double? lifetimeEnd; public override double LifetimeEnd { get { var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; - return Math.Max(endTime + LifetimeOffset, base.LifetimeEnd); + return lifetimeEnd ?? endTime + LifetimeOffset; } - set { base.LifetimeEnd = value; } + set { lifetimeEnd = value; } } protected override void AddNested(DrawableHitObject h) From 376f99c1e3f05ac2eaa773d74ba4db25b0fd7bb8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 14:32:55 +0900 Subject: [PATCH 06/24] Make VisibleTimeRange transform work again. --- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index b765b533a0..d21b07490a 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -5,7 +5,9 @@ using OpenTK.Input; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Transforms; using osu.Framework.Input; +using osu.Framework.MathUtils; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; @@ -71,7 +73,23 @@ namespace osu.Game.Rulesets.UI private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) { - this.TransformTo(nameof(VisibleTimeRange), newTimeRange, duration, easing); + this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing)); + } + + private class TransformVisibleTimeRange : Transform> + { + private double valueAt(double time) + { + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + } + + public override string TargetMember => "VisibleTimeRange.Value"; + + protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); + protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; } /// From c6447e40f92368fef7ca796e200a80ada951e949 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 14:56:26 +0900 Subject: [PATCH 07/24] Reduce implementation overhead for nested playfields (e.g. playfield + columns). --- osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs | 6 ------ osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 15 +++++++++------ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 11 +++++++++++ osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs | 13 +++++++------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 04185f0872..a34765448c 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -114,12 +114,6 @@ namespace osu.Game.Rulesets.Mania.UI protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f); - protected override void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) - { - base.ApplySpeedAdjustment(controlPoint); - Playfield.Columns.ForEach(c => c.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint))); - } - protected override SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Basic); } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 3b1dc58e4f..4b240e4659 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -52,7 +52,8 @@ namespace osu.Game.Rulesets.Mania.UI private readonly FlowContainer columns; public IEnumerable Columns => columns.Children; - private readonly ScrollingHitObjectContainer barLineContainer; + protected override Container Content => barLineContainer; + private readonly Container barLineContainer; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -67,7 +68,7 @@ namespace osu.Game.Rulesets.Mania.UI if (columnCount <= 0) throw new ArgumentException("Can't have zero or fewer columns."); - Children = new Drawable[] + InternalChildren = new Drawable[] { new Container { @@ -111,13 +112,12 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new ScrollingHitObjectContainer(Axes.Y) + barLineContainer = new Container { Name = "Bar lines", Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.Y, - VisibleTimeRange = VisibleTimeRange // Width is set in the Update method } } @@ -127,7 +127,11 @@ namespace osu.Game.Rulesets.Mania.UI }; for (int i = 0; i < columnCount; i++) - columns.Add(new Column { VisibleTimeRange = VisibleTimeRange }); + { + var c = new Column { VisibleTimeRange = VisibleTimeRange }; + columns.Add(c); + AddNested(c); + } } [BackgroundDependencyLoader] @@ -202,7 +206,6 @@ namespace osu.Game.Rulesets.Mania.UI public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); public void Add(DrawableBarLine barline) => barLineContainer.Add(barline); - public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.AddSpeedAdjustment(speedAdjustment); protected override void Update() { diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index d21b07490a..8850bd6b96 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -53,6 +53,17 @@ namespace osu.Game.Rulesets.UI }; } + private List> nestedPlayfields; + public IEnumerable> NestedPlayfields => nestedPlayfields; + + protected void AddNested(ScrollingPlayfield otherPlayfield) + { + if (nestedPlayfields == null) + nestedPlayfields = new List>(); + + nestedPlayfields.Add(otherPlayfield); + } + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (state.Keyboard.ControlPressed) diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs index 5d6293c802..4a560748c1 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs @@ -35,7 +35,13 @@ namespace osu.Game.Rulesets.UI [BackgroundDependencyLoader] private void load() { - DefaultControlPoints.ForEach(c => ApplySpeedAdjustment(c)); + DefaultControlPoints.ForEach(c => applySpeedAdjustment(c, Playfield)); + } + + private void applySpeedAdjustment(MultiplierControlPoint controlPoint, ScrollingPlayfield playfield) + { + playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); + playfield.NestedPlayfields.ForEach(p => applySpeedAdjustment(controlPoint, p)); } protected override void ApplyBeatmap() @@ -99,11 +105,6 @@ namespace osu.Game.Rulesets.UI return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone()); } - protected virtual void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) - { - Playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); - } - protected abstract SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint); } } From 068dfcb19aeeaf1ce1a3bbb29b9451625771f2f5 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 15:22:31 +0900 Subject: [PATCH 08/24] Default CreateSpeedAdjustmentContainer implementation. --- osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs | 2 +- osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 6be721f6e7..c7249d5b84 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Timing /// Creates a new . /// /// The which provides the speed adjustments for this container. - protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) + public SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) { ControlPoint = controlPoint; diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs index 4a560748c1..5f8bebc213 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs @@ -86,6 +86,9 @@ namespace osu.Game.Rulesets.UI .GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First()); DefaultControlPoints.AddRange(timingChanges); + + if (DefaultControlPoints.Count == 0) + DefaultControlPoints.Add(new MultiplierControlPoint()); } /// @@ -105,6 +108,6 @@ namespace osu.Game.Rulesets.UI return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone()); } - protected abstract SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint); + protected virtual SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new SpeedAdjustmentContainer(controlPoint); } } From a3efca9c357874b3d15cd0a75a43b5b64cb92a06 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 16:02:38 +0900 Subject: [PATCH 09/24] Reduce implementation overhead in actually positioning hitobjects and making them scroll. --- .../Visual/TestCaseScrollingHitObjects.cs | 16 +--------------- .../Objects/Drawables/DrawableManiaHitObject.cs | 3 --- osu.Game.Rulesets.Mania/UI/Column.cs | 2 -- .../Drawables/DrawableScrollingHitObject.cs | 14 ++++++++++++++ .../Objects/Drawables/IScrollingHitObject.cs | 8 +++++++- osu.Game/Rulesets/Timing/ScrollingContainer.cs | 4 ++-- .../Rulesets/Timing/SpeedAdjustmentContainer.cs | 8 ++++++-- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 4 ++-- 8 files changed, 32 insertions(+), 27 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs index 6b30cc4f32..30ad5871f2 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs @@ -31,7 +31,6 @@ namespace osu.Desktop.Tests.Visual public TestCaseScrollingHitObjects() { OsuSpriteText timeRangeText; - ScrollingPlayfield.ScrollingHitObjectContainer scrollingHitObjectContainer; timeRangeBindable = new BindableDouble(2000) { @@ -71,12 +70,6 @@ namespace osu.Desktop.Tests.Visual RelativeSizeAxes = Axes.Both, Alpha = 0.25f }, - scrollingHitObjectContainer = new ScrollingPlayfield.ScrollingHitObjectContainer(Axes.Y) - { - RelativeSizeAxes = Axes.Both, - VisibleTimeRange = timeRangeBindable, - Masking = true, - }, new OsuSpriteText { Text = "t minus 0", @@ -111,17 +104,12 @@ namespace osu.Desktop.Tests.Visual }); timeRangeBindable.TriggerChange(); - - scrollingHitObjectContainer.AddSpeedAdjustment(new TestSpeedAdjustmentContainer(new MultiplierControlPoint())); - - AddStep("Add hit object", () => scrollingHitObjectContainer.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 2000 }))); } protected override void Update() { base.Update(); - topTime.Text = Time.Current.ToString("#,#"); bottomTime.Text = (Time.Current + timeRangeBindable.Value).ToString("#,#"); } @@ -154,13 +142,11 @@ namespace osu.Desktop.Tests.Visual } } - private class TestDrawableHitObject : DrawableHitObject, IScrollingHitObject + private class TestDrawableHitObject : DrawableScrollingHitObject { private readonly Box background; private const float height = 14; - public BindableDouble LifetimeOffset { get; } = new BindableDouble(); - public TestDrawableHitObject(HitObject hitObject) : base(hitObject) { diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs index cb1352fc4a..c1b2df8898 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs @@ -27,9 +27,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables if (key != null) Key.BindTo(key); - - RelativePositionAxes = Axes.Y; - Y = (float)HitObject.StartTime; } public override Color4 AccentColour diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 424ed77783..694e8c8126 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -192,8 +192,6 @@ namespace osu.Game.Rulesets.Mania.UI } } - public void Add(SpeedAdjustmentContainer speedAdjustment) => HitObjects.AddSpeedAdjustment(speedAdjustment); - /// /// Adds a DrawableHitObject to this Playfield. /// diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index 52b8d3e12d..ec206928b2 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -3,6 +3,7 @@ using System; using osu.Framework.Configuration; +using osu.Framework.Graphics; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects.Types; @@ -17,6 +18,19 @@ namespace osu.Game.Rulesets.Objects.Drawables { public BindableDouble LifetimeOffset { get; } = new BindableDouble(); + Axes IScrollingHitObject.ScrollingAxes + { + set + { + RelativePositionAxes = value; + + if ((value & Axes.X) > 0) + X = (float)HitObject.StartTime; + if ((value & Axes.Y) > 0) + Y = (float)HitObject.StartTime; + } + } + protected DrawableScrollingHitObject(TObject hitObject) : base(hitObject) { diff --git a/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs index 560f15f133..30b65237a4 100644 --- a/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/IScrollingHitObject.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// An interface that exposes properties required for scrolling hit objects to be properly displayed. /// - public interface IScrollingHitObject : IDrawable + internal interface IScrollingHitObject : IDrawable { /// /// Time offset before the hit object start time at which this becomes visible and the time offset @@ -21,5 +21,11 @@ namespace osu.Game.Rulesets.Objects.Drawables /// /// BindableDouble LifetimeOffset { get; } + + /// + /// Axes which this will scroll through. + /// This is set by the container which this scrolls through. + /// + Axes ScrollingAxes { set; } } } \ No newline at end of file diff --git a/osu.Game/Rulesets/Timing/ScrollingContainer.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs index daeca5a910..dcedf102aa 100644 --- a/osu.Game/Rulesets/Timing/ScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -53,6 +53,8 @@ namespace osu.Game.Rulesets.Timing /// internal MultiplierControlPoint ControlPoint; + private Cached durationBacking; + protected override int Compare(Drawable x, Drawable y) { var xHitObject = x as DrawableHitObject; @@ -93,8 +95,6 @@ namespace osu.Game.Rulesets.Timing base.InvalidateFromChild(invalidation); } - private Cached durationBacking; - private double computeDuration() { if (!Children.Any()) diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index c7249d5b84..f3475621c7 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -37,7 +37,6 @@ namespace osu.Game.Rulesets.Timing /// /// Axes which the content of this container will scroll through. /// - /// public Axes ScrollingAxes { get; internal set; } public readonly MultiplierControlPoint ControlPoint; @@ -83,7 +82,12 @@ namespace osu.Game.Rulesets.Timing public override void Add(DrawableHitObject drawable) { var scrollingHitObject = drawable as IScrollingHitObject; - scrollingHitObject?.LifetimeOffset.BindTo(VisibleTimeRange); + + if (scrollingHitObject != null) + { + scrollingHitObject.LifetimeOffset.BindTo(VisibleTimeRange); + scrollingHitObject.ScrollingAxes = ScrollingAxes; + } base.Add(drawable); } diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 8850bd6b96..1dd4ac508b 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.UI set { visibleTimeRange.BindTo(value); } } - public new readonly ScrollingHitObjectContainer HitObjects; + internal new readonly ScrollingHitObjectContainer HitObjects; protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) : base(customWidth) @@ -112,7 +112,7 @@ namespace osu.Game.Rulesets.UI /// necessary for the contained s. /// /// - public class ScrollingHitObjectContainer : HitObjectContainer> + internal class ScrollingHitObjectContainer : HitObjectContainer> { private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; /// From fc252f88889a20985557d38bd4ab9451cfd4c824 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 16:24:51 +0900 Subject: [PATCH 10/24] Remove exception (this is set in SpeedAdjustmentContainer). --- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 1dd4ac508b..27267f8a79 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -191,9 +191,6 @@ namespace osu.Game.Rulesets.UI continue; } - if (hitObject.RelativePositionAxes != target.ScrollingAxes) - throw new InvalidOperationException($"Make sure to set all {nameof(DrawableHitObject)}'s {nameof(RelativePositionAxes)} are equal to the correct axes of scrolling ({target.ScrollingAxes})."); - target.Add(hitObject); } } From 0d3797b497921362e9839e522d0212e93635364c Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 16:25:06 +0900 Subject: [PATCH 11/24] Remove TestCaseScrollingHitObjects, replace with TestCaseScrollingPlayfield. --- .../Visual/TestCaseScrollingHitObjects.cs | 210 ------------------ .../Visual/TestCaseScrollingPlayfield.cs | 150 +++++++++++++ osu.Desktop.Tests/osu.Desktop.Tests.csproj | 2 +- 3 files changed, 151 insertions(+), 211 deletions(-) delete mode 100644 osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs create mode 100644 osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs deleted file mode 100644 index 30ad5871f2..0000000000 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingHitObjects.cs +++ /dev/null @@ -1,210 +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.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; -using osu.Game.Graphics.Sprites; -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Timing; -using OpenTK; -using OpenTK.Graphics; -using osu.Game.Rulesets.UI; -using osu.Game.Rulesets.Judgements; -using System; - -namespace osu.Desktop.Tests.Visual -{ - public class TestCaseScrollingHitObjects : OsuTestCase - { - public override string Description => "SpeedAdjustmentContainer/ScrollingContainer"; - - private readonly BindableDouble timeRangeBindable; - private readonly OsuSpriteText bottomLabel; - private readonly SpriteText topTime; - private readonly SpriteText bottomTime; - - public TestCaseScrollingHitObjects() - { - OsuSpriteText timeRangeText; - - timeRangeBindable = new BindableDouble(2000) - { - MinValue = 200, - MaxValue = 4000, - }; - - SliderBar timeRange; - Add(timeRange = new BasicSliderBar - { - Size = new Vector2(200, 20), - SelectionColor = Color4.Pink, - KeyboardStep = 100 - }); - - Add(timeRangeText = new OsuSpriteText - { - X = 210, - TextSize = 16, - }); - - timeRange.Current.BindTo(timeRangeBindable); - timeRangeBindable.ValueChanged += v => timeRangeText.Text = $"Visible Range: {v:#,#.#}"; - timeRangeBindable.ValueChanged += v => bottomLabel.Text = $"t minus {v:#,#}"; - - AddRange(new Drawable[] - { - new Container - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(100, 500), - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.25f - }, - new OsuSpriteText - { - Text = "t minus 0", - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.TopRight, - }, - bottomLabel = new OsuSpriteText - { - Text = "t minus x", - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomLeft, - }, - topTime = new OsuSpriteText - { - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.TopLeft, - Origin = Anchor.TopRight, - }, - bottomTime = new OsuSpriteText - { - Margin = new MarginPadding(2), - TextSize = 14, - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomRight, - }, - } - } - }); - - timeRangeBindable.TriggerChange(); - } - - protected override void Update() - { - base.Update(); - - bottomTime.Text = (Time.Current + timeRangeBindable.Value).ToString("#,#"); - } - - private class TestSpeedAdjustmentContainer : SpeedAdjustmentContainer - { - public override bool RemoveWhenNotAlive => false; - - public TestSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) - : base(controlPoint) - { - } - - protected override ScrollingContainer CreateScrollingContainer() => new TestScrollingContainer(ControlPoint); - - private class TestScrollingContainer : ScrollingContainer - { - private readonly MultiplierControlPoint controlPoint; - - public TestScrollingContainer(MultiplierControlPoint controlPoint) - { - this.controlPoint = controlPoint; - } - - protected override void Update() - { - base.Update(); - - Y = (float)(controlPoint.StartTime - Time.Current); - } - } - } - - private class TestDrawableHitObject : DrawableScrollingHitObject - { - private readonly Box background; - private const float height = 14; - - public TestDrawableHitObject(HitObject hitObject) - : base(hitObject) - { - AutoSizeAxes = Axes.Y; - RelativeSizeAxes = Axes.X; - RelativePositionAxes = Axes.Y; - - Y = (float)hitObject.StartTime; - - Children = new Drawable[] - { - background = new Box - { - RelativeSizeAxes = Axes.X, - Height = height, - }, - new Box - { - RelativeSizeAxes = Axes.X, - Colour = Color4.Cyan, - Height = 1, - }, - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Colour = Color4.Black, - TextSize = height, - Font = @"Exo2.0-BoldItalic", - Text = $"{hitObject.StartTime:#,#}" - } - }; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - this.FadeInFromZero(250, Easing.OutQuint); - } - - protected override void Update() - { - base.Update(); - if (Time.Current >= HitObject.StartTime) - background.Colour = Color4.Red; - } - - protected override Judgement CreateJudgement() => new TestJudgement(); - - protected override void UpdateState(ArmedState state) - { - } - - private class TestJudgement : Judgement - { - public override string ResultString { get { throw new NotImplementedException(); } } - public override string MaxResultString { get { throw new NotImplementedException(); } } - } - } - } -} diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs new file mode 100644 index 0000000000..07f59fe876 --- /dev/null +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using OpenTK; +using osu.Desktop.Tests.Beatmaps; +using osu.Framework.Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; +using osu.Framework.Timing; +using osu.Game.Beatmaps; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Beatmaps; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.Timing; +using osu.Game.Rulesets.UI; + +namespace osu.Desktop.Tests.Visual +{ + /// + /// The most minimal implementation of a playfield with scrolling hit objects. + /// + public class TestCaseScrollingPlayfield : TestCase + { + public TestCaseScrollingPlayfield() + { + Clock = new FramedClock(); + + var objects = new List(); + + int time = 1500; + for (int i = 0; i < 50; i++) + { + objects.Add(new TestHitObject { StartTime = time }); + + time += 500; + } + + Beatmap b = new Beatmap + { + HitObjects = objects, + BeatmapInfo = new BeatmapInfo + { + Difficulty = new BeatmapDifficulty(), + Metadata = new BeatmapMetadata + { + Artist = @"Unknown", + Title = @"Sample Beatmap", + Author = @"peppy", + } + } + }; + + WorkingBeatmap beatmap = new TestWorkingBeatmap(b); + + Add(new TestHitRenderer(beatmap, true)); + } + + private class TestHitRenderer : SpeedAdjustedHitRenderer + { + public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(beatmap, isForCurrentRuleset) + { + } + + public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor(); + + protected override BeatmapConverter CreateBeatmapConverter() => new TestBeatmapConverter(); + + protected override Playfield CreatePlayfield() => new TestPlayfield(); + + protected override DrawableHitObject GetVisualRepresentation(TestHitObject h) => new DrawableTestHitObject(h); + } + + private class TestScoreProcessor : ScoreProcessor + { + protected override void OnNewJudgement(TestJudgement judgement) + { + } + } + + private class TestBeatmapConverter : BeatmapConverter + { + protected override IEnumerable ValidConversionTypes => new[] { typeof(HitObject) }; + + protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) + { + yield return original as TestHitObject; + } + } + + private class DrawableTestHitObject : DrawableScrollingHitObject + { + public DrawableTestHitObject(TestHitObject hitObject) + : base(hitObject) + { + Anchor = Anchor.CentreLeft; + Origin = Anchor.Centre; + + AutoSizeAxes = Axes.Both; + + Add(new Circle + { + Size = new Vector2(50) + }); + } + + protected override TestJudgement CreateJudgement() => new TestJudgement(); + + protected override void UpdateState(ArmedState state) + { + } + } + + private class TestPlayfield : ScrollingPlayfield + { + protected override Container Content => content; + private readonly Container content; + + public TestPlayfield() + : base(Axes.X) + { + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.2f + }, + content = new Container { RelativeSizeAxes = Axes.Both } + }; + } + } + + + private class TestHitObject : HitObject + { + } + + private class TestJudgement : Judgement + { + public override string ResultString { get { throw new NotImplementedException(); } } + public override string MaxResultString { get { throw new NotImplementedException(); } } + } + } +} \ No newline at end of file diff --git a/osu.Desktop.Tests/osu.Desktop.Tests.csproj b/osu.Desktop.Tests/osu.Desktop.Tests.csproj index 5058d2eed5..87ec805288 100644 --- a/osu.Desktop.Tests/osu.Desktop.Tests.csproj +++ b/osu.Desktop.Tests/osu.Desktop.Tests.csproj @@ -98,7 +98,7 @@ - + From 933740664c1925dcdc64745c9b045e31916911a4 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 16:43:54 +0900 Subject: [PATCH 12/24] SpeedAdjustedHitRenderer -> ScrollingHitRenderer for consistent naming. --- osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs | 9 ++------- osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs | 2 +- .../Objects/Drawables/DrawableScrollingHitObject.cs | 2 ++ ...eedAdjustedHitRenderer.cs => ScrollingHitRenderer.cs} | 4 ++-- osu.Game/osu.Game.csproj | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) rename osu.Game/Rulesets/UI/{SpeedAdjustedHitRenderer.cs => ScrollingHitRenderer.cs} (93%) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 07f59fe876..cc12c3ca61 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -46,12 +46,7 @@ namespace osu.Desktop.Tests.Visual BeatmapInfo = new BeatmapInfo { Difficulty = new BeatmapDifficulty(), - Metadata = new BeatmapMetadata - { - Artist = @"Unknown", - Title = @"Sample Beatmap", - Author = @"peppy", - } + Metadata = new BeatmapMetadata() } }; @@ -60,7 +55,7 @@ namespace osu.Desktop.Tests.Visual Add(new TestHitRenderer(beatmap, true)); } - private class TestHitRenderer : SpeedAdjustedHitRenderer + private class TestHitRenderer : ScrollingHitRenderer { public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(beatmap, isForCurrentRuleset) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index a34765448c..65be8a4e88 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -30,7 +30,7 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania.UI { - public class ManiaHitRenderer : SpeedAdjustedHitRenderer + public class ManiaHitRenderer : ScrollingHitRenderer { /// /// Preferred column count. This will only have an effect during the initialization of the play field. diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index ec206928b2..6861f15c40 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -11,6 +11,8 @@ namespace osu.Game.Rulesets.Objects.Drawables { /// /// A basic class that overrides and implements . + /// This object does not need to have its set to be able to scroll, as this will + /// will be set by the scrolling container that contains it. /// public abstract class DrawableScrollingHitObject : DrawableHitObject, IScrollingHitObject where TObject : HitObject diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs similarity index 93% rename from osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs rename to osu.Game/Rulesets/UI/ScrollingHitRenderer.cs index 5f8bebc213..ee549f5223 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs @@ -20,14 +20,14 @@ namespace osu.Game.Rulesets.UI /// A type of that exposes s to be used /// in s. /// - public abstract class SpeedAdjustedHitRenderer : HitRenderer + public abstract class ScrollingHitRenderer : HitRenderer where TObject : HitObject where TJudgement : Judgement where TPlayfield : ScrollingPlayfield { protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); - protected SpeedAdjustedHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + protected ScrollingHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) : base(beatmap, isForCurrentRuleset) { } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 342a02ba60..b200d55ade 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -339,7 +339,7 @@ - + From 9c0a0b1e2c3c0cbfd3a34958bd4cb07cc3f0ca1b Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 17:25:40 +0900 Subject: [PATCH 13/24] Rewrite/add comments. --- .../Timing/LinearScrollingContainer.cs | 3 +- .../Rulesets/Timing/ScrollingContainer.cs | 54 +++-------------- .../Timing/SpeedAdjustmentContainer.cs | 25 ++++---- osu.Game/Rulesets/UI/ScrollingHitRenderer.cs | 19 ++++-- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 60 ++++++++++++++----- 5 files changed, 81 insertions(+), 80 deletions(-) diff --git a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs index b86165997b..8c2b863d5e 100644 --- a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs @@ -7,8 +7,7 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.Timing { /// - /// A which scrolls relative to the control point start time. - /// This is the default returned by the base . + /// A which scrolls linearly relative to the start time. /// internal class LinearScrollingContainer : ScrollingContainer { diff --git a/osu.Game/Rulesets/Timing/ScrollingContainer.cs b/osu.Game/Rulesets/Timing/ScrollingContainer.cs index dcedf102aa..1cb5e42251 100644 --- a/osu.Game/Rulesets/Timing/ScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/ScrollingContainer.cs @@ -13,29 +13,13 @@ using osu.Game.Rulesets.Objects.Types; namespace osu.Game.Rulesets.Timing { /// - /// A collection of hit objects which scrolls within a . - /// - /// - /// This container handles the conversion between time and position through and - /// such that hit objects added to this container should have time values set as their - /// positions/sizes to make proper use of this container. - /// - /// - /// - /// This container will auto-size to the total duration of the contained hit objects along the desired auto-sizing axes such that the resulting size - /// of this container will be a value representing the total duration of all contained hit objects. - /// - /// - /// - /// This container is and must always be relatively-sized and positioned to its such that the parent can utilise - /// and to apply further time offsets to this collection of hit objects. - /// + /// A container that scrolls relative to the current time. Will autosize to the total duration of all contained hit objects along the scrolling axes. /// public abstract class ScrollingContainer : Container { private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; /// - /// Gets or sets the range of time that is visible by the length of this container. + /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// public BindableDouble VisibleTimeRange { @@ -44,34 +28,17 @@ namespace osu.Game.Rulesets.Timing } /// - /// Axes through which this timing section scrolls. This is set by the . + /// The axes through which this scrolls. This is set by the . /// internal Axes ScrollingAxes; /// - /// The control point that provides the speed adjustments for this container. This is set by the . + /// The control point that defines the speed adjustments for this container. This is set by the . /// internal MultiplierControlPoint ControlPoint; private Cached durationBacking; - protected override int Compare(Drawable x, Drawable y) - { - var xHitObject = x as DrawableHitObject; - var yHitObject = y as DrawableHitObject; - - // If either of the two drawables are not hit objects, fall back to the base comparer - if (xHitObject?.HitObject == null || yHitObject?.HitObject == null) - return base.Compare(x, y); - - // Compare by start time - int i = yHitObject.HitObject.StartTime.CompareTo(xHitObject.HitObject.StartTime); - if (i != 0) - return i; - - return base.Compare(x, y); - } - /// /// Creates a new . /// @@ -106,13 +73,8 @@ namespace osu.Game.Rulesets.Timing if (baseDuration == 0) baseDuration = 1; - // Scrolling ruleset hit objects typically have anchors+origins set to the hit object's start time, but if the hit object doesn't implement IHasEndTime and lies on the control point - // then the baseDuration above will be 0. This will cause problems with masking when it is further set as the value for Size in Update(). We _want_ the timing section bounds to - // completely enclose the hit object to avoid the masking optimisations. - // - // To do this we need to find a duration that corresponds to the absolute size of the element that extrudes beyond the timing section's bounds and add that to baseDuration. - // We can utilize the fact that the Size and RelativeChildSpace are 1:1, meaning that an change in duration for the timing section has no change to the hit object's positioning - // and simply find the largest absolutely-sized element in this timing section. This introduces a little bit of error, but will never under-estimate the duration. + // This container needs to resize such that it completely encloses the hit objects to avoid masking optimisations. This is done by converting the largest + // absolutely-sized element along the scrolling axes and adding a corresponding duration value. This introduces a bit of error, but will never under-estimate.ion. // Find the largest element that is absolutely-sized along ScrollingAxes float maxAbsoluteSize = Children.Where(c => (c.RelativeSizeAxes & ScrollingAxes) == 0) @@ -129,7 +91,7 @@ namespace osu.Game.Rulesets.Timing /// /// The maximum duration of any one hit object inside this . This is calculated as the maximum - /// end time between all hit objects relative to this 's . + /// duration of all hit objects relative to this 's . /// public double Duration => durationBacking.IsValid ? durationBacking : (durationBacking.Value = computeDuration()); @@ -137,7 +99,7 @@ namespace osu.Game.Rulesets.Timing { base.Update(); - // We want our size and position-space along ScrollingAxes to span our duration to completely enclose all the hit objects + // We want our size and position-space along the scrolling axes to span our duration to completely enclose all the hit objects Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)Duration : Size.X, (ScrollingAxes & Axes.Y) > 0 ? (float)Duration : Size.Y); // And we need to make sure the hit object's position-space doesn't change due to our resizing RelativeChildSize = Size; diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index f3475621c7..4d5db9f720 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -11,19 +11,14 @@ using OpenTK; namespace osu.Game.Rulesets.Timing { /// - /// A container for hit objects which applies applies the speed adjustments defined by the properties of a - /// to affect the scroll speed of the contained . - /// - /// - /// This container must always be relatively-sized to its parent to provide the speed adjustments. This container will provide the speed adjustments - /// by modifying its size while maintaining a constant for its children - /// + /// A container that provides the speed adjustments defined by s to affect the scroll speed + /// of container s. /// public class SpeedAdjustmentContainer : Container { private readonly Bindable visibleTimeRange = new Bindable { Default = 1000 }; /// - /// Gets or sets the range of time that is visible by the length of this container. + /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// public Bindable VisibleTimeRange { @@ -35,10 +30,13 @@ namespace osu.Game.Rulesets.Timing private Container content; /// - /// Axes which the content of this container will scroll through. + /// The axes which the content of this container will scroll through. /// public Axes ScrollingAxes { get; internal set; } + /// + /// The that defines the speed adjustments. + /// public readonly MultiplierControlPoint ControlPoint; private ScrollingContainer scrollingContainer; @@ -46,11 +44,10 @@ namespace osu.Game.Rulesets.Timing /// /// Creates a new . /// - /// The which provides the speed adjustments for this container. + /// The that defines the speed adjustments. public SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) { ControlPoint = controlPoint; - RelativeSizeAxes = Axes.Both; } @@ -93,17 +90,17 @@ namespace osu.Game.Rulesets.Timing } /// - /// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time. + /// Whether a falls within this s affecting timespan. /// public bool CanContain(DrawableHitObject hitObject) => CanContain(hitObject.HitObject.StartTime); /// - /// Whether this speed adjustment can contain an object placed at a time value. This is true if the time occurs after this speed adjustment. + /// Whether a point in time falls within this s affecting timespan. /// public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime; /// - /// Creates the container which contains a collection of hit objects and scrolls through this SpeedAdjustmentContainer. + /// Creates the which contains the scrolling s of this container. /// /// The . protected virtual ScrollingContainer CreateScrollingContainer() => new LinearScrollingContainer(ScrollingAxes, ControlPoint); diff --git a/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs index ee549f5223..da4340ac7a 100644 --- a/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs +++ b/osu.Game/Rulesets/UI/ScrollingHitRenderer.cs @@ -17,14 +17,19 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { /// - /// A type of that exposes s to be used - /// in s. + /// A type of that supports a . + /// s inside this will scroll within the playfield. /// public abstract class ScrollingHitRenderer : HitRenderer where TObject : HitObject where TJudgement : Judgement where TPlayfield : ScrollingPlayfield { + /// + /// Provides the default s that adjust the scrolling rate of s + /// inside this . + /// + /// protected readonly SortedList DefaultControlPoints = new SortedList(Comparer.Default); protected ScrollingHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) @@ -87,15 +92,16 @@ namespace osu.Game.Rulesets.UI DefaultControlPoints.AddRange(timingChanges); + // If we have no control points, add a default one if (DefaultControlPoints.Count == 0) DefaultControlPoints.Add(new MultiplierControlPoint()); } /// - /// Generates a control point with the default timing change/difficulty change from the beatmap at a time. + /// Generates a with the default timing change/difficulty change from the beatmap at a time. /// /// The time to create the control point at. - /// The at . + /// The default at . public MultiplierControlPoint CreateControlPointAt(double time) { if (DefaultControlPoints.Count == 0) @@ -108,6 +114,11 @@ namespace osu.Game.Rulesets.UI return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone()); } + /// + /// Creates a that facilitates the movement of hit objects. + /// + /// The that provides the speed adjustments for the hitobjects. + /// The . protected virtual SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new SpeedAdjustmentContainer(controlPoint); } } diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 27267f8a79..9d3a474b71 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -15,17 +15,33 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { + /// + /// A type of specialized towards scrolling . + /// public class ScrollingPlayfield : Playfield where TObject : HitObject where TJudgement : Judgement { + /// + /// The default span of time visible by the length of the scrolling axes. + /// This is clamped between and . + /// private const double time_span_default = 1500; + /// + /// The minimum span of time that may be visible by the length of the scrolling axes. + /// private const double time_span_min = 50; + /// + /// The maximum span of time that may be visible by the length of the scrolling axes. + /// private const double time_span_max = 10000; + /// + /// The step increase/decrease of the span of time visible by the length of the scrolling axes. + /// private const double time_span_step = 50; /// - /// Gets or sets the range of time that is visible by the length of this playfield the scrolling axis direction. + /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. /// private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) @@ -35,14 +51,26 @@ namespace osu.Game.Rulesets.UI MaxValue = time_span_max }; + /// + /// The span of time visible by the length of the scrolling axes. + /// + /// public BindableDouble VisibleTimeRange { get { return visibleTimeRange; } set { visibleTimeRange.BindTo(value); } } + /// + /// The container that contains the s and s. + /// internal new readonly ScrollingHitObjectContainer HitObjects; + /// + /// Creates a new . + /// + /// The axes on which s in this container should scroll. + /// Whether we want our internal coordinate system to be scaled to a specified width protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) : base(customWidth) { @@ -54,8 +82,16 @@ namespace osu.Game.Rulesets.UI } private List> nestedPlayfields; + /// + /// All the s nested inside this playfield. + /// public IEnumerable> NestedPlayfields => nestedPlayfields; + /// + /// Adds a to this playfield. The nested + /// will be given all of the same speed adjustments as this playfield. + /// + /// The to add. protected void AddNested(ScrollingPlayfield otherPlayfield) { if (nestedPlayfields == null) @@ -104,19 +140,13 @@ namespace osu.Game.Rulesets.UI } /// - /// A collection of s. - /// - /// - /// This container redirects any 's added to it to the - /// which provides the speed adjustment active at the start time of the hit object. Furthermore, this container provides the - /// necessary for the contained s. - /// + /// A container that provides the foundation for sorting s into s. /// internal class ScrollingHitObjectContainer : HitObjectContainer> { private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; /// - /// Gets or sets the range of time that is visible by the length of this container. + /// Gets or sets the range of time that is visible by the length of the scrolling axes. /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. /// public Bindable VisibleTimeRange @@ -126,9 +156,6 @@ namespace osu.Game.Rulesets.UI } protected override Container> Content => content; - /// - /// The following is never used - it only exists for the purpose of being able to use AddInternal below. - /// private Container> content; /// @@ -146,9 +173,14 @@ namespace osu.Game.Rulesets.UI { this.scrollingAxes = scrollingAxes; + // The following is never used - it only exists for the purpose of being able to use AddInternal below. content = new Container>(); } + /// + /// Adds a to this container. + /// + /// The . public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment) { speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); @@ -157,8 +189,8 @@ namespace osu.Game.Rulesets.UI } /// - /// Adds a hit object to this . The hit objects will be kept in a queue - /// and will be processed when new s are added to this . + /// Adds a hit object to this . The hit objects will be queued to be processed + /// new s are added to this . /// /// The hit object to add. public override void Add(DrawableHitObject hitObject) From f3c05fe232275aee82656d60d927e2becfed9200 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 17:34:57 +0900 Subject: [PATCH 14/24] CI fixes. --- osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs | 4 ---- .../Objects/Drawables/DrawableManiaHitObject.cs | 1 - osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs | 1 - osu.Game.Rulesets.Mania/UI/Column.cs | 5 +---- osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs | 5 +---- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 4 ---- .../Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs | 1 - osu.Game/Rulesets/Timing/LinearScrollingContainer.cs | 1 - osu.Game/Rulesets/UI/HitRenderer.cs | 1 + osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 4 ++-- 10 files changed, 5 insertions(+), 22 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index cc12c3ca61..b5dabc3a97 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -2,21 +2,17 @@ using System; using System.Collections.Generic; using OpenTK; using osu.Desktop.Tests.Beatmaps; -using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Testing; using osu.Framework.Timing; using osu.Game.Beatmaps; -using osu.Game.Rulesets; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Scoring; -using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.UI; namespace osu.Desktop.Tests.Visual diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs index c1b2df8898..10dc607ec3 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableManiaHitObject.cs @@ -4,7 +4,6 @@ using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Configuration; -using osu.Framework.Graphics; using osu.Game.Rulesets.Mania.Judgements; using osu.Game.Rulesets.Objects.Drawables; diff --git a/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs index 2cb14f224e..699acc477b 100644 --- a/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/GravityScrollingContainer.cs @@ -1,7 +1,6 @@ // 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; 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 694e8c8126..9fbc9ba5e7 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -14,12 +14,9 @@ using osu.Game.Graphics; using osu.Game.Rulesets.Objects.Drawables; using System; using osu.Framework.Configuration; -using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.UI; -using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Judgements; -using osu.Framework.Allocation; namespace osu.Game.Rulesets.Mania.UI { @@ -195,7 +192,7 @@ namespace osu.Game.Rulesets.Mania.UI /// /// Adds a DrawableHitObject to this Playfield. /// - /// The DrawableHitObject to add. + /// The DrawableHitObject to add. public override void Add(DrawableHitObject hitObject) { hitObject.AccentColour = AccentColour; diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 65be8a4e88..0b8ad10b16 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -17,7 +17,6 @@ using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Beatmaps; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Judgements; -using osu.Game.Rulesets.Mania.Mods; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Scoring; @@ -97,9 +96,7 @@ namespace osu.Game.Rulesets.Mania.UI protected override DrawableHitObject GetVisualRepresentation(ManiaHitObject h) { - var maniaPlayfield = (ManiaPlayfield)Playfield; - - Bindable key = maniaPlayfield.Columns.ElementAt(h.Column).Key; + Bindable key = Playfield.Columns.ElementAt(h.Column).Key; var holdNote = h as HoldNote; if (holdNote != null) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 4b240e4659..ba6d947729 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -15,12 +15,8 @@ using OpenTK.Input; using System.Linq; using System.Collections.Generic; using osu.Game.Rulesets.Objects.Drawables; -using osu.Framework.Input; using osu.Game.Rulesets.Mania.Objects.Drawables; -using osu.Game.Rulesets.Timing; -using osu.Framework.Configuration; using osu.Framework.Graphics.Shapes; -using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Rulesets.Mania.UI { diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index 6861f15c40..243fd79b6f 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -1,7 +1,6 @@ // 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.Configuration; using osu.Framework.Graphics; using osu.Game.Rulesets.Judgements; diff --git a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs index 8c2b863d5e..db497b7664 100644 --- a/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs +++ b/osu.Game/Rulesets/Timing/LinearScrollingContainer.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Graphics; -using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.Timing { diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index fd43078c2b..286d3a40f4 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -322,6 +322,7 @@ namespace osu.Game.Rulesets.UI /// /// A derivable HitRenderer that manages the Playfield and HitObjects. /// + /// The type of Playfield contained by this HitRenderer. /// The type of HitObject contained by this HitRenderer. /// The type of Judgement of DrawableHitObjects contained by this HitRenderer. public abstract class HitRenderer : HitRenderer diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 9d3a474b71..ffd7a993f0 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -16,7 +16,7 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { /// - /// A type of specialized towards scrolling . + /// A type of specialized towards scrolling s. /// public class ScrollingPlayfield : Playfield where TObject : HitObject @@ -156,7 +156,7 @@ namespace osu.Game.Rulesets.UI } protected override Container> Content => content; - private Container> content; + private readonly Container> content; /// /// Hit objects that are to be re-processed on the next update. From 12f9793fecd7bcc8c8aa284a7b34c3dbd1a17fc1 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 17:45:45 +0900 Subject: [PATCH 15/24] Fix mania bar lines not working. --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index ba6d947729..72b82ab60b 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -48,8 +48,8 @@ namespace osu.Game.Rulesets.Mania.UI private readonly FlowContainer columns; public IEnumerable Columns => columns.Children; - protected override Container Content => barLineContainer; - private readonly Container barLineContainer; + protected override Container Content => content; + private readonly Container content; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -108,7 +108,7 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new Container + content = new Container { Name = "Bar lines", Anchor = Anchor.TopCentre, @@ -201,13 +201,13 @@ namespace osu.Game.Rulesets.Mania.UI } public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); - public void Add(DrawableBarLine barline) => barLineContainer.Add(barline); + public void Add(DrawableBarLine barline) => HitObjects.Add(barline); protected override void Update() { // Due to masking differences, it is not possible to get the width of the columns container automatically // While masking on effectively only the Y-axis, so we need to set the width of the bar line container manually - barLineContainer.Width = columns.Width; + content.Width = columns.Width; } } } From bd2ef4dc6b23f902e8d631cde551a92c75b5b5de Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 18:03:44 +0900 Subject: [PATCH 16/24] Line endings + license headers. --- .../Visual/TestCaseScrollingPlayfield.cs | 283 +++++----- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 497 +++++++++--------- 2 files changed, 393 insertions(+), 387 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index b5dabc3a97..6f93d50ff1 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -1,141 +1,144 @@ -using System; -using System.Collections.Generic; -using OpenTK; -using osu.Desktop.Tests.Beatmaps; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Framework.Testing; -using osu.Framework.Timing; -using osu.Game.Beatmaps; -using osu.Game.Rulesets.Beatmaps; -using osu.Game.Rulesets.Judgements; -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Scoring; -using osu.Game.Rulesets.UI; - -namespace osu.Desktop.Tests.Visual -{ - /// - /// The most minimal implementation of a playfield with scrolling hit objects. - /// - public class TestCaseScrollingPlayfield : TestCase - { - public TestCaseScrollingPlayfield() - { - Clock = new FramedClock(); - - var objects = new List(); - - int time = 1500; - for (int i = 0; i < 50; i++) - { - objects.Add(new TestHitObject { StartTime = time }); - - time += 500; - } - - Beatmap b = new Beatmap - { - HitObjects = objects, - BeatmapInfo = new BeatmapInfo - { - Difficulty = new BeatmapDifficulty(), - Metadata = new BeatmapMetadata() - } - }; - - WorkingBeatmap beatmap = new TestWorkingBeatmap(b); - - Add(new TestHitRenderer(beatmap, true)); - } - - private class TestHitRenderer : ScrollingHitRenderer - { - public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) - : base(beatmap, isForCurrentRuleset) - { - } - - public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor(); - - protected override BeatmapConverter CreateBeatmapConverter() => new TestBeatmapConverter(); - - protected override Playfield CreatePlayfield() => new TestPlayfield(); - - protected override DrawableHitObject GetVisualRepresentation(TestHitObject h) => new DrawableTestHitObject(h); - } - - private class TestScoreProcessor : ScoreProcessor - { - protected override void OnNewJudgement(TestJudgement judgement) - { - } - } - - private class TestBeatmapConverter : BeatmapConverter - { - protected override IEnumerable ValidConversionTypes => new[] { typeof(HitObject) }; - - protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) - { - yield return original as TestHitObject; - } - } - - private class DrawableTestHitObject : DrawableScrollingHitObject - { - public DrawableTestHitObject(TestHitObject hitObject) - : base(hitObject) - { - Anchor = Anchor.CentreLeft; - Origin = Anchor.Centre; - - AutoSizeAxes = Axes.Both; - - Add(new Circle - { - Size = new Vector2(50) - }); - } - - protected override TestJudgement CreateJudgement() => new TestJudgement(); - - protected override void UpdateState(ArmedState state) - { - } - } - - private class TestPlayfield : ScrollingPlayfield - { - protected override Container Content => content; - private readonly Container content; - - public TestPlayfield() - : base(Axes.X) - { - InternalChildren = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Alpha = 0.2f - }, - content = new Container { RelativeSizeAxes = Axes.Both } - }; - } - } - - - private class TestHitObject : HitObject - { - } - - private class TestJudgement : Judgement - { - public override string ResultString { get { throw new NotImplementedException(); } } - public override string MaxResultString { get { throw new NotImplementedException(); } } - } - } +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using OpenTK; +using osu.Desktop.Tests.Beatmaps; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Testing; +using osu.Framework.Timing; +using osu.Game.Beatmaps; +using osu.Game.Rulesets.Beatmaps; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; + +namespace osu.Desktop.Tests.Visual +{ + /// + /// The most minimal implementation of a playfield with scrolling hit objects. + /// + public class TestCaseScrollingPlayfield : TestCase + { + public TestCaseScrollingPlayfield() + { + Clock = new FramedClock(); + + var objects = new List(); + + int time = 1500; + for (int i = 0; i < 50; i++) + { + objects.Add(new TestHitObject { StartTime = time }); + + time += 500; + } + + Beatmap b = new Beatmap + { + HitObjects = objects, + BeatmapInfo = new BeatmapInfo + { + Difficulty = new BeatmapDifficulty(), + Metadata = new BeatmapMetadata() + } + }; + + WorkingBeatmap beatmap = new TestWorkingBeatmap(b); + + Add(new TestHitRenderer(beatmap, true)); + } + + private class TestHitRenderer : ScrollingHitRenderer + { + public TestHitRenderer(WorkingBeatmap beatmap, bool isForCurrentRuleset) + : base(beatmap, isForCurrentRuleset) + { + } + + public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor(); + + protected override BeatmapConverter CreateBeatmapConverter() => new TestBeatmapConverter(); + + protected override Playfield CreatePlayfield() => new TestPlayfield(); + + protected override DrawableHitObject GetVisualRepresentation(TestHitObject h) => new DrawableTestHitObject(h); + } + + private class TestScoreProcessor : ScoreProcessor + { + protected override void OnNewJudgement(TestJudgement judgement) + { + } + } + + private class TestBeatmapConverter : BeatmapConverter + { + protected override IEnumerable ValidConversionTypes => new[] { typeof(HitObject) }; + + protected override IEnumerable ConvertHitObject(HitObject original, Beatmap beatmap) + { + yield return original as TestHitObject; + } + } + + private class DrawableTestHitObject : DrawableScrollingHitObject + { + public DrawableTestHitObject(TestHitObject hitObject) + : base(hitObject) + { + Anchor = Anchor.CentreLeft; + Origin = Anchor.Centre; + + AutoSizeAxes = Axes.Both; + + Add(new Circle + { + Size = new Vector2(50) + }); + } + + protected override TestJudgement CreateJudgement() => new TestJudgement(); + + protected override void UpdateState(ArmedState state) + { + } + } + + private class TestPlayfield : ScrollingPlayfield + { + protected override Container Content => content; + private readonly Container content; + + public TestPlayfield() + : base(Axes.X) + { + InternalChildren = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.2f + }, + content = new Container { RelativeSizeAxes = Axes.Both } + }; + } + } + + + private class TestHitObject : HitObject + { + } + + private class TestJudgement : Judgement + { + public override string ResultString { get { throw new NotImplementedException(); } } + public override string MaxResultString { get { throw new NotImplementedException(); } } + } + } } \ No newline at end of file diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index ffd7a993f0..1a88c74ebc 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -1,248 +1,251 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenTK.Input; -using osu.Framework.Configuration; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Input; -using osu.Framework.MathUtils; -using osu.Game.Rulesets.Judgements; -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Timing; - -namespace osu.Game.Rulesets.UI -{ - /// - /// A type of specialized towards scrolling s. - /// - public class ScrollingPlayfield : Playfield - where TObject : HitObject - where TJudgement : Judgement - { - /// - /// The default span of time visible by the length of the scrolling axes. - /// This is clamped between and . - /// - private const double time_span_default = 1500; - /// - /// The minimum span of time that may be visible by the length of the scrolling axes. - /// - private const double time_span_min = 50; - /// - /// The maximum span of time that may be visible by the length of the scrolling axes. - /// - private const double time_span_max = 10000; - /// - /// The step increase/decrease of the span of time visible by the length of the scrolling axes. - /// - private const double time_span_step = 50; - - /// - /// Gets or sets the range of time that is visible by the length of the scrolling axes. - /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. - /// - private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) - { - Default = time_span_default, - MinValue = time_span_min, - MaxValue = time_span_max - }; - - /// - /// The span of time visible by the length of the scrolling axes. - /// - /// - public BindableDouble VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - - /// - /// The container that contains the s and s. - /// - internal new readonly ScrollingHitObjectContainer HitObjects; - - /// - /// Creates a new . - /// - /// The axes on which s in this container should scroll. - /// Whether we want our internal coordinate system to be scaled to a specified width - protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) - : base(customWidth) - { - base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) - { - RelativeSizeAxes = Axes.Both, - VisibleTimeRange = VisibleTimeRange - }; - } - - private List> nestedPlayfields; - /// - /// All the s nested inside this playfield. - /// - public IEnumerable> NestedPlayfields => nestedPlayfields; - - /// - /// Adds a to this playfield. The nested - /// will be given all of the same speed adjustments as this playfield. - /// - /// The to add. - protected void AddNested(ScrollingPlayfield otherPlayfield) - { - if (nestedPlayfields == null) - nestedPlayfields = new List>(); - - nestedPlayfields.Add(otherPlayfield); - } - - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) - { - if (state.Keyboard.ControlPressed) - { - switch (args.Key) - { - case Key.Minus: - transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint); - break; - case Key.Plus: - transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint); - break; - } - } - - return false; - } - - private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) - { - this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing)); - } - - private class TransformVisibleTimeRange : Transform> - { - private double valueAt(double time) - { - if (time < StartTime) return StartValue; - if (time >= EndTime) return EndValue; - - return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); - } - - public override string TargetMember => "VisibleTimeRange.Value"; - - protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); - protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; - } - - /// - /// A container that provides the foundation for sorting s into s. - /// - internal class ScrollingHitObjectContainer : HitObjectContainer> - { - private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; - /// - /// Gets or sets the range of time that is visible by the length of the scrolling axes. - /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. - /// - public Bindable VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } - - protected override Container> Content => content; - private readonly Container> content; - - /// - /// Hit objects that are to be re-processed on the next update. - /// - private readonly Queue> queuedHitObjects = new Queue>(); - - private readonly Axes scrollingAxes; - - /// - /// Creates a new . - /// - /// The axes upon which hit objects should appear to scroll inside this container. - public ScrollingHitObjectContainer(Axes scrollingAxes) - { - this.scrollingAxes = scrollingAxes; - - // The following is never used - it only exists for the purpose of being able to use AddInternal below. - content = new Container>(); - } - - /// - /// Adds a to this container. - /// - /// The . - public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment) - { - speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); - speedAdjustment.ScrollingAxes = scrollingAxes; - AddInternal(speedAdjustment); - } - - /// - /// Adds a hit object to this . The hit objects will be queued to be processed - /// new s are added to this . - /// - /// The hit object to add. - public override void Add(DrawableHitObject hitObject) - { - if (!(hitObject is IScrollingHitObject)) - throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); - - queuedHitObjects.Enqueue(hitObject); - } - - protected override void Update() - { - base.Update(); - - // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op - // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. - - // An external count is kept because hit objects that can't be added are re-queued - int count = queuedHitObjects.Count; - while (count-- > 0) - { - var hitObject = queuedHitObjects.Dequeue(); - - var target = adjustmentContainerFor(hitObject); - if (target == null) - { - // We can't add this hit object to a speed adjustment container yet, so re-queue it - // for re-processing when the layout next invalidated - queuedHitObjects.Enqueue(hitObject); - continue; - } - - target.Add(hitObject); - } - } - - /// - /// Finds the which provides the speed adjustment active at the start time - /// of a hit object. If there is no active at the start time of the hit object, - /// then the first (time-wise) speed adjustment is returned. - /// - /// The hit object to find the active for. - /// The active at 's start time. Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(hitObject)) ?? InternalChildren.OfType().LastOrDefault(); - - /// - /// Finds the which provides the speed adjustment active at a time. - /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. - /// - /// The time to find the active at. - /// The active at . Null if there are no speed adjustments. - private SpeedAdjustmentContainer adjustmentContainerAt(double time) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(time)) ?? InternalChildren.OfType().LastOrDefault(); - } - } +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using OpenTK.Input; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Transforms; +using osu.Framework.Input; +using osu.Framework.MathUtils; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Timing; + +namespace osu.Game.Rulesets.UI +{ + /// + /// A type of specialized towards scrolling s. + /// + public class ScrollingPlayfield : Playfield + where TObject : HitObject + where TJudgement : Judgement + { + /// + /// The default span of time visible by the length of the scrolling axes. + /// This is clamped between and . + /// + private const double time_span_default = 1500; + /// + /// The minimum span of time that may be visible by the length of the scrolling axes. + /// + private const double time_span_min = 50; + /// + /// The maximum span of time that may be visible by the length of the scrolling axes. + /// + private const double time_span_max = 10000; + /// + /// The step increase/decrease of the span of time visible by the length of the scrolling axes. + /// + private const double time_span_step = 50; + + /// + /// Gets or sets the range of time that is visible by the length of the scrolling axes. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) + { + Default = time_span_default, + MinValue = time_span_min, + MaxValue = time_span_max + }; + + /// + /// The span of time visible by the length of the scrolling axes. + /// + /// + public BindableDouble VisibleTimeRange + { + get { return visibleTimeRange; } + set { visibleTimeRange.BindTo(value); } + } + + /// + /// The container that contains the s and s. + /// + internal new readonly ScrollingHitObjectContainer HitObjects; + + /// + /// Creates a new . + /// + /// The axes on which s in this container should scroll. + /// Whether we want our internal coordinate system to be scaled to a specified width + protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) + : base(customWidth) + { + base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) + { + RelativeSizeAxes = Axes.Both, + VisibleTimeRange = VisibleTimeRange + }; + } + + private List> nestedPlayfields; + /// + /// All the s nested inside this playfield. + /// + public IEnumerable> NestedPlayfields => nestedPlayfields; + + /// + /// Adds a to this playfield. The nested + /// will be given all of the same speed adjustments as this playfield. + /// + /// The to add. + protected void AddNested(ScrollingPlayfield otherPlayfield) + { + if (nestedPlayfields == null) + nestedPlayfields = new List>(); + + nestedPlayfields.Add(otherPlayfield); + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + { + if (state.Keyboard.ControlPressed) + { + switch (args.Key) + { + case Key.Minus: + transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint); + break; + case Key.Plus: + transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint); + break; + } + } + + return false; + } + + private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None) + { + this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing)); + } + + private class TransformVisibleTimeRange : Transform> + { + private double valueAt(double time) + { + if (time < StartTime) return StartValue; + if (time >= EndTime) return EndValue; + + return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing); + } + + public override string TargetMember => "VisibleTimeRange.Value"; + + protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); + protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; + } + + /// + /// A container that provides the foundation for sorting s into s. + /// + internal class ScrollingHitObjectContainer : HitObjectContainer> + { + private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; + /// + /// Gets or sets the range of time that is visible by the length of the scrolling axes. + /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. + /// + public Bindable VisibleTimeRange + { + get { return visibleTimeRange; } + set { visibleTimeRange.BindTo(value); } + } + + protected override Container> Content => content; + private readonly Container> content; + + /// + /// Hit objects that are to be re-processed on the next update. + /// + private readonly Queue> queuedHitObjects = new Queue>(); + + private readonly Axes scrollingAxes; + + /// + /// Creates a new . + /// + /// The axes upon which hit objects should appear to scroll inside this container. + public ScrollingHitObjectContainer(Axes scrollingAxes) + { + this.scrollingAxes = scrollingAxes; + + // The following is never used - it only exists for the purpose of being able to use AddInternal below. + content = new Container>(); + } + + /// + /// Adds a to this container. + /// + /// The . + public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment) + { + speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); + speedAdjustment.ScrollingAxes = scrollingAxes; + AddInternal(speedAdjustment); + } + + /// + /// Adds a hit object to this . The hit objects will be queued to be processed + /// new s are added to this . + /// + /// The hit object to add. + public override void Add(DrawableHitObject hitObject) + { + if (!(hitObject is IScrollingHitObject)) + throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); + + queuedHitObjects.Enqueue(hitObject); + } + + protected override void Update() + { + base.Update(); + + // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op + // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. + + // An external count is kept because hit objects that can't be added are re-queued + int count = queuedHitObjects.Count; + while (count-- > 0) + { + var hitObject = queuedHitObjects.Dequeue(); + + var target = adjustmentContainerFor(hitObject); + if (target == null) + { + // We can't add this hit object to a speed adjustment container yet, so re-queue it + // for re-processing when the layout next invalidated + queuedHitObjects.Enqueue(hitObject); + continue; + } + + target.Add(hitObject); + } + } + + /// + /// Finds the which provides the speed adjustment active at the start time + /// of a hit object. If there is no active at the start time of the hit object, + /// then the first (time-wise) speed adjustment is returned. + /// + /// The hit object to find the active for. + /// The active at 's start time. Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerFor(DrawableHitObject hitObject) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(hitObject)) ?? InternalChildren.OfType().LastOrDefault(); + + /// + /// Finds the which provides the speed adjustment active at a time. + /// If there is no active at the time, then the first (time-wise) speed adjustment is returned. + /// + /// The time to find the active at. + /// The active at . Null if there are no speed adjustments. + private SpeedAdjustmentContainer adjustmentContainerAt(double time) => InternalChildren.OfType().FirstOrDefault(c => c.CanContain(time)) ?? InternalChildren.OfType().LastOrDefault(); + } + } } \ No newline at end of file From bcd1b61529fe105b4ae1a63e0a22338d7e767cd6 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 18:11:45 +0900 Subject: [PATCH 17/24] Use OsuTestCase. --- osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 6f93d50ff1..21f1aa603a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -8,7 +8,6 @@ using osu.Desktop.Tests.Beatmaps; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Testing; using osu.Framework.Timing; using osu.Game.Beatmaps; using osu.Game.Rulesets.Beatmaps; @@ -23,7 +22,7 @@ namespace osu.Desktop.Tests.Visual /// /// The most minimal implementation of a playfield with scrolling hit objects. /// - public class TestCaseScrollingPlayfield : TestCase + public class TestCaseScrollingPlayfield : OsuTestCase { public TestCaseScrollingPlayfield() { From c5ce86b9f3a1252f012391216c180c6c7cfa2568 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 12:59:50 +0900 Subject: [PATCH 18/24] Add reversing capability to ScrollingPlayfield. --- .../Visual/TestCaseScrollingPlayfield.cs | 8 +++++- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 4 ++- .../Timing/SpeedAdjustmentContainer.cs | 19 ++++++++++++- osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 27 ++++++++++++------- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 21f1aa603a..8334992d5a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -24,6 +24,8 @@ namespace osu.Desktop.Tests.Visual /// public class TestCaseScrollingPlayfield : OsuTestCase { + private readonly TestHitRenderer hitRenderer; + public TestCaseScrollingPlayfield() { Clock = new FramedClock(); @@ -50,7 +52,9 @@ namespace osu.Desktop.Tests.Visual WorkingBeatmap beatmap = new TestWorkingBeatmap(b); - Add(new TestHitRenderer(beatmap, true)); + Add(hitRenderer = new TestHitRenderer(beatmap, true)); + + AddStep("Reverse direction", () => hitRenderer.Playfield.Reversed.Value = !hitRenderer.Playfield.Reversed); } private class TestHitRenderer : ScrollingHitRenderer @@ -60,6 +64,8 @@ namespace osu.Desktop.Tests.Visual { } + public new TestPlayfield Playfield => base.Playfield; + public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor(); protected override BeatmapConverter CreateBeatmapConverter() => new TestBeatmapConverter(); diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 72b82ab60b..b836b54fa8 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -124,7 +124,9 @@ namespace osu.Game.Rulesets.Mania.UI for (int i = 0; i < columnCount; i++) { - var c = new Column { VisibleTimeRange = VisibleTimeRange }; + var c = new Column(); + c.VisibleTimeRange.BindTo(VisibleTimeRange); + columns.Add(c); AddNested(c); } diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 4d5db9f720..de4bc8a22b 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -26,6 +26,16 @@ namespace osu.Game.Rulesets.Timing set { visibleTimeRange.BindTo(value); } } + private readonly BindableBool reversed = new BindableBool(); + /// + /// Whether to reverse the scrolling direction is reversed. + /// + public BindableBool Reversed + { + get { return reversed; } + set { reversed.BindTo(value); } + } + protected override Container Content => content; private Container content; @@ -70,7 +80,14 @@ namespace osu.Game.Rulesets.Timing // The speed adjustment happens by modifying our size by the multiplier while maintaining the visible time range as the relatve size for our children Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? multiplier : 1, (ScrollingAxes & Axes.Y) > 0 ? multiplier : 1); - RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); + + if (Reversed) + { + RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)-VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)-VisibleTimeRange : 1); + RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0); + } + else + RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); } public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange; diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 1a88c74ebc..685eaa8e65 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -44,10 +44,10 @@ namespace osu.Game.Rulesets.UI private const double time_span_step = 50; /// - /// Gets or sets the range of time that is visible by the length of the scrolling axes. + /// The span of time that is visible by the length of the scrolling axes. /// For example, only hit objects with start time less than or equal to 1000 will be visible with = 1000. /// - private readonly BindableDouble visibleTimeRange = new BindableDouble(time_span_default) + public readonly BindableDouble VisibleTimeRange = new BindableDouble(time_span_default) { Default = time_span_default, MinValue = time_span_min, @@ -55,14 +55,9 @@ namespace osu.Game.Rulesets.UI }; /// - /// The span of time visible by the length of the scrolling axes. + /// Whether to reverse the scrolling direction is reversed. /// - /// - public BindableDouble VisibleTimeRange - { - get { return visibleTimeRange; } - set { visibleTimeRange.BindTo(value); } - } + public readonly BindableBool Reversed = new BindableBool(); /// /// The container that contains the s and s. @@ -80,7 +75,8 @@ namespace osu.Game.Rulesets.UI base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) { RelativeSizeAxes = Axes.Both, - VisibleTimeRange = VisibleTimeRange + VisibleTimeRange = VisibleTimeRange, + Reversed = Reversed }; } @@ -158,6 +154,16 @@ namespace osu.Game.Rulesets.UI set { visibleTimeRange.BindTo(value); } } + private readonly BindableBool reversed = new BindableBool(); + /// + /// Whether to reverse the scrolling direction is reversed. + /// + public BindableBool Reversed + { + get { return reversed; } + set { reversed.BindTo(value); } + } + protected override Container> Content => content; private readonly Container> content; @@ -188,6 +194,7 @@ namespace osu.Game.Rulesets.UI { speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); speedAdjustment.ScrollingAxes = scrollingAxes; + speedAdjustment.Reversed = Reversed; AddInternal(speedAdjustment); } From ee7bb1b4f5a787fea871d07adc029ab22f5348ac Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 8 Aug 2017 09:20:54 +0900 Subject: [PATCH 19/24] Don't set RelativePositionAxes when setting ScrollingAxes (cherry picked from commit debe13629f07da44eb14489aa959eb772127c11e) --- .../Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs index 243fd79b6f..f67dd4dfea 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableScrollingHitObject.cs @@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Objects.Drawables { set { - RelativePositionAxes = value; + RelativePositionAxes |= value; if ((value & Axes.X) > 0) X = (float)HitObject.StartTime; From a95aa90adc101f545ec7813baba14cb22b76ff46 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 8 Aug 2017 10:53:59 +0900 Subject: [PATCH 20/24] Allow DrawableHitObjects to be removed from a Playfield (cherry picked from commit 3926238be992dfb4cb1e2b34f0e4f742b06157e1) --- osu.Game/Rulesets/UI/Playfield.cs | 6 ++++++ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index 5f07df5088..ade2c2d070 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -82,6 +82,12 @@ namespace osu.Game.Rulesets.UI /// The DrawableHitObject to add. public virtual void Add(DrawableHitObject h) => HitObjects.Add(h); + /// + /// Remove a DrawableHitObject from this Playfield. + /// + /// The DrawableHitObject to remove. + public virtual void Remove(DrawableHitObject h) => HitObjects.Remove(h); + /// /// Triggered when an object's Judgement is updated. /// diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 685eaa8e65..96d3765eb5 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -211,6 +211,13 @@ namespace osu.Game.Rulesets.UI queuedHitObjects.Enqueue(hitObject); } + public override bool Remove(DrawableHitObject hitObject) + { + foreach (var c in InternalChildren.OfType()) + c.Remove(hitObject); + return true; + } + protected override void Update() { base.Update(); From e54abe8d0af71d30b21997b9709554e4e7966cd7 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 13:23:46 +0900 Subject: [PATCH 21/24] Fix not removing queued hit objects. --- .../Timing/SpeedAdjustmentContainer.cs | 3 +++ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 27 ++++++++----------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index de4bc8a22b..f521fa18c4 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -87,7 +87,10 @@ namespace osu.Game.Rulesets.Timing RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0); } else + { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); + RelativeChildOffset = Vector2.Zero; + } } public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange; diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index 96d3765eb5..adfcb6c971 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -170,7 +170,7 @@ namespace osu.Game.Rulesets.UI /// /// Hit objects that are to be re-processed on the next update. /// - private readonly Queue> queuedHitObjects = new Queue>(); + private readonly List> queuedHitObjects = new List>(); private readonly Axes scrollingAxes; @@ -208,14 +208,15 @@ namespace osu.Game.Rulesets.UI if (!(hitObject is IScrollingHitObject)) throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}."); - queuedHitObjects.Enqueue(hitObject); + queuedHitObjects.Add(hitObject); } public override bool Remove(DrawableHitObject hitObject) { - foreach (var c in InternalChildren.OfType()) - c.Remove(hitObject); - return true; + bool removed = InternalChildren.OfType().Any(c => c.Remove(hitObject)); + removed = removed || queuedHitObjects.Remove(hitObject); + + return removed; } protected override void Update() @@ -225,22 +226,16 @@ namespace osu.Game.Rulesets.UI // Todo: At the moment this is going to re-process every single Update, however this will only be a null-op // when there are no SpeedAdjustmentContainers available. This should probably error or something, but it's okay for now. - // An external count is kept because hit objects that can't be added are re-queued - int count = queuedHitObjects.Count; - while (count-- > 0) + for (int i = queuedHitObjects.Count - 1; i >= 0; i--) { - var hitObject = queuedHitObjects.Dequeue(); + var hitObject = queuedHitObjects[i]; var target = adjustmentContainerFor(hitObject); - if (target == null) + if (target != null) { - // We can't add this hit object to a speed adjustment container yet, so re-queue it - // for re-processing when the layout next invalidated - queuedHitObjects.Enqueue(hitObject); - continue; + target.Add(hitObject); + queuedHitObjects.RemoveAt(i); } - - target.Add(hitObject); } } From 80c95d5b26e46a8729a05ebd215b68402d425e22 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 13:24:15 +0900 Subject: [PATCH 22/24] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 107c551767..dd0daafcfc 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 107c5517670ca88dbe8c83a97e37e99ac5742ee6 +Subproject commit dd0daafcfc0d625bb588c8e12d7db58bc00c255e From 25202b522df20b2765e6e2ba79c07984387b23d9 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 14:10:26 +0900 Subject: [PATCH 23/24] Fix not setting Origin + Anchors properly when reversing. --- osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index f521fa18c4..d582f19660 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -85,11 +85,13 @@ namespace osu.Game.Rulesets.Timing { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)-VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)-VisibleTimeRange : 1); RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0); + Origin = Anchor = Anchor.BottomLeft; } else { RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1); RelativeChildOffset = Vector2.Zero; + Anchor = Anchor = Anchor.TopLeft; } } From 9e01b47a093629c61062821b776f1c5560ac8e24 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Tue, 8 Aug 2017 14:15:08 +0900 Subject: [PATCH 24/24] Convert to local object. --- osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs index 8334992d5a..7f067efa78 100644 --- a/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs +++ b/osu.Desktop.Tests/Visual/TestCaseScrollingPlayfield.cs @@ -24,8 +24,6 @@ namespace osu.Desktop.Tests.Visual /// public class TestCaseScrollingPlayfield : OsuTestCase { - private readonly TestHitRenderer hitRenderer; - public TestCaseScrollingPlayfield() { Clock = new FramedClock(); @@ -52,6 +50,7 @@ namespace osu.Desktop.Tests.Visual WorkingBeatmap beatmap = new TestWorkingBeatmap(b); + TestHitRenderer hitRenderer; Add(hitRenderer = new TestHitRenderer(beatmap, true)); AddStep("Reverse direction", () => hitRenderer.Playfield.Reversed.Value = !hitRenderer.Playfield.Reversed);