From: Daniel Karbach Date: Fri, 10 Aug 2012 20:43:03 +0000 (+0200) Subject: added hit tracking to timers X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=049f304d41e9aa8b5821e298fcb68c1b9a7e97d6;p=l2e.git added hit tracking to timers --- diff --git a/src/app/Timer.h b/src/app/Timer.h index 465ed64..0a08541 100644 --- a/src/app/Timer.h +++ b/src/app/Timer.h @@ -10,18 +10,20 @@ #include #include +#include namespace app { template struct TimerData { - TimerData() : time(0), target(0), refCount(0) { } - TimerData(Time target) : time(0), target(target), refCount(0) { } + TimerData() : time(0), target(0), refCount(0), justHit(false) { } + TimerData(Time target) : time(0), target(target), refCount(0), justHit(false) { } Time time; Time target; int refCount; + bool justHit; }; @@ -57,6 +59,25 @@ public: Time Remaining() const { return data ? (data->target - data->time) : Time(); } + int Iteration() const { + return (data && data->target > 0) ? std::floor(data->time / data->target) : 0; + } + bool JustHit() const { + return data && data->justHit; + } + + void Reset() { + if (data) data->time = 0; + } + void Restart() { + if (data) { + if (data->target > 0 && data->justHit) { + data->time -= data->target; + } else { + data->time = 0; + } + } + } private: TimerData