-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsHelper.cpp
More file actions
51 lines (38 loc) · 920 Bytes
/
WindowsHelper.cpp
File metadata and controls
51 lines (38 loc) · 920 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
44
45
46
47
48
49
50
51
#include "WindowsHelper.h"
WindowsHelper::WindowsHelper(){
}
WindowsHelper::~WindowsHelper(){
}
#ifndef WIN32
struct timeval last_tv;
#endif
float WindowsHelper::getMsElapsed() {
#ifdef _WIN32
static ULONGLONG prevCount = 0;
static float freq = 0;
ULONGLONG count = 0;
float delta = 0.0f;
if (freq == 0.0f){
LARGE_INTEGER iFreq;
QueryPerformanceFrequency(&iFreq);
freq = float(iFreq.QuadPart) / 1000.0f;
}
QueryPerformanceCounter((LARGE_INTEGER*)&count);
if (prevCount){
delta = float(count - prevCount) / freq;
}
prevCount = count;
return delta;
#else
struct timeval tv;
gettimeofday(&tv,NULL);
double secs = (tv.tv_sec - last_tv.tv_sec) + 1e-6 * (tv.tv_usec - last_tv.tv_usec);
// convert to ms
secs *= 1000.0f;
last_tv = tv;
if(secs > 0.00001f)
return secs;
else
return 0.001f;
#endif
}