mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:20:04 +08:00
More refactorings/renamespacings/xmldocs
This commit is contained in:
parent
df4fce2c57
commit
82fcabb8f0
@ -6,16 +6,16 @@ using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class MultiplayerCatchupSyncManagerTest : OsuTestScene
|
||||
public class MultiplayerCatchUpSyncManagerTest : OsuTestScene
|
||||
{
|
||||
private TestManualClock master;
|
||||
private MultiplayerCatchupSyncManager catchupSyncManager;
|
||||
private SpectatorCatchUpSyncManager syncManager;
|
||||
|
||||
private TestSpectatorSlaveClock slave1;
|
||||
private TestSpectatorSlaveClock slave2;
|
||||
@ -23,11 +23,11 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
catchupSyncManager = new MultiplayerCatchupSyncManager(master = new TestManualClock());
|
||||
catchupSyncManager.AddSlave(slave1 = new TestSpectatorSlaveClock(1));
|
||||
catchupSyncManager.AddSlave(slave2 = new TestSpectatorSlaveClock(2));
|
||||
syncManager = new SpectatorCatchUpSyncManager(master = new TestManualClock());
|
||||
syncManager.AddSlave(slave1 = new TestSpectatorSlaveClock(1));
|
||||
syncManager.AddSlave(slave2 = new TestSpectatorSlaveClock(2));
|
||||
|
||||
Schedule(() => Child = catchupSyncManager);
|
||||
Schedule(() => Child = syncManager);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -47,7 +47,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
[Test]
|
||||
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);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
public void TestMasterClockStartsWhenAnyReadyForMaximumDelayTime()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
setAllWaiting(false);
|
||||
|
||||
setMasterTime(MultiplayerCatchupSyncManager.SYNC_TARGET + 1);
|
||||
setMasterTime(SpectatorCatchUpSyncManager.SYNC_TARGET + 1);
|
||||
assertCatchingUp(() => slave1, false);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
setAllWaiting(false);
|
||||
|
||||
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 1);
|
||||
setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 1);
|
||||
assertCatchingUp(() => slave1, true);
|
||||
assertCatchingUp(() => slave2, true);
|
||||
}
|
||||
@ -83,8 +83,8 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
setAllWaiting(false);
|
||||
|
||||
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 1);
|
||||
setSlaveTime(() => slave1, MultiplayerCatchupSyncManager.SYNC_TARGET + 1);
|
||||
setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 1);
|
||||
setSlaveTime(() => slave1, SpectatorCatchUpSyncManager.SYNC_TARGET + 1);
|
||||
assertCatchingUp(() => slave1, true);
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
setAllWaiting(false);
|
||||
|
||||
setMasterTime(MultiplayerCatchupSyncManager.MAX_SYNC_OFFSET + 2);
|
||||
setSlaveTime(() => slave1, MultiplayerCatchupSyncManager.SYNC_TARGET);
|
||||
setMasterTime(SpectatorCatchUpSyncManager.MAX_SYNC_OFFSET + 2);
|
||||
setSlaveTime(() => slave1, SpectatorCatchUpSyncManager.SYNC_TARGET);
|
||||
assertCatchingUp(() => slave1, false);
|
||||
assertCatchingUp(() => slave2, true);
|
||||
}
|
||||
@ -104,7 +104,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
setAllWaiting(false);
|
||||
|
||||
setSlaveTime(() => slave1, -MultiplayerCatchupSyncManager.SYNC_TARGET);
|
||||
setSlaveTime(() => slave1, -SpectatorCatchUpSyncManager.SYNC_TARGET);
|
||||
assertCatchingUp(() => slave1, false);
|
||||
assertSlaveState(() => slave1, true);
|
||||
}
|
||||
@ -114,7 +114,7 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
{
|
||||
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.
|
||||
assertCatchingUp(() => slave1, false);
|
||||
@ -162,10 +162,10 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
private void assertSlaveState(Func<TestSpectatorSlaveClock> slave, bool 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);
|
||||
IBindable<bool> IMultiplayerSpectatorSlaveClock.WaitingOnFrames => WaitingOnFrames;
|
||||
IBindable<bool> ISpectatorSlaveClock.WaitingOnFrames => WaitingOnFrames;
|
||||
|
||||
public bool IsCatchingUp { get; set; }
|
||||
|
||||
@ -183,6 +183,16 @@ namespace osu.Game.Tests.OnlinePlay
|
||||
Start();
|
||||
});
|
||||
}
|
||||
|
||||
public void ProcessFrame()
|
||||
{
|
||||
}
|
||||
|
||||
public double ElapsedFrameTime => 0;
|
||||
|
||||
public double FramesPerSecond => 0;
|
||||
|
||||
public FrameTimeInfo TimeInfo => default;
|
||||
}
|
||||
|
||||
private class TestManualClock : ManualClock, IAdjustableClock
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Online.Spectator;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Screens.Spectate;
|
||||
|
||||
@ -24,7 +25,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
|
||||
private readonly PlayerInstance[] instances;
|
||||
private MasterGameplayClockContainer masterClockContainer;
|
||||
private IMultiplayerSpectatorSyncManager syncManager;
|
||||
private ISpectatorSyncManager syncManager;
|
||||
private PlayerGrid grid;
|
||||
private MultiplayerSpectatorLeaderboard leaderboard;
|
||||
|
||||
@ -65,7 +66,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
|
||||
InternalChildren = new[]
|
||||
{
|
||||
(Drawable)(syncManager = new MultiplayerCatchupSyncManager(masterClockContainer)),
|
||||
(Drawable)(syncManager = new SpectatorCatchUpSyncManager(masterClockContainer)),
|
||||
masterClockContainer
|
||||
};
|
||||
|
||||
@ -101,7 +102,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
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)
|
||||
{
|
||||
|
@ -5,15 +5,16 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
{
|
||||
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)
|
||||
{
|
||||
this.gameplayClock = gameplayClock;
|
||||
|
@ -6,6 +6,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Users;
|
||||
|
||||
@ -20,11 +21,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
public WorkingBeatmap Beatmap { get; private set; }
|
||||
|
||||
public readonly Score Score;
|
||||
public readonly MultiplayerSpectatorSlaveClock GameplayClock;
|
||||
public readonly SpectatorCatchUpSlaveClock GameplayClock;
|
||||
|
||||
private OsuScreenStack stack;
|
||||
|
||||
public PlayerInstance(Score score, MultiplayerSpectatorSlaveClock gameplayClock)
|
||||
public PlayerInstance(Score score, SpectatorCatchUpSlaveClock gameplayClock)
|
||||
{
|
||||
Score = score;
|
||||
GameplayClock = gameplayClock;
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -5,9 +5,9 @@ using System;
|
||||
using osu.Framework.Bindables;
|
||||
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>
|
||||
/// The catchup rate.
|
||||
@ -16,7 +16,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||
|
||||
private readonly IFrameBasedClock masterClock;
|
||||
|
||||
public MultiplayerSpectatorSlaveClock(IFrameBasedClock masterClock)
|
||||
public SpectatorCatchUpSlaveClock(IFrameBasedClock masterClock)
|
||||
{
|
||||
this.masterClock = masterClock;
|
||||
}
|
@ -7,9 +7,12 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
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>
|
||||
/// 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>
|
||||
/// The slave clocks.
|
||||
/// </summary>
|
||||
private readonly List<IMultiplayerSpectatorSlaveClock> slaves = new List<IMultiplayerSpectatorSlaveClock>();
|
||||
private readonly List<ISpectatorSlaveClock> slaves = new List<ISpectatorSlaveClock>();
|
||||
|
||||
private bool hasStarted;
|
||||
private double? firstStartAttemptTime;
|
||||
|
||||
public MultiplayerCatchupSyncManager(IAdjustableClock master)
|
||||
public SpectatorCatchUpSyncManager(IAdjustableClock 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()
|
||||
{
|
Loading…
Reference in New Issue
Block a user