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

Track time in a simpler way in TrackVirtualManual

This commit is contained in:
Dean Herbert 2020-03-06 01:28:59 +09:00
parent 583e2c3f4a
commit e3509c742c

View File

@ -229,10 +229,10 @@ namespace osu.Game.Tests.Visual
/// </summary>
public class TrackVirtualManual : Track
{
private readonly StopwatchClock stopwatchClock = new StopwatchClock();
private readonly IFrameBasedClock referenceClock;
private bool running;
public TrackVirtualManual(IFrameBasedClock referenceClock)
{
this.referenceClock = referenceClock;
@ -241,32 +241,55 @@ namespace osu.Game.Tests.Visual
public override bool Seek(double seek)
{
var offset = Math.Clamp(seek, 0, Length);
accumulated = Math.Min(seek, Length);
lastReferenceTime = null;
stopwatchClock.Seek(offset);
return offset == seek;
return accumulated == seek;
}
public override void Start() => stopwatchClock.Start();
public override void Start()
{
running = true;
}
public override void Reset()
{
stopwatchClock.Seek(0);
Seek(0);
base.Reset();
}
public override void Stop() => stopwatchClock.Stop();
public override void Stop()
{
if (running)
{
running = false;
lastReferenceTime = null;
}
}
public override bool IsRunning => stopwatchClock.IsRunning;
public override bool IsRunning => running;
public override double CurrentTime => stopwatchClock.CurrentTime;
private double? lastReferenceTime;
private double accumulated;
public override double CurrentTime => Math.Min(accumulated, Length);
protected override void UpdateState()
{
base.UpdateState();
stopwatchClock.Rate = Rate * referenceClock.Rate;
if (running)
{
double refTime = referenceClock.CurrentTime;
if (lastReferenceTime.HasValue)
accumulated += (refTime - lastReferenceTime.Value) * Rate;
lastReferenceTime = refTime;
}
Console.WriteLine($"t={CurrentTime}");
if (CurrentTime >= Length)
{