2022-08-05 10:17:01 +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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2022-08-09 03:27:46 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2022-08-05 10:17:01 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
2022-08-15 02:12:11 +08:00
|
|
|
namespace osu.Game.Screens.Play.HUD.ClicksPerSecond
|
2022-08-05 10:17:01 +08:00
|
|
|
{
|
2022-08-15 02:12:11 +08:00
|
|
|
public partial class ClicksPerSecondCalculator : Component
|
2022-08-05 10:17:01 +08:00
|
|
|
{
|
2022-09-08 17:22:53 +08:00
|
|
|
private readonly List<double> timestamps = new List<double>();
|
2022-08-05 10:17:01 +08:00
|
|
|
|
2022-08-09 03:27:46 +08:00
|
|
|
[Resolved]
|
2022-08-24 23:12:52 +08:00
|
|
|
private IGameplayClock gameplayClock { get; set; } = null!;
|
2022-08-05 10:17:01 +08:00
|
|
|
|
2022-09-08 17:22:53 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private DrawableRuleset? drawableRuleset { get; set; }
|
2022-08-07 06:53:00 +08:00
|
|
|
|
2022-08-24 23:12:52 +08:00
|
|
|
public int Value { get; private set; }
|
2022-08-05 10:17:01 +08:00
|
|
|
|
2022-09-08 18:14:23 +08:00
|
|
|
// Even though `FrameStabilityContainer` caches as a `GameplayClock`, we need to check it directly via `drawableRuleset`
|
|
|
|
// as this calculator is not contained within the `FrameStabilityContainer` and won't see the dependency.
|
2022-09-08 17:22:53 +08:00
|
|
|
private IGameplayClock clock => drawableRuleset?.FrameStableClock ?? gameplayClock;
|
|
|
|
|
2022-08-15 02:12:11 +08:00
|
|
|
public ClicksPerSecondCalculator()
|
2022-08-05 10:17:01 +08:00
|
|
|
{
|
2022-08-09 03:27:46 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2022-08-05 10:17:01 +08:00
|
|
|
}
|
|
|
|
|
2022-09-08 17:22:53 +08:00
|
|
|
public void AddInputTimestamp() => timestamps.Add(clock.CurrentTime);
|
|
|
|
|
2022-08-24 23:12:52 +08:00
|
|
|
protected override void Update()
|
2022-08-05 10:17:01 +08:00
|
|
|
{
|
2022-08-24 23:12:52 +08:00
|
|
|
base.Update();
|
2022-08-07 06:53:00 +08:00
|
|
|
|
2022-09-08 17:22:53 +08:00
|
|
|
double latestValidTime = clock.CurrentTime;
|
2022-09-08 22:03:15 +08:00
|
|
|
double earliestTimeValid = latestValidTime - 1000 * gameplayClock.GetTrueGameplayRate();
|
2022-08-05 10:17:01 +08:00
|
|
|
|
2022-09-08 17:22:53 +08:00
|
|
|
int count = 0;
|
2022-08-09 03:27:46 +08:00
|
|
|
|
2022-09-08 17:22:53 +08:00
|
|
|
for (int i = timestamps.Count - 1; i >= 0; i--)
|
2022-08-09 03:27:46 +08:00
|
|
|
{
|
2022-09-08 17:22:53 +08:00
|
|
|
// handle rewinding by removing future timestamps as we go
|
|
|
|
if (timestamps[i] > latestValidTime)
|
|
|
|
{
|
|
|
|
timestamps.RemoveAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timestamps[i] >= earliestTimeValid)
|
|
|
|
count++;
|
2022-08-09 03:27:46 +08:00
|
|
|
}
|
2022-09-08 17:22:53 +08:00
|
|
|
|
|
|
|
Value = count;
|
2022-08-09 03:27:46 +08:00
|
|
|
}
|
2022-08-05 10:17:01 +08:00
|
|
|
}
|
|
|
|
}
|