1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 05:33:21 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneClicksPerSecondCalculator.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

132 lines
4.7 KiB
C#
Raw Normal View History

// 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 System;
using System.Collections.Generic;
using NUnit.Framework;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD.ClicksPerSecond;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
2022-09-08 18:20:26 +08:00
public partial class TestSceneClicksPerSecondCalculator : OsuTestScene
{
private ClicksPerSecondController controller = null!;
2022-09-08 18:05:13 +08:00
private TestGameplayClock manualGameplayClock = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create components", () =>
{
2022-09-08 18:05:13 +08:00
manualGameplayClock = new TestGameplayClock();
2022-09-08 18:05:13 +08:00
Child = new DependencyProvidingContainer
{
2022-09-08 18:05:13 +08:00
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] { (typeof(IGameplayClock), manualGameplayClock) },
Children = new Drawable[]
{
controller = new ClicksPerSecondController(),
2022-09-08 18:05:13 +08:00
new DependencyProvidingContainer
{
2022-09-08 18:05:13 +08:00
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] { (typeof(ClicksPerSecondController), controller) },
2022-09-08 18:05:13 +08:00
Child = new ClicksPerSecondCounter
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
}
}
2022-09-08 18:05:13 +08:00
},
};
});
}
[Test]
public void TestBasicConsistency()
{
2022-09-08 18:05:13 +08:00
seek(1000);
AddStep("add inputs in past", () => addInputs(new double[] { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900 }));
checkClicksPerSecondValue(10);
}
[Test]
public void TestRateAdjustConsistency()
{
2022-09-08 18:05:13 +08:00
seek(1000);
AddStep("add inputs in past", () => addInputs(new double[] { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900 }));
checkClicksPerSecondValue(10);
AddStep("set rate 0.5x", () => manualGameplayClock.TrueGameplayRate = 0.5);
checkClicksPerSecondValue(5);
}
[Test]
public void TestInputsDiscardedOnRewind()
{
seek(1000);
2022-09-08 18:05:13 +08:00
AddStep("add inputs in past", () => addInputs(new double[] { 0, 100, 200, 300, 400, 500, 600, 700, 800, 900 }));
checkClicksPerSecondValue(10);
seek(500);
checkClicksPerSecondValue(6);
seek(1000);
2022-09-08 18:05:13 +08:00
checkClicksPerSecondValue(6);
2022-08-22 06:03:24 +08:00
}
private void checkClicksPerSecondValue(int i) => AddAssert("clicks/s is correct", () => controller.Value, () => Is.EqualTo(i));
2022-09-08 18:05:13 +08:00
private void seekClockImmediately(double time) => manualGameplayClock.CurrentTime = time;
2022-08-22 06:03:24 +08:00
2022-09-08 18:05:13 +08:00
private void seek(double time) => AddStep($"Seek to {time}ms", () => seekClockImmediately(time));
2022-08-22 06:03:24 +08:00
private void addInputs(IEnumerable<double> inputs)
{
2022-09-08 18:05:13 +08:00
double baseTime = manualGameplayClock.CurrentTime;
foreach (double timestamp in inputs)
{
2022-09-08 18:05:13 +08:00
seekClockImmediately(timestamp);
controller.AddInputTimestamp();
}
2022-09-08 18:05:13 +08:00
seekClockImmediately(baseTime);
}
2022-09-08 18:05:13 +08:00
private class TestGameplayClock : IGameplayClock
{
2022-09-08 18:05:13 +08:00
public double CurrentTime { get; set; }
2022-09-08 18:05:13 +08:00
public double Rate => 1;
2022-09-08 18:05:13 +08:00
public bool IsRunning => true;
public double TrueGameplayRate { set => adjustableAudioComponent.Tempo.Value = value; }
private readonly AudioAdjustments adjustableAudioComponent = new AudioAdjustments();
public void ProcessFrame()
{
2022-08-22 06:03:24 +08:00
}
2022-09-08 18:05:13 +08:00
public double ElapsedFrameTime => throw new NotImplementedException();
public double FramesPerSecond => throw new NotImplementedException();
public FrameTimeInfo TimeInfo => throw new NotImplementedException();
public double StartTime => throw new NotImplementedException();
public IAdjustableAudioComponent AdjustmentsFromMods => adjustableAudioComponent;
2022-09-08 18:05:13 +08:00
public IEnumerable<double> NonGameplayAdjustments => throw new NotImplementedException();
public IBindable<bool> IsPaused => throw new NotImplementedException();
public bool IsRewinding => false;
}
}
}