2019-04-24 06:23:31 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public class TestSceneFrameStabilityContainer : OsuTestScene
|
2019-04-24 06:23:31 +00:00
|
|
|
{
|
2019-04-24 06:46:21 +00:00
|
|
|
private readonly ManualClock manualClock;
|
2019-04-24 06:23:31 +00:00
|
|
|
|
2019-04-24 06:46:21 +00:00
|
|
|
private readonly Container mainContainer;
|
2019-04-24 06:23:31 +00:00
|
|
|
|
|
|
|
private ClockConsumingChild consumer;
|
|
|
|
|
2019-05-14 19:37:25 +00:00
|
|
|
public TestSceneFrameStabilityContainer()
|
2019-04-24 06:23:31 +00:00
|
|
|
{
|
|
|
|
Child = mainContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Clock = new FramedClock(manualClock = new ManualClock()),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestLargeJumps()
|
|
|
|
{
|
2019-04-24 06:46:21 +00:00
|
|
|
seekManualTo(0);
|
2019-04-24 06:23:31 +00:00
|
|
|
createStabilityContainer();
|
|
|
|
seekManualTo(100000);
|
|
|
|
|
|
|
|
confirmSeek(100000);
|
|
|
|
checkFrameCount(6000);
|
|
|
|
|
|
|
|
seekManualTo(0);
|
|
|
|
|
|
|
|
confirmSeek(0);
|
|
|
|
checkFrameCount(12000);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSmallJumps()
|
|
|
|
{
|
2019-04-24 06:46:21 +00:00
|
|
|
seekManualTo(0);
|
2019-04-24 06:23:31 +00:00
|
|
|
createStabilityContainer();
|
|
|
|
seekManualTo(40);
|
|
|
|
|
|
|
|
confirmSeek(40);
|
|
|
|
checkFrameCount(3);
|
|
|
|
|
|
|
|
seekManualTo(0);
|
|
|
|
|
|
|
|
confirmSeek(0);
|
|
|
|
checkFrameCount(6);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSingleFrameJump()
|
|
|
|
{
|
2019-04-24 06:46:21 +00:00
|
|
|
seekManualTo(0);
|
2019-04-24 06:23:31 +00:00
|
|
|
createStabilityContainer();
|
|
|
|
seekManualTo(8);
|
|
|
|
confirmSeek(8);
|
|
|
|
checkFrameCount(1);
|
|
|
|
|
|
|
|
seekManualTo(16);
|
|
|
|
confirmSeek(16);
|
|
|
|
checkFrameCount(2);
|
|
|
|
}
|
|
|
|
|
2019-05-09 07:36:47 +00:00
|
|
|
[Test]
|
|
|
|
public void TestInitialSeekWithGameplayStart()
|
|
|
|
{
|
|
|
|
seekManualTo(1000);
|
|
|
|
createStabilityContainer(30000);
|
|
|
|
|
|
|
|
confirmSeek(1000);
|
|
|
|
checkFrameCount(0);
|
|
|
|
|
|
|
|
seekManualTo(10000);
|
|
|
|
confirmSeek(10000);
|
|
|
|
|
|
|
|
checkFrameCount(1);
|
|
|
|
|
|
|
|
seekManualTo(130000);
|
|
|
|
confirmSeek(130000);
|
|
|
|
|
|
|
|
checkFrameCount(6002);
|
|
|
|
}
|
|
|
|
|
2019-04-24 06:23:31 +00:00
|
|
|
[Test]
|
|
|
|
public void TestInitialSeek()
|
|
|
|
{
|
|
|
|
seekManualTo(100000);
|
|
|
|
createStabilityContainer();
|
|
|
|
|
|
|
|
confirmSeek(100000);
|
|
|
|
checkFrameCount(0);
|
|
|
|
}
|
|
|
|
|
2019-05-09 07:37:34 +00:00
|
|
|
private const int max_frames_catchup = 50;
|
|
|
|
|
|
|
|
private void createStabilityContainer(double gameplayStartTime = double.MinValue) => AddStep("create container", () =>
|
|
|
|
mainContainer.Child = new FrameStabilityContainer(gameplayStartTime) { MaxCatchUpFrames = max_frames_catchup }
|
|
|
|
.WithChild(consumer = new ClockConsumingChild()));
|
2019-04-24 06:23:31 +00:00
|
|
|
|
|
|
|
private void seekManualTo(double time) => AddStep($"seek manual clock to {time}", () => manualClock.CurrentTime = time);
|
|
|
|
|
|
|
|
private void confirmSeek(double time) => AddUntilStep($"wait for seek to {time}", () => consumer.Clock.CurrentTime == time);
|
|
|
|
|
|
|
|
private void checkFrameCount(int frames) =>
|
|
|
|
AddAssert($"elapsed frames is {frames}", () => consumer.ElapsedFrames == frames);
|
|
|
|
|
|
|
|
public class ClockConsumingChild : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
private readonly OsuSpriteText text2;
|
|
|
|
private readonly OsuSpriteText text3;
|
|
|
|
|
|
|
|
public ClockConsumingChild()
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
text = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
text2 = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
text3 = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public int ElapsedFrames;
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (Clock.ElapsedFrameTime != 0)
|
|
|
|
ElapsedFrames++;
|
|
|
|
|
|
|
|
text.Text = $"current time: {Clock.CurrentTime:F0}";
|
|
|
|
if (Clock.ElapsedFrameTime != 0)
|
|
|
|
text2.Text = $"last elapsed frame time: {Clock.ElapsedFrameTime:F0}";
|
|
|
|
text3.Text = $"total frames: {ElapsedFrames:F0}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|