1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-10-16 06:00:45 +00:00
msfs-popout-panel-manager/SimconnectAgent/FpsCalc.cs

37 lines
923 B
C#
Raw Permalink Normal View History

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;
}
}
}