2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-28 22:59:08 +00:00
|
|
|
|
using System;
|
2017-09-08 16:00:17 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-07 21:55:05 +00:00
|
|
|
|
namespace osu.Game.Storyboards
|
|
|
|
|
{
|
|
|
|
|
public class CommandLoop : CommandTimelineGroup
|
|
|
|
|
{
|
2017-09-08 10:11:57 +00:00
|
|
|
|
public double LoopStartTime;
|
2021-10-01 09:24:46 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The total number of times this loop is played back. Always greater than zero.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly int TotalIterations;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-16 11:15:16 +00:00
|
|
|
|
public override double StartTime => LoopStartTime + CommandsStartTime;
|
2023-02-06 07:39:44 +00:00
|
|
|
|
|
|
|
|
|
public override double EndTime =>
|
|
|
|
|
// In an ideal world, we would multiply the command duration by TotalIterations here.
|
|
|
|
|
// Unfortunately this would clash with how stable handled end times, and results in some storyboards playing outro
|
|
|
|
|
// sequences for minutes or hours.
|
|
|
|
|
StartTime + CommandsDuration;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-01 09:24:46 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Construct a new command loop.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="startTime">The start time of the loop.</param>
|
|
|
|
|
/// <param name="repeatCount">The number of times the loop should repeat. Should be greater than zero. Zero means a single playback.</param>
|
|
|
|
|
public CommandLoop(double startTime, int repeatCount)
|
2017-09-07 21:55:05 +00:00
|
|
|
|
{
|
2021-10-01 09:24:46 +00:00
|
|
|
|
if (repeatCount < 0) throw new ArgumentException("Repeat count must be zero or above.", nameof(repeatCount));
|
|
|
|
|
|
2017-09-08 10:11:57 +00:00
|
|
|
|
LoopStartTime = startTime;
|
2021-10-01 09:24:46 +00:00
|
|
|
|
TotalIterations = repeatCount + 1;
|
2017-09-07 21:55:05 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-08 16:00:17 +00:00
|
|
|
|
public override IEnumerable<CommandTimeline<T>.TypedCommand> GetCommands<T>(CommandTimelineSelector<T> timelineSelector, double offset = 0)
|
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
for (int loop = 0; loop < TotalIterations; loop++)
|
2017-09-08 16:00:17 +00:00
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double loopOffset = LoopStartTime + loop * CommandsDuration;
|
2017-09-08 16:00:17 +00:00
|
|
|
|
foreach (var command in base.GetCommands(timelineSelector, offset + loopOffset))
|
|
|
|
|
yield return command;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-07 21:55:05 +00:00
|
|
|
|
public override string ToString()
|
2021-10-01 09:24:46 +00:00
|
|
|
|
=> $"{LoopStartTime} x{TotalIterations}";
|
2017-09-07 21:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|