summaryrefslogtreecommitdiffhomepage
path: root/Timer.cpp
diff options
context:
space:
mode:
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();
+ }
+ }
+}
+