Add second definition of EndTime for storyboard elements to account for loops in lifetime

This commit is contained in:
Dean Herbert 2023-04-25 15:22:11 +09:00
parent dce0c5fac8
commit e330052852
4 changed files with 25 additions and 1 deletions

View File

@ -110,7 +110,9 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(2000, background.Elements[0].StartTime);
Assert.AreEqual(2000, (background.Elements[0] as StoryboardAnimation)?.EarliestTransformTime);
Assert.AreEqual(12000, (background.Elements[0] as StoryboardAnimation)?.GetEndTime());
Assert.AreEqual(3000, (background.Elements[0] as StoryboardAnimation)?.GetEndTime());
Assert.AreEqual(12000, (background.Elements[0] as StoryboardAnimation)?.EndTimeForDisplay);
}
}

View File

@ -311,6 +311,7 @@ namespace osu.Game.Tests.Visual.Background
public bool IsDrawable => true;
public double StartTime => double.MinValue;
public double EndTime => double.MaxValue;
public double EndTimeForDisplay => double.MaxValue;
public Drawable CreateDrawable() => new DrawableTestStoryboardElement();
}

View File

@ -12,9 +12,17 @@ namespace osu.Game.Storyboards
{
/// <summary>
/// The time at which the <see cref="IStoryboardElement"/> ends.
/// This is consumed to extend the length of a storyboard to ensure all visuals are played to completion.
/// </summary>
double EndTime { get; }
/// <summary>
/// The time this element displays until.
/// This is used for lifetime purposes, and includes long playing animations which don't necessarily extend
/// a storyboard's play time.
/// </summary>
double EndTimeForDisplay { get; }
/// <summary>
/// The duration of the StoryboardElement.
/// </summary>

View File

@ -81,6 +81,19 @@ namespace osu.Game.Storyboards
}
}
public double EndTimeForDisplay
{
get
{
double latestEndTime = TimelineGroup.EndTime;
foreach (var l in loops)
latestEndTime = Math.Max(latestEndTime, l.StartTime + l.CommandsDuration * l.TotalIterations);
return latestEndTime;
}
}
public bool HasCommands => TimelineGroup.HasCommands || loops.Any(l => l.HasCommands);
private delegate void DrawablePropertyInitializer<in T>(Drawable drawable, T value);