lxgui
utils_periodic_timer.hpp
1 #ifndef LXGUI_UTILS_PERIODIC_TIMER_HPP
2 #define LXGUI_UTILS_PERIODIC_TIMER_HPP
3 
4 #include "lxgui/lxgui.hpp"
5 
6 namespace lxgui::utils {
7 
15 public:
16  enum class start_type {
18  paused,
20  now,
23  };
24 
31  periodic_timer(double duration, start_type type, bool ticks_now);
32 
37  double get_elapsed() const;
38 
43  double get_period() const;
44 
49  bool is_paused() const;
50 
55  bool ticks();
56 
58  void stop();
59 
61  void start();
62 
64  void pause();
65 
67  void zero();
68 
73  void update(double delta);
74 
75 private:
76  double elapsed_ = 0.0;
77  double duration_ = 0.0;
78  bool paused_ = true;
79  bool first_tick_ = true;
80 
82 };
83 
84 } // namespace lxgui::utils
85 
86 #endif
void stop()
Pauses the timer and resets it.
periodic_timer(double duration, start_type type, bool ticks_now)
Default constructor.
bool is_paused() const
Cheks if this periodic_timer is paused.
double get_elapsed() const
Returns the time elapsed since the last tick.
@ first_tick
The timer will start when you first call ticks()
@ now
The timer starts immediatly after it is created.
@ paused
The timer will start if you call start()
void zero()
Resets the timer but doesn't pause it.
bool ticks()
Checks if the timer's period has been reached.
void update(double delta)
Updates this timer (adds time).
double get_period() const
Returns the period of the periodic_timer.
void start()
Starts the timer but doesn't reset it.