Skip to content

Commit

Permalink
Merge pull request #5380 from peppy/deocupled-avoid-source-seek
Browse files Browse the repository at this point in the history
Avoid performing `Seek` operations on a decoupled source when the source is not running
  • Loading branch information
smoogipoo authored Aug 25, 2022
2 parents 0894ea1 + fc9fae2 commit 5beb940
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion osu.Framework.Tests/Clocks/DecoupleableClockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ public void TestSourceSeekedByDecoupledSeek()
decoupleable.IsCoupled = false;
decoupleable.Seek(1000);

Assert.AreEqual(decoupleable.CurrentTime, source.CurrentTime, "Source time should match coupled time.");
Assert.AreEqual(decoupleable.CurrentTime, 1000, "Decoupled time should match seek target.");
// Seek on the source is not performed as the clock is stopped.
Assert.AreNotEqual(source.CurrentTime, decoupleable.CurrentTime, "Source time should not match coupled time.");
}

/// <summary>
Expand Down
12 changes: 7 additions & 5 deletions osu.Framework/Timing/DecoupleableInterpolatingFramedClock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ public bool Seek(double position)

Debug.Assert(adjustableSource != null);

// Begin by performing a seek on the source clock.
bool success = adjustableSource.Seek(position);

if (IsCoupled)
{
// Begin by performing a seek on the source clock.
bool success = adjustableSource.Seek(position);

// If coupled, regardless of the success of the seek on the source, use the updated
// source's current position. This is done because in the case of a seek failure, the
// source may update the value
Expand All @@ -198,8 +198,10 @@ public bool Seek(double position)
// If decoupled, a seek operation should cause the decoupled clock to seek regardless
// of whether the source clock could handle the target location.

// In the case of the source seek failing, ensure the source is stopped for safety..
if (!success)
// In the case the source is running, attempt a seek and stop it if that seek fails.
// Note that we don't need to perform a seek if the source is not running.
// This is important to improve performance in the decoupled case if the source clock's Seek call is not immediate.
if (adjustableSource.IsRunning && !adjustableSource.Seek(position))
adjustableSource?.Stop();

// ..then perform the requested seek precisely on the decoupled clock.
Expand Down

0 comments on commit 5beb940

Please sign in to comment.