-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.h
43 lines (39 loc) · 910 Bytes
/
Timer.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
#ifndef TIMER_H
#define TIMER_H
#include <Windows.h>
namespace Rendering {
class Timer {
public:
Timer() : startTicks(0), endTicks(0) {
QueryPerformanceFrequency((LARGE_INTEGER*)&frequency);
}
void Start() {
startTicks = endTicks = GetTimeNow();
}
int Stop() {
endTicks = GetTimeNow();
return GetTicksElapsed();
}
void Restart() {
Start();
}
int GetTicksElapsed() {
return int(GetTimeNow() - startTicks);
}
int GetTicksPerMillisecond() { return (int)frequency; }
double GetElapsedTime() {
return double(GetTicksElapsed()) / double(GetTicksPerMillisecond());
}
bool IsStopped() { return endTicks != startTicks; }
private:
__int64 GetTimeNow() {
__int64 time;
QueryPerformanceCounter((LARGE_INTEGER*)&time);
return time;
}
__int64 frequency; //frequency of timer
__int64 startTicks; //start time
__int64 endTicks; //end time
};
}
#endif