1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:02:53 +08:00

Move MasterClockState handling in to SpectatorSyncManager

This commit is contained in:
Dean Herbert 2022-08-24 15:51:54 +09:00
parent d33d705684
commit 683d49c608
2 changed files with 22 additions and 30 deletions

View File

@ -4,11 +4,9 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
@ -52,7 +50,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
private PlayerGrid grid = null!;
private MultiSpectatorLeaderboard leaderboard = null!;
private PlayerArea? currentAudioSource;
private bool canStartMasterClock;
private readonly Room room;
private readonly MultiplayerRoomUser[] users;
@ -159,7 +156,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
masterClockContainer.Reset();
syncManager.ReadyToStart += onReadyToStart;
syncManager.MasterState.BindValueChanged(onMasterStateChanged, true);
}
protected override void Update()
@ -192,27 +188,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
masterClockContainer.StartTime = startTime;
masterClockContainer.Reset(true);
// 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)
{
Logger.Log($"{nameof(MultiSpectatorScreen)}'s master clock become {state.NewValue}");
switch (state.NewValue)
{
case MasterClockState.Synchronised:
if (canStartMasterClock)
masterClockContainer.Start();
break;
case MasterClockState.TooFarAhead:
masterClockContainer.Stop();
break;
}
}
protected override void OnNewPlayingUserState(int userId, SpectatorState spectatorState)

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
@ -35,11 +36,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// </summary>
public event Action? ReadyToStart;
/// <summary>
/// The catch-up state of the master clock.
/// </summary>
public IBindable<MasterClockState> MasterState => masterState;
public double CurrentMasterTime => masterClock.CurrentTime;
/// <summary>
@ -55,11 +51,32 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
private readonly Bindable<MasterClockState> masterState = new Bindable<MasterClockState>();
private bool hasStarted;
private double? firstStartAttemptTime;
public SpectatorSyncManager(GameplayClockContainer master)
{
masterClock = master;
masterState.BindValueChanged(onMasterStateChanged);
}
private void onMasterStateChanged(ValueChangedEvent<MasterClockState> state)
{
Logger.Log($"{nameof(SpectatorSyncManager)}'s master clock become {state.NewValue}");
switch (state.NewValue)
{
case MasterClockState.Synchronised:
if (hasStarted)
masterClock.Start();
break;
case MasterClockState.TooFarAhead:
masterClock.Stop();
break;
}
}
/// <summary>