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-22 22:52:22 +08:00
|
|
|
using JetBrains.Annotations;
|
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;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|
|
|
{
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A single spectated player within a <see cref="MultiSpectatorScreen"/>.
|
|
|
|
/// </summary>
|
2021-04-22 22:39:02 +08:00
|
|
|
public class MultiSpectatorPlayer : SpectatorPlayer
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2021-04-21 22:21:03 +08:00
|
|
|
private readonly Bindable<bool> waitingOnFrames = new Bindable<bool>(true);
|
2021-04-26 16:19:44 +08:00
|
|
|
private readonly ISpectatorPlayerClock spectatorPlayerClock;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
2021-04-22 22:52:22 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="MultiSpectatorPlayer"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="score">The score containing the player's replay.</param>
|
2021-04-26 16:19:44 +08:00
|
|
|
/// <param name="spectatorPlayerClock">The clock controlling the gameplay running state.</param>
|
|
|
|
public MultiSpectatorPlayer([NotNull] Score score, [NotNull] ISpectatorPlayerClock spectatorPlayerClock)
|
2021-08-16 15:48:40 +08:00
|
|
|
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2021-04-26 16:19:44 +08:00
|
|
|
this.spectatorPlayerClock = spectatorPlayerClock;
|
2021-04-14 19:39:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-15 18:37:45 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-04-26 16:19:44 +08:00
|
|
|
spectatorPlayerClock.WaitingOnFrames.BindTo(waitingOnFrames);
|
2021-08-13 11:28:07 +08:00
|
|
|
|
2021-08-13 12:28:57 +08:00
|
|
|
HUDOverlay.PlayerSettingsOverlay.Expire();
|
2021-08-13 12:29:55 +08:00
|
|
|
HUDOverlay.HoldToQuit.Expire();
|
2021-04-21 22:21:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
2021-04-22 22:52:22 +08:00
|
|
|
|
|
|
|
// This is required because the frame stable clock is set to WaitingOnFrames = false for one frame.
|
2021-06-02 14:44:04 +08:00
|
|
|
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-26 16:19:44 +08:00
|
|
|
=> new SpectatorGameplayClockContainer(spectatorPlayerClock);
|
2021-04-14 19:39:14 +08:00
|
|
|
|
2021-04-26 16:19:44 +08:00
|
|
|
private class SpectatorGameplayClockContainer : GameplayClockContainer
|
2021-04-14 19:39:14 +08:00
|
|
|
{
|
2021-04-26 16:19:44 +08:00
|
|
|
public SpectatorGameplayClockContainer([NotNull] IClock sourceClock)
|
2021-04-21 22:22:36 +08:00
|
|
|
: base(sourceClock)
|
|
|
|
{
|
2022-01-30 01:17:57 +08:00
|
|
|
// the container should initially be in a stopped state until the catch-up clock is started by the sync manager.
|
|
|
|
Stop();
|
2021-04-21 22:22:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
2021-04-26 16:19:44 +08:00
|
|
|
// The player clock's running state is controlled externally, but the local pausing state needs to be updated to stop gameplay.
|
2021-04-21 22:22:36 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|