2021-04-08 21:07:00 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-04-15 18:37:45 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-04-21 22:21:03 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-04-14 19:39:14 +08:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Game.Scoring;
|
2021-04-15 18:32:55 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|
|
|
{
|
|
|
|
public class MultiplayerSpectatorPlayer : SpectatorPlayer
|
|
|
|
{
|
2021-04-21 22:21:03 +08:00
|
|
|
private readonly Bindable<bool> waitingOnFrames = new Bindable<bool>(true);
|
|
|
|
private readonly Score score;
|
|
|
|
private readonly ISlaveClock slaveClock;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2021-04-21 22:21:03 +08:00
|
|
|
public MultiplayerSpectatorPlayer(Score score, ISlaveClock slaveClock)
|
2021-04-08 21:07:00 +08:00
|
|
|
: base(score)
|
|
|
|
{
|
2021-04-21 22:21:03 +08:00
|
|
|
this.score = score;
|
|
|
|
this.slaveClock = slaveClock;
|
2021-04-14 19:39:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-15 18:37:45 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-04-21 22:21:03 +08:00
|
|
|
slaveClock.WaitingOnFrames.BindTo(waitingOnFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
waitingOnFrames.Value = DrawableRuleset.FrameStableClock.WaitingOnFrames.Value || score.Replay.Frames.Count == 0;
|
2021-04-15 18:37:45 +08:00
|
|
|
}
|
|
|
|
|
2021-04-14 19:39:14 +08:00
|
|
|
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
|
2021-04-21 22:22:36 +08:00
|
|
|
=> new SlaveGameplayClockContainer(slaveClock);
|
2021-04-14 19:39:14 +08:00
|
|
|
|
2021-04-21 22:22:36 +08:00
|
|
|
private class SlaveGameplayClockContainer : GameplayClockContainer
|
2021-04-14 19:39:14 +08:00
|
|
|
{
|
2021-04-21 22:22:36 +08:00
|
|
|
public SlaveGameplayClockContainer(IClock sourceClock)
|
|
|
|
: base(sourceClock)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
// The slave clock's running state is controlled by the sync manager, but the local pausing state needs to be updated to stop gameplay.
|
|
|
|
if (SourceClock.IsRunning)
|
|
|
|
Start();
|
|
|
|
else
|
|
|
|
Stop();
|
|
|
|
|
|
|
|
base.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override GameplayClock CreateGameplayClock(IFrameBasedClock source) => new GameplayClock(source);
|
2021-04-14 19:39:14 +08:00
|
|
|
}
|
2021-04-08 21:07:00 +08:00
|
|
|
}
|
|
|
|
}
|