1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Cache last event time value to avoid super expensive LINQ

This commit is contained in:
Dean Herbert 2021-05-04 16:48:13 +09:00
parent b380be7169
commit 18779b1d1e

View File

@ -20,6 +20,13 @@ namespace osu.Game.Storyboards.Drawables
[Cached]
public Storyboard Storyboard { get; }
/// <summary>
/// Whether the storyboard is considered finished.
/// </summary>
public IBindable<bool> HasStoryboardEnded => hasStoryboardEnded;
private readonly BindableBool hasStoryboardEnded = new BindableBool();
protected override Container<DrawableStoryboardLayer> Content { get; }
protected override Vector2 DrawScale => new Vector2(Parent.DrawHeight / 480);
@ -40,6 +47,8 @@ namespace osu.Game.Storyboards.Drawables
public override bool RemoveCompletedTransforms => false;
private double? lastEventEndTime;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
@ -74,6 +83,14 @@ namespace osu.Game.Storyboards.Drawables
Add(layer.CreateDrawable());
}
lastEventEndTime = Storyboard.LatestEventTime;
}
protected override void Update()
{
base.Update();
hasStoryboardEnded.Value = lastEventEndTime == null || Time.Current >= lastEventEndTime;
}
public DrawableStoryboardLayer OverlayLayer => Children.Single(layer => layer.Name == "Overlay");
@ -83,25 +100,5 @@ namespace osu.Game.Storyboards.Drawables
foreach (var layer in Children)
layer.Enabled = passing ? layer.Layer.VisibleWhenPassing : layer.Layer.VisibleWhenFailing;
}
protected override void Update()
{
base.Update();
updateHasStoryboardEnded();
}
/// <summary>
/// Whether the storyboard is considered finished.
/// </summary>
public IBindable<bool> HasStoryboardEnded => hasStoryboardEnded;
private readonly BindableBool hasStoryboardEnded = new BindableBool();
private void updateHasStoryboardEnded()
{
hasStoryboardEnded.Value =
Storyboard.LatestEventTime == null ||
Time.Current >= Storyboard.LatestEventTime;
}
}
}