X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2FTimer.h;h=13f48f3d7d38ec884c38234fc4fdc7355e1f990c;hb=3f9f41338d8100a719e161a3a1cdda9dd227e2b4;hp=465ed64e45edc14a13faa7f462b70e35275e83a1;hpb=bce16ed519add0d5398d504d2554395c43c74571;p=l2e.git diff --git a/src/app/Timer.h b/src/app/Timer.h index 465ed64..13f48f3 100644 --- a/src/app/Timer.h +++ b/src/app/Timer.h @@ -10,18 +10,21 @@ #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), repeat(false) { } + TimerData(Time target, bool repeat) : time(0), target(target), refCount(0), justHit(false), repeat(repeat) { } Time time; Time target; int refCount; + bool justHit; + bool repeat; }; @@ -45,11 +48,14 @@ public: } public: - bool Running() const { + bool Started() const { return data; } bool Finished() const { - return data ? data->time >= data->target : false; + return data && data->target != Time() && !data->repeat && data->time >= data->target; + } + bool Running() const { + return data && !Finished(); } Time Elapsed() const { return data ? data->time : Time(); @@ -57,6 +63,31 @@ public: Time Remaining() const { return data ? (data->target - data->time) : Time(); } + int Iteration() const { + return (data && data->target > Time()) ? std::floor(data->time / data->target) : Time(); + } + bool JustHit() const { + return data && data->justHit; + } + + void Clear() { + if (data) { + --data->refCount; + data = 0; + } + } + void Reset() { + if (data) data->time = Time(); + } + void Restart() { + if (data) { + if (data->target > Time() && data->justHit) { + data->time -= data->target; + } else { + data->time = Time(); + } + } + } private: TimerData