1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 04:49:40 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneClicksPerSecond.cs

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

125 lines
4.4 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.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
{
public class TestSceneClicksPerSecond : OsuTestScene
{
private ClicksPerSecondCalculator calculator = 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[]
{
2022-09-08 18:05:13 +08:00
calculator = new ClicksPerSecondCalculator(),
new DependencyProvidingContainer
{
2022-09-08 18:05:13 +08:00
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] { (typeof(ClicksPerSecondCalculator), calculator) },
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
}
2022-09-08 18:05:13 +08:00
private void checkClicksPerSecondValue(int i) => AddAssert("clicks/s is correct", () => calculator.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);
calculator.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;
2022-09-08 18:05:13 +08:00
public double TrueGameplayRate { get; set; } = 1;
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 IEnumerable<double> NonGameplayAdjustments => throw new NotImplementedException();
public IBindable<bool> IsPaused => throw new NotImplementedException();
}
}
}