]> git.localhorst.tv Git - blank.git/blobdiff - src/app/IntervalTimer.hpp
also post UI messages to graphical output
[blank.git] / src / app / IntervalTimer.hpp
index e5d02481e676d9c618388b626b9931f8caf6fc5a..bcf1baef29e290fafbe90079d4daabc05052914b 100644 (file)
@@ -4,9 +4,15 @@
 
 namespace blank {
 
+/// Timer that hits every n milliseconds. Resolution is that of the
+/// delta values passed to Update(), minimum 1ms.
+/// Also tracks the number of iterations as well as milliseconds
+/// passed.
 class IntervalTimer {
 
 public:
+       /// Create a timer that hits every interval_ms milliseconds.
+       /// Initial state is stopped.
        explicit IntervalTimer(int interval_ms) noexcept
        : intv(interval_ms) { }
 
@@ -17,13 +23,20 @@ public:
                value = 0;
                speed = 0;
        }
+       void Reset() noexcept {
+               value = 0;
+       }
 
        bool Running() const noexcept {
                return speed != 0;
        }
+       /// true if an interval boundary was passed by the last call to Update()
        bool Hit() const noexcept {
                return Running() && value % intv < last_dt;
        }
+       bool HitOnce() const noexcept {
+               return value >= intv;
+       }
        int Elapsed() const noexcept {
                return value;
        }