Skip to content

Commit 2fb1078

Browse files
committed
Fix interpolating clocks' drift recovery being frame rate dependent
This should largely alleviate any remaining concerns of stutters due to ppy/osu#22488. In testing, on both windows and macOS the delay for bass to start playback is around 10 ms. If there is no interpolation, this would cause a 10 ms stutter. I've confirmed that interpolation *does* alleviate this already. The problem is that depending on the update frame rate, it doesn't do a great job. With this change, the drift is spread out over multiple frames, which should make the issue much less visible to an end user (gameplay will run slightly slower for a brief period rather than outright stopping).
1 parent 0722f55 commit 2fb1078

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

osu.Framework/Timing/InterpolatingFramedClock.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using osu.Framework.Utils;
67

78
namespace osu.Framework.Timing
89
{
@@ -100,11 +101,15 @@ public void ProcessFrame()
100101

101102
if (IsInterpolating)
102103
{
103-
// apply time increase from interpolation.
104+
// Apply time increase from interpolation.
104105
currentTime += realtimeClock.ElapsedFrameTime * Rate;
105-
// if we differ from the elapsed time of the source, let's adjust for the difference.
106-
// TODO: this is frame rate depending, and can result in unexpected results.
107-
currentTime += (framedSourceClock.CurrentTime - currentTime) / 8;
106+
107+
// Then check the post-interpolated time.
108+
// If we differ from the current time of the source, gradually approach the ground truth.
109+
//
110+
// The remaining error halves every halfTime ms.
111+
// This may need further tweaking to be less discernible by users (upwards, likely?).
112+
currentTime = Interpolation.DampContinuously(currentTime, framedSourceClock.CurrentTime, 50, realtimeClock.ElapsedFrameTime);
108113

109114
bool withinAllowableError = Math.Abs(framedSourceClock.CurrentTime - currentTime) <= AllowableErrorMilliseconds * Rate;
110115

0 commit comments

Comments
 (0)