mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Remove ISpectatorPlayerClock
interface
Too many levels of redirection. One interface with one implementation is not useful, IMO.
This commit is contained in:
parent
882dd93942
commit
31f657fe01
@ -21,9 +21,9 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
private GameplayClockContainer master;
|
||||
private CatchUpSyncManager syncManager;
|
||||
|
||||
private Dictionary<ISpectatorPlayerClock, int> clocksById;
|
||||
private ISpectatorPlayerClock player1;
|
||||
private ISpectatorPlayerClock player2;
|
||||
private Dictionary<CatchUpSpectatorPlayerClock, int> clocksById;
|
||||
private CatchUpSpectatorPlayerClock player1;
|
||||
private CatchUpSpectatorPlayerClock player2;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@ -32,7 +32,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
player1 = syncManager.CreateManagedClock();
|
||||
player2 = syncManager.CreateManagedClock();
|
||||
|
||||
clocksById = new Dictionary<ISpectatorPlayerClock, int>
|
||||
clocksById = new Dictionary<CatchUpSpectatorPlayerClock, int>
|
||||
{
|
||||
{ player1, 1 },
|
||||
{ player2, 2 }
|
||||
@ -145,7 +145,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
assertPlayerClockState(() => player1, false);
|
||||
}
|
||||
|
||||
private void setWaiting(Func<ISpectatorPlayerClock> playerClock, bool waiting)
|
||||
private void setWaiting(Func<CatchUpSpectatorPlayerClock> playerClock, bool waiting)
|
||||
=> AddStep($"set player clock {clocksById[playerClock()]} waiting = {waiting}", () => playerClock().WaitingOnFrames.Value = waiting);
|
||||
|
||||
private void setAllWaiting(bool waiting) => AddStep($"set all player clocks waiting = {waiting}", () =>
|
||||
@ -160,13 +160,13 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
/// <summary>
|
||||
/// clock.Time = master.Time - offsetFromMaster
|
||||
/// </summary>
|
||||
private void setPlayerClockTime(Func<ISpectatorPlayerClock> playerClock, double offsetFromMaster)
|
||||
private void setPlayerClockTime(Func<CatchUpSpectatorPlayerClock> playerClock, double offsetFromMaster)
|
||||
=> AddStep($"set player clock {clocksById[playerClock()]} = master - {offsetFromMaster}", () => playerClock().Seek(master.CurrentTime - offsetFromMaster));
|
||||
|
||||
private void assertCatchingUp(Func<ISpectatorPlayerClock> playerClock, bool catchingUp) =>
|
||||
private void assertCatchingUp(Func<CatchUpSpectatorPlayerClock> playerClock, bool catchingUp) =>
|
||||
AddAssert($"player clock {clocksById[playerClock()]} {(catchingUp ? "is" : "is not")} catching up", () => playerClock().IsCatchingUp == catchingUp);
|
||||
|
||||
private void assertPlayerClockState(Func<ISpectatorPlayerClock> playerClock, bool running)
|
||||
private void assertPlayerClockState(Func<CatchUpSpectatorPlayerClock> playerClock, bool running)
|
||||
=> AddAssert($"player clock {clocksById[playerClock()]} {(running ? "is" : "is not")} running", () => playerClock().IsRunning == running);
|
||||
|
||||
private class TestManualClock : ManualClock, IAdjustableClock
|
||||
|
@ -9,9 +9,9 @@ using osu.Game.Screens.Play;
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ISpectatorPlayerClock"/> which catches up using rate adjustment.
|
||||
/// A <see cref="CatchUpSpectatorPlayerClock"/> which catches up using rate adjustment.
|
||||
/// </summary>
|
||||
public class CatchUpSpectatorPlayerClock : ISpectatorPlayerClock
|
||||
public class CatchUpSpectatorPlayerClock : IFrameBasedClock, IAdjustableClock
|
||||
{
|
||||
/// <summary>
|
||||
/// The catch up rate.
|
||||
@ -31,8 +31,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
|
||||
public void Reset() => CurrentTime = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Starts this <see cref="CatchUpSpectatorPlayerClock"/>.
|
||||
/// </summary>
|
||||
public void Start() => IsRunning = true;
|
||||
|
||||
/// <summary>
|
||||
/// Stops this <see cref="CatchUpSpectatorPlayerClock"/>.
|
||||
/// </summary>
|
||||
public void Stop() => IsRunning = false;
|
||||
|
||||
void IAdjustableClock.Start()
|
||||
@ -89,8 +95,17 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ using osu.Game.Screens.Play;
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the synchronisation between one or more <see cref="ISpectatorPlayerClock"/>s in relation to a master clock.
|
||||
/// Manages the synchronisation between one or more <see cref="CatchUpSpectatorPlayerClock"/>s in relation to a master clock.
|
||||
/// </summary>
|
||||
public class CatchUpSyncManager : Component
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
/// <summary>
|
||||
/// The player clocks.
|
||||
/// </summary>
|
||||
private readonly List<ISpectatorPlayerClock> playerClocks = new List<ISpectatorPlayerClock>();
|
||||
private readonly List<CatchUpSpectatorPlayerClock> playerClocks = new List<CatchUpSpectatorPlayerClock>();
|
||||
|
||||
private readonly Bindable<MasterClockState> masterState = new Bindable<MasterClockState>();
|
||||
|
||||
@ -61,10 +61,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new managed <see cref="ISpectatorPlayerClock"/>.
|
||||
/// Create a new managed <see cref="CatchUpSpectatorPlayerClock"/>.
|
||||
/// </summary>
|
||||
/// <returns>The newly created <see cref="ISpectatorPlayerClock"/>.</returns>
|
||||
public ISpectatorPlayerClock CreateManagedClock()
|
||||
/// <returns>The newly created <see cref="CatchUpSpectatorPlayerClock"/>.</returns>
|
||||
public CatchUpSpectatorPlayerClock CreateManagedClock()
|
||||
{
|
||||
var clock = new CatchUpSpectatorPlayerClock(MasterClock);
|
||||
playerClocks.Add(clock);
|
||||
@ -72,10 +72,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an <see cref="ISpectatorPlayerClock"/>, stopping it from being managed by this <see cref="CatchUpSyncManager"/>.
|
||||
/// Removes an <see cref="CatchUpSpectatorPlayerClock"/>, stopping it from being managed by this <see cref="CatchUpSyncManager"/>.
|
||||
/// </summary>
|
||||
/// <param name="clock">The <see cref="ISpectatorPlayerClock"/> to remove.</param>
|
||||
public void RemoveManagedClock(ISpectatorPlayerClock clock)
|
||||
/// <param name="clock">The <see cref="CatchUpSpectatorPlayerClock"/> to remove.</param>
|
||||
public void RemoveManagedClock(CatchUpSpectatorPlayerClock clock)
|
||||
{
|
||||
playerClocks.Remove(clock);
|
||||
clock.Stop();
|
||||
|
@ -1,37 +0,0 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Timing;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
{
|
||||
/// <summary>
|
||||
/// A clock which is used by <see cref="MultiSpectatorPlayer"/>s and managed by an <see cref="CatchUpSyncManager"/>.
|
||||
/// </summary>
|
||||
public interface ISpectatorPlayerClock : IFrameBasedClock, IAdjustableClock
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts this <see cref="ISpectatorPlayerClock"/>.
|
||||
/// </summary>
|
||||
new void Start();
|
||||
|
||||
/// <summary>
|
||||
/// Stops this <see cref="ISpectatorPlayerClock"/>.
|
||||
/// </summary>
|
||||
new void Stop();
|
||||
|
||||
/// <summary>
|
||||
/// Whether this clock is waiting on frames to continue playback.
|
||||
/// </summary>
|
||||
Bindable<bool> WaitingOnFrames { get; }
|
||||
|
||||
/// <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>
|
||||
bool IsCatchingUp { get; set; }
|
||||
}
|
||||
}
|
@ -15,14 +15,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
public class MultiSpectatorPlayer : SpectatorPlayer
|
||||
{
|
||||
private readonly Bindable<bool> waitingOnFrames = new Bindable<bool>(true);
|
||||
private readonly ISpectatorPlayerClock spectatorPlayerClock;
|
||||
private readonly CatchUpSpectatorPlayerClock spectatorPlayerClock;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MultiSpectatorPlayer"/>.
|
||||
/// </summary>
|
||||
/// <param name="score">The score containing the player's replay.</param>
|
||||
/// <param name="spectatorPlayerClock">The clock controlling the gameplay running state.</param>
|
||||
public MultiSpectatorPlayer(Score score, ISpectatorPlayerClock spectatorPlayerClock)
|
||||
public MultiSpectatorPlayer(Score score, CatchUpSpectatorPlayerClock spectatorPlayerClock)
|
||||
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
|
||||
{
|
||||
this.spectatorPlayerClock = spectatorPlayerClock;
|
||||
|
@ -177,7 +177,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
}
|
||||
}
|
||||
|
||||
private bool isCandidateAudioSource(ISpectatorPlayerClock? clock)
|
||||
private bool isCandidateAudioSource(CatchUpSpectatorPlayerClock? clock)
|
||||
=> clock?.IsRunning == true && !clock.IsCatchingUp && !clock.WaitingOnFrames.Value;
|
||||
|
||||
private void onReadyToStart()
|
||||
|
@ -38,9 +38,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
public readonly int UserId;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ISpectatorPlayerClock"/> used to control the gameplay running state of a loaded <see cref="Player"/>.
|
||||
/// The <see cref="CatchUpSpectatorPlayerClock"/> used to control the gameplay running state of a loaded <see cref="Player"/>.
|
||||
/// </summary>
|
||||
public readonly ISpectatorPlayerClock GameplayClock;
|
||||
public readonly CatchUpSpectatorPlayerClock GameplayClock;
|
||||
|
||||
/// <summary>
|
||||
/// The currently-loaded score.
|
||||
@ -55,7 +55,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
private readonly LoadingLayer loadingLayer;
|
||||
private OsuScreenStack? stack;
|
||||
|
||||
public PlayerArea(int userId, ISpectatorPlayerClock clock)
|
||||
public PlayerArea(int userId, CatchUpSpectatorPlayerClock clock)
|
||||
{
|
||||
UserId = userId;
|
||||
GameplayClock = clock;
|
||||
|
Loading…
Reference in New Issue
Block a user