mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Make MultiSpectatorScreen and tests more resillient to timing
This commit is contained in:
@ -82,8 +82,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
start(new[] { PLAYER_1_ID, PLAYER_2_ID });
|
start(new[] { PLAYER_1_ID, PLAYER_2_ID });
|
||||||
loadSpectateScreen();
|
loadSpectateScreen();
|
||||||
|
|
||||||
sendFrames(PLAYER_1_ID, 20);
|
sendFrames(PLAYER_1_ID, 40);
|
||||||
sendFrames(PLAYER_2_ID, 10);
|
sendFrames(PLAYER_2_ID, 20);
|
||||||
|
|
||||||
checkPaused(PLAYER_2_ID, true);
|
checkPaused(PLAYER_2_ID, true);
|
||||||
checkPausedInstant(PLAYER_1_ID, false);
|
checkPausedInstant(PLAYER_1_ID, false);
|
||||||
@ -196,6 +196,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
sendFrames(PLAYER_1_ID, 10);
|
sendFrames(PLAYER_1_ID, 10);
|
||||||
sendFrames(PLAYER_2_ID, 20);
|
sendFrames(PLAYER_2_ID, 20);
|
||||||
|
checkPaused(PLAYER_1_ID, false);
|
||||||
assertMuted(PLAYER_1_ID, false);
|
assertMuted(PLAYER_1_ID, false);
|
||||||
assertMuted(PLAYER_2_ID, true);
|
assertMuted(PLAYER_2_ID, true);
|
||||||
|
|
||||||
@ -297,7 +298,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
=> AddUntilStep($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().GameplayClock.IsRunning != state);
|
=> AddUntilStep($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().GameplayClock.IsRunning != state);
|
||||||
|
|
||||||
private void checkPausedInstant(int userId, bool state)
|
private void checkPausedInstant(int userId, bool state)
|
||||||
=> AddAssert($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().GameplayClock.IsRunning != state);
|
{
|
||||||
|
checkPaused(userId, state);
|
||||||
|
|
||||||
|
// Todo: The following should work, but is broken because SpectatorScreen retrieves the WorkingBeatmap via the BeatmapManager, bypassing the test scene clock and running real-time.
|
||||||
|
// AddAssert($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType<GameplayClockContainer>().First().GameplayClock.IsRunning != state);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertMuted(int userId, bool muted)
|
private void assertMuted(int userId, bool muted)
|
||||||
=> AddAssert($"{userId} {(muted ? "is" : "is not")} muted", () => getInstance(userId).Mute == muted);
|
=> AddAssert($"{userId} {(muted ? "is" : "is not")} muted", () => getInstance(userId).Mute == muted);
|
||||||
|
@ -43,6 +43,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
private PlayerGrid grid;
|
private PlayerGrid grid;
|
||||||
private MultiSpectatorLeaderboard leaderboard;
|
private MultiSpectatorLeaderboard leaderboard;
|
||||||
private PlayerArea currentAudioSource;
|
private PlayerArea currentAudioSource;
|
||||||
|
private bool canStartMasterClock;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="MultiSpectatorScreen"/>.
|
/// Creates a new <see cref="MultiSpectatorScreen"/>.
|
||||||
@ -108,17 +109,17 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
|
|
||||||
leaderboardContainer.Add(leaderboard);
|
leaderboardContainer.Add(leaderboard);
|
||||||
});
|
});
|
||||||
|
|
||||||
syncManager.ReadyToStart += onReadyToStart;
|
|
||||||
syncManager.MasterState.BindValueChanged(onMasterStateChanged, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
masterClockContainer.Stop();
|
|
||||||
masterClockContainer.Reset();
|
masterClockContainer.Reset();
|
||||||
|
masterClockContainer.Stop();
|
||||||
|
|
||||||
|
syncManager.ReadyToStart += onReadyToStart;
|
||||||
|
syncManager.MasterState.BindValueChanged(onMasterStateChanged, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -151,6 +152,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
|
|
||||||
masterClockContainer.Seek(startTime);
|
masterClockContainer.Seek(startTime);
|
||||||
masterClockContainer.Start();
|
masterClockContainer.Start();
|
||||||
|
|
||||||
|
// Although the clock has been started, this flag is set to allow for later synchronisation state changes to also be able to start it.
|
||||||
|
canStartMasterClock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onMasterStateChanged(ValueChangedEvent<MasterClockState> state)
|
private void onMasterStateChanged(ValueChangedEvent<MasterClockState> state)
|
||||||
@ -158,7 +162,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
switch (state.NewValue)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
case MasterClockState.Synchronised:
|
case MasterClockState.Synchronised:
|
||||||
|
if (canStartMasterClock)
|
||||||
masterClockContainer.Start();
|
masterClockContainer.Start();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MasterClockState.TooFarAhead:
|
case MasterClockState.TooFarAhead:
|
||||||
|
Reference in New Issue
Block a user