mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 12:42:54 +08:00
Add support to SpectatorClient
to resend failed frame bundles
This commit is contained in:
parent
b0a74a6851
commit
5ff4d3f8e5
@ -168,8 +168,6 @@ namespace osu.Game.Online.Spectator
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendFrames(FrameDataBundle data) => lastSend = SendFramesInternal(data);
|
|
||||||
|
|
||||||
public void EndPlaying(GameplayState state)
|
public void EndPlaying(GameplayState state)
|
||||||
{
|
{
|
||||||
// This method is most commonly called via Dispose(), which is can be asynchronous (via the AsyncDisposalQueue).
|
// This method is most commonly called via Dispose(), which is can be asynchronous (via the AsyncDisposalQueue).
|
||||||
@ -180,7 +178,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (pendingFrames.Count > 0)
|
if (pendingFrames.Count > 0)
|
||||||
purgePendingFrames(true);
|
purgePendingFrames();
|
||||||
|
|
||||||
IsPlaying = false;
|
IsPlaying = false;
|
||||||
currentBeatmap = null;
|
currentBeatmap = null;
|
||||||
@ -230,9 +228,11 @@ namespace osu.Game.Online.Spectator
|
|||||||
|
|
||||||
protected abstract Task StopWatchingUserInternal(int userId);
|
protected abstract Task StopWatchingUserInternal(int userId);
|
||||||
|
|
||||||
|
private readonly Queue<FrameDataBundle> pendingFrameBundles = new Queue<FrameDataBundle>();
|
||||||
|
|
||||||
private readonly Queue<LegacyReplayFrame> pendingFrames = new Queue<LegacyReplayFrame>();
|
private readonly Queue<LegacyReplayFrame> pendingFrames = new Queue<LegacyReplayFrame>();
|
||||||
|
|
||||||
private double lastSendTime;
|
private double lastPurgeTime;
|
||||||
|
|
||||||
private Task? lastSend;
|
private Task? lastSend;
|
||||||
|
|
||||||
@ -242,7 +242,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
if (pendingFrames.Count > 0 && Time.Current - lastSendTime > TIME_BETWEEN_SENDS)
|
if (pendingFrames.Count > 0 && Time.Current - lastPurgeTime > TIME_BETWEEN_SENDS)
|
||||||
purgePendingFrames();
|
purgePendingFrames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,23 +260,41 @@ namespace osu.Game.Online.Spectator
|
|||||||
purgePendingFrames();
|
purgePendingFrames();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void purgePendingFrames(bool force = false)
|
private void purgePendingFrames()
|
||||||
{
|
{
|
||||||
if (lastSend?.IsCompleted == false && !force)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (pendingFrames.Count == 0)
|
if (pendingFrames.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var frames = pendingFrames.ToArray();
|
|
||||||
|
|
||||||
pendingFrames.Clear();
|
|
||||||
|
|
||||||
Debug.Assert(currentScore != null);
|
Debug.Assert(currentScore != null);
|
||||||
|
|
||||||
SendFrames(new FrameDataBundle(currentScore.ScoreInfo, frames));
|
var frames = pendingFrames.ToArray();
|
||||||
|
var bundle = new FrameDataBundle(currentScore.ScoreInfo, frames);
|
||||||
|
|
||||||
lastSendTime = Time.Current;
|
pendingFrames.Clear();
|
||||||
|
lastPurgeTime = Time.Current;
|
||||||
|
|
||||||
|
pendingFrameBundles.Enqueue(bundle);
|
||||||
|
|
||||||
|
sendNextBundleIfRequired();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNextBundleIfRequired()
|
||||||
|
{
|
||||||
|
if (lastSend?.IsCompleted == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!pendingFrameBundles.TryPeek(out var bundle))
|
||||||
|
return;
|
||||||
|
|
||||||
|
lastSend = SendFramesInternal(bundle);
|
||||||
|
lastSend.ContinueWith(t => Schedule(() =>
|
||||||
|
{
|
||||||
|
// If the last bundle send wasn't successful, try again without dequeuing.
|
||||||
|
if (t.IsCompletedSuccessfully)
|
||||||
|
pendingFrameBundles.Dequeue();
|
||||||
|
|
||||||
|
sendNextBundleIfRequired();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user