Fix wrong clock being seeked when unpausing

This commit is contained in:
smoogipoo 2018-05-28 03:34:58 +09:00
parent 8ae2a3696f
commit 3abfd4711d
1 changed files with 13 additions and 8 deletions

View File

@ -44,13 +44,18 @@ public class PauseContainer : Container
public Action OnResume;
public Action OnPause;
private readonly IAdjustableClock adjustableClock;
private readonly FramedClock framedClock;
private readonly DecoupleableInterpolatingFramedClock decoupledClock;
public PauseContainer(FramedClock framedClock, IAdjustableClock adjustableClock)
/// <summary>
/// Creates a new <see cref="PauseContainer"/>.
/// </summary>
/// <param name="framedClock">The gameplay clock. This is the clock that will process frames.</param>
/// <param name="decoupledClock">The seekable clock. This is the clock that will be paused and resumed.</param>
public PauseContainer(FramedClock framedClock, DecoupleableInterpolatingFramedClock decoupledClock)
{
this.framedClock = framedClock;
this.adjustableClock = adjustableClock;
this.decoupledClock = decoupledClock;
RelativeSizeAxes = Axes.Both;
@ -80,7 +85,7 @@ public void Pause(bool force = false) => Schedule(() => // Scheduled to ensure a
if (IsPaused) return;
// stop the seekable clock (stops the audio eventually)
adjustableClock.Stop();
decoupledClock.Stop();
IsPaused = true;
OnPause?.Invoke();
@ -97,10 +102,10 @@ public void Resume()
IsResuming = false;
lastPauseActionTime = Time.Current;
// seek back to the time of the framed clock.
// this accounts for the audio clock potentially taking time to enter a completely stopped state.
adjustableClock.Seek(framedClock.CurrentTime);
adjustableClock.Start();
// Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time
// This accounts for the audio clock source potentially taking time to enter a completely stopped state
decoupledClock.Seek(decoupledClock.CurrentTime);
decoupledClock.Start();
OnResume?.Invoke();
pauseOverlay.Hide();