Refactor pause logic so GameplayClockContainer is in control

This commit is contained in:
Dean Herbert
2019-03-16 14:20:10 +09:00
parent 15dd132c92
commit 465c95e952
3 changed files with 33 additions and 27 deletions

View File

@ -118,11 +118,16 @@ namespace osu.Game.Screens.Play
// This accounts for the audio clock source potentially taking time to enter a completely stopped state // This accounts for the audio clock source potentially taking time to enter a completely stopped state
adjustableClock.Seek(adjustableClock.CurrentTime); adjustableClock.Seek(adjustableClock.CurrentTime);
adjustableClock.Start(); adjustableClock.Start();
IsPaused.Value = false;
} }
public void Seek(double time) => adjustableClock.Seek(time); public void Seek(double time) => adjustableClock.Seek(time);
public void Stop() => adjustableClock.Stop(); public void Stop()
{
adjustableClock.Stop();
IsPaused.Value = true;
}
public void ResetLocalAdjustments() public void ResetLocalAdjustments()
{ {

View File

@ -41,8 +41,8 @@ namespace osu.Game.Screens.Play
public Action OnRetry; public Action OnRetry;
public Action OnQuit; public Action OnQuit;
public Action Stop; public Action RequestPause;
public Action Start; public Action<Action> RequestResume;
/// <summary> /// <summary>
/// Creates a new <see cref="PausableGameplayContainer"/>. /// Creates a new <see cref="PausableGameplayContainer"/>.
@ -70,15 +70,12 @@ namespace osu.Game.Screens.Play
}; };
} }
public void Pause(bool force = false) => Schedule(() => // Scheduled to ensure a stable position in execution order, no matter how it was called. public void Pause() => Schedule(() => // Scheduled to ensure a stable position in execution order, no matter how it was called.
{ {
if (!CanPause && !force) return; if (!CanPause) return;
if (IsPaused.Value) return;
// stop the seekable clock (stops the audio eventually) // stop the seekable clock (stops the audio eventually)
Stop?.Invoke(); RequestPause?.Invoke();
IsPaused.Value = true;
pauseOverlay.Show(); pauseOverlay.Show();
@ -89,14 +86,13 @@ namespace osu.Game.Screens.Play
{ {
if (!IsPaused.Value) return; if (!IsPaused.Value) return;
IsResuming = false;
lastPauseActionTime = Time.Current;
IsPaused.Value = false;
Start?.Invoke();
pauseOverlay.Hide(); pauseOverlay.Hide();
RequestResume?.Invoke(() =>
{
IsResuming = false;
lastPauseActionTime = Time.Current;
});
} }
private OsuGameBase game; private OsuGameBase game;

View File

@ -111,10 +111,14 @@ namespace osu.Game.Screens.Play
Retries = RestartCount, Retries = RestartCount,
OnRetry = restart, OnRetry = restart,
OnQuit = performUserRequestedExit, OnQuit = performUserRequestedExit,
Start = gameplayClockContainer.Start, RequestResume = completion =>
Stop = gameplayClockContainer.Stop, {
gameplayClockContainer.Start();
completion();
},
RequestPause = gameplayClockContainer.Stop,
IsPaused = { BindTarget = gameplayClockContainer.IsPaused }, IsPaused = { BindTarget = gameplayClockContainer.IsPaused },
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value, CheckCanPause = () => CanPause,
Children = new[] Children = new[]
{ {
StoryboardContainer = CreateStoryboardContainer(), StoryboardContainer = CreateStoryboardContainer(),
@ -337,6 +341,9 @@ namespace osu.Game.Screens.Play
base.OnSuspending(next); base.OnSuspending(next);
} }
public bool CanPause => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded.Value
&& (PausableGameplayContainer?.IsPaused.Value == false || PausableGameplayContainer?.IsResuming == true);
public override bool OnExiting(IScreen next) public override bool OnExiting(IScreen next)
{ {
if (onCompletionEvent != null) if (onCompletionEvent != null)
@ -346,18 +353,16 @@ namespace osu.Game.Screens.Play
return true; return true;
} }
if ((!AllowPause || HasFailed || !ValidForResume || PausableGameplayContainer?.IsPaused.Value != false || RulesetContainer?.HasReplayLoaded.Value != false) && (!PausableGameplayContainer?.IsResuming ?? true)) if (LoadedBeatmapSuccessfully && CanPause)
{ {
gameplayClockContainer.ResetLocalAdjustments(); PausableGameplayContainer?.Pause();
return true;
fadeOut();
return base.OnExiting(next);
} }
if (LoadedBeatmapSuccessfully) gameplayClockContainer.ResetLocalAdjustments();
PausableGameplayContainer?.Pause();
return true; fadeOut();
return base.OnExiting(next);
} }
private void fadeOut(bool instant = false) private void fadeOut(bool instant = false)