nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Timer.hpp
1#ifndef TIMER_H_DEFINED
2#define TIMER_H_DEFINED
3
4#include <sys/time.h>
5
7class Timer
8{
9public:
10 Timer();
11
14 void start();
15
17 void pause();
18
20 void unpause();
21
23 bool isRunning();
24
26 bool isPaused();
27
29 // @note If the timer's not started, will return 0.
30 suseconds_t delta_us();
31
33 suseconds_t delta_ms();
34
36 suseconds_t delta_s();
37
38protected:
39 suseconds_t startMark;
40 suseconds_t stopMark;
41 suseconds_t pausedMark;
42
43 bool running;
44 bool paused;
45};
46
47#endif /* TIMER_H_DEFINED */
48
Definition Timer.hpp:8
void pause()
Temporarily stops the timer.
Definition Timer.cpp:34
bool isRunning()
Tells if the timer's still running (hasn't called stop())
Definition Timer.cpp:53
void start()
Sets a starting point for the timer.
Definition Timer.cpp:26
suseconds_t delta_us()
Returns the whole timer's difference in milisseconds.
Definition Timer.cpp:61
void unpause()
Restarts the timer if it was paused.
Definition Timer.cpp:43
suseconds_t delta_ms()
Returns the milisseconds part of the timer's difference.
Definition Timer.cpp:75
suseconds_t delta_s()
Returns the seconds part of the timer's difference.
Definition Timer.cpp:79
bool isPaused()
Tells if the timer's paused.
Definition Timer.cpp:57