| | 1 | | namespace DCL.FPSDisplay |
| | 2 | | { |
| | 3 | | public class LinealBufferFPSCounter |
| | 4 | | { |
| | 5 | | public const int MAX_BUFFER_SIZE = 1000; |
| 4 | 6 | | public readonly float[] values = new float[MAX_BUFFER_SIZE]; |
| | 7 | |
|
| 0 | 8 | | public int begin { get; private set; } = 0; |
| 0 | 9 | | public int end { get; private set; } = 0; |
| 0 | 10 | | public float secondsBetweenBeginAndEnd { get; private set; } = 0; |
| 0 | 11 | | public float secondsInBuffer { get; private set; } = 0; |
| 0 | 12 | | public int countBetweenBeginAndEnd { get; private set; } = 0; |
| | 13 | |
|
| | 14 | | public void AddDeltaTime(float valueInSeconds) |
| | 15 | | { |
| 3701 | 16 | | values[end++] = valueInSeconds; |
| 3701 | 17 | | secondsInBuffer += valueInSeconds; |
| 3701 | 18 | | secondsBetweenBeginAndEnd += valueInSeconds; |
| 3701 | 19 | | countBetweenBeginAndEnd++; |
| | 20 | |
|
| 3701 | 21 | | if (end == MAX_BUFFER_SIZE) |
| 3 | 22 | | end = 0; |
| | 23 | |
|
| 7203 | 24 | | while (secondsBetweenBeginAndEnd > 1) |
| | 25 | | { |
| 3502 | 26 | | secondsInBuffer -= values[begin]; |
| 3502 | 27 | | secondsBetweenBeginAndEnd -= values[begin++]; |
| 3502 | 28 | | countBetweenBeginAndEnd--; |
| 3502 | 29 | | if (begin == MAX_BUFFER_SIZE) |
| 2 | 30 | | begin = 0; |
| | 31 | | } |
| 3701 | 32 | | } |
| 0 | 33 | | public float CurrentFPSCount() { return countBetweenBeginAndEnd; } |
| 0 | 34 | | public float GetTotalSeconds() { return secondsInBuffer; } |
| | 35 | | } |
| | 36 | | } |