mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:23:00 +08:00
Remove local "next frame" storage
This commit is contained in:
parent
e18f4cd4ba
commit
58d71e4aea
@ -41,8 +41,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
|
||||
private int nextFrame;
|
||||
|
||||
private BeatmapSetInfo importedBeatmap;
|
||||
|
||||
private int importedBeatmapId;
|
||||
@ -51,8 +49,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("reset sent frames", () => nextFrame = 0);
|
||||
|
||||
AddStep("import beatmap", () =>
|
||||
{
|
||||
importedBeatmap = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Result;
|
||||
@ -105,7 +101,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
waitForPlayer();
|
||||
checkPaused(true);
|
||||
|
||||
sendFrames(1000); // send enough frames to ensure play won't be paused
|
||||
// send enough frames to ensure play won't be paused
|
||||
sendFrames(100);
|
||||
|
||||
checkPaused(false);
|
||||
}
|
||||
@ -114,12 +111,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
public void TestSpectatingDuringGameplay()
|
||||
{
|
||||
start();
|
||||
sendFrames(300);
|
||||
|
||||
loadSpectatingScreen();
|
||||
waitForPlayer();
|
||||
|
||||
AddStep("advance frame count", () => nextFrame = 300);
|
||||
sendFrames();
|
||||
sendFrames(300);
|
||||
|
||||
AddUntilStep("playing from correct point in time", () => player.ChildrenOfType<DrawableRuleset>().First().FrameStableClock.CurrentTime > 30000);
|
||||
}
|
||||
@ -220,11 +217,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
|
||||
private void sendFrames(int count = 10)
|
||||
{
|
||||
AddStep("send frames", () =>
|
||||
{
|
||||
testSpectatorClient.SendFrames(streamingUser.Id, nextFrame, count);
|
||||
nextFrame += count;
|
||||
});
|
||||
AddStep("send frames", () => testSpectatorClient.SendFrames(streamingUser.Id, count));
|
||||
}
|
||||
|
||||
private void loadSpectatingScreen()
|
||||
|
@ -96,10 +96,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
// For player 2, send frames in sets of 10.
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
spectatorClient.SendFrames(PLAYER_1_ID, i, 1);
|
||||
spectatorClient.SendFrames(PLAYER_1_ID, 1);
|
||||
|
||||
if (i % 10 == 0)
|
||||
spectatorClient.SendFrames(PLAYER_2_ID, i, 10);
|
||||
spectatorClient.SendFrames(PLAYER_2_ID, 10);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
private MultiSpectatorScreen spectatorScreen;
|
||||
|
||||
private readonly List<int> playingUserIds = new List<int>();
|
||||
private readonly Dictionary<int, int> nextFrame = new Dictionary<int, int>();
|
||||
|
||||
private BeatmapSetInfo importedSet;
|
||||
private BeatmapInfo importedBeatmap;
|
||||
@ -55,8 +54,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("reset sent frames", () => nextFrame.Clear());
|
||||
|
||||
AddStep("add streaming client", () =>
|
||||
{
|
||||
Remove(spectatorClient);
|
||||
@ -80,8 +77,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
|
||||
playingUserIds.Add(PLAYER_1_ID);
|
||||
playingUserIds.Add(PLAYER_2_ID);
|
||||
nextFrame[PLAYER_1_ID] = 0;
|
||||
nextFrame[PLAYER_2_ID] = 0;
|
||||
});
|
||||
|
||||
loadSpectateScreen(false);
|
||||
@ -253,7 +248,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Client.CurrentMatchPlayingUserIds.Add(id);
|
||||
spectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||
playingUserIds.Add(id);
|
||||
nextFrame[id] = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -264,7 +258,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
spectatorClient.EndPlay(userId);
|
||||
playingUserIds.Remove(userId);
|
||||
nextFrame.Remove(userId);
|
||||
});
|
||||
}
|
||||
|
||||
@ -275,10 +268,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep("send frames", () =>
|
||||
{
|
||||
foreach (int id in userIds)
|
||||
{
|
||||
spectatorClient.SendFrames(id, nextFrame[id], count);
|
||||
nextFrame[id] += count;
|
||||
}
|
||||
spectatorClient.SendFrames(id, count);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,15 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
{
|
||||
public class TestSpectatorClient : SpectatorClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum number of frames sent per bundle via <see cref="SendFrames"/>.
|
||||
/// </summary>
|
||||
public const int FRAME_BUNDLE_SIZE = 10;
|
||||
|
||||
public override IBindable<bool> IsConnected { get; } = new Bindable<bool>(true);
|
||||
|
||||
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!;
|
||||
@ -35,6 +41,7 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
public void StartPlay(int userId, int beatmapId)
|
||||
{
|
||||
userBeatmapDictionary[userId] = beatmapId;
|
||||
userNextFrameDictionary[userId] = 0;
|
||||
sendPlayingState(userId);
|
||||
}
|
||||
|
||||
@ -57,24 +64,41 @@ namespace osu.Game.Tests.Visual.Spectator
|
||||
public new void Schedule(Action action) => base.Schedule(action);
|
||||
|
||||
/// <summary>
|
||||
/// Sends frames for an arbitrary user.
|
||||
/// Sends frames for an arbitrary user, in bundles containing 10 frames each.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user to send frames for.</param>
|
||||
/// <param name="index">The frame index.</param>
|
||||
/// <param name="count">The number of frames to send.</param>
|
||||
public void SendFrames(int userId, int index, int count)
|
||||
/// <param name="count">The total number of frames to send.</param>
|
||||
public void SendFrames(int userId, int count)
|
||||
{
|
||||
var frames = new List<LegacyReplayFrame>();
|
||||
|
||||
for (int i = index; i < index + count; i++)
|
||||
{
|
||||
var buttonState = i == index + count - 1 ? ReplayButtonState.None : ReplayButtonState.Left1;
|
||||
int currentFrameIndex = userNextFrameDictionary[userId];
|
||||
int lastFrameIndex = currentFrameIndex + count - 1;
|
||||
|
||||
frames.Add(new LegacyReplayFrame(i * 100, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
|
||||
for (; currentFrameIndex <= lastFrameIndex; currentFrameIndex++)
|
||||
{
|
||||
// This is done in the next frame so that currentFrameIndex is updated to the correct value.
|
||||
if (frames.Count == FRAME_BUNDLE_SIZE)
|
||||
flush();
|
||||
|
||||
var buttonState = currentFrameIndex == lastFrameIndex ? ReplayButtonState.None : ReplayButtonState.Left1;
|
||||
frames.Add(new LegacyReplayFrame(currentFrameIndex * 100, RNG.Next(0, 512), RNG.Next(0, 512), buttonState));
|
||||
}
|
||||
|
||||
var bundle = new FrameDataBundle(new ScoreInfo { Combo = index + count }, frames);
|
||||
((ISpectatorClient)this).UserSentFrames(userId, bundle);
|
||||
flush();
|
||||
|
||||
userNextFrameDictionary[userId] = currentFrameIndex;
|
||||
|
||||
void flush()
|
||||
{
|
||||
if (frames.Count == 0)
|
||||
return;
|
||||
|
||||
var bundle = new FrameDataBundle(new ScoreInfo { Combo = currentFrameIndex }, frames.ToArray());
|
||||
((ISpectatorClient)this).UserSentFrames(userId, bundle);
|
||||
|
||||
frames.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected override Task BeginPlayingInternal(SpectatorState state)
|
||||
|
Loading…
Reference in New Issue
Block a user