-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFpsMonitor.cpp
More file actions
43 lines (34 loc) · 758 Bytes
/
Copy pathFpsMonitor.cpp
File metadata and controls
43 lines (34 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Created by jwc on 2/22/19.
//
#include "FpsMonitor.h"
FpsMonitor::FpsMonitor()
{
head = tail = 0;
count = 0;
}
void FpsMonitor::mark(double sampleTime)
{
ween(sampleTime);
samples[tail] = sampleTime;
int newTail = (tail + 1) % FpsMonitor_bound;
if (newTail == head)
{
head = (head + 1) % FpsMonitor_bound;
count--;
}
tail = newTail;
count++;
}
double FpsMonitor::fps()
{
if (count == 0) return 0;
return count / (double) (samples[(tail+FpsMonitor_bound-1)%FpsMonitor_bound] - samples[head]);
}
void FpsMonitor::ween(double time) {
while (head != tail && time-samples[head] >= FpsMonitor_timeWindow)
{
head = (head + 1) % FpsMonitor_bound;
count--;
}
}