-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimer.h
37 lines (26 loc) · 1.41 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
#ifndef TIMER_GUARDIAN
#define TIMER_GUARDIAN
class Timer
{
public:
explicit Timer (bool started = false) : m_startTicks(-1), m_totalTicks(0) { if (started) start(); }
Timer (const Timer& other) { operator=(other); }
~Timer (void) {}
Timer& operator= (const Timer& other) { m_startTicks = other.m_startTicks; m_totalTicks = other.m_totalTicks; return *this; }
void start (void) { m_startTicks = queryTicks(); }
void unstart (void) { m_startTicks = -1; }
float getElapsed (void) { return ticksToSecs(getElapsedTicks()); }
float end (void); // return elapsed, total += elapsed, restart
float getTotal (void) const { return ticksToSecs(m_totalTicks); }
void clearTotal (void) { m_totalTicks = 0; }
private:
static long long int queryTicks (void);
static float ticksToSecs (long long int ticks);
long long int getElapsedTicks (void); // return time since start, start if unstarted
private:
static double s_ticksToSecsCoef;
static long long int s_prevTicks;
long long int m_startTicks;
long long int m_totalTicks;
};
#endif