]> git.localhorst.tv Git - blank.git/blobdiff - src/app/IntervalTimer.hpp
group entity updates in as few packets as possible
[blank.git] / src / app / IntervalTimer.hpp
index 0d6790be20850ebfb9276fc62f88b09408793917..5240f5d3f60a419e8593b5e883dab9fd5c8e8d1c 100644 (file)
@@ -13,7 +13,7 @@ class IntervalTimer {
 public:
        /// Create a timer that hits every interval_ms milliseconds.
        /// Initial state is stopped.
-       explicit IntervalTimer(int interval_ms) noexcept
+       explicit IntervalTimer(int interval_ms = 0) noexcept
        : intv(interval_ms) { }
 
        void Start() noexcept {
@@ -23,6 +23,9 @@ public:
                value = 0;
                speed = 0;
        }
+       void Reset() noexcept {
+               value = 0;
+       }
 
        bool Running() const noexcept {
                return speed != 0;
@@ -31,12 +34,21 @@ public:
        bool Hit() const noexcept {
                return Running() && value % intv < last_dt;
        }
+       bool HitOnce() const noexcept {
+               return Running() && value >= intv;
+       }
        int Elapsed() const noexcept {
                return value;
        }
+       int Interval() const noexcept {
+               return intv;
+       }
        int Iteration() const noexcept {
                return value / intv;
        }
+       void PopIteration() noexcept {
+               value -= intv;
+       }
 
        void Update(int dt) noexcept {
                value += dt * speed;