nsnake
Classic snake game for the terminal
Timer.hpp
1 #ifndef TIMER_H_DEFINED
2 #define TIMER_H_DEFINED
3 
4 #include <sys/time.h>
5 
7 class Timer
8 {
9 public:
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 
38 protected:
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 
bool isRunning()
Tells if the timer&#39;s still running (hasn&#39;t called stop())
Definition: Timer.cpp:53
bool isPaused()
Tells if the timer&#39;s paused.
Definition: Timer.cpp:57
suseconds_t delta_s()
Returns the seconds part of the timer&#39;s difference.
Definition: Timer.cpp:79
void start()
Sets a starting point for the timer.
Definition: Timer.cpp:26
suseconds_t delta_us()
Returns the whole timer&#39;s difference in milisseconds.
Definition: Timer.cpp:61
void pause()
Temporarily stops the timer.
Definition: Timer.cpp:34
suseconds_t delta_ms()
Returns the milisseconds part of the timer&#39;s difference.
Definition: Timer.cpp:75
Definition: Timer.hpp:7
void unpause()
Restarts the timer if it was paused.
Definition: Timer.cpp:43