1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Handle different gameplay rates when seeking on master clock

This commit is contained in:
Salman Ahmed 2022-01-29 23:06:31 +03:00
parent 2b999f9780
commit 6556a7e3c3

View File

@ -43,7 +43,7 @@ namespace osu.Game.Screens.Play
Precision = 0.1, Precision = 0.1,
}; };
private double totalOffset => userOffsetClock.Offset + platformOffsetClock.Offset; private double totalAppliedOffset => userOffsetClock.RateAdjustedOffset + platformOffsetClock.RateAdjustedOffset;
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1); private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
@ -52,8 +52,8 @@ namespace osu.Game.Screens.Play
private readonly bool startAtGameplayStart; private readonly bool startAtGameplayStart;
private readonly double firstHitObjectTime; private readonly double firstHitObjectTime;
private FramedOffsetClock userOffsetClock; private HardwareCorrectionOffsetClock userOffsetClock;
private FramedOffsetClock platformOffsetClock; private HardwareCorrectionOffsetClock platformOffsetClock;
private MasterGameplayClock masterGameplayClock; private MasterGameplayClock masterGameplayClock;
private Bindable<double> userAudioOffset; private Bindable<double> userAudioOffset;
private double startOffset; private double startOffset;
@ -128,7 +128,7 @@ namespace osu.Game.Screens.Play
{ {
// remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track. // remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track.
// we may want to consider reversing the application of offsets in the future as it may feel more correct. // we may want to consider reversing the application of offsets in the future as it may feel more correct.
base.Seek(time - totalOffset); base.Seek(time - totalAppliedOffset);
} }
/// <summary> /// <summary>
@ -214,13 +214,25 @@ namespace osu.Game.Screens.Play
private class HardwareCorrectionOffsetClock : FramedOffsetClock private class HardwareCorrectionOffsetClock : FramedOffsetClock
{ {
// 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 implementation already adds offset at 1.0 rate, so we only add the difference from that here.
public override double CurrentTime => base.CurrentTime + offsetAdjust;
private readonly BindableDouble pauseRateAdjust; private readonly BindableDouble pauseRateAdjust;
private double offsetAdjust; private double offset;
public new double Offset
{
get => offset;
set
{
if (value == offset)
return;
offset = value;
updateOffset();
}
}
public double RateAdjustedOffset => base.Offset;
public HardwareCorrectionOffsetClock(IClock source, BindableDouble pauseRateAdjust) public HardwareCorrectionOffsetClock(IClock source, BindableDouble pauseRateAdjust)
: base(source) : base(source)
@ -231,10 +243,17 @@ namespace osu.Game.Screens.Play
public override void ProcessFrame() public override void ProcessFrame()
{ {
base.ProcessFrame(); base.ProcessFrame();
updateOffset();
}
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. // 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) if (pauseRateAdjust.Value == 1)
offsetAdjust = Offset * (Rate - 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;
}
} }
} }