1 #include <Misc/Timer.hpp> 6 #define MICRO_IN_SECONDS 1000000 11 static suseconds_t get_ticks()
14 gettimeofday(&(tmp), NULL);
16 return tmp.tv_usec + (tmp.tv_sec * MICRO_IN_SECONDS);
28 this->startMark = get_ticks();
36 if (!running || paused)
return;
38 this->pausedMark = get_ticks() - (this->startMark);
40 this->running =
false;
45 if (!paused || running)
return;
47 this->startMark = (get_ticks()) - (this->pausedMark);
63 if (this->isRunning())
64 return get_ticks() - this->startMark;
67 return this->pausedMark;
70 if (this->startMark == 0)
73 return (this->pausedMark) - (this->startMark);
77 return this->delta_us() / 1000;
81 return this->delta_ms() / 1000;
bool isRunning()
Tells if the timer's still running (hasn't called stop())
bool isPaused()
Tells if the timer's paused.
suseconds_t delta_s()
Returns the seconds part of the timer's difference.
void start()
Sets a starting point for the timer.
suseconds_t delta_us()
Returns the whole timer's difference in milisseconds.
void pause()
Temporarily stops the timer.
suseconds_t delta_ms()
Returns the milisseconds part of the timer's difference.
void unpause()
Restarts the timer if it was paused.