Merge branch 'simplify-shoc' into fix-scrolling-lifetime

# Conflicts:
#	osu.Game/Rulesets/UI/Scrolling/ScrollingHitObjectContainer.cs
This commit is contained in:
ekrctb 2021-05-31 16:50:47 +09:00
commit 948a14a627
1 changed files with 28 additions and 69 deletions

View File

@ -18,12 +18,7 @@ public class ScrollingHitObjectContainer : HitObjectContainer
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
/// <summary>
/// Hit objects which require lifetime computation in the next update call.
/// </summary>
private readonly HashSet<DrawableHitObject> toComputeLifetime = new HashSet<DrawableHitObject>();
/// <summary>
/// A set containing all <see cref="HitObjectContainer.AliveObjects"/> which have an up-to-date layout.
/// A set of top-level <see cref="DrawableHitObject"/>s which have an up-to-date layout.
/// </summary>
private readonly HashSet<DrawableHitObject> layoutComputed = new HashSet<DrawableHitObject>();
@ -54,7 +49,6 @@ public override void Clear()
{
base.Clear();
toComputeLifetime.Clear();
layoutComputed.Clear();
}
@ -83,7 +77,7 @@ public double TimeAtScreenSpacePosition(Vector2 screenSpacePosition)
flipPositionIfRequired(ref position);
return scrollingInfo.Algorithm.TimeAt(position, Time.Current, scrollingInfo.TimeRange.Value, getLength());
return scrollingInfo.Algorithm.TimeAt(position, Time.Current, scrollingInfo.TimeRange.Value, scrollLength);
}
/// <summary>
@ -91,7 +85,7 @@ public double TimeAtScreenSpacePosition(Vector2 screenSpacePosition)
/// </summary>
public Vector2 ScreenSpacePositionAtTime(double time)
{
var pos = scrollingInfo.Algorithm.PositionAt(time, Time.Current, scrollingInfo.TimeRange.Value, getLength());
var pos = scrollingInfo.Algorithm.PositionAt(time, Time.Current, scrollingInfo.TimeRange.Value, scrollLength);
flipPositionIfRequired(ref pos);
@ -106,7 +100,9 @@ public Vector2 ScreenSpacePositionAtTime(double time)
}
}
private float getLength()
private float scrollLength
{
get
{
switch (scrollingInfo.Direction.Value)
{
@ -118,6 +114,7 @@ private float getLength()
return DrawHeight;
}
}
}
private float getBreadth()
{
@ -150,51 +147,31 @@ private void flipPositionIfRequired(ref float position)
}
}
protected override void OnAdd(DrawableHitObject drawableHitObject) => onAddRecursive(drawableHitObject);
protected override void OnRemove(DrawableHitObject drawableHitObject) => onRemoveRecursive(drawableHitObject);
private void onAddRecursive(DrawableHitObject hitObject)
protected override void OnAdd(DrawableHitObject drawableHitObject)
{
invalidateHitObject(hitObject);
hitObject.DefaultsApplied += invalidateHitObject;
foreach (var nested in hitObject.NestedHitObjects)
onAddRecursive(nested);
invalidateHitObject(drawableHitObject);
drawableHitObject.DefaultsApplied += invalidateHitObject;
}
private void onRemoveRecursive(DrawableHitObject hitObject)
protected override void OnRemove(DrawableHitObject drawableHitObject)
{
toComputeLifetime.Remove(hitObject);
layoutComputed.Remove(hitObject);
layoutComputed.Remove(drawableHitObject);
hitObject.DefaultsApplied -= invalidateHitObject;
foreach (var nested in hitObject.NestedHitObjects)
onRemoveRecursive(nested);
drawableHitObject.DefaultsApplied -= invalidateHitObject;
}
/// <summary>
/// Make this <see cref="DrawableHitObject"/> lifetime and layout computed in next update.
/// </summary>
private void invalidateHitObject(DrawableHitObject hitObject)
{
// Lifetime computation is delayed until next update because
// when the hit object is not pooled this container is not loaded here and `scrollLength` cannot be computed.
toComputeLifetime.Add(hitObject);
hitObject.LifetimeStart = computeOriginAdjustedLifetimeStart(hitObject);
layoutComputed.Remove(hitObject);
}
private float scrollLength;
protected override void Update()
{
base.Update();
if (!layoutCache.IsValid)
{
toComputeLifetime.Clear();
if (layoutCache.IsValid) return;
layoutComputed.Clear();
// Reset lifetime to the conservative estimation.
@ -204,27 +181,9 @@ protected override void Update()
scrollingInfo.Algorithm.Reset();
switch (direction.Value)
{
case ScrollingDirection.Up:
case ScrollingDirection.Down:
scrollLength = DrawSize.Y;
break;
default:
scrollLength = DrawSize.X;
break;
}
layoutCache.Validate();
}
foreach (var hitObject in toComputeLifetime)
hitObject.LifetimeStart = computeOriginAdjustedLifetimeStart(hitObject);
toComputeLifetime.Clear();
}
protected override void UpdateAfterChildrenLife()
{
base.UpdateAfterChildrenLife();