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

Fix broken spectator playback test scene

This commit is contained in:
Dan Balasescu 2022-02-04 19:03:52 +09:00
parent a289582f7c
commit dd63b1a350

View File

@ -3,12 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -20,7 +16,6 @@ using osu.Framework.Testing;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Replays; using osu.Game.Replays;
using osu.Game.Replays.Legacy; using osu.Game.Replays.Legacy;
@ -32,6 +27,7 @@ using osu.Game.Rulesets.Replays.Types;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Tests.Visual.Spectator;
using osu.Game.Tests.Visual.UserInterface; using osu.Game.Tests.Visual.UserInterface;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -47,68 +43,32 @@ namespace osu.Game.Tests.Visual.Gameplay
private Replay replay; private Replay replay;
private readonly IBindableList<int> users = new BindableList<int>();
private TestReplayRecorder recorder;
private ManualClock manualClock; private ManualClock manualClock;
private OsuSpriteText latencyDisplay; private OsuSpriteText latencyDisplay;
private TestFramedReplayInputHandler replayHandler; private TestFramedReplayInputHandler replayHandler;
[Resolved]
private IAPIProvider api { get; set; }
[Resolved]
private SpectatorClient spectatorClient { get; set; }
[Cached]
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public void SetUpSteps()
{ {
AddStep("Reset recorder state", cleanUpState);
AddStep("Setup containers", () => AddStep("Setup containers", () =>
{ {
replay = new Replay(); replay = new Replay();
manualClock = new ManualClock(); manualClock = new ManualClock();
SpectatorClient spectatorClient;
spectatorClient.OnNewFrames += onNewFrames; Child = new DependencyProvidingContainer
users.BindTo(spectatorClient.PlayingUsers);
users.BindCollectionChanged((obj, args) =>
{ {
switch (args.Action) RelativeSizeAxes = Axes.Both,
CachedDependencies = new[]
{ {
case NotifyCollectionChangedAction.Add: (typeof(SpectatorClient), (object)(spectatorClient = new TestSpectatorClient())),
Debug.Assert(args.NewItems != null); (typeof(GameplayState), new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>()))
},
foreach (int user in args.NewItems)
{
if (user == api.LocalUser.Value.Id)
spectatorClient.WatchUser(user);
}
break;
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);
foreach (int user in args.OldItems)
{
if (user == api.LocalUser.Value.Id)
spectatorClient.StopWatchingUser(user);
}
break;
}
}, true);
Children = new Drawable[] Children = new Drawable[]
{ {
spectatorClient,
new GridContainer new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -118,7 +78,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique) recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
{ {
Recorder = recorder = new TestReplayRecorder Recorder = new TestReplayRecorder
{ {
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos), ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
}, },
@ -178,7 +138,10 @@ namespace osu.Game.Tests.Visual.Gameplay
} }
}, },
latencyDisplay = new OsuSpriteText() latencyDisplay = new OsuSpriteText()
}
}; };
spectatorClient.OnNewFrames += onNewFrames;
}); });
} }
@ -238,20 +201,6 @@ namespace osu.Game.Tests.Visual.Gameplay
manualClock.CurrentTime = time.Value; manualClock.CurrentTime = time.Value;
} }
[TearDownSteps]
public void TearDown()
{
AddStep("stop recorder", cleanUpState);
}
private void cleanUpState()
{
// Ensure previous recorder is disposed else it may affect the global playing state of `SpectatorClient`.
recorder?.RemoveAndDisposeImmediately();
recorder = null;
spectatorClient.OnNewFrames -= onNewFrames;
}
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame> public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
{ {
public TestFramedReplayInputHandler(Replay replay) public TestFramedReplayInputHandler(Replay replay)