From ba8014bbd973b9857ee70fe2d84598a83cd787c1 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 12 Jun 2017 15:20:34 +0900 Subject: [PATCH] Cleanups + xmldoc rewordings/improvements. --- .../Mods/IGenerateSpeedAdjustments.cs | 9 +++++ .../Mods/ManiaModGravity.cs | 13 +++--- .../BasicScrollingDrawableTimingSection.cs | 11 +++-- .../GravityScrollingDrawableTimingSection.cs | 13 +++--- .../Rulesets/Timing/DrawableTimingSection.cs | 25 ++++-------- .../Rulesets/Timing/MultiplierControlPoint.cs | 23 ++++++++++- .../Timing/SpeedAdjustmentCollection.cs | 40 ++++++++++--------- .../Timing/SpeedAdjustmentContainer.cs | 30 ++++++++------ osu.Game/Rulesets/UI/HitRenderer.cs | 10 ++++- 9 files changed, 108 insertions(+), 66 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs b/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs index 1545f4cf89..f179aa2ff8 100644 --- a/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs +++ b/osu.Game.Rulesets.Mania/Mods/IGenerateSpeedAdjustments.cs @@ -7,8 +7,17 @@ using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.Mania.Mods { + /// + /// A type of mod which generates speed adjustments that scroll the hit objects and bar lines. + /// internal interface IGenerateSpeedAdjustments { + /// + /// Applies this mod to a hit renderer. + /// + /// The hit renderer to apply to. + /// The per-column list of speed adjustments for hit objects. + /// The list of speed adjustments for bar lines. void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges); } } diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs index d36b187599..1ba8ac4710 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaModGravity.cs @@ -7,7 +7,6 @@ using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mods; using osu.Game.Graphics; using osu.Game.Rulesets.Mania.Timing; -using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Timing; using osu.Game.Rulesets.Mania.Objects.Drawables; @@ -23,21 +22,21 @@ namespace osu.Game.Rulesets.Mania.Mods public void ApplyToHitRenderer(ManiaHitRenderer hitRenderer, ref List[] hitObjectTimingChanges, ref List barlineTimingChanges) { - foreach (HitObject obj in hitRenderer.Objects) + // We have to generate one speed adjustment per hit object for gravity + foreach (ManiaHitObject obj in hitRenderer.Objects) { - var maniaObject = obj as ManiaHitObject; - if (maniaObject == null) - continue; - MultiplierControlPoint controlPoint = hitRenderer.CreateControlPointAt(obj.StartTime); + // Beat length has too large of an effect for gravity, so we'll force it to a constant value for now controlPoint.TimingPoint.BeatLength = 1000; - hitObjectTimingChanges[maniaObject.Column].Add(new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Gravity)); + hitObjectTimingChanges[obj.Column].Add(new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Gravity)); } + // Like with hit objects, we need to generate one speed adjustment per bar line foreach (DrawableBarLine barLine in hitRenderer.BarLines) { var controlPoint = hitRenderer.CreateControlPointAt(barLine.HitObject.StartTime); + // Beat length has too large of an effect for gravity, so we'll force it to a constant value for now controlPoint.TimingPoint.BeatLength = 1000; barlineTimingChanges.Add(new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Gravity)); diff --git a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs index 58f7e522be..f579567a6c 100644 --- a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs @@ -6,21 +6,24 @@ 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 timingSection; + private readonly MultiplierControlPoint controlPoint; - public BasicScrollingDrawableTimingSection(MultiplierControlPoint timingSection) + public BasicScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) : base(Axes.Y) { - this.timingSection = timingSection; + this.controlPoint = controlPoint; } protected override void Update() { base.Update(); - Y = (float)(timingSection.StartTime - Time.Current); + Y = (float)(controlPoint.StartTime - Time.Current); } } } diff --git a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs index b0e41cfbae..df8daa43dd 100644 --- a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs @@ -6,14 +6,17 @@ 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. + /// internal class GravityScrollingDrawableTimingSection : DrawableTimingSection { - private readonly MultiplierControlPoint timingSection; + private readonly MultiplierControlPoint controlPoint; - public GravityScrollingDrawableTimingSection(MultiplierControlPoint timingSection) + public GravityScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) : base(Axes.Y) { - this.timingSection = timingSection; + this.controlPoint = controlPoint; } protected override void UpdateAfterChildren() @@ -21,9 +24,9 @@ namespace osu.Game.Rulesets.Mania.Timing base.UpdateAfterChildren(); // The gravity-adjusted start position - float startPos = (float)computeGravityTime(timingSection.StartTime); + float startPos = (float)computeGravityTime(controlPoint.StartTime); // The gravity-adjusted end position - float endPos = (float)computeGravityTime(timingSection.StartTime + RelativeChildSize.Y); + float endPos = (float)computeGravityTime(controlPoint.StartTime + RelativeChildSize.Y); Y = startPos; Height = endPos - startPos; diff --git a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs b/osu.Game/Rulesets/Timing/DrawableTimingSection.cs index 131dc1dc0e..846df34e25 100644 --- a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs +++ b/osu.Game/Rulesets/Timing/DrawableTimingSection.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 System.Collections.Generic; using System.Linq; using osu.Framework.Caching; @@ -24,19 +23,21 @@ namespace osu.Game.Rulesets.Timing /// /// /// - /// This container will auto-size to the total size of its children along the desired auto-sizing axes such that the reasulting size - /// of this container will also be a time value. + /// 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. + /// 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. /// /// public abstract class DrawableTimingSection : Container { private readonly BindableDouble visibleTimeRange = new BindableDouble(); + /// + /// Gets or sets the range of time that is visible by the length of this container. + /// public BindableDouble VisibleTimeRange { get { return visibleTimeRange; } @@ -57,18 +58,8 @@ namespace osu.Game.Rulesets.Timing { this.autoSizingAxes = autoSizingAxes; + RelativeSizeAxes = Axes.Both; RelativePositionAxes = Axes.Both; - - // We need a default size since RelativeSizeAxes is overridden - Size = Vector2.One; - } - - public override Axes AutoSizeAxes { set { throw new InvalidOperationException($"{nameof(DrawableTimingSection)} must always be relatively-sized."); } } - - public override Axes RelativeSizeAxes - { - get { return Axes.Both; } - set { throw new InvalidOperationException($"{nameof(DrawableTimingSection)} must always be relatively-sized."); } } public override void InvalidateFromChild(Invalidation invalidation) diff --git a/osu.Game/Rulesets/Timing/MultiplierControlPoint.cs b/osu.Game/Rulesets/Timing/MultiplierControlPoint.cs index 2037174a5c..c6b5fa83e6 100644 --- a/osu.Game/Rulesets/Timing/MultiplierControlPoint.cs +++ b/osu.Game/Rulesets/Timing/MultiplierControlPoint.cs @@ -10,27 +10,46 @@ namespace osu.Game.Rulesets.Timing public class MultiplierControlPoint : IJsonSerializable, IComparable { /// - /// The time in milliseconds at which this control point starts. + /// The time in milliseconds at which this starts. /// public readonly double StartTime; /// - /// The multiplier which this control point provides. + /// The multiplier which this provides. /// public double Multiplier => 1000 / TimingPoint.BeatLength / DifficultyPoint.SpeedMultiplier; + /// + /// The that provides the timing information for this . + /// public TimingControlPoint TimingPoint = new TimingControlPoint(); + + /// + /// The that provides additional difficulty information for this . + /// public DifficultyControlPoint DifficultyPoint = new DifficultyControlPoint(); + /// + /// Creates a . This is required for JSON serialization + /// public MultiplierControlPoint() { } + /// + /// Creates a . + /// + /// The start time of this . public MultiplierControlPoint(double startTime) { StartTime = startTime; } + /// + /// Creates a by copying another . + /// + /// The start time of this . + /// The to copy. public MultiplierControlPoint(double startTime, MultiplierControlPoint other) : this(startTime) { diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs index 550f77dab2..03bbe6528d 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs @@ -15,14 +15,16 @@ namespace osu.Game.Rulesets.Timing /// A collection of s. /// /// - /// This container provides for the 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(); /// - /// The amount of time visible by span of this container. + /// 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 @@ -32,15 +34,16 @@ namespace osu.Game.Rulesets.Timing } /// - /// Adds a hit object to the most applicable timing section in this container. + /// Adds a hit object to the which provides the speed adjustment + /// active at the start time of the hit object. /// /// The hit object to add. public void Add(DrawableHitObject hitObject) { - var target = timingSectionFor(hitObject); + var target = adjustmentContainerFor(hitObject); if (target == null) - throw new ArgumentException("No timing section could be found that can contain the hit object.", nameof(hitObject)); + throw new ArgumentException("No speed adjustment could be found that can contain the hit object.", nameof(hitObject)); target.Add(hitObject); } @@ -51,33 +54,34 @@ namespace osu.Game.Rulesets.Timing base.Add(speedAdjustment); } - protected override IComparer DepthComparer => new TimingSectionReverseStartTimeComparer(); + protected override IComparer DepthComparer => new SpeedAdjustmentContainerReverseStartTimeComparer(); /// - /// Finds the most applicable timing section that can contain a hit object. If the hit object occurs before the first (time-wise) - /// timing section, then the timing section returned is the first (time-wise) timing section. + /// 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 contain. - /// The last (time-wise) timing section which can contain . Null if no timing section exists. - private SpeedAdjustmentContainer timingSectionFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)) ?? Children.LastOrDefault(); + /// 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(); /// - /// Compares two timing sections by their start time, falling back to creation order if their start time is equal. - /// This will compare the two timing sections in reverse order. + /// Compares two speed adjustment containers by their control point start time, falling back to creation order + // if their control point start time is equal. This will compare the two speed adjustment containers in reverse order. /// - private class TimingSectionReverseStartTimeComparer : ReverseCreationOrderDepthComparer + private class SpeedAdjustmentContainerReverseStartTimeComparer : ReverseCreationOrderDepthComparer { public override int Compare(Drawable x, Drawable y) { - var timingChangeX = x as SpeedAdjustmentContainer; - var timingChangeY = y as SpeedAdjustmentContainer; + var speedAdjustmentX = x as SpeedAdjustmentContainer; + var speedAdjustmentY = y as SpeedAdjustmentContainer; // If either of the two drawables are not hit objects, fall back to the base comparer - if (timingChangeX?.MultiplierControlPoint == null || timingChangeY?.MultiplierControlPoint == null) + if (speedAdjustmentX?.MultiplierControlPoint == null || speedAdjustmentY?.MultiplierControlPoint == null) return base.Compare(x, y); // Compare by start time - int i = timingChangeY.MultiplierControlPoint.StartTime.CompareTo(timingChangeX.MultiplierControlPoint.StartTime); + int i = speedAdjustmentY.MultiplierControlPoint.StartTime.CompareTo(speedAdjustmentX.MultiplierControlPoint.StartTime); return i != 0 ? i : base.Compare(x, y); } diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index a6f94ccf6c..7021c1435b 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.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.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; @@ -12,18 +11,29 @@ using OpenTK; namespace osu.Game.Rulesets.Timing { /// - /// A container for hit objects which applies applies the speed adjustments defined by the properties - /// to its to affect the scroll speed. + /// 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 + /// /// public abstract class SpeedAdjustmentContainer : Container { private readonly Bindable visibleTimeRange = new Bindable(); + /// + /// Gets or sets the range of time that is visible by the length of this container. + /// public Bindable VisibleTimeRange { get { return visibleTimeRange; } set { visibleTimeRange.BindTo(value); } } + /// + /// The which provides the speed adjustments for this container. + /// public readonly MultiplierControlPoint MultiplierControlPoint; protected override Container Content => content; @@ -34,12 +44,14 @@ namespace osu.Game.Rulesets.Timing /// /// Creates a new . /// - /// The multiplier control point that provides the speed adjustments for this container. - /// The axes through which this drawable timing section scrolls through. + /// The which provides the speed adjustments for this container. + /// The axes through which the content of this container should scroll through. protected SpeedAdjustmentContainer(MultiplierControlPoint multiplierControlPoint, Axes scrollingAxes) { this.scrollingAxes = scrollingAxes; + RelativeSizeAxes = Axes.Both; + MultiplierControlPoint = multiplierControlPoint; } @@ -54,12 +66,6 @@ namespace osu.Game.Rulesets.Timing AddInternal(content = timingSection); } - public override Axes RelativeSizeAxes - { - get { return Axes.Both; } - set { throw new InvalidOperationException($"{nameof(SpeedAdjustmentContainer)} must always be relatively-sized."); } - } - protected override void Update() { float multiplier = (float)MultiplierControlPoint.Multiplier; @@ -77,7 +83,7 @@ namespace osu.Game.Rulesets.Timing /// /// Creates the container which handles the movement of a collection of hit objects. /// - /// The drawable timing section. + /// The . protected abstract DrawableTimingSection CreateTimingSection(); } } \ No newline at end of file diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 43c350184e..056ee2044f 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -120,6 +120,11 @@ namespace osu.Game.Rulesets.UI /// public Beatmap Beatmap; + /// + /// All the converted hit objects contained by this hit renderer. + /// + public override IEnumerable Objects => Beatmap.HitObjects; + /// /// The mods which are to be applied. /// @@ -206,7 +211,10 @@ namespace osu.Game.Rulesets.UI public sealed override bool ProvidingUserCursor => !HasReplayLoaded && Playfield.ProvidingUserCursor; - public override IEnumerable Objects => Beatmap.HitObjects; + /// + /// All the converted hit objects contained by this hit renderer. + /// + public new IEnumerable Objects => Beatmap.HitObjects; protected override bool AllObjectsJudged => drawableObjects.All(h => h.Judged);