2019-03-26 07:13:58 +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.
|
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
2019-03-26 07:13:58 +00:00
|
|
|
using NUnit.Framework;
|
2019-11-21 09:50:54 +00:00
|
|
|
using osu.Framework.Graphics;
|
2020-01-09 04:43:44 +00:00
|
|
|
using osu.Framework.Utils;
|
2019-03-26 07:13:58 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2019-11-15 05:47:28 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-03-26 07:13:58 +00:00
|
|
|
using osu.Game.Screens.Play;
|
2019-11-21 09:50:54 +00:00
|
|
|
using osu.Game.Storyboards;
|
2019-03-26 07:13:58 +00:00
|
|
|
using osu.Game.Tests.Beatmaps;
|
2019-11-21 09:50:54 +00:00
|
|
|
using osuTK;
|
2019-03-26 07:13:58 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
2019-11-15 05:15:09 +00:00
|
|
|
public class TestSceneLeadIn : RateAdjustedBeatmapTestScene
|
2019-03-26 07:13:58 +00:00
|
|
|
{
|
|
|
|
private LeadInPlayer player;
|
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
private const double lenience_ms = 10;
|
2019-03-26 07:13:58 +00:00
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
private const double first_hit_object = 2170;
|
2019-03-26 07:13:58 +00:00
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
[TestCase(1000, 0)]
|
|
|
|
[TestCase(2000, 0)]
|
|
|
|
[TestCase(3000, first_hit_object - 3000)]
|
|
|
|
[TestCase(10000, first_hit_object - 10000)]
|
|
|
|
public void TestLeadInProducesCorrectStartTime(double leadIn, double expectedStartTime)
|
2019-03-26 07:13:58 +00:00
|
|
|
{
|
2019-11-15 05:47:28 +00:00
|
|
|
loadPlayerWithBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo)
|
|
|
|
{
|
2019-11-21 09:21:49 +00:00
|
|
|
BeatmapInfo = { AudioLeadIn = leadIn }
|
2019-11-15 05:47:28 +00:00
|
|
|
});
|
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
AddAssert($"first frame is {expectedStartTime}", () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(player.FirstFrameClockTime != null);
|
|
|
|
return Precision.AlmostEquals(player.FirstFrameClockTime.Value, expectedStartTime, lenience_ms);
|
|
|
|
});
|
2019-03-26 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 09:50:54 +00:00
|
|
|
[TestCase(1000, 0)]
|
|
|
|
[TestCase(0, 0)]
|
|
|
|
[TestCase(-1000, -1000)]
|
|
|
|
[TestCase(-10000, -10000)]
|
2021-03-09 06:45:03 +00:00
|
|
|
public void TestStoryboardProducesCorrectStartTimeSimpleAlpha(double firstStoryboardEvent, double expectedStartTime)
|
2019-11-21 09:50:54 +00:00
|
|
|
{
|
|
|
|
var storyboard = new Storyboard();
|
|
|
|
|
|
|
|
var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero);
|
2021-03-09 06:45:03 +00:00
|
|
|
|
2019-11-21 09:50:54 +00:00
|
|
|
sprite.TimelineGroup.Alpha.Add(Easing.None, firstStoryboardEvent, firstStoryboardEvent + 500, 0, 1);
|
|
|
|
|
|
|
|
storyboard.GetLayer("Background").Add(sprite);
|
|
|
|
|
|
|
|
loadPlayerWithBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo), storyboard);
|
2021-03-09 06:45:03 +00:00
|
|
|
|
|
|
|
AddAssert($"first frame is {expectedStartTime}", () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(player.FirstFrameClockTime != null);
|
|
|
|
return Precision.AlmostEquals(player.FirstFrameClockTime.Value, expectedStartTime, lenience_ms);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1000, 0, false)]
|
|
|
|
[TestCase(0, 0, false)]
|
|
|
|
[TestCase(-1000, -1000, false)]
|
|
|
|
[TestCase(-10000, -10000, false)]
|
|
|
|
[TestCase(1000, 0, true)]
|
|
|
|
[TestCase(0, 0, true)]
|
|
|
|
[TestCase(-1000, -1000, true)]
|
|
|
|
[TestCase(-10000, -10000, true)]
|
|
|
|
public void TestStoryboardProducesCorrectStartTimeFadeInAfterOtherEvents(double firstStoryboardEvent, double expectedStartTime, bool addEventToLoop)
|
|
|
|
{
|
|
|
|
var storyboard = new Storyboard();
|
|
|
|
|
|
|
|
var sprite = new StoryboardSprite("unknown", Anchor.TopLeft, Vector2.Zero);
|
|
|
|
|
|
|
|
// these should be ignored as we have an alpha visibility blocker proceeding this command.
|
|
|
|
sprite.TimelineGroup.Scale.Add(Easing.None, -20000, -18000, 0, 1);
|
|
|
|
var loopGroup = sprite.AddLoop(-20000, 50);
|
|
|
|
loopGroup.Scale.Add(Easing.None, -20000, -18000, 0, 1);
|
|
|
|
|
|
|
|
var target = addEventToLoop ? loopGroup : sprite.TimelineGroup;
|
2021-12-14 06:08:00 +00:00
|
|
|
double targetTime = addEventToLoop ? 20000 : 0;
|
|
|
|
target.Alpha.Add(Easing.None, targetTime + firstStoryboardEvent, targetTime + firstStoryboardEvent + 500, 0, 1);
|
2021-03-09 06:45:03 +00:00
|
|
|
|
|
|
|
// these should be ignored due to being in the future.
|
|
|
|
sprite.TimelineGroup.Alpha.Add(Easing.None, 18000, 20000, 0, 1);
|
2021-12-14 06:08:00 +00:00
|
|
|
loopGroup.Alpha.Add(Easing.None, 38000, 40000, 0, 1);
|
2021-03-09 06:45:03 +00:00
|
|
|
|
|
|
|
storyboard.GetLayer("Background").Add(sprite);
|
|
|
|
|
|
|
|
loadPlayerWithBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo), storyboard);
|
2019-11-21 09:50:54 +00:00
|
|
|
|
|
|
|
AddAssert($"first frame is {expectedStartTime}", () =>
|
|
|
|
{
|
|
|
|
Debug.Assert(player.FirstFrameClockTime != null);
|
|
|
|
return Precision.AlmostEquals(player.FirstFrameClockTime.Value, expectedStartTime, lenience_ms);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadPlayerWithBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
2019-03-26 07:13:58 +00:00
|
|
|
{
|
2019-11-15 05:47:28 +00:00
|
|
|
AddStep("create player", () =>
|
|
|
|
{
|
2019-11-21 09:50:54 +00:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(beatmap, storyboard);
|
2019-11-15 05:47:28 +00:00
|
|
|
LoadScreen(player = new LeadInPlayer());
|
|
|
|
});
|
2019-03-26 07:13:58 +00:00
|
|
|
|
2019-11-15 05:47:28 +00:00
|
|
|
AddUntilStep("player loaded", () => player.IsLoaded && player.Alpha == 1);
|
2019-03-26 07:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 05:47:28 +00:00
|
|
|
private class LeadInPlayer : TestPlayer
|
2019-03-26 07:13:58 +00:00
|
|
|
{
|
2019-05-31 06:58:46 +00:00
|
|
|
public LeadInPlayer()
|
|
|
|
: base(false, false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-26 07:13:58 +00:00
|
|
|
public double? FirstFrameClockTime;
|
|
|
|
|
|
|
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
|
|
|
|
|
|
|
public double GameplayStartTime => DrawableRuleset.GameplayStartTime;
|
|
|
|
|
2019-11-21 09:21:49 +00:00
|
|
|
public double FirstHitObjectTime => DrawableRuleset.Objects.First().StartTime;
|
|
|
|
|
2019-03-26 07:13:58 +00:00
|
|
|
public double GameplayClockTime => GameplayClockContainer.GameplayClock.CurrentTime;
|
|
|
|
|
2021-04-20 09:41:09 +00:00
|
|
|
protected override void Update()
|
2019-03-26 07:13:58 +00:00
|
|
|
{
|
2021-04-20 09:41:09 +00:00
|
|
|
base.Update();
|
2019-05-31 06:58:46 +00:00
|
|
|
|
2019-03-26 07:13:58 +00:00
|
|
|
if (!FirstFrameClockTime.HasValue)
|
|
|
|
{
|
|
|
|
FirstFrameClockTime = GameplayClockContainer.GameplayClock.CurrentTime;
|
|
|
|
AddInternal(new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = $"GameplayStartTime: {DrawableRuleset.GameplayStartTime} "
|
2019-11-21 09:21:49 +00:00
|
|
|
+ $"FirstHitObjectTime: {FirstHitObjectTime} "
|
2019-03-26 07:13:58 +00:00
|
|
|
+ $"LeadInTime: {Beatmap.Value.BeatmapInfo.AudioLeadIn} "
|
|
|
|
+ $"FirstFrameClockTime: {FirstFrameClockTime}"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|