-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNA_Timer.cpp
More file actions
50 lines (41 loc) · 819 Bytes
/
NA_Timer.cpp
File metadata and controls
50 lines (41 loc) · 819 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
#include "NA_Timer.h"
#include <time.h>
#ifdef _WIN32
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#endif
NA_Timer::NA_Timer(double d)
{
duration = d;
start = time(NULL);
}
NA_Timer::~NA_Timer(void)
{
}
void NA_Timer::setDuration(double d)
{
duration = d;
}
bool NA_Timer::hasElapsed()
{
if(duration < difftime(time(NULL),start))
return true;
//else
return false;
}
void NA_Timer::restart()
{
start = time(NULL);
}
void NA_Timer::wait()
{
while (!hasElapsed())
{
#ifdef _WIN32
Sleep(250*(duration - difftime(time(NULL), start))); //quarter of a second mulitplied by remianing duration (which is in seconds)
#endif
}
}