mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Update TestSceneReplayReocorder
to be safer about disposal
This commit is contained in:
parent
50a5f52f92
commit
0d3d22d3e1
@ -43,83 +43,88 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Cached]
|
[Cached]
|
||||||
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
private GameplayState gameplayState = new GameplayState(new Beatmap(), new OsuRuleset(), Array.Empty<Mod>());
|
||||||
|
|
||||||
[SetUp]
|
[SetUpSteps]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUpSteps()
|
||||||
{
|
{
|
||||||
replay = new Replay();
|
AddStep("Reset recorder state", cleanUpState);
|
||||||
|
|
||||||
Add(new GridContainer
|
AddStep("Setup containers", () =>
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
replay = new Replay();
|
||||||
Content = new[]
|
|
||||||
|
Add(new GridContainer
|
||||||
{
|
{
|
||||||
new Drawable[]
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Content = new[]
|
||||||
{
|
{
|
||||||
recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
new Drawable[]
|
||||||
{
|
{
|
||||||
Recorder = recorder = new TestReplayRecorder(new Score
|
recordingManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
||||||
{
|
{
|
||||||
Replay = replay,
|
Recorder = recorder = new TestReplayRecorder(new Score
|
||||||
ScoreInfo = { BeatmapInfo = gameplayState.Beatmap.BeatmapInfo }
|
|
||||||
})
|
|
||||||
{
|
|
||||||
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
|
|
||||||
},
|
|
||||||
Child = new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
{
|
||||||
new Box
|
Replay = replay,
|
||||||
|
ScoreInfo = { BeatmapInfo = gameplayState.Beatmap.BeatmapInfo }
|
||||||
|
})
|
||||||
|
{
|
||||||
|
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos),
|
||||||
|
},
|
||||||
|
Child = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Colour = Color4.Brown,
|
new Box
|
||||||
RelativeSizeAxes = Axes.Both,
|
{
|
||||||
},
|
Colour = Color4.Brown,
|
||||||
new OsuSpriteText
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
},
|
||||||
Text = "Recording",
|
new OsuSpriteText
|
||||||
Scale = new Vector2(3),
|
{
|
||||||
Anchor = Anchor.Centre,
|
Text = "Recording",
|
||||||
Origin = Anchor.Centre,
|
Scale = new Vector2(3),
|
||||||
},
|
Anchor = Anchor.Centre,
|
||||||
new TestInputConsumer()
|
Origin = Anchor.Centre,
|
||||||
}
|
},
|
||||||
},
|
new TestInputConsumer()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Drawable[]
|
}
|
||||||
{
|
},
|
||||||
playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
new Drawable[]
|
||||||
{
|
{
|
||||||
ReplayInputHandler = new TestFramedReplayInputHandler(replay)
|
playbackManager = new TestRulesetInputManager(TestSceneModSettings.CreateTestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
||||||
{
|
{
|
||||||
GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos),
|
ReplayInputHandler = new TestFramedReplayInputHandler(replay)
|
||||||
},
|
|
||||||
Child = new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
{
|
||||||
new Box
|
GamefieldToScreenSpace = pos => playbackManager.ToScreenSpace(pos),
|
||||||
|
},
|
||||||
|
Child = new Container
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
Colour = Color4.DarkBlue,
|
new Box
|
||||||
RelativeSizeAxes = Axes.Both,
|
{
|
||||||
},
|
Colour = Color4.DarkBlue,
|
||||||
new OsuSpriteText
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
},
|
||||||
Text = "Playback",
|
new OsuSpriteText
|
||||||
Scale = new Vector2(3),
|
{
|
||||||
Anchor = Anchor.Centre,
|
Text = "Playback",
|
||||||
Origin = Anchor.Centre,
|
Scale = new Vector2(3),
|
||||||
},
|
Anchor = Anchor.Centre,
|
||||||
new TestInputConsumer()
|
Origin = Anchor.Centre,
|
||||||
}
|
},
|
||||||
},
|
new TestInputConsumer()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasic()
|
public void TestBasic()
|
||||||
@ -184,7 +189,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[TearDownSteps]
|
[TearDownSteps]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
AddStep("stop recorder", () => recorder.Expire());
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
|
public class TestFramedReplayInputHandler : FramedReplayInputHandler<TestReplayFrame>
|
||||||
|
Loading…
Reference in New Issue
Block a user