1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 05:13:22 +08:00

Fix TrackVirtualManual not respecting rate adjustments

This commit is contained in:
smoogipoo 2020-03-03 12:59:41 +09:00
parent 1e26df64b6
commit a1aecd4c39

View File

@ -229,17 +229,10 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
public class TrackVirtualManual : Track public class TrackVirtualManual : Track
{ {
private readonly StopwatchClock stopwatchClock = new StopwatchClock();
private readonly IFrameBasedClock referenceClock; private readonly IFrameBasedClock referenceClock;
private readonly ManualClock clock = new ManualClock();
private bool running;
/// <summary>
/// Local offset added to the reference clock to resolve correct time.
/// </summary>
private double offset;
public TrackVirtualManual(IFrameBasedClock referenceClock) public TrackVirtualManual(IFrameBasedClock referenceClock)
{ {
this.referenceClock = referenceClock; this.referenceClock = referenceClock;
@ -248,60 +241,32 @@ namespace osu.Game.Tests.Visual
public override bool Seek(double seek) public override bool Seek(double seek)
{ {
offset = Math.Clamp(seek, 0, Length); var offset = Math.Clamp(seek, 0, Length);
lastReferenceTime = null;
stopwatchClock.Seek(offset);
return offset == seek; return offset == seek;
} }
public override void Start() public override void Start() => stopwatchClock.Start();
{
running = true;
}
public override void Reset() public override void Reset()
{ {
Seek(0); stopwatchClock.Seek(0);
base.Reset(); base.Reset();
} }
public override void Stop() public override void Stop() => stopwatchClock.Stop();
{
if (running)
{
running = false;
// on stopping, the current value should be transferred out of the clock, as we can no longer rely on
// the referenceClock (which will still be counting time).
offset = clock.CurrentTime;
lastReferenceTime = null;
}
}
public override bool IsRunning => running; public override bool IsRunning => stopwatchClock.IsRunning;
private double? lastReferenceTime; public override double CurrentTime => stopwatchClock.CurrentTime;
public override double CurrentTime => clock.CurrentTime;
protected override void UpdateState() protected override void UpdateState()
{ {
base.UpdateState(); base.UpdateState();
if (running) stopwatchClock.Rate = Rate * referenceClock.Rate;
{
double refTime = referenceClock.CurrentTime;
if (!lastReferenceTime.HasValue)
{
// if the clock just started running, the current value should be transferred to the offset
// (to zero the progression of time).
offset -= refTime;
}
lastReferenceTime = refTime;
}
clock.CurrentTime = Math.Min((lastReferenceTime ?? 0) + offset, Length);
if (CurrentTime >= Length) if (CurrentTime >= Length)
{ {