-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.h
42 lines (37 loc) · 812 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
#pragma once
#include <Windows.h>
class Timer {
long long startTime;
long long lastCallToUpdate;
long long currentCallToUpdate;
long long frequency;
public:
Timer() {
LARGE_INTEGER t;
QueryPerformanceFrequency(&t);
frequency = t.QuadPart;
Reset();
}
void Reset() {
//Set the Current time:
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
startTime = t.QuadPart;
currentCallToUpdate = t.QuadPart;
lastCallToUpdate = t.QuadPart;
}
void Update() {
lastCallToUpdate = currentCallToUpdate;
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
currentCallToUpdate = t.QuadPart;
}
double GetTimeTotal() {
double d = currentCallToUpdate - startTime;
return d / frequency;
}
double GetTimeDelta() {
double d = currentCallToUpdate - lastCallToUpdate;
return d / frequency;
}
};