-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.h
64 lines (49 loc) · 1.21 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef TIMER_H_
#define TIMER_H_
#include <sys/time.h>
/*
struct for checking how long it has been since the start of the turn.
*/
#ifdef _WIN32 //Windows timer (DON'T USE THIS TIMER UNLESS YOU'RE ON WINDOWS!)
#include <io.h>
#include <windows.h>
struct Timer
{
clock_t startTime, currentTime;
Timer()
{
};
void start()
{
startTime = clock();
};
double getTime()
{
currentTime = clock();
return (double)(currentTime - startTime);
};
};
#else //Mac/Linux Timer
struct Timer
{
timeval timer;
double startTime, currentTime;
Timer()
{
};
//starts the timer
void start()
{
gettimeofday(&timer, NULL);
startTime = timer.tv_sec+(timer.tv_usec/1000000.0);
};
//returns how long it has been since the timer was last started in milliseconds
double getTime()
{
gettimeofday(&timer, NULL);
currentTime = timer.tv_sec+(timer.tv_usec/1000000.0);
return (currentTime-startTime)*1000.0;
};
};
#endif
#endif //TIMER_H_