-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMultiSpectatorPlayer.cs
More file actions
103 lines (85 loc) · 4.59 KB
/
MultiSpectatorPlayer.cs
File metadata and controls
103 lines (85 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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.
using System;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Game.Beatmaps;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.Leaderboards;
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
/// <summary>
/// A single spectated player within a <see cref="MultiSpectatorScreen"/>.
/// </summary>
public partial class MultiSpectatorPlayer : SpectatorPlayer
{
/// <summary>
/// All adjustments applied to the clock of this <see cref="MultiSpectatorPlayer"/> which come from mods.
/// </summary>
public IAggregateAudioAdjustment ClockAdjustmentsFromMods => clockAdjustmentsFromMods;
private readonly AudioAdjustments clockAdjustmentsFromMods = new AudioAdjustments();
private readonly SpectatorPlayerClock spectatorPlayerClock;
// purposefully cached as empty - the multi spectator screen already has one leaderboard, on the left of all the player instances
[Cached(typeof(IGameplayLeaderboardProvider))]
private readonly EmptyGameplayLeaderboardProvider leaderboardProvider = new EmptyGameplayLeaderboardProvider();
/// <summary>
/// Creates a new <see cref="MultiSpectatorPlayer"/>.
/// </summary>
/// <param name="score">The score containing the player's replay.</param>
/// <param name="spectatorPlayerClock">The clock controlling the gameplay running state.</param>
public MultiSpectatorPlayer(Score score, SpectatorPlayerClock spectatorPlayerClock)
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
{
this.spectatorPlayerClock = spectatorPlayerClock;
ShowSettingsOverlay = false;
}
[BackgroundDependencyLoader]
private void load(CancellationToken cancellationToken)
{
// HUD overlay may not be loaded if load has been cancelled early.
if (cancellationToken.IsCancellationRequested)
return;
if (!LoadedBeatmapSuccessfully)
return;
// also applied in `MultiplayerPlayer.load()`
ScoreProcessor.ApplyNewJudgementsWhenFailed = true;
HUDOverlay.HoldToQuit.Expire();
}
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.
if (GameplayClockContainer.IsRunning)
GameplayClockContainer.Start();
else
GameplayClockContainer.Stop();
base.Update();
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// This is required because the frame stable clock is set to WaitingOnFrames = false for one frame.
spectatorPlayerClock.WaitingOnFrames = DrawableRuleset.FrameStableClock.WaitingOnFrames.Value || Score.Replay.Frames.Count == 0;
}
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
{
// 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);
clockAdjustmentsFromMods.BindAdjustments(gameplayClockContainer.AdjustmentsFromMods);
return gameplayClockContainer;
}
protected override ResultsScreen CreateResults(ScoreInfo score) => new MultiSpectatorResultsScreen(score);
protected override void PerformFail()
{
// base logic intentionally suppressed - failing in multiplayer only marks the score with F rank
// see also: `MultiplayerPlayer.PerformFail()`
ScoreProcessor.FailScore(Score.ScoreInfo);
}
protected override void ConcludeFailedScore(Score score)
=> throw new NotSupportedException($"{nameof(MultiSpectatorPlayer)} should never be calling {nameof(ConcludeFailedScore)}. Failing in multiplayer only marks the score with F rank.");
}
}