blob: 7885e7390ffd4d85e44145cc15914b623ddb63a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "Timer.h"
Timer::Timer(std::chrono::milliseconds interval, bool cyclic) :
m_start_time(clock_type::now()),
m_interval(interval),
m_running(false),
m_cyclic(cyclic)
{
}
void Timer::start()
{
m_running = true;
m_start_time = clock_type::now();
}
void Timer::stop()
{
m_running = false;
}
bool Timer::is_elapsed() const
{
return m_start_time + m_interval < clock_type::now();
}
void Timer::update()
{
if (m_running && is_elapsed()) {
elapsed();
if (m_cyclic) {
start();
} else {
stop();
}
}
}
|