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.
|
|
|
|
|
2022-09-13 13:21:54 +08:00
|
|
|
using System.Threading;
|
2021-04-15 18:37:45 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-09-08 15:59:20 +08:00
|
|
|
using osu.Framework.Audio;
|
2021-04-14 19:39:14 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-04-08 21:07:00 +08:00
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Screens.Play;
|
2022-12-12 17:56:43 +08:00
|
|
|
using osu.Game.Screens.Ranking;
|
2021-04-08 21:07:00 +08:00
|
|
|
|
|
|
|
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 partial class MultiSpectatorPlayer : SpectatorPlayer
|
2021-04-08 21:07:00 +08:00
|
|
|
{
|
2022-09-08 16:14:06 +08:00
|
|
|
/// <summary>
|
|
|
|
/// All adjustments applied to the clock of this <see cref="MultiSpectatorPlayer"/> which come from mods.
|
|
|
|
/// </summary>
|
2022-09-08 16:37:02 +08:00
|
|
|
public IAggregateAudioAdjustment ClockAdjustmentsFromMods => clockAdjustmentsFromMods;
|
2022-09-08 15:59:20 +08:00
|
|
|
|
2022-09-08 16:37:02 +08:00
|
|
|
private readonly AudioAdjustments clockAdjustmentsFromMods = new AudioAdjustments();
|
2022-08-24 14:07:04 +08:00
|
|
|
private readonly SpectatorPlayerClock 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>
|
2022-08-24 14:07:04 +08:00
|
|
|
public MultiSpectatorPlayer(Score score, SpectatorPlayerClock 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]
|
2022-09-13 13:21:54 +08:00
|
|
|
private void load(CancellationToken cancellationToken)
|
2021-04-15 18:37:45 +08:00
|
|
|
{
|
2022-09-13 13:21:54 +08:00
|
|
|
// HUD overlay may not be loaded if load has been cancelled early.
|
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-08-15 15:56:16 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
// The player clock's running state is controlled externally, but the local pausing state needs to be updated to start/stop gameplay.
|
2023-09-22 12:16:51 +08:00
|
|
|
if (GameplayClockContainer.IsRunning)
|
2022-08-15 15:56:16 +08:00
|
|
|
GameplayClockContainer.Start();
|
|
|
|
else
|
|
|
|
GameplayClockContainer.Stop();
|
|
|
|
|
|
|
|
base.Update();
|
|
|
|
}
|
|
|
|
|
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.
|
2022-08-24 14:40:47 +08:00
|
|
|
spectatorPlayerClock.WaitingOnFrames = 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)
|
2022-09-08 16:14:06 +08:00
|
|
|
{
|
2023-09-22 13:26:33 +08:00
|
|
|
// Importantly, we don't want to apply decoupling because SpectatorPlayerClock updates its IsRunning directly.
|
|
|
|
// If we applied decoupling, this state change wouldn't actually cause the clock to stop.
|
|
|
|
// TODO: Can we just use Start/Stop rather than this workaround, now that DecouplingClock is more sane?
|
|
|
|
var gameplayClockContainer = new GameplayClockContainer(spectatorPlayerClock, applyOffsets: false, requireDecoupling: false);
|
2022-09-08 16:37:02 +08:00
|
|
|
clockAdjustmentsFromMods.BindAdjustments(gameplayClockContainer.AdjustmentsFromMods);
|
2022-09-08 16:14:06 +08:00
|
|
|
return gameplayClockContainer;
|
|
|
|
}
|
2022-12-12 17:56:43 +08:00
|
|
|
|
|
|
|
protected override ResultsScreen CreateResults(ScoreInfo score) => new MultiSpectatorResultsScreen(score);
|
2021-04-08 21:07:00 +08:00
|
|
|
}
|
|
|
|
}
|