1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 03:22:55 +08:00

Reduce implementation overhead in actually positioning hitobjects and making them scroll.

This commit is contained in:
smoogipooo 2017-08-07 16:02:38 +09:00
parent 068dfcb19a
commit a3efca9c35
8 changed files with 32 additions and 27 deletions

View File

@ -31,7 +31,6 @@ namespace osu.Desktop.Tests.Visual
public TestCaseScrollingHitObjects() public TestCaseScrollingHitObjects()
{ {
OsuSpriteText timeRangeText; OsuSpriteText timeRangeText;
ScrollingPlayfield<HitObject, Judgement>.ScrollingHitObjectContainer scrollingHitObjectContainer;
timeRangeBindable = new BindableDouble(2000) timeRangeBindable = new BindableDouble(2000)
{ {
@ -71,12 +70,6 @@ namespace osu.Desktop.Tests.Visual
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0.25f Alpha = 0.25f
}, },
scrollingHitObjectContainer = new ScrollingPlayfield<HitObject, Judgement>.ScrollingHitObjectContainer(Axes.Y)
{
RelativeSizeAxes = Axes.Both,
VisibleTimeRange = timeRangeBindable,
Masking = true,
},
new OsuSpriteText new OsuSpriteText
{ {
Text = "t minus 0", Text = "t minus 0",
@ -111,17 +104,12 @@ namespace osu.Desktop.Tests.Visual
}); });
timeRangeBindable.TriggerChange(); 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() protected override void Update()
{ {
base.Update(); base.Update();
topTime.Text = Time.Current.ToString("#,#");
bottomTime.Text = (Time.Current + timeRangeBindable.Value).ToString("#,#"); bottomTime.Text = (Time.Current + timeRangeBindable.Value).ToString("#,#");
} }
@ -154,13 +142,11 @@ namespace osu.Desktop.Tests.Visual
} }
} }
private class TestDrawableHitObject : DrawableHitObject<HitObject, Judgement>, IScrollingHitObject private class TestDrawableHitObject : DrawableScrollingHitObject<HitObject, Judgement>
{ {
private readonly Box background; private readonly Box background;
private const float height = 14; private const float height = 14;
public BindableDouble LifetimeOffset { get; } = new BindableDouble();
public TestDrawableHitObject(HitObject hitObject) public TestDrawableHitObject(HitObject hitObject)
: base(hitObject) : base(hitObject)
{ {

View File

@ -27,9 +27,6 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
if (key != null) if (key != null)
Key.BindTo(key); Key.BindTo(key);
RelativePositionAxes = Axes.Y;
Y = (float)HitObject.StartTime;
} }
public override Color4 AccentColour public override Color4 AccentColour

View File

@ -192,8 +192,6 @@ namespace osu.Game.Rulesets.Mania.UI
} }
} }
public void Add(SpeedAdjustmentContainer speedAdjustment) => HitObjects.AddSpeedAdjustment(speedAdjustment);
/// <summary> /// <summary>
/// Adds a DrawableHitObject to this Playfield. /// Adds a DrawableHitObject to this Playfield.
/// </summary> /// </summary>

View File

@ -3,6 +3,7 @@
using System; using System;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
@ -17,6 +18,19 @@ namespace osu.Game.Rulesets.Objects.Drawables
{ {
public BindableDouble LifetimeOffset { get; } = new BindableDouble(); 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) protected DrawableScrollingHitObject(TObject hitObject)
: base(hitObject) : base(hitObject)
{ {

View File

@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary> /// <summary>
/// An interface that exposes properties required for scrolling hit objects to be properly displayed. /// An interface that exposes properties required for scrolling hit objects to be properly displayed.
/// </summary> /// </summary>
public interface IScrollingHitObject : IDrawable internal interface IScrollingHitObject : IDrawable
{ {
/// <summary> /// <summary>
/// Time offset before the hit object start time at which this <see cref="IScrollingHitObject"/> becomes visible and the time offset /// Time offset before the hit object start time at which this <see cref="IScrollingHitObject"/> becomes visible and the time offset
@ -21,5 +21,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </para> /// </para>
/// </summary> /// </summary>
BindableDouble LifetimeOffset { get; } BindableDouble LifetimeOffset { get; }
/// <summary>
/// Axes which this <see cref="IScrollingHitObject"/> will scroll through.
/// This is set by the container which this scrolls through.
/// </summary>
Axes ScrollingAxes { set; }
} }
} }

View File

@ -53,6 +53,8 @@ namespace osu.Game.Rulesets.Timing
/// </summary> /// </summary>
internal MultiplierControlPoint ControlPoint; internal MultiplierControlPoint ControlPoint;
private Cached<double> durationBacking;
protected override int Compare(Drawable x, Drawable y) protected override int Compare(Drawable x, Drawable y)
{ {
var xHitObject = x as DrawableHitObject; var xHitObject = x as DrawableHitObject;
@ -93,8 +95,6 @@ namespace osu.Game.Rulesets.Timing
base.InvalidateFromChild(invalidation); base.InvalidateFromChild(invalidation);
} }
private Cached<double> durationBacking;
private double computeDuration() private double computeDuration()
{ {
if (!Children.Any()) if (!Children.Any())

View File

@ -37,7 +37,6 @@ namespace osu.Game.Rulesets.Timing
/// <summary> /// <summary>
/// Axes which the content of this container will scroll through. /// Axes which the content of this container will scroll through.
/// </summary> /// </summary>
/// <returns></returns>
public Axes ScrollingAxes { get; internal set; } public Axes ScrollingAxes { get; internal set; }
public readonly MultiplierControlPoint ControlPoint; public readonly MultiplierControlPoint ControlPoint;
@ -83,7 +82,12 @@ namespace osu.Game.Rulesets.Timing
public override void Add(DrawableHitObject drawable) public override void Add(DrawableHitObject drawable)
{ {
var scrollingHitObject = drawable as IScrollingHitObject; var scrollingHitObject = drawable as IScrollingHitObject;
scrollingHitObject?.LifetimeOffset.BindTo(VisibleTimeRange);
if (scrollingHitObject != null)
{
scrollingHitObject.LifetimeOffset.BindTo(VisibleTimeRange);
scrollingHitObject.ScrollingAxes = ScrollingAxes;
}
base.Add(drawable); base.Add(drawable);
} }

View File

@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.UI
set { visibleTimeRange.BindTo(value); } set { visibleTimeRange.BindTo(value); }
} }
public new readonly ScrollingHitObjectContainer HitObjects; internal new readonly ScrollingHitObjectContainer HitObjects;
protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null) protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null)
: base(customWidth) : base(customWidth)
@ -112,7 +112,7 @@ namespace osu.Game.Rulesets.UI
/// necessary <see cref="VisibleTimeRange"/> for the contained <see cref="SpeedAdjustmentContainer"/>s. /// necessary <see cref="VisibleTimeRange"/> for the contained <see cref="SpeedAdjustmentContainer"/>s.
/// </para> /// </para>
/// </summary> /// </summary>
public class ScrollingHitObjectContainer : HitObjectContainer<DrawableHitObject<TObject, TJudgement>> internal class ScrollingHitObjectContainer : HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
{ {
private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 }; private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 };
/// <summary> /// <summary>