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 @@ public class TestCaseScrollingHitObjects : OsuTestCase
public TestCaseScrollingHitObjects()
{
OsuSpriteText timeRangeText;
ScrollingPlayfield<HitObject, Judgement>.ScrollingHitObjectContainer scrollingHitObjectContainer;
timeRangeBindable = new BindableDouble(2000)
{
@ -71,12 +70,6 @@ public TestCaseScrollingHitObjects()
RelativeSizeAxes = Axes.Both,
Alpha = 0.25f
},
scrollingHitObjectContainer = new ScrollingPlayfield<HitObject, Judgement>.ScrollingHitObjectContainer(Axes.Y)
{
RelativeSizeAxes = Axes.Both,
VisibleTimeRange = timeRangeBindable,
Masking = true,
},
new OsuSpriteText
{
Text = "t minus 0",
@ -111,17 +104,12 @@ public TestCaseScrollingHitObjects()
});
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 @@ protected override void Update()
}
}
private class TestDrawableHitObject : DrawableHitObject<HitObject, Judgement>, IScrollingHitObject
private class TestDrawableHitObject : DrawableScrollingHitObject<HitObject, Judgement>
{
private readonly Box background;
private const float height = 14;
public BindableDouble LifetimeOffset { get; } = new BindableDouble();
public TestDrawableHitObject(HitObject hitObject)
: base(hitObject)
{

View File

@ -27,9 +27,6 @@ protected DrawableManiaHitObject(TObject hitObject, Bindable<Key> key = null)
if (key != null)
Key.BindTo(key);
RelativePositionAxes = Axes.Y;
Y = (float)HitObject.StartTime;
}
public override Color4 AccentColour

View File

@ -192,8 +192,6 @@ public Color4 AccentColour
}
}
public void Add(SpeedAdjustmentContainer speedAdjustment) => HitObjects.AddSpeedAdjustment(speedAdjustment);
/// <summary>
/// Adds a DrawableHitObject to this Playfield.
/// </summary>

View File

@ -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 @@ public abstract class DrawableScrollingHitObject<TObject, TJudgement> : Drawable
{
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)
{

View File

@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary>
/// An interface that exposes properties required for scrolling hit objects to be properly displayed.
/// </summary>
public interface IScrollingHitObject : IDrawable
internal interface IScrollingHitObject : IDrawable
{
/// <summary>
/// Time offset before the hit object start time at which this <see cref="IScrollingHitObject"/> becomes visible and the time offset
@ -21,5 +21,11 @@ public interface IScrollingHitObject : IDrawable
/// </para>
/// </summary>
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 @@ public BindableDouble VisibleTimeRange
/// </summary>
internal MultiplierControlPoint ControlPoint;
private Cached<double> durationBacking;
protected override int Compare(Drawable x, Drawable y)
{
var xHitObject = x as DrawableHitObject;
@ -93,8 +95,6 @@ public override void InvalidateFromChild(Invalidation invalidation)
base.InvalidateFromChild(invalidation);
}
private Cached<double> durationBacking;
private double computeDuration()
{
if (!Children.Any())

View File

@ -37,7 +37,6 @@ public Bindable<double> VisibleTimeRange
/// <summary>
/// Axes which the content of this container will scroll through.
/// </summary>
/// <returns></returns>
public Axes ScrollingAxes { get; internal set; }
public readonly MultiplierControlPoint ControlPoint;
@ -83,7 +82,12 @@ protected override void Update()
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);
}

View File

@ -41,7 +41,7 @@ public BindableDouble VisibleTimeRange
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 @@ private double valueAt(double time)
/// necessary <see cref="VisibleTimeRange"/> for the contained <see cref="SpeedAdjustmentContainer"/>s.
/// </para>
/// </summary>
public class ScrollingHitObjectContainer : HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
internal class ScrollingHitObjectContainer : HitObjectContainer<DrawableHitObject<TObject, TJudgement>>
{
private readonly BindableDouble visibleTimeRange = new BindableDouble { Default = 1000 };
/// <summary>