diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-04 11:28:20 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-04 11:28:20 +0100 |
commit | b2c35cdf69a9084806ac7930cf4475980d596cf6 (patch) | |
tree | b74b8f2ee2c66c59f7385407cfc34c2a0a16961f /Timer.cpp | |
parent | aaafcea7e26791acbf5b9612e3fb396edcdfcc8f (diff) |
Separate out implementation from headers
Diffstat (limited to 'Timer.cpp')
-rw-r--r-- | Timer.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -1 +1,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(); + } + } +} + |