summaryrefslogtreecommitdiffhomepage
path: root/Timer.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-04 11:28:20 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-04 11:28:20 +0100
commitb2c35cdf69a9084806ac7930cf4475980d596cf6 (patch)
treeb74b8f2ee2c66c59f7385407cfc34c2a0a16961f /Timer.cpp
parentaaafcea7e26791acbf5b9612e3fb396edcdfcc8f (diff)
Separate out implementation from headers
Diffstat (limited to 'Timer.cpp')
-rw-r--r--Timer.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Timer.cpp b/Timer.cpp
index afe5d24..7885e73 100644
--- a/Timer.cpp
+++ b/Timer.cpp
@@ -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();
+ }
+ }
+}
+