1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 13:22:55 +08:00

Change running state of SpectatorPlayerClock using IsRunning

This commit is contained in:
Dean Herbert 2022-08-24 15:17:56 +09:00
parent 0c9a4ec13c
commit a86fc6f248
2 changed files with 26 additions and 35 deletions

View File

@ -22,7 +22,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public double CurrentTime { get; private set; }
public bool IsRunning { get; private set; }
/// <summary>
/// Whether this clock is waiting on frames to continue playback.
/// </summary>
public Bindable<bool> WaitingOnFrames { get; } = new Bindable<bool>(true);
/// <summary>
/// Whether this clock is behind the master clock and running at a higher rate to catch up to it.
/// </summary>
/// <remarks>
/// Of note, this will be false if this clock is *ahead* of the master clock.
/// </remarks>
public bool IsCatchingUp { get; set; }
/// <summary>
/// Whether this spectator clock should be running.
/// Use instead of <see cref="Start"/> / <see cref="Stop"/> to control time.
/// </summary>
public bool IsRunning { get; set; }
public SpectatorPlayerClock(GameplayClockContainer masterClock)
{
@ -31,24 +48,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public void Reset() => CurrentTime = 0;
/// <summary>
/// Starts this <see cref="SpectatorPlayerClock"/>.
/// </summary>
public void Start() => IsRunning = true;
/// <summary>
/// Stops this <see cref="SpectatorPlayerClock"/>.
/// </summary>
public void Stop() => IsRunning = false;
void IAdjustableClock.Start()
public void Start()
{
// Our running state should only be managed by an ISyncManager, ignore calls from external sources.
// Our running state should only be managed by SpectatorSyncManager via IsRunning.
}
void IAdjustableClock.Stop()
public void Stop()
{
// Our running state should only be managed by an ISyncManager, ignore calls from external sources.
// Our running state should only be managed by an SpectatorSyncManager via IsRunning.
}
public bool Seek(double position)
@ -94,18 +101,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public double FramesPerSecond { get; private set; }
public FrameTimeInfo TimeInfo => new FrameTimeInfo { Elapsed = ElapsedFrameTime, Current = CurrentTime };
/// <summary>
/// Whether this clock is waiting on frames to continue playback.
/// </summary>
public Bindable<bool> WaitingOnFrames { get; } = new Bindable<bool>(true);
/// <summary>
/// Whether this clock is behind the master clock and running at a higher rate to catch up to it.
/// </summary>
/// <remarks>
/// Of note, this will be false if this clock is *ahead* of the master clock.
/// </remarks>
public bool IsCatchingUp { get; set; }
}
}

View File

@ -80,7 +80,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public void RemoveManagedClock(SpectatorPlayerClock clock)
{
playerClocks.Remove(clock);
clock.Stop();
clock.IsRunning = false;
}
protected override void Update()
@ -91,7 +91,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
// Ensure all player clocks are stopped until the start succeeds.
foreach (var clock in playerClocks)
clock.Stop();
clock.IsRunning = true;
return;
}
@ -153,15 +153,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
// Importantly, set the clock to a non-catchup state. if this isn't done, updateMasterState may incorrectly pause the master clock
// when it is required to be running (ie. if all players are ahead of the master).
clock.IsCatchingUp = false;
clock.Stop();
clock.IsRunning = false;
continue;
}
// Make sure the player clock is running if it can.
if (!clock.WaitingOnFrames.Value)
clock.Start();
else
clock.Stop();
clock.IsRunning = !clock.WaitingOnFrames.Value;
if (clock.IsCatchingUp)
{