mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Merge branch 'simplify-shoc' into fix-scrolling-lifetime
# Conflicts: # osu.Game/Rulesets/UI/Scrolling/ScrollingHitObjectContainer.cs
This commit is contained in:
@ -18,12 +18,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
private readonly IBindable<ScrollingDirection> direction = new Bindable<ScrollingDirection>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Hit objects which require lifetime computation in the next update call.
|
/// A set of top-level <see cref="DrawableHitObject"/>s which have an up-to-date layout.
|
||||||
/// </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.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly HashSet<DrawableHitObject> layoutComputed = new HashSet<DrawableHitObject>();
|
private readonly HashSet<DrawableHitObject> layoutComputed = new HashSet<DrawableHitObject>();
|
||||||
|
|
||||||
@ -54,7 +49,6 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
{
|
{
|
||||||
base.Clear();
|
base.Clear();
|
||||||
|
|
||||||
toComputeLifetime.Clear();
|
|
||||||
layoutComputed.Clear();
|
layoutComputed.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +77,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
|
|
||||||
flipPositionIfRequired(ref position);
|
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>
|
/// <summary>
|
||||||
@ -91,7 +85,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2 ScreenSpacePositionAtTime(double time)
|
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);
|
flipPositionIfRequired(ref pos);
|
||||||
|
|
||||||
@ -106,16 +100,19 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getLength()
|
private float scrollLength
|
||||||
{
|
{
|
||||||
switch (scrollingInfo.Direction.Value)
|
get
|
||||||
{
|
{
|
||||||
case ScrollingDirection.Left:
|
switch (scrollingInfo.Direction.Value)
|
||||||
case ScrollingDirection.Right:
|
{
|
||||||
return DrawWidth;
|
case ScrollingDirection.Left:
|
||||||
|
case ScrollingDirection.Right:
|
||||||
|
return DrawWidth;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return DrawHeight;
|
return DrawHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,79 +147,41 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAdd(DrawableHitObject drawableHitObject) => onAddRecursive(drawableHitObject);
|
protected override void OnAdd(DrawableHitObject drawableHitObject)
|
||||||
|
|
||||||
protected override void OnRemove(DrawableHitObject drawableHitObject) => onRemoveRecursive(drawableHitObject);
|
|
||||||
|
|
||||||
private void onAddRecursive(DrawableHitObject hitObject)
|
|
||||||
{
|
{
|
||||||
invalidateHitObject(hitObject);
|
invalidateHitObject(drawableHitObject);
|
||||||
|
drawableHitObject.DefaultsApplied += invalidateHitObject;
|
||||||
hitObject.DefaultsApplied += invalidateHitObject;
|
|
||||||
|
|
||||||
foreach (var nested in hitObject.NestedHitObjects)
|
|
||||||
onAddRecursive(nested);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRemoveRecursive(DrawableHitObject hitObject)
|
protected override void OnRemove(DrawableHitObject drawableHitObject)
|
||||||
{
|
{
|
||||||
toComputeLifetime.Remove(hitObject);
|
layoutComputed.Remove(drawableHitObject);
|
||||||
layoutComputed.Remove(hitObject);
|
|
||||||
|
|
||||||
hitObject.DefaultsApplied -= invalidateHitObject;
|
drawableHitObject.DefaultsApplied -= invalidateHitObject;
|
||||||
|
|
||||||
foreach (var nested in hitObject.NestedHitObjects)
|
|
||||||
onRemoveRecursive(nested);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Make this <see cref="DrawableHitObject"/> lifetime and layout computed in next update.
|
|
||||||
/// </summary>
|
|
||||||
private void invalidateHitObject(DrawableHitObject hitObject)
|
private void invalidateHitObject(DrawableHitObject hitObject)
|
||||||
{
|
{
|
||||||
// Lifetime computation is delayed until next update because
|
hitObject.LifetimeStart = computeOriginAdjustedLifetimeStart(hitObject);
|
||||||
// when the hit object is not pooled this container is not loaded here and `scrollLength` cannot be computed.
|
|
||||||
toComputeLifetime.Add(hitObject);
|
|
||||||
layoutComputed.Remove(hitObject);
|
layoutComputed.Remove(hitObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float scrollLength;
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (!layoutCache.IsValid)
|
if (layoutCache.IsValid) return;
|
||||||
{
|
|
||||||
toComputeLifetime.Clear();
|
|
||||||
layoutComputed.Clear();
|
|
||||||
|
|
||||||
// Reset lifetime to the conservative estimation.
|
layoutComputed.Clear();
|
||||||
// If a drawable becomes alive by this lifetime, its lifetime will be updated to a more precise lifetime in the next update.
|
|
||||||
foreach (var entry in Entries)
|
|
||||||
entry.SetInitialLifetime();
|
|
||||||
|
|
||||||
scrollingInfo.Algorithm.Reset();
|
// Reset lifetime to the conservative estimation.
|
||||||
|
// If a drawable becomes alive by this lifetime, its lifetime will be updated to a more precise lifetime in the next update.
|
||||||
|
foreach (var entry in Entries)
|
||||||
|
entry.SetInitialLifetime();
|
||||||
|
|
||||||
switch (direction.Value)
|
scrollingInfo.Algorithm.Reset();
|
||||||
{
|
|
||||||
case ScrollingDirection.Up:
|
|
||||||
case ScrollingDirection.Down:
|
|
||||||
scrollLength = DrawSize.Y;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
layoutCache.Validate();
|
||||||
scrollLength = DrawSize.X;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
layoutCache.Validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var hitObject in toComputeLifetime)
|
|
||||||
hitObject.LifetimeStart = computeOriginAdjustedLifetimeStart(hitObject);
|
|
||||||
|
|
||||||
toComputeLifetime.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildrenLife()
|
protected override void UpdateAfterChildrenLife()
|
||||||
|
Reference in New Issue
Block a user