mirror of https://github.com/quasar/Quasar.git
38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace xServer.Core.Helper
|
|
{
|
|
public class FrameCounter
|
|
{
|
|
public long TotalFrames { get; private set; }
|
|
public float TotalSeconds { get; private set; }
|
|
public float AverageFramesPerSecond { get; private set; }
|
|
public float CurrentFramesPerSecond { get; private set; }
|
|
|
|
public const int MAXIMUM_SAMPLES = 100;
|
|
|
|
private Queue<float> _sampleBuffer = new Queue<float>();
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
CurrentFramesPerSecond = 1.0f / deltaTime;
|
|
|
|
_sampleBuffer.Enqueue(CurrentFramesPerSecond);
|
|
|
|
if (_sampleBuffer.Count > MAXIMUM_SAMPLES)
|
|
{
|
|
_sampleBuffer.Dequeue();
|
|
AverageFramesPerSecond = _sampleBuffer.Average(i => i);
|
|
}
|
|
else
|
|
{
|
|
AverageFramesPerSecond = CurrentFramesPerSecond;
|
|
}
|
|
|
|
TotalFrames++;
|
|
TotalSeconds += deltaTime;
|
|
}
|
|
}
|
|
}
|