Merge branch 'master' into autoplay-pause-support

This commit is contained in:
Dan Balasescu
2021-06-03 13:26:00 +09:00
committed by GitHub
75 changed files with 391 additions and 344 deletions

View File

@ -35,11 +35,11 @@ namespace osu.Game.Rulesets.Objects
HitObject = hitObject;
startTimeBindable.BindTo(HitObject.StartTimeBindable);
startTimeBindable.BindValueChanged(_ => setInitialLifetime(), true);
startTimeBindable.BindValueChanged(_ => SetInitialLifetime(), true);
// Subscribe to this event before the DrawableHitObject so that the local callback is invoked before the entry is re-applied as a result of DefaultsApplied.
// This way, the DrawableHitObject can use OnApply() to overwrite the LifetimeStart that was set inside setInitialLifetime().
HitObject.DefaultsApplied += _ => setInitialLifetime();
HitObject.DefaultsApplied += _ => SetInitialLifetime();
}
// The lifetime, as set by the hitobject.
@ -94,6 +94,6 @@ namespace osu.Game.Rulesets.Objects
/// <summary>
/// Set <see cref="LifetimeEntry.LifetimeStart"/> using <see cref="InitialLifetimeOffset"/>.
/// </summary>
private void setInitialLifetime() => LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
internal void SetInitialLifetime() => LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
}
}

View File

@ -3,6 +3,7 @@
#nullable enable
using System;
using System.Diagnostics;
using osu.Framework.Graphics.Performance;
using osu.Framework.Graphics.Pooling;
@ -26,14 +27,13 @@ namespace osu.Game.Rulesets.Objects.Pooling
/// </summary>
protected bool HasEntryApplied { get; private set; }
// Drawable's lifetime gets out of sync with entry's lifetime if entry's lifetime is modified.
// We cannot delegate getter to `Entry.LifetimeStart` because it is incompatible with `LifetimeManagementContainer` due to how lifetime change is detected.
public override double LifetimeStart
{
get => base.LifetimeStart;
set
{
base.LifetimeStart = value;
if (Entry == null && LifetimeStart != value)
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
if (Entry != null)
Entry.LifetimeStart = value;
@ -45,7 +45,8 @@ namespace osu.Game.Rulesets.Objects.Pooling
get => base.LifetimeEnd;
set
{
base.LifetimeEnd = value;
if (Entry == null && LifetimeEnd != value)
throw new InvalidOperationException($"Cannot modify lifetime of {nameof(PoolableDrawableWithLifetime<TEntry>)} when entry is not set");
if (Entry != null)
Entry.LifetimeEnd = value;
@ -79,9 +80,8 @@ namespace osu.Game.Rulesets.Objects.Pooling
free();
Entry = entry;
base.LifetimeStart = entry.LifetimeStart;
base.LifetimeEnd = entry.LifetimeEnd;
entry.LifetimeChanged += setLifetimeFromEntry;
setLifetimeFromEntry(entry);
OnApply(entry);
@ -117,11 +117,19 @@ namespace osu.Game.Rulesets.Objects.Pooling
OnFree(Entry);
Entry.LifetimeChanged -= setLifetimeFromEntry;
Entry = null;
base.LifetimeStart = double.MinValue;
base.LifetimeEnd = double.MaxValue;
HasEntryApplied = false;
}
private void setLifetimeFromEntry(LifetimeEntry entry)
{
Debug.Assert(entry == Entry);
base.LifetimeStart = entry.LifetimeStart;
base.LifetimeEnd = entry.LifetimeEnd;
}
}
}

View File

@ -172,11 +172,12 @@ namespace osu.Game.Rulesets.UI.Scrolling
if (layoutCache.IsValid) return;
foreach (var hitObject in Objects)
{
if (hitObject.HitObject != null)
invalidateHitObject(hitObject);
}
layoutComputed.Clear();
// 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();
scrollingInfo.Algorithm.Reset();