1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Add a paired schedule in SpectatorClient.BeginPlaying

Optimally, I would like to remove the `Schedule` in `EndPlaying`, but it
turns out quite a few test are relying on this at very least. Adding a
paired schedule ensure that order of operations is correct, at least.
This commit is contained in:
Dean Herbert 2021-12-06 16:34:15 +09:00
parent a13067eaa4
commit 7a333ffdcc

View File

@ -136,30 +136,32 @@ namespace osu.Game.Online.Spectator
public void BeginPlaying(GameplayState state, Score score) public void BeginPlaying(GameplayState state, Score score)
{ {
Debug.Assert(ThreadSafety.IsUpdateThread); // This schedule is only here to match the one below in `EndPlaying`.
Schedule(() =>
{
if (IsPlaying)
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
if (IsPlaying) IsPlaying = true;
throw new InvalidOperationException($"Cannot invoke {nameof(BeginPlaying)} when already playing");
IsPlaying = true; // transfer state at point of beginning play
currentState.BeatmapID = score.ScoreInfo.BeatmapInfo.OnlineID;
currentState.RulesetID = score.ScoreInfo.RulesetID;
currentState.Mods = score.ScoreInfo.Mods.Select(m => new APIMod(m)).ToArray();
// transfer state at point of beginning play currentBeatmap = state.Beatmap;
currentState.BeatmapID = score.ScoreInfo.BeatmapInfo.OnlineID; currentScore = score;
currentState.RulesetID = score.ScoreInfo.RulesetID;
currentState.Mods = score.ScoreInfo.Mods.Select(m => new APIMod(m)).ToArray();
currentBeatmap = state.Beatmap; BeginPlayingInternal(currentState);
currentScore = score; });
BeginPlayingInternal(currentState);
} }
public void SendFrames(FrameDataBundle data) => lastSend = SendFramesInternal(data); public void SendFrames(FrameDataBundle data) => lastSend = SendFramesInternal(data);
public void EndPlaying() public void EndPlaying()
{ {
// This method is most commonly called via Dispose(), which is asynchronous. // This method is most commonly called via Dispose(), which is can be asynchronous (via the AsyncDisposalQueue).
// Todo: This should not be a thing, but requires framework changes. // We probably need to find a better way to handle this...
Schedule(() => Schedule(() =>
{ {
if (!IsPlaying) if (!IsPlaying)