Merge pull request #15048 from bdach/frame-stability-container-direction-flip

Fix key counter overlay not rewinding count fully
This commit is contained in:
Dean Herbert 2021-10-13 10:11:09 +09:00 committed by GitHub
commit d3c3aa620f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -103,6 +103,30 @@ public void TestInitialSeek()
checkFrameCount(0);
}
[Test]
public void TestRatePreservedWhenTimeNotProgressing()
{
AddStep("set manual clock rate", () => manualClock.Rate = 1);
seekManualTo(5000);
createStabilityContainer();
checkRate(1);
seekManualTo(10000);
checkRate(1);
AddWaitStep("wait some", 3);
checkRate(1);
seekManualTo(5000);
checkRate(-1);
AddWaitStep("wait some", 3);
checkRate(-1);
seekManualTo(10000);
checkRate(1);
}
private const int max_frames_catchup = 50;
private void createStabilityContainer(double gameplayStartTime = double.MinValue) => AddStep("create container", () =>
@ -116,6 +140,9 @@ private void createStabilityContainer(double gameplayStartTime = double.MinValue
private void checkFrameCount(int frames) =>
AddAssert($"elapsed frames is {frames}", () => consumer.ElapsedFrames == frames);
private void checkRate(double rate) =>
AddAssert($"clock rate is {rate}", () => consumer.Clock.Rate == rate);
public class ClockConsumingChild : CompositeDrawable
{
private readonly OsuSpriteText text;

View File

@ -55,7 +55,10 @@ public FrameStabilityContainer(double gameplayStartTime = double.MinValue)
/// <summary>
/// The current direction of playback to be exposed to frame stable children.
/// </summary>
private int direction;
/// <remarks>
/// Initially it is presumed that playback will proceed in the forward direction.
/// </remarks>
private int direction = 1;
[BackgroundDependencyLoader(true)]
private void load(GameplayClock clock, ISamplePlaybackDisabler sampleDisabler)
@ -139,7 +142,9 @@ private void updateClock()
state = PlaybackState.NotValid;
}
if (state == PlaybackState.Valid)
// if the proposed time is the same as the current time, assume that the clock will continue progressing in the same direction as previously.
// this avoids spurious flips in direction from -1 to 1 during rewinds.
if (state == PlaybackState.Valid && proposedTime != manualClock.CurrentTime)
direction = proposedTime >= manualClock.CurrentTime ? 1 : -1;
double timeBehind = Math.Abs(proposedTime - parentGameplayClock.CurrentTime);