2024-03-14 22:50:32 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MSFSPopoutPanelManager.SimConnectAgent
|
|
|
|
|
{
|
|
|
|
|
public class FpsCalc
|
|
|
|
|
{
|
2024-03-15 12:55:55 +00:00
|
|
|
|
private const int FpsLen = 25;
|
2024-03-14 22:50:32 +00:00
|
|
|
|
private static readonly float[] FpsStatistic = new float[FpsLen];
|
|
|
|
|
private static int _fpsIndex = -1;
|
|
|
|
|
|
|
|
|
|
public static int GetAverageFps(int newValue)
|
|
|
|
|
{
|
|
|
|
|
if (_fpsIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < FpsLen; i++)
|
|
|
|
|
FpsStatistic[i] = newValue;
|
|
|
|
|
|
|
|
|
|
_fpsIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FpsStatistic[_fpsIndex] = newValue;
|
|
|
|
|
_fpsIndex++;
|
|
|
|
|
if (_fpsIndex >= FpsLen)
|
|
|
|
|
_fpsIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var fps = 0;
|
|
|
|
|
if (_fpsIndex != -1)
|
|
|
|
|
fps = Convert.ToInt32(FpsStatistic.Sum() / FpsLen);
|
|
|
|
|
|
|
|
|
|
return fps;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|