lxgui
utils_periodic_timer.cpp
1 #include "lxgui/utils_periodic_timer.hpp"
2 
3 namespace lxgui::utils {
4 
5 periodic_timer::periodic_timer(double duration, start_type type, bool ticks_now) :
6  elapsed_(ticks_now ? duration : 0.0), duration_(duration), type_(type) {
7  if (type == start_type::now)
8  start();
9 }
10 
12  return elapsed_;
13 }
14 
16  return duration_;
17 }
18 
20  return paused_;
21 }
22 
24  if (type_ == start_type::first_tick && first_tick_) {
25  start();
26  first_tick_ = false;
27  }
28 
29  if (elapsed_ >= duration_) {
30  if (!paused_)
31  zero();
32 
33  return true;
34  } else
35  return false;
36 }
37 
39  elapsed_ = 0.0;
40  paused_ = true;
41 }
42 
44  paused_ = true;
45 }
46 
48  paused_ = false;
49 }
50 
52  elapsed_ = 0.0;
53 }
54 
55 void periodic_timer::update(double delta) {
56  elapsed_ += delta;
57 }
58 
59 } // namespace lxgui::utils
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.
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.