mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Move MasterClockState
handling in to SpectatorSyncManager
This commit is contained in:
@ -4,11 +4,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
@ -52,7 +50,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
private PlayerGrid grid = null!;
|
private PlayerGrid grid = null!;
|
||||||
private MultiSpectatorLeaderboard leaderboard = null!;
|
private MultiSpectatorLeaderboard leaderboard = null!;
|
||||||
private PlayerArea? currentAudioSource;
|
private PlayerArea? currentAudioSource;
|
||||||
private bool canStartMasterClock;
|
|
||||||
|
|
||||||
private readonly Room room;
|
private readonly Room room;
|
||||||
private readonly MultiplayerRoomUser[] users;
|
private readonly MultiplayerRoomUser[] users;
|
||||||
@ -159,7 +156,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
masterClockContainer.Reset();
|
masterClockContainer.Reset();
|
||||||
|
|
||||||
syncManager.ReadyToStart += onReadyToStart;
|
syncManager.ReadyToStart += onReadyToStart;
|
||||||
syncManager.MasterState.BindValueChanged(onMasterStateChanged, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -192,27 +188,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
|
|
||||||
masterClockContainer.StartTime = startTime;
|
masterClockContainer.StartTime = startTime;
|
||||||
masterClockContainer.Reset(true);
|
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)
|
protected override void OnNewPlayingUserState(int userId, SpectatorState spectatorState)
|
||||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
||||||
@ -35,11 +36,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action? ReadyToStart;
|
public event Action? ReadyToStart;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The catch-up state of the master clock.
|
|
||||||
/// </summary>
|
|
||||||
public IBindable<MasterClockState> MasterState => masterState;
|
|
||||||
|
|
||||||
public double CurrentMasterTime => masterClock.CurrentTime;
|
public double CurrentMasterTime => masterClock.CurrentTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -55,11 +51,32 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|||||||
private readonly Bindable<MasterClockState> masterState = new Bindable<MasterClockState>();
|
private readonly Bindable<MasterClockState> masterState = new Bindable<MasterClockState>();
|
||||||
|
|
||||||
private bool hasStarted;
|
private bool hasStarted;
|
||||||
|
|
||||||
private double? firstStartAttemptTime;
|
private double? firstStartAttemptTime;
|
||||||
|
|
||||||
public SpectatorSyncManager(GameplayClockContainer master)
|
public SpectatorSyncManager(GameplayClockContainer master)
|
||||||
{
|
{
|
||||||
masterClock = 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>
|
/// <summary>
|
||||||
|
Reference in New Issue
Block a user