1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:07:52 +08:00

More refactorings/renamespacings/xmldocs

This commit is contained in:
smoogipoo 2021-04-15 19:32:55 +09:00
parent df4fce2c57
commit 82fcabb8f0
10 changed files with 105 additions and 66 deletions

View File

@ -6,16 +6,16 @@ using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate; using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
namespace osu.Game.Tests.OnlinePlay namespace osu.Game.Tests.OnlinePlay
{ {
[HeadlessTest] [HeadlessTest]
public class MultiplayerCatchupSyncManagerTest : OsuTestScene public class MultiplayerCatchUpSyncManagerTest : OsuTestScene
{ {
private TestManualClock master; private TestManualClock master;
private MultiplayerCatchupSyncManager catchupSyncManager; private SpectatorCatchUpSyncManager syncManager;
private TestSpectatorSlaveClock slave1; private TestSpectatorSlaveClock slave1;
private TestSpectatorSlaveClock slave2; private TestSpectatorSlaveClock slave2;
@ -23,11 +23,11 @@ namespace osu.Game.Tests.OnlinePlay
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
catchupSyncManager = new MultiplayerCatchupSyncManager(master = new TestManualClock()); syncManager = new SpectatorCatchUpSyncManager(master = new TestManualClock());
catchupSyncManager.AddSlave(slave1 = new TestSpectatorSlaveClock(1)); syncManager.AddSlave(slave1 = new TestSpectatorSlaveClock(1));
catchupSyncManager.AddSlave(slave2 = new TestSpectatorSlaveClock(2)); syncManager.AddSlave(slave2 = new TestSpectatorSlaveClock(2));
Schedule(() => Child = catchupSyncManager); Schedule(() => Child = syncManager);
} }
[Test] [Test]
@ -47,7 +47,7 @@ namespace osu.Game.Tests.OnlinePlay
[Test] [Test]
public void TestMasterClockDoesNotStartWhenNoneReadyForMaximumDelayTime() public void TestMasterClockDoesNotStartWhenNoneReadyForMaximumDelayTime()
{ {
AddWaitStep($"wait {MultiplayerCatchupSyncManager.MAXIMUM_START_DELAY} milliseconds", (int)Math.Ceiling(MultiplayerCatchupSyncManager.MAXIMUM_START_DELAY / TimePerAction)); AddWaitStep($"wait {SpectatorCatchUpSyncManager.MAXIMUM_START_DELAY} milliseconds", (int)Math.Ceiling(SpectatorCatchUpSyncManager.MAXIMUM_START_DELAY / TimePerAction));
assertMasterState(false); assertMasterState(false);
} }
@ -55,7 +55,7 @@ namespace osu.Game.Tests.OnlinePlay
public void TestMasterClockStartsWhenAnyReadyForMaximumDelayTime() public void TestMasterClockStartsWhenAnyReadyForMaximumDelayTime()
{ {
setWaiting(() => slave1, false); setWaiting(() => slave1, false);
AddWaitStep($"wait {MultiplayerCatchupSyncManager.MAXIMUM_START_DELAY} milliseconds", (int)Math.Ceiling(MultiplayerCatchupSyncManager.MAXIMUM_START_DELAY / TimePerAction)); AddWaitStep($"wait {SpectatorCatchUpSyncManager.MAXIMUM_START_DELAY} milliseconds", (int)Math.Ceiling(SpectatorCatchUpSyncManager.MAXIMUM_START_DELAY / TimePerAction));
assertMasterState(true); assertMasterState(true);
} }
@ -64,7 +64,7 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setMasterTime(MultiplayerCatchupSyncManager.SYNC_TARGET + 1); setMasterTime(SpectatorCatchUpSyncManager.SYNC_TARGET + 1);
assertCatchingUp(() => slave1, false); assertCatchingUp(() => slave1, false);
} }
@ -73,7 +73,7 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 1); setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 1);
assertCatchingUp(() => slave1, true); assertCatchingUp(() => slave1, true);
assertCatchingUp(() => slave2, true); assertCatchingUp(() => slave2, true);
} }
@ -83,8 +83,8 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 1); setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 1);
setSlaveTime(() => slave1, MultiplayerCatchupSyncManager.SYNC_TARGET + 1); setSlaveTime(() => slave1, SpectatorCatchUpSyncManager.SYNC_TARGET + 1);
assertCatchingUp(() => slave1, true); assertCatchingUp(() => slave1, true);
} }
@ -93,8 +93,8 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 2); setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 2);
setSlaveTime(() => slave1, MultiplayerCatchupSyncManager.SYNC_TARGET); setSlaveTime(() => slave1, SpectatorCatchUpSyncManager.SYNC_TARGET);
assertCatchingUp(() => slave1, false); assertCatchingUp(() => slave1, false);
assertCatchingUp(() => slave2, true); assertCatchingUp(() => slave2, true);
} }
@ -104,7 +104,7 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setSlaveTime(() => slave1, -MultiplayerCatchupSyncManager.SYNC_TARGET); setSlaveTime(() => slave1, -SpectatorCatchUpSyncManager.SYNC_TARGET);
assertCatchingUp(() => slave1, false); assertCatchingUp(() => slave1, false);
assertSlaveState(() => slave1, true); assertSlaveState(() => slave1, true);
} }
@ -114,7 +114,7 @@ namespace osu.Game.Tests.OnlinePlay
{ {
setAllWaiting(false); setAllWaiting(false);
setSlaveTime(() => slave1, -MultiplayerCatchupSyncManager.SYNC_TARGET - 1); setSlaveTime(() => slave1, -SpectatorCatchUpSyncManager.SYNC_TARGET - 1);
// This is a silent catchup, where IsCatchingUp = false but IsRunning = false also. // This is a silent catchup, where IsCatchingUp = false but IsRunning = false also.
assertCatchingUp(() => slave1, false); assertCatchingUp(() => slave1, false);
@ -162,10 +162,10 @@ namespace osu.Game.Tests.OnlinePlay
private void assertSlaveState(Func<TestSpectatorSlaveClock> slave, bool running) private void assertSlaveState(Func<TestSpectatorSlaveClock> slave, bool running)
=> AddAssert($"slave {slave().Id} {(running ? "is" : "is not")} running", () => slave().IsRunning == running); => AddAssert($"slave {slave().Id} {(running ? "is" : "is not")} running", () => slave().IsRunning == running);
private class TestSpectatorSlaveClock : TestManualClock, IMultiplayerSpectatorSlaveClock private class TestSpectatorSlaveClock : TestManualClock, ISpectatorSlaveClock
{ {
public readonly Bindable<bool> WaitingOnFrames = new Bindable<bool>(true); public readonly Bindable<bool> WaitingOnFrames = new Bindable<bool>(true);
IBindable<bool> IMultiplayerSpectatorSlaveClock.WaitingOnFrames => WaitingOnFrames; IBindable<bool> ISpectatorSlaveClock.WaitingOnFrames => WaitingOnFrames;
public bool IsCatchingUp { get; set; } public bool IsCatchingUp { get; set; }
@ -183,6 +183,16 @@ namespace osu.Game.Tests.OnlinePlay
Start(); Start();
}); });
} }
public void ProcessFrame()
{
}
public double ElapsedFrameTime => 0;
public double FramesPerSecond => 0;
public FrameTimeInfo TimeInfo => default;
} }
private class TestManualClock : ManualClock, IAdjustableClock private class TestManualClock : ManualClock, IAdjustableClock

View File

@ -1,15 +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
{
public interface IMultiplayerSpectatorSlaveClock : IAdjustableClock
{
IBindable<bool> WaitingOnFrames { get; }
bool IsCatchingUp { get; set; }
}
}

View File

@ -1,16 +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.Timing;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
public interface IMultiplayerSpectatorSyncManager
{
IAdjustableClock Master { get; }
void AddSlave(IMultiplayerSpectatorSlaveClock clock);
void RemoveSlave(IMultiplayerSpectatorSlaveClock clock);
}
}

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Screens.Spectate; using osu.Game.Screens.Spectate;
@ -24,7 +25,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
private readonly PlayerInstance[] instances; private readonly PlayerInstance[] instances;
private MasterGameplayClockContainer masterClockContainer; private MasterGameplayClockContainer masterClockContainer;
private IMultiplayerSpectatorSyncManager syncManager; private ISpectatorSyncManager syncManager;
private PlayerGrid grid; private PlayerGrid grid;
private MultiplayerSpectatorLeaderboard leaderboard; private MultiplayerSpectatorLeaderboard leaderboard;
@ -65,7 +66,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
InternalChildren = new[] InternalChildren = new[]
{ {
(Drawable)(syncManager = new MultiplayerCatchupSyncManager(masterClockContainer)), (Drawable)(syncManager = new SpectatorCatchUpSyncManager(masterClockContainer)),
masterClockContainer masterClockContainer
}; };
@ -101,7 +102,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
leaderboard.RemoveClock(existingInstance.User.Id); leaderboard.RemoveClock(existingInstance.User.Id);
} }
LoadComponentAsync(instances[userIndex] = new PlayerInstance(gameplayState.Score, new MultiplayerSpectatorSlaveClock(masterClockContainer.GameplayClock)), d => LoadComponentAsync(instances[userIndex] = new PlayerInstance(gameplayState.Score, new SpectatorCatchUpSlaveClock(masterClockContainer.GameplayClock)), d =>
{ {
if (instances[userIndex] == d) if (instances[userIndex] == d)
{ {

View File

@ -5,15 +5,16 @@ using osu.Framework.Bindables;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{ {
public class MultiplayerSpectatorPlayer : SpectatorPlayer public class MultiplayerSpectatorPlayer : SpectatorPlayer
{ {
private readonly MultiplayerSpectatorSlaveClock gameplayClock; private readonly SpectatorCatchUpSlaveClock gameplayClock;
public MultiplayerSpectatorPlayer(Score score, MultiplayerSpectatorSlaveClock gameplayClock) public MultiplayerSpectatorPlayer(Score score, SpectatorCatchUpSlaveClock gameplayClock)
: base(score) : base(score)
{ {
this.gameplayClock = gameplayClock; this.gameplayClock = gameplayClock;

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Users; using osu.Game.Users;
@ -20,11 +21,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public WorkingBeatmap Beatmap { get; private set; } public WorkingBeatmap Beatmap { get; private set; }
public readonly Score Score; public readonly Score Score;
public readonly MultiplayerSpectatorSlaveClock GameplayClock; public readonly SpectatorCatchUpSlaveClock GameplayClock;
private OsuScreenStack stack; private OsuScreenStack stack;
public PlayerInstance(Score score, MultiplayerSpectatorSlaveClock gameplayClock) public PlayerInstance(Score score, SpectatorCatchUpSlaveClock gameplayClock)
{ {
Score = score; Score = score;
GameplayClock = gameplayClock; GameplayClock = gameplayClock;

View File

@ -0,0 +1,24 @@
// 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.Sync
{
/// <summary>
/// A clock which is used by <see cref="MultiplayerSpectatorPlayer"/>s and managed by an <see cref="ISpectatorSyncManager"/>.
/// </summary>
public interface ISpectatorSlaveClock : IFrameBasedClock, IAdjustableClock
{
/// <summary>
/// Whether this clock is waiting on frames to continue playback.
/// </summary>
IBindable<bool> WaitingOnFrames { get; }
/// <summary>
/// Whether this clock is resynchronising to the master clock.
/// </summary>
bool IsCatchingUp { get; set; }
}
}

View File

@ -0,0 +1,30 @@
// 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.Timing;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync
{
/// <summary>
/// Manages the synchronisation between one or more slave clocks in relation to a master clock.
/// </summary>
public interface ISpectatorSyncManager
{
/// <summary>
/// The master clock which slaves should synchronise to.
/// </summary>
IAdjustableClock Master { get; }
/// <summary>
/// Adds a slave clock.
/// </summary>
/// <param name="clock">The clock to add.</param>
void AddSlave(ISpectatorSlaveClock clock);
/// <summary>
/// Removes a slave clock.
/// </summary>
/// <param name="clock">The clock to remove.</param>
void RemoveSlave(ISpectatorSlaveClock clock);
}
}

View File

@ -5,9 +5,9 @@ using System;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Timing; using osu.Framework.Timing;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync
{ {
public class MultiplayerSpectatorSlaveClock : IFrameBasedClock, IMultiplayerSpectatorSlaveClock public class SpectatorCatchUpSlaveClock : ISpectatorSlaveClock
{ {
/// <summary> /// <summary>
/// The catchup rate. /// The catchup rate.
@ -16,7 +16,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
private readonly IFrameBasedClock masterClock; private readonly IFrameBasedClock masterClock;
public MultiplayerSpectatorSlaveClock(IFrameBasedClock masterClock) public SpectatorCatchUpSlaveClock(IFrameBasedClock masterClock)
{ {
this.masterClock = masterClock; this.masterClock = masterClock;
} }

View File

@ -7,9 +7,12 @@ using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Timing; using osu.Framework.Timing;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync
{ {
public class MultiplayerCatchupSyncManager : Component, IMultiplayerSpectatorSyncManager /// <summary>
/// A <see cref="ISpectatorSyncManager"/> which synchronises de-synced slave clocks through catchup.
/// </summary>
public class SpectatorCatchUpSyncManager : Component, ISpectatorSyncManager
{ {
/// <summary> /// <summary>
/// The offset from the master clock to which slaves should be synchronised to. /// The offset from the master clock to which slaves should be synchronised to.
@ -34,19 +37,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// <summary> /// <summary>
/// The slave clocks. /// The slave clocks.
/// </summary> /// </summary>
private readonly List<IMultiplayerSpectatorSlaveClock> slaves = new List<IMultiplayerSpectatorSlaveClock>(); private readonly List<ISpectatorSlaveClock> slaves = new List<ISpectatorSlaveClock>();
private bool hasStarted; private bool hasStarted;
private double? firstStartAttemptTime; private double? firstStartAttemptTime;
public MultiplayerCatchupSyncManager(IAdjustableClock master) public SpectatorCatchUpSyncManager(IAdjustableClock master)
{ {
Master = master; Master = master;
} }
public void AddSlave(IMultiplayerSpectatorSlaveClock clock) => slaves.Add(clock); public void AddSlave(ISpectatorSlaveClock clock) => slaves.Add(clock);
public void RemoveSlave(IMultiplayerSpectatorSlaveClock clock) => slaves.Remove(clock); public void RemoveSlave(ISpectatorSlaveClock clock) => slaves.Remove(clock);
protected override void Update() protected override void Update()
{ {