mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 22:33:05 +08:00
Merge pull request #26605 from peppy/simplify-gameplay-pause
Simplify gameplay pause sequence
This commit is contained in:
commit
493d495992
@ -93,15 +93,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
double currentTime = masterClock.CurrentTime;
|
||||
|
||||
bool goingForward = currentTime >= (masterClock.LastStopTime ?? lastStopTime);
|
||||
bool goingForward = currentTime >= lastStopTime;
|
||||
|
||||
alwaysGoingForward &= goingForward;
|
||||
|
||||
if (!goingForward)
|
||||
Logger.Log($"Went too far backwards (last stop: {lastStopTime:N1} current: {currentTime:N1})");
|
||||
|
||||
if (masterClock.LastStopTime != null)
|
||||
lastStopTime = masterClock.LastStopTime.Value;
|
||||
};
|
||||
});
|
||||
|
||||
@ -125,7 +122,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
resumeAndConfirm();
|
||||
|
||||
AddAssert("Resumed without seeking forward", () => Player.LastResumeTime, () => Is.LessThanOrEqualTo(Player.LastPauseTime));
|
||||
AddAssert("continued playing forward", () => Player.LastResumeTime, () => Is.GreaterThanOrEqualTo(Player.LastPauseTime));
|
||||
|
||||
AddUntilStep("player playing", () => Player.LocalUserPlaying.Value);
|
||||
}
|
||||
|
@ -27,11 +27,6 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
private readonly bool applyOffsets;
|
||||
|
||||
/// <summary>
|
||||
/// The total frequency adjustment from pause transforms. Should eventually be handled in a better way.
|
||||
/// </summary>
|
||||
public readonly BindableDouble ExternalPauseFrequencyAdjust = new BindableDouble(1);
|
||||
|
||||
private readonly OffsetCorrectionClock? userGlobalOffsetClock;
|
||||
private readonly OffsetCorrectionClock? platformOffsetClock;
|
||||
private readonly OffsetCorrectionClock? userBeatmapOffsetClock;
|
||||
@ -69,13 +64,13 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
// Audio timings in general with newer BASS versions don't match stable.
|
||||
// This only seems to be required on windows. We need to eventually figure out why, with a bit of luck.
|
||||
platformOffsetClock = new OffsetCorrectionClock(interpolatedTrack, ExternalPauseFrequencyAdjust) { Offset = RuntimeInfo.OS == RuntimeInfo.Platform.Windows ? 15 : 0 };
|
||||
platformOffsetClock = new OffsetCorrectionClock(interpolatedTrack) { Offset = RuntimeInfo.OS == RuntimeInfo.Platform.Windows ? 15 : 0 };
|
||||
|
||||
// User global offset (set in settings) should also be applied.
|
||||
userGlobalOffsetClock = new OffsetCorrectionClock(platformOffsetClock, ExternalPauseFrequencyAdjust);
|
||||
userGlobalOffsetClock = new OffsetCorrectionClock(platformOffsetClock);
|
||||
|
||||
// User per-beatmap offset will be applied to this final clock.
|
||||
finalClockSource = userBeatmapOffsetClock = new OffsetCorrectionClock(userGlobalOffsetClock, ExternalPauseFrequencyAdjust);
|
||||
finalClockSource = userBeatmapOffsetClock = new OffsetCorrectionClock(userGlobalOffsetClock);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -78,8 +78,6 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
isPaused.Value = false;
|
||||
|
||||
PrepareStart();
|
||||
|
||||
// The case which caused this to be added is FrameStabilityContainer, which manages its own current and elapsed time.
|
||||
// Because we generally update our own current time quicker than children can query it (via Start/Seek/Update),
|
||||
// this means that the first frame ever exposed to children may have a non-zero current time.
|
||||
@ -99,14 +97,6 @@ namespace osu.Game.Screens.Play
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When <see cref="Start"/> is called, this will be run to give an opportunity to prepare the clock at the correct
|
||||
/// start location.
|
||||
/// </summary>
|
||||
protected virtual void PrepareStart()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seek to a specific time in gameplay.
|
||||
/// </summary>
|
||||
|
@ -7,7 +7,6 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -60,17 +59,6 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private readonly double skipTargetTime;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the time at which the last <see cref="StopGameplayClock"/> call was triggered.
|
||||
/// This is used to ensure we resume from that precise point in time, ignoring the proceeding frequency ramp.
|
||||
///
|
||||
/// Optimally, we'd have gameplay ramp down with the frequency, but I believe this was intentionally disabled
|
||||
/// to avoid fails occurring after the pause screen has been shown.
|
||||
///
|
||||
/// In the future I want to change this.
|
||||
/// </summary>
|
||||
internal double? LastStopTime;
|
||||
|
||||
[Resolved]
|
||||
private MusicController musicController { get; set; } = null!;
|
||||
|
||||
@ -113,71 +101,17 @@ namespace osu.Game.Screens.Play
|
||||
return time;
|
||||
}
|
||||
|
||||
protected override void StopGameplayClock()
|
||||
{
|
||||
LastStopTime = GameplayClock.CurrentTime;
|
||||
|
||||
if (IsLoaded)
|
||||
{
|
||||
// During normal operation, the source is stopped after performing a frequency ramp.
|
||||
this.TransformBindableTo(GameplayClock.ExternalPauseFrequencyAdjust, 0, 200, Easing.Out).OnComplete(_ =>
|
||||
{
|
||||
if (IsPaused.Value)
|
||||
base.StopGameplayClock();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
base.StopGameplayClock();
|
||||
|
||||
// If not yet loaded, we still want to ensure relevant state is correct, as it is used for offset calculations.
|
||||
GameplayClock.ExternalPauseFrequencyAdjust.Value = 0;
|
||||
|
||||
// We must also process underlying gameplay clocks to update rate-adjusted offsets with the new frequency adjustment.
|
||||
// Without doing this, an initial seek may be performed with the wrong offset.
|
||||
GameplayClock.ProcessFrame();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Seek(double time)
|
||||
{
|
||||
// Safety in case the clock is seeked while stopped.
|
||||
LastStopTime = null;
|
||||
elapsedValidationTime = null;
|
||||
|
||||
base.Seek(time);
|
||||
}
|
||||
|
||||
protected override void PrepareStart()
|
||||
{
|
||||
if (LastStopTime != null)
|
||||
{
|
||||
Seek(LastStopTime.Value);
|
||||
LastStopTime = null;
|
||||
}
|
||||
else
|
||||
base.PrepareStart();
|
||||
}
|
||||
|
||||
protected override void StartGameplayClock()
|
||||
{
|
||||
addAdjustmentsToTrack();
|
||||
|
||||
base.StartGameplayClock();
|
||||
|
||||
if (IsLoaded)
|
||||
{
|
||||
this.TransformBindableTo(GameplayClock.ExternalPauseFrequencyAdjust, 1, 200, Easing.In);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If not yet loaded, we still want to ensure relevant state is correct, as it is used for offset calculations.
|
||||
GameplayClock.ExternalPauseFrequencyAdjust.Value = 1;
|
||||
|
||||
// We must also process underlying gameplay clocks to update rate-adjusted offsets with the new frequency adjustment.
|
||||
// Without doing this, an initial seek may be performed with the wrong offset.
|
||||
GameplayClock.ProcessFrame();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -273,7 +207,6 @@ namespace osu.Game.Screens.Play
|
||||
musicController.ResetTrackAdjustments();
|
||||
|
||||
track.BindAdjustments(AdjustmentsFromMods);
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, GameplayClock.ExternalPauseFrequencyAdjust);
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, UserPlaybackRate);
|
||||
|
||||
speedAdjustmentsApplied = true;
|
||||
@ -285,7 +218,6 @@ namespace osu.Game.Screens.Play
|
||||
return;
|
||||
|
||||
track.UnbindAdjustments(AdjustmentsFromMods);
|
||||
track.RemoveAdjustment(AdjustableProperty.Frequency, GameplayClock.ExternalPauseFrequencyAdjust);
|
||||
track.RemoveAdjustment(AdjustableProperty.Frequency, UserPlaybackRate);
|
||||
|
||||
speedAdjustmentsApplied = false;
|
||||
|
@ -1,15 +1,12 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Timing;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
public class OffsetCorrectionClock : FramedOffsetClock
|
||||
{
|
||||
private readonly BindableDouble pauseRateAdjust;
|
||||
|
||||
private double offset;
|
||||
|
||||
public new double Offset
|
||||
@ -28,10 +25,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public double RateAdjustedOffset => base.Offset;
|
||||
|
||||
public OffsetCorrectionClock(IClock source, BindableDouble pauseRateAdjust)
|
||||
public OffsetCorrectionClock(IClock source)
|
||||
: base(source)
|
||||
{
|
||||
this.pauseRateAdjust = pauseRateAdjust;
|
||||
}
|
||||
|
||||
public override void ProcessFrame()
|
||||
@ -41,13 +37,9 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
|
||||
private void updateOffset()
|
||||
{
|
||||
// changing this during the pause transform effect will cause a potentially large offset to be suddenly applied as we approach zero rate.
|
||||
if (pauseRateAdjust.Value == 1)
|
||||
{
|
||||
// we always want to apply the same real-time offset, so it should be adjusted by the difference in playback rate (from realtime) to achieve this.
|
||||
base.Offset = Offset * Rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user