#pragma once #include #include using namespace std::chrono_literals; using clock_type = std::chrono::high_resolution_clock; class Timer { public: Timer(std::chrono::milliseconds interval, bool cyclic) : m_start_time(clock_type::now()), m_interval(interval), m_running(false), m_cyclic(cyclic) {} // connect to this signal boost::signals2::signal elapsed; void start() { m_running = true; m_start_time = clock_type::now(); } void stop() { m_running = false; } bool is_elapsed() { return m_start_time + m_interval < clock_type::now(); } void update() { if (m_running && is_elapsed()) { elapsed(); if (m_cyclic) { start(); } else { stop(); } } } private: std::chrono::time_point m_start_time; std::chrono::milliseconds m_interval; bool m_running; bool m_cyclic; };