mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-10-16 14:10:45 +00:00
36 lines
923 B
C#
36 lines
923 B
C#
using System;
|
|
using System.Linq;
|
|
|
|
namespace MSFSPopoutPanelManager.SimConnectAgent
|
|
{
|
|
public class FpsCalc
|
|
{
|
|
private const int FpsLen = 25;
|
|
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;
|
|
}
|
|
}
|
|
}
|