forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPSTracker.h
55 lines (40 loc) · 957 Bytes
/
FPSTracker.h
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
44
45
46
47
48
49
50
51
52
#pragma once
class FPSTracker
{
public:
void Init(float UpdateInterval)
{
m_fLastIntervalFPS = 0;
m_fUpdateInterval = UpdateInterval;
BeginInterval();
}
void Update()
{
if (m_fIntervalEnd <= Time::GetTimeElapsed())
{
double Elapsed = Time::GetTimeElapsed() - m_fIntervalStart;
m_fLastIntervalFPS = (float)(m_iIntervalFrames / Elapsed);
BeginInterval();
}
}
void IncrementFrame()
{
m_iIntervalFrames++;
}
float GetFPS()
{
return m_fLastIntervalFPS;
}
private:
void BeginInterval()
{
m_iIntervalFrames = 0;
m_fIntervalStart = Time::GetTimeElapsed();
m_fIntervalEnd = Time::GetTimeElapsed() + m_fUpdateInterval;
}
DWORD m_iIntervalFrames;
double m_fIntervalStart;
double m_fIntervalEnd;
float m_fUpdateInterval;
float m_fLastIntervalFPS;
};