2019-09-24 09:53:26 +08: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.
|
|
|
|
|
|
2020-08-02 18:57:15 +08:00
|
|
|
|
using System;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
|
using osu.Framework.Timing;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
using osu.Game.Replays;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2020-07-09 04:37:45 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Replays;
|
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
|
|
|
|
using osu.Game.Rulesets.Replays;
|
2019-10-14 05:43:46 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-07-09 04:37:45 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2021-04-14 16:47:11 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2019-11-21 17:50:54 +08:00
|
|
|
|
using osu.Game.Storyboards;
|
2020-07-21 10:21:17 +08:00
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
using osuTK;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
|
|
|
|
public class TestSceneSpinnerRotation : TestSceneOsuPlayer
|
|
|
|
|
{
|
2021-10-13 14:30:58 +08:00
|
|
|
|
private const double spinner_start_time = 100;
|
|
|
|
|
private const double spinner_duration = 6000;
|
|
|
|
|
|
2019-09-24 09:53:26 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private AudioManager audioManager { get; set; }
|
|
|
|
|
|
2019-09-26 09:38:20 +08:00
|
|
|
|
protected override bool Autoplay => true;
|
|
|
|
|
|
2020-07-21 10:21:17 +08:00
|
|
|
|
protected override TestPlayer CreatePlayer(Ruleset ruleset) => new ScoreExposedPlayer();
|
2019-10-14 05:43:46 +08:00
|
|
|
|
|
2019-11-21 17:50:54 +08:00
|
|
|
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
|
2020-08-04 20:53:00 +08:00
|
|
|
|
=> new ClockBackedTestWorkingBeatmap(beatmap, storyboard, new FramedClock(new ManualClock { Rate = 1 }), audioManager);
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
|
|
|
|
private DrawableSpinner drawableSpinner;
|
2020-07-09 02:44:27 +08:00
|
|
|
|
private SpriteIcon spinnerSymbol => drawableSpinner.ChildrenOfType<SpriteIcon>().Single();
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
2020-08-26 23:21:50 +08:00
|
|
|
|
AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
|
2020-03-05 10:25:07 +08:00
|
|
|
|
AddStep("retrieve spinner", () => drawableSpinner = (DrawableSpinner)Player.DrawableRuleset.Playfield.AllHitObjects.First());
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinnerRewindingRotation()
|
|
|
|
|
{
|
2020-08-02 18:57:15 +08:00
|
|
|
|
double trackerRotationTolerance = 0;
|
|
|
|
|
|
2019-09-24 09:53:26 +08:00
|
|
|
|
addSeekStep(5000);
|
2020-08-02 18:57:15 +08:00
|
|
|
|
AddStep("calculate rotation tolerance", () =>
|
|
|
|
|
{
|
|
|
|
|
trackerRotationTolerance = Math.Abs(drawableSpinner.RotationTracker.Rotation * 0.1f);
|
|
|
|
|
});
|
2020-07-29 19:01:01 +08:00
|
|
|
|
AddAssert("is disc rotation not almost 0", () => !Precision.AlmostEquals(drawableSpinner.RotationTracker.Rotation, 0, 100));
|
2020-11-15 04:10:12 +08:00
|
|
|
|
AddAssert("is disc rotation absolute not almost 0", () => !Precision.AlmostEquals(drawableSpinner.Result.RateAdjustedRotation, 0, 100));
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
|
|
|
|
addSeekStep(0);
|
2020-08-02 18:57:15 +08:00
|
|
|
|
AddAssert("is disc rotation almost 0", () => Precision.AlmostEquals(drawableSpinner.RotationTracker.Rotation, 0, trackerRotationTolerance));
|
2020-11-15 04:10:12 +08:00
|
|
|
|
AddAssert("is disc rotation absolute almost 0", () => Precision.AlmostEquals(drawableSpinner.Result.RateAdjustedRotation, 0, 100));
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinnerMiddleRewindingRotation()
|
|
|
|
|
{
|
2020-08-02 18:57:15 +08:00
|
|
|
|
double finalCumulativeTrackerRotation = 0;
|
|
|
|
|
double finalTrackerRotation = 0, trackerRotationTolerance = 0;
|
|
|
|
|
double finalSpinnerSymbolRotation = 0, spinnerSymbolRotationTolerance = 0;
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
2021-10-13 14:30:58 +08:00
|
|
|
|
addSeekStep(spinner_start_time + 5000);
|
2020-08-02 18:57:15 +08:00
|
|
|
|
AddStep("retrieve disc rotation", () =>
|
|
|
|
|
{
|
|
|
|
|
finalTrackerRotation = drawableSpinner.RotationTracker.Rotation;
|
|
|
|
|
trackerRotationTolerance = Math.Abs(finalTrackerRotation * 0.05f);
|
|
|
|
|
});
|
|
|
|
|
AddStep("retrieve spinner symbol rotation", () =>
|
|
|
|
|
{
|
|
|
|
|
finalSpinnerSymbolRotation = spinnerSymbol.Rotation;
|
|
|
|
|
spinnerSymbolRotationTolerance = Math.Abs(finalSpinnerSymbolRotation * 0.05f);
|
|
|
|
|
});
|
2020-11-15 04:10:12 +08:00
|
|
|
|
AddStep("retrieve cumulative disc rotation", () => finalCumulativeTrackerRotation = drawableSpinner.Result.RateAdjustedRotation);
|
2019-09-24 09:53:26 +08:00
|
|
|
|
|
2021-10-13 14:30:58 +08:00
|
|
|
|
addSeekStep(spinner_start_time + 2500);
|
2020-08-02 20:54:41 +08:00
|
|
|
|
AddAssert("disc rotation rewound",
|
2020-07-09 02:44:27 +08:00
|
|
|
|
// we want to make sure that the rotation at time 2500 is in the same direction as at time 5000, but about half-way in.
|
2020-08-02 18:57:15 +08:00
|
|
|
|
// due to the exponential damping applied we're allowing a larger margin of error of about 10%
|
|
|
|
|
// (5% relative to the final rotation value, but we're half-way through the spin).
|
|
|
|
|
() => Precision.AlmostEquals(drawableSpinner.RotationTracker.Rotation, finalTrackerRotation / 2, trackerRotationTolerance));
|
2020-08-02 20:54:41 +08:00
|
|
|
|
AddAssert("symbol rotation rewound",
|
2020-08-02 18:57:15 +08:00
|
|
|
|
() => Precision.AlmostEquals(spinnerSymbol.Rotation, finalSpinnerSymbolRotation / 2, spinnerSymbolRotationTolerance));
|
|
|
|
|
AddAssert("is cumulative rotation rewound",
|
|
|
|
|
// cumulative rotation is not damped, so we're treating it as the "ground truth" and allowing a comparatively smaller margin of error.
|
2020-11-15 04:10:12 +08:00
|
|
|
|
() => Precision.AlmostEquals(drawableSpinner.Result.RateAdjustedRotation, finalCumulativeTrackerRotation / 2, 100));
|
2020-07-09 02:44:27 +08:00
|
|
|
|
|
2021-10-13 14:30:58 +08:00
|
|
|
|
addSeekStep(spinner_start_time + 5000);
|
2020-07-09 02:44:27 +08:00
|
|
|
|
AddAssert("is disc rotation almost same",
|
2020-08-02 18:57:15 +08:00
|
|
|
|
() => Precision.AlmostEquals(drawableSpinner.RotationTracker.Rotation, finalTrackerRotation, trackerRotationTolerance));
|
2020-07-09 02:44:27 +08:00
|
|
|
|
AddAssert("is symbol rotation almost same",
|
2020-08-02 18:57:15 +08:00
|
|
|
|
() => Precision.AlmostEquals(spinnerSymbol.Rotation, finalSpinnerSymbolRotation, spinnerSymbolRotationTolerance));
|
|
|
|
|
AddAssert("is cumulative rotation almost same",
|
2020-11-15 04:10:12 +08:00
|
|
|
|
() => Precision.AlmostEquals(drawableSpinner.Result.RateAdjustedRotation, finalCumulativeTrackerRotation, 100));
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-09 04:37:45 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRotationDirection([Values(true, false)] bool clockwise)
|
|
|
|
|
{
|
|
|
|
|
if (clockwise)
|
2020-08-11 01:51:00 +08:00
|
|
|
|
transformReplay(flip);
|
2020-07-09 04:37:45 +08:00
|
|
|
|
|
2019-09-24 09:53:26 +08:00
|
|
|
|
addSeekStep(5000);
|
2020-07-09 04:37:45 +08:00
|
|
|
|
|
2020-07-29 19:01:01 +08:00
|
|
|
|
AddAssert("disc spin direction correct", () => clockwise ? drawableSpinner.RotationTracker.Rotation > 0 : drawableSpinner.RotationTracker.Rotation < 0);
|
2020-07-09 04:37:45 +08:00
|
|
|
|
AddAssert("spinner symbol direction correct", () => clockwise ? spinnerSymbol.Rotation > 0 : spinnerSymbol.Rotation < 0);
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 01:51:00 +08:00
|
|
|
|
private Replay flip(Replay scoreReplay) => new Replay
|
2020-07-09 04:37:45 +08:00
|
|
|
|
{
|
|
|
|
|
Frames = scoreReplay
|
|
|
|
|
.Frames
|
|
|
|
|
.Cast<OsuReplayFrame>()
|
|
|
|
|
.Select(replayFrame =>
|
|
|
|
|
{
|
|
|
|
|
var flippedPosition = new Vector2(OsuPlayfield.BASE_SIZE.X - replayFrame.Position.X, replayFrame.Position.Y);
|
|
|
|
|
return new OsuReplayFrame(replayFrame.Time, flippedPosition, replayFrame.Actions.ToArray());
|
|
|
|
|
})
|
|
|
|
|
.Cast<ReplayFrame>()
|
|
|
|
|
.ToList()
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-14 05:43:46 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinnerNormalBonusRewinding()
|
|
|
|
|
{
|
2021-10-13 14:30:58 +08:00
|
|
|
|
addSeekStep(spinner_start_time + 1000);
|
2019-10-14 05:43:46 +08:00
|
|
|
|
|
|
|
|
|
AddAssert("player score matching expected bonus score", () =>
|
|
|
|
|
{
|
2022-02-16 16:33:55 +08:00
|
|
|
|
double totalScore = ((ScoreExposedPlayer)Player).ScoreProcessor.TotalScore.Value;
|
2020-11-15 04:10:12 +08:00
|
|
|
|
return totalScore == (int)(drawableSpinner.Result.RateAdjustedRotation / 360) * new SpinnerTick().CreateJudgement().MaxNumericResult;
|
2019-10-14 05:43:46 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addSeekStep(0);
|
|
|
|
|
|
|
|
|
|
AddAssert("player score is 0", () => ((ScoreExposedPlayer)Player).ScoreProcessor.TotalScore.Value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinnerCompleteBonusRewinding()
|
|
|
|
|
{
|
|
|
|
|
addSeekStep(2500);
|
|
|
|
|
addSeekStep(0);
|
|
|
|
|
|
|
|
|
|
AddAssert("player score is 0", () => ((ScoreExposedPlayer)Player).ScoreProcessor.TotalScore.Value == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 08:08:05 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestSpinPerMinuteOnRewind()
|
|
|
|
|
{
|
|
|
|
|
double estimatedSpm = 0;
|
|
|
|
|
|
2020-07-21 18:22:42 +08:00
|
|
|
|
addSeekStep(1000);
|
2021-03-26 18:09:44 +08:00
|
|
|
|
AddStep("retrieve spm", () => estimatedSpm = drawableSpinner.SpinsPerMinute.Value);
|
2019-12-18 08:08:05 +08:00
|
|
|
|
|
2020-07-21 18:22:42 +08:00
|
|
|
|
addSeekStep(2000);
|
2021-03-26 18:09:44 +08:00
|
|
|
|
AddAssert("spm still valid", () => Precision.AlmostEquals(drawableSpinner.SpinsPerMinute.Value, estimatedSpm, 1.0));
|
2019-12-18 15:07:14 +08:00
|
|
|
|
|
2020-07-21 18:22:42 +08:00
|
|
|
|
addSeekStep(1000);
|
2021-03-26 18:09:44 +08:00
|
|
|
|
AddAssert("spm still valid", () => Precision.AlmostEquals(drawableSpinner.SpinsPerMinute.Value, estimatedSpm, 1.0));
|
2019-12-18 08:08:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 02:04:14 +08:00
|
|
|
|
[TestCase(0.5)]
|
|
|
|
|
[TestCase(2.0)]
|
|
|
|
|
public void TestSpinUnaffectedByClockRate(double rate)
|
|
|
|
|
{
|
|
|
|
|
double expectedProgress = 0;
|
|
|
|
|
double expectedSpm = 0;
|
|
|
|
|
|
|
|
|
|
addSeekStep(1000);
|
|
|
|
|
AddStep("retrieve spinner state", () =>
|
|
|
|
|
{
|
|
|
|
|
expectedProgress = drawableSpinner.Progress;
|
2021-03-26 18:09:44 +08:00
|
|
|
|
expectedSpm = drawableSpinner.SpinsPerMinute.Value;
|
2020-08-11 02:04:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addSeekStep(0);
|
|
|
|
|
|
2021-04-14 16:47:11 +08:00
|
|
|
|
AddStep("adjust track rate", () => ((MasterGameplayClockContainer)Player.GameplayClockContainer).UserPlaybackRate.Value = rate);
|
2020-08-11 02:04:14 +08:00
|
|
|
|
|
|
|
|
|
addSeekStep(1000);
|
|
|
|
|
AddAssert("progress almost same", () => Precision.AlmostEquals(expectedProgress, drawableSpinner.Progress, 0.05));
|
2021-03-26 18:09:44 +08:00
|
|
|
|
AddAssert("spm almost same", () => Precision.AlmostEquals(expectedSpm, drawableSpinner.SpinsPerMinute.Value, 2.0));
|
2020-08-11 02:04:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 09:53:26 +08:00
|
|
|
|
private void addSeekStep(double time)
|
|
|
|
|
{
|
2021-06-29 22:23:21 +08:00
|
|
|
|
AddStep($"seek to {time}", () => Player.GameplayClockContainer.Seek(time));
|
2020-03-05 10:25:07 +08:00
|
|
|
|
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, Player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 01:51:00 +08:00
|
|
|
|
private void transformReplay(Func<Replay, Replay> replayTransformation) => AddStep("set replay", () =>
|
|
|
|
|
{
|
|
|
|
|
var drawableRuleset = this.ChildrenOfType<DrawableOsuRuleset>().Single();
|
|
|
|
|
var score = drawableRuleset.ReplayScore;
|
|
|
|
|
var transformedScore = new Score
|
|
|
|
|
{
|
|
|
|
|
ScoreInfo = score.ScoreInfo,
|
|
|
|
|
Replay = replayTransformation.Invoke(score.Replay)
|
|
|
|
|
};
|
|
|
|
|
drawableRuleset.SetReplayScore(transformedScore);
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-24 09:53:26 +08:00
|
|
|
|
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new Beatmap
|
|
|
|
|
{
|
|
|
|
|
HitObjects = new List<HitObject>
|
|
|
|
|
{
|
|
|
|
|
new Spinner
|
|
|
|
|
{
|
|
|
|
|
Position = new Vector2(256, 192),
|
2021-10-13 14:30:58 +08:00
|
|
|
|
StartTime = spinner_start_time,
|
|
|
|
|
Duration = spinner_duration
|
2019-09-24 09:53:26 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-10-14 05:43:46 +08:00
|
|
|
|
|
|
|
|
|
private class ScoreExposedPlayer : TestPlayer
|
|
|
|
|
{
|
|
|
|
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
|
|
|
|
|
|
|
|
|
public ScoreExposedPlayer()
|
|
|
|
|
: base(false, false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-24 09:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|