mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 13:13:22 +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]
|
[Resolved]
|
||||||
private OsuGameBase game { get; set; }
|
private OsuGameBase game { get; set; }
|
||||||
|
|
||||||
private int nextFrame;
|
|
||||||
|
|
||||||
private BeatmapSetInfo importedBeatmap;
|
private BeatmapSetInfo importedBeatmap;
|
||||||
|
|
||||||
private int importedBeatmapId;
|
private int importedBeatmapId;
|
||||||
@ -51,8 +49,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
AddStep("reset sent frames", () => nextFrame = 0);
|
|
||||||
|
|
||||||
AddStep("import beatmap", () =>
|
AddStep("import beatmap", () =>
|
||||||
{
|
{
|
||||||
importedBeatmap = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Result;
|
importedBeatmap = ImportBeatmapTest.LoadOszIntoOsu(game, virtualTrack: true).Result;
|
||||||
@ -105,7 +101,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
waitForPlayer();
|
waitForPlayer();
|
||||||
checkPaused(true);
|
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);
|
checkPaused(false);
|
||||||
}
|
}
|
||||||
@ -114,12 +111,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
public void TestSpectatingDuringGameplay()
|
public void TestSpectatingDuringGameplay()
|
||||||
{
|
{
|
||||||
start();
|
start();
|
||||||
|
sendFrames(300);
|
||||||
|
|
||||||
loadSpectatingScreen();
|
loadSpectatingScreen();
|
||||||
waitForPlayer();
|
waitForPlayer();
|
||||||
|
|
||||||
AddStep("advance frame count", () => nextFrame = 300);
|
sendFrames(300);
|
||||||
sendFrames();
|
|
||||||
|
|
||||||
AddUntilStep("playing from correct point in time", () => player.ChildrenOfType<DrawableRuleset>().First().FrameStableClock.CurrentTime > 30000);
|
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)
|
private void sendFrames(int count = 10)
|
||||||
{
|
{
|
||||||
AddStep("send frames", () =>
|
AddStep("send frames", () => testSpectatorClient.SendFrames(streamingUser.Id, count));
|
||||||
{
|
|
||||||
testSpectatorClient.SendFrames(streamingUser.Id, nextFrame, count);
|
|
||||||
nextFrame += count;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSpectatingScreen()
|
private void loadSpectatingScreen()
|
||||||
|
@ -96,10 +96,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
// For player 2, send frames in sets of 10.
|
// For player 2, send frames in sets of 10.
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
spectatorClient.SendFrames(PLAYER_1_ID, i, 1);
|
spectatorClient.SendFrames(PLAYER_1_ID, 1);
|
||||||
|
|
||||||
if (i % 10 == 0)
|
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 MultiSpectatorScreen spectatorScreen;
|
||||||
|
|
||||||
private readonly List<int> playingUserIds = new List<int>();
|
private readonly List<int> playingUserIds = new List<int>();
|
||||||
private readonly Dictionary<int, int> nextFrame = new Dictionary<int, int>();
|
|
||||||
|
|
||||||
private BeatmapSetInfo importedSet;
|
private BeatmapSetInfo importedSet;
|
||||||
private BeatmapInfo importedBeatmap;
|
private BeatmapInfo importedBeatmap;
|
||||||
@ -55,8 +54,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
AddStep("reset sent frames", () => nextFrame.Clear());
|
|
||||||
|
|
||||||
AddStep("add streaming client", () =>
|
AddStep("add streaming client", () =>
|
||||||
{
|
{
|
||||||
Remove(spectatorClient);
|
Remove(spectatorClient);
|
||||||
@ -80,8 +77,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
|
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
|
||||||
playingUserIds.Add(PLAYER_1_ID);
|
playingUserIds.Add(PLAYER_1_ID);
|
||||||
playingUserIds.Add(PLAYER_2_ID);
|
playingUserIds.Add(PLAYER_2_ID);
|
||||||
nextFrame[PLAYER_1_ID] = 0;
|
|
||||||
nextFrame[PLAYER_2_ID] = 0;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loadSpectateScreen(false);
|
loadSpectateScreen(false);
|
||||||
@ -253,7 +248,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Client.CurrentMatchPlayingUserIds.Add(id);
|
Client.CurrentMatchPlayingUserIds.Add(id);
|
||||||
spectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
spectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||||
playingUserIds.Add(id);
|
playingUserIds.Add(id);
|
||||||
nextFrame[id] = 0;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -264,7 +258,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
spectatorClient.EndPlay(userId);
|
spectatorClient.EndPlay(userId);
|
||||||
playingUserIds.Remove(userId);
|
playingUserIds.Remove(userId);
|
||||||
nextFrame.Remove(userId);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,10 +268,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
AddStep("send frames", () =>
|
AddStep("send frames", () =>
|
||||||
{
|
{
|
||||||
foreach (int id in userIds)
|
foreach (int id in userIds)
|
||||||
{
|
spectatorClient.SendFrames(id, count);
|
||||||
spectatorClient.SendFrames(id, nextFrame[id], count);
|
|
||||||
nextFrame[id] += count;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,15 @@ namespace osu.Game.Tests.Visual.Spectator
|
|||||||
{
|
{
|
||||||
public class TestSpectatorClient : SpectatorClient
|
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);
|
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> userBeatmapDictionary = new Dictionary<int, int>();
|
||||||
|
private readonly Dictionary<int, int> userNextFrameDictionary = new Dictionary<int, int>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; } = null!;
|
private IAPIProvider api { get; set; } = null!;
|
||||||
@ -35,6 +41,7 @@ namespace osu.Game.Tests.Visual.Spectator
|
|||||||
public void StartPlay(int userId, int beatmapId)
|
public void StartPlay(int userId, int beatmapId)
|
||||||
{
|
{
|
||||||
userBeatmapDictionary[userId] = beatmapId;
|
userBeatmapDictionary[userId] = beatmapId;
|
||||||
|
userNextFrameDictionary[userId] = 0;
|
||||||
sendPlayingState(userId);
|
sendPlayingState(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,24 +64,41 @@ namespace osu.Game.Tests.Visual.Spectator
|
|||||||
public new void Schedule(Action action) => base.Schedule(action);
|
public new void Schedule(Action action) => base.Schedule(action);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends frames for an arbitrary user.
|
/// Sends frames for an arbitrary user, in bundles containing 10 frames each.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user to send frames for.</param>
|
/// <param name="userId">The user to send frames for.</param>
|
||||||
/// <param name="index">The frame index.</param>
|
/// <param name="count">The total number of frames to send.</param>
|
||||||
/// <param name="count">The number of frames to send.</param>
|
public void SendFrames(int userId, int count)
|
||||||
public void SendFrames(int userId, int index, int count)
|
|
||||||
{
|
{
|
||||||
var frames = new List<LegacyReplayFrame>();
|
var frames = new List<LegacyReplayFrame>();
|
||||||
|
|
||||||
for (int i = index; i < index + count; i++)
|
int currentFrameIndex = userNextFrameDictionary[userId];
|
||||||
{
|
int lastFrameIndex = currentFrameIndex + count - 1;
|
||||||
var buttonState = i == index + count - 1 ? ReplayButtonState.None : ReplayButtonState.Left1;
|
|
||||||
|
|
||||||
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);
|
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);
|
((ISpectatorClient)this).UserSentFrames(userId, bundle);
|
||||||
|
|
||||||
|
frames.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task BeginPlayingInternal(SpectatorState state)
|
protected override Task BeginPlayingInternal(SpectatorState state)
|
||||||
|
Loading…
Reference in New Issue
Block a user