X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FIntervalTimer.hpp;h=06caa5e21b9bb5c805a1f2e73d68d89c855f8996;hb=045a6ec084bf1fb4df3c6ade4a88932cf61bed23;hp=e5d02481e676d9c618388b626b9931f8caf6fc5a;hpb=b7d09e1e35ef90282c97509e0020b20db3c7ea9f;p=blank.git diff --git a/src/app/IntervalTimer.hpp b/src/app/IntervalTimer.hpp index e5d0248..06caa5e 100644 --- a/src/app/IntervalTimer.hpp +++ b/src/app/IntervalTimer.hpp @@ -4,10 +4,16 @@ 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: - explicit IntervalTimer(int interval_ms) noexcept + /// Create a timer that hits every interval_ms milliseconds. + /// Initial state is stopped. + explicit IntervalTimer(int interval_ms = 0) noexcept : intv(interval_ms) { } void Start() noexcept { @@ -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 Running() && value >= intv; + } int Elapsed() const noexcept { return value; }