1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

Merge pull request #16690 from smoogipoo/flush-frames-end-play

Purge final spectator frames before ending play
This commit is contained in:
Dean Herbert 2022-01-31 15:40:41 +09:00 committed by GitHub
commit 95582a9023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 6 deletions

View File

@ -15,11 +15,14 @@ using osu.Game.Online.Spectator;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens;
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Visual.Multiplayer;
using osu.Game.Tests.Visual.Spectator;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
@ -200,6 +203,21 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("screen didn't change", () => Stack.CurrentScreen is SoloSpectator);
}
[Test]
public void TestFinalFramesPurgedBeforeEndingPlay()
{
AddStep("begin playing", () => spectatorClient.BeginPlaying(new GameplayState(new TestBeatmap(new OsuRuleset().RulesetInfo), new OsuRuleset()), new Score()));
AddStep("send frames and finish play", () =>
{
spectatorClient.HandleFrame(new OsuReplayFrame(1000, Vector2.Zero));
spectatorClient.EndPlaying();
});
// We can't access API because we're an "online" test.
AddAssert("last received frame has time = 1000", () => spectatorClient.LastReceivedUserFrames.First().Value.Time == 1000);
}
private OsuFramedReplayInputHandler replayHandler =>
(OsuFramedReplayInputHandler)Stack.ChildrenOfType<OsuInputManager>().First().ReplayInputHandler;

View File

@ -184,7 +184,7 @@ namespace osu.Game.Tests.Visual.Gameplay
private void onNewFrames(int userId, FrameDataBundle frames)
{
Logger.Log($"Received {frames.Frames.Count()} new frames ({string.Join(',', frames.Frames.Select(f => ((int)f.Time).ToString()))})");
Logger.Log($"Received {frames.Frames.Count} new frames ({string.Join(',', frames.Frames.Select(f => ((int)f.Time).ToString()))})");
foreach (var legacyFrame in frames.Frames)
{

View File

@ -20,16 +20,16 @@ namespace osu.Game.Online.Spectator
public FrameHeader Header { get; set; }
[Key(1)]
public IEnumerable<LegacyReplayFrame> Frames { get; set; }
public IList<LegacyReplayFrame> Frames { get; set; }
public FrameDataBundle(ScoreInfo score, IEnumerable<LegacyReplayFrame> frames)
public FrameDataBundle(ScoreInfo score, IList<LegacyReplayFrame> frames)
{
Frames = frames;
Header = new FrameHeader(score);
}
[JsonConstructor]
public FrameDataBundle(FrameHeader header, IEnumerable<LegacyReplayFrame> frames)
public FrameDataBundle(FrameHeader header, IList<LegacyReplayFrame> frames)
{
Header = header;
Frames = frames;

View File

@ -167,6 +167,9 @@ namespace osu.Game.Online.Spectator
if (!IsPlaying)
return;
if (pendingFrames.Count > 0)
purgePendingFrames(true);
IsPlaying = false;
currentBeatmap = null;
@ -238,9 +241,12 @@ namespace osu.Game.Online.Spectator
purgePendingFrames();
}
private void purgePendingFrames()
private void purgePendingFrames(bool force = false)
{
if (lastSend?.IsCompleted == false)
if (lastSend?.IsCompleted == false && !force)
return;
if (pendingFrames.Count == 0)
return;
var frames = pendingFrames.ToArray();

View File

@ -14,6 +14,7 @@ using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.Spectator;
using osu.Game.Replays.Legacy;
using osu.Game.Rulesets.Replays;
using osu.Game.Scoring;
namespace osu.Game.Tests.Visual.Spectator
@ -27,12 +28,25 @@ namespace osu.Game.Tests.Visual.Spectator
public override IBindable<bool> IsConnected { get; } = new Bindable<bool>(true);
public IReadOnlyDictionary<int, ReplayFrame> LastReceivedUserFrames => lastReceivedUserFrames;
private readonly Dictionary<int, ReplayFrame> lastReceivedUserFrames = new Dictionary<int, ReplayFrame>();
private readonly Dictionary<int, int> userBeatmapDictionary = new Dictionary<int, int>();
private readonly Dictionary<int, int> userNextFrameDictionary = new Dictionary<int, int>();
[Resolved]
private IAPIProvider api { get; set; } = null!;
public TestSpectatorClient()
{
OnNewFrames += (i, bundle) =>
{
if (PlayingUsers.Contains(i))
lastReceivedUserFrames[i] = bundle.Frames[^1];
};
}
/// <summary>
/// Starts play for an arbitrary user.
/// </summary>