X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FTimer.h;fp=src%2Fapp%2FTimer.h;h=0a085418739be44a53c24e83281de511d201a394;hb=049f304d41e9aa8b5821e298fcb68c1b9a7e97d6;hp=465ed64e45edc14a13faa7f462b70e35275e83a1;hpb=69123d71dacfdd6592c00ead8b92b6441d0f0228;p=l2e.git 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