diff --git a/osu.Game.Tests/NonVisual/GameplayClockTest.cs b/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs
similarity index 96%
rename from osu.Game.Tests/NonVisual/GameplayClockTest.cs
rename to osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs
index 9854a5731e..f9f4ead644 100644
--- a/osu.Game.Tests/NonVisual/GameplayClockTest.cs
+++ b/osu.Game.Tests/NonVisual/GameplayClockContainerTest.cs
@@ -9,7 +9,7 @@ using osu.Game.Screens.Play;
namespace osu.Game.Tests.NonVisual
{
[TestFixture]
- public class GameplayClockTest
+ public class GameplayClockContainerTest
{
[TestCase(0)]
[TestCase(1)]
diff --git a/osu.Game/Screens/Play/GameplayClockContainer.cs b/osu.Game/Screens/Play/GameplayClockContainer.cs
index 468e172714..a5d6cbf2e1 100644
--- a/osu.Game/Screens/Play/GameplayClockContainer.cs
+++ b/osu.Game/Screens/Play/GameplayClockContainer.cs
@@ -15,7 +15,7 @@ using osu.Framework.Utils;
namespace osu.Game.Screens.Play
{
///
- /// Encapsulates gameplay timing logic and provides a via DI for gameplay components to use.
+ /// Encapsulates gameplay timing logic and provides a via DI for gameplay components to use.
///
public class GameplayClockContainer : Container, IAdjustableClock, IGameplayClock
{
@@ -24,15 +24,8 @@ namespace osu.Game.Screens.Play
///
public IBindable IsPaused => isPaused;
- private readonly BindableBool isPaused = new BindableBool(true);
-
///
- /// The adjustable source clock used for gameplay. Should be used for seeks and clock control.
- ///
- protected readonly DecoupleableInterpolatingFramedClock AdjustableSource;
-
- ///
- /// The source clock.
+ /// The source clock. Should generally not be used for any timekeeping purposes.
///
public IClock SourceClock { get; private set; }
@@ -55,7 +48,14 @@ namespace osu.Game.Screens.Play
///
/// The final clock which is exposed to gameplay components.
///
- protected IFrameBasedClock GameplayClock { get; private set; } = null!;
+ protected IFrameBasedClock FramedClock { get; private set; } = null!;
+
+ private readonly BindableBool isPaused = new BindableBool(true);
+
+ ///
+ /// The adjustable source clock used for gameplay. Should be used for seeks and clock control.
+ ///
+ private readonly DecoupleableInterpolatingFramedClock decoupledClock;
///
/// Creates a new .
@@ -67,7 +67,7 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both;
- AdjustableSource = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
+ decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
IsPaused.BindValueChanged(OnIsPausedChanged);
}
@@ -75,7 +75,7 @@ namespace osu.Game.Screens.Play
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
- GameplayClock = CreateGameplayClock(AdjustableSource);
+ FramedClock = CreateGameplayClock(decoupledClock);
dependencies.CacheAs(this);
@@ -89,13 +89,13 @@ namespace osu.Game.Screens.Play
{
ensureSourceClockSet();
- if (!AdjustableSource.IsRunning)
+ if (!decoupledClock.IsRunning)
{
// Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time
// This accounts for the clock source potentially taking time to enter a completely stopped state
- Seek(GameplayClock.CurrentTime);
+ Seek(FramedClock.CurrentTime);
- AdjustableSource.Start();
+ decoupledClock.Start();
}
isPaused.Value = false;
@@ -109,10 +109,10 @@ namespace osu.Game.Screens.Play
{
Logger.Log($"{nameof(GameplayClockContainer)} seeking to {time}");
- AdjustableSource.Seek(time);
+ decoupledClock.Seek(time);
// Manually process to make sure the gameplay clock is correctly updated after a seek.
- GameplayClock.ProcessFrame();
+ FramedClock.ProcessFrame();
OnSeek?.Invoke();
}
@@ -129,7 +129,7 @@ namespace osu.Game.Screens.Play
public void Reset(bool startClock = false)
{
// Manually stop the source in order to not affect the IsPaused state.
- AdjustableSource.Stop();
+ decoupledClock.Stop();
if (!IsPaused.Value || startClock)
Start();
@@ -142,10 +142,10 @@ namespace osu.Game.Screens.Play
/// Changes the source clock.
///
/// The new source.
- protected void ChangeSource(IClock sourceClock) => AdjustableSource.ChangeSource(SourceClock = sourceClock);
+ protected void ChangeSource(IClock sourceClock) => decoupledClock.ChangeSource(SourceClock = sourceClock);
///
- /// Ensures that the is set to , if it hasn't been given a source yet.
+ /// Ensures that the is set to , if it hasn't been given a source yet.
/// This is usually done before a seek to avoid accidentally seeking only the adjustable source in decoupled mode,
/// but not the actual source clock.
/// That will pretty much only happen on the very first call of this method, as the source clock is passed in the constructor,
@@ -153,38 +153,38 @@ namespace osu.Game.Screens.Play
///
private void ensureSourceClockSet()
{
- if (AdjustableSource.Source == null)
+ if (decoupledClock.Source == null)
ChangeSource(SourceClock);
}
protected override void Update()
{
if (!IsPaused.Value)
- GameplayClock.ProcessFrame();
+ FramedClock.ProcessFrame();
base.Update();
}
///
- /// Invoked when the value of is changed to start or stop the clock.
+ /// Invoked when the value of is changed to start or stop the clock.
///
/// Whether the clock should now be paused.
protected virtual void OnIsPausedChanged(ValueChangedEvent isPaused)
{
if (isPaused.NewValue)
- AdjustableSource.Stop();
+ decoupledClock.Stop();
else
- AdjustableSource.Start();
+ decoupledClock.Start();
}
///
- /// Creates the final which is exposed via DI to be used by gameplay components.
+ /// Creates the final which is exposed via DI to be used by gameplay components.
///
///
/// Any intermediate clocks such as platform offsets should be applied here.
///
/// The providing the source time.
- /// The final .
+ /// The final .
protected virtual IFrameBasedClock CreateGameplayClock(IFrameBasedClock source) => source;
#region IAdjustableClock
@@ -201,15 +201,15 @@ namespace osu.Game.Screens.Play
double IAdjustableClock.Rate
{
- get => GameplayClock.Rate;
+ get => FramedClock.Rate;
set => throw new NotSupportedException();
}
- public double Rate => GameplayClock.Rate;
+ public double Rate => FramedClock.Rate;
- public double CurrentTime => GameplayClock.CurrentTime;
+ public double CurrentTime => FramedClock.CurrentTime;
- public bool IsRunning => GameplayClock.IsRunning;
+ public bool IsRunning => FramedClock.IsRunning;
#endregion
@@ -218,11 +218,11 @@ namespace osu.Game.Screens.Play
// Handled via update. Don't process here to safeguard from external usages potentially processing frames additional times.
}
- public double ElapsedFrameTime => GameplayClock.ElapsedFrameTime;
+ public double ElapsedFrameTime => FramedClock.ElapsedFrameTime;
- public double FramesPerSecond => GameplayClock.FramesPerSecond;
+ public double FramesPerSecond => FramedClock.FramesPerSecond;
- public FrameTimeInfo TimeInfo => GameplayClock.TimeInfo;
+ public FrameTimeInfo TimeInfo => FramedClock.TimeInfo;
public double TrueGameplayRate
{
diff --git a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs
index 0427792392..ea4f767109 100644
--- a/osu.Game/Screens/Play/MasterGameplayClockContainer.cs
+++ b/osu.Game/Screens/Play/MasterGameplayClockContainer.cs
@@ -35,8 +35,6 @@ namespace osu.Game.Screens.Play
///
public const double MINIMUM_SKIP_TIME = 1000;
- protected Track Track => (Track)SourceClock;
-
public readonly BindableNumber UserPlaybackRate = new BindableDouble(1)
{
Default = 1,
@@ -133,7 +131,7 @@ namespace osu.Game.Screens.Play
this.TransformBindableTo(pauseFreqAdjust, 0, 200, Easing.Out).OnComplete(_ =>
{
if (IsPaused.Value == isPaused.NewValue)
- AdjustableSource.Stop();
+ base.OnIsPausedChanged(isPaused);
});
}
else
@@ -142,14 +140,14 @@ namespace osu.Game.Screens.Play
else
{
if (isPaused.NewValue)
- AdjustableSource.Stop();
+ base.OnIsPausedChanged(isPaused);
// If not yet loaded, we still want to ensure relevant state is correct, as it is used for offset calculations.
pauseFreqAdjust.Value = isPaused.NewValue ? 0 : 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();
+ FramedClock.ProcessFrame();
}
}
@@ -178,12 +176,12 @@ namespace osu.Game.Screens.Play
///
public void Skip()
{
- if (GameplayClock.CurrentTime > skipTargetTime - MINIMUM_SKIP_TIME)
+ if (FramedClock.CurrentTime > skipTargetTime - MINIMUM_SKIP_TIME)
return;
double skipTarget = skipTargetTime - MINIMUM_SKIP_TIME;
- if (GameplayClock.CurrentTime < 0 && skipTarget > 6000)
+ if (FramedClock.CurrentTime < 0 && skipTarget > 6000)
// double skip exception for storyboards with very long intros
skipTarget = 0;
@@ -218,8 +216,11 @@ namespace osu.Game.Screens.Play
if (speedAdjustmentsApplied)
return;
- Track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
- Track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
+ if (SourceClock is Track track)
+ {
+ track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
+ track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
+ }
nonGameplayAdjustments.Add(pauseFreqAdjust);
nonGameplayAdjustments.Add(UserPlaybackRate);
@@ -232,8 +233,11 @@ namespace osu.Game.Screens.Play
if (!speedAdjustmentsApplied)
return;
- Track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
- Track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
+ if (SourceClock is Track track)
+ {
+ track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
+ track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
+ }
nonGameplayAdjustments.Remove(pauseFreqAdjust);
nonGameplayAdjustments.Remove(UserPlaybackRate);