1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 23:12:56 +08:00

Fix incorrect handling of reference clocks when no parent IGameplayClock is available

This commit is contained in:
Dean Herbert 2022-08-15 19:17:41 +09:00
parent 04d88b8216
commit 9bc2e91de0

View File

@ -10,6 +10,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Input.Handlers; using osu.Game.Input.Handlers;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -56,6 +57,8 @@ namespace osu.Game.Rulesets.UI
private IGameplayClock? parentGameplayClock; private IGameplayClock? parentGameplayClock;
private IClock referenceClock = null!;
/// <summary> /// <summary>
/// The current direction of playback to be exposed to frame stable children. /// The current direction of playback to be exposed to frame stable children.
/// </summary> /// </summary>
@ -65,18 +68,15 @@ namespace osu.Game.Rulesets.UI
private int direction = 1; private int direction = 1;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IGameplayClock? clock) private void load(IGameplayClock? gameplayClock)
{ {
if (clock != null) if (gameplayClock != null)
{ {
parentGameplayClock = clock; parentGameplayClock = gameplayClock;
IsPaused.BindTo(parentGameplayClock.IsPaused); IsPaused.BindTo(parentGameplayClock.IsPaused);
} }
}
protected override void LoadComplete() referenceClock = gameplayClock ?? Clock;
{
base.LoadComplete();
Clock = this; Clock = this;
} }
@ -128,7 +128,7 @@ namespace osu.Game.Rulesets.UI
state = PlaybackState.Valid; state = PlaybackState.Valid;
} }
double proposedTime = Clock.CurrentTime; double proposedTime = referenceClock.CurrentTime;
if (FrameStablePlayback) if (FrameStablePlayback)
// if we require frame stability, the proposed time will be adjusted to move at most one known // if we require frame stability, the proposed time will be adjusted to move at most one known
@ -148,14 +148,14 @@ namespace osu.Game.Rulesets.UI
if (state == PlaybackState.Valid && proposedTime != manualClock.CurrentTime) if (state == PlaybackState.Valid && proposedTime != manualClock.CurrentTime)
direction = proposedTime >= manualClock.CurrentTime ? 1 : -1; direction = proposedTime >= manualClock.CurrentTime ? 1 : -1;
double timeBehind = Math.Abs(proposedTime - Clock.CurrentTime); double timeBehind = Math.Abs(proposedTime - CurrentTime);
IsCatchingUp.Value = timeBehind > 200; IsCatchingUp.Value = timeBehind > 200;
WaitingOnFrames.Value = state == PlaybackState.NotValid; WaitingOnFrames.Value = state == PlaybackState.NotValid;
manualClock.CurrentTime = proposedTime; manualClock.CurrentTime = proposedTime;
manualClock.Rate = Math.Abs(Clock.Rate) * direction; manualClock.Rate = Math.Abs(referenceClock.Rate) * direction;
manualClock.IsRunning = Clock.IsRunning; manualClock.IsRunning = referenceClock.IsRunning;
// determine whether catch-up is required. // determine whether catch-up is required.
if (state == PlaybackState.Valid && timeBehind > 0) if (state == PlaybackState.Valid && timeBehind > 0)
@ -244,7 +244,7 @@ namespace osu.Game.Rulesets.UI
public bool IsRunning => framedClock.IsRunning; public bool IsRunning => framedClock.IsRunning;
public void ProcessFrame() => framedClock.ProcessFrame(); public void ProcessFrame() { }
public double ElapsedFrameTime => framedClock.ElapsedFrameTime; public double ElapsedFrameTime => framedClock.ElapsedFrameTime;
@ -256,7 +256,23 @@ namespace osu.Game.Rulesets.UI
#region Delegation of IGameplayClock #region Delegation of IGameplayClock
public double TrueGameplayRate => parentGameplayClock?.TrueGameplayRate ?? 1; public double TrueGameplayRate
{
get
{
double baseRate = Rate;
foreach (double adjustment in NonGameplayAdjustments)
{
if (Precision.AlmostEquals(adjustment, 0))
return 0;
baseRate /= adjustment;
}
return baseRate;
}
}
public double? StartTime => parentGameplayClock?.StartTime; public double? StartTime => parentGameplayClock?.StartTime;