Add Timer class

This commit is contained in:
Unknown
2020-03-27 21:05:27 -04:00
parent cb534ae372
commit 33317eb4df
2 changed files with 70 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include <algorithm>
class Timer {
public:
void setTimeout(const float timeout) {
timeout_ = timeout;
}
void setInterval(const float interval) {
interval_ = interval;
}
void start() {
running_ = true;
}
void stop() {
running_ = false;
}
void update() {
if (running_)
timer_ = std::min(timer_ + interval_, timeout_);
}
void reset() {
timer_ = 0.0f;
}
bool expired() {
return timer_ >= timeout_;
}
private:
float timer_ = 0.0f;
float timeout_ = 0.0f;
float interval_ = 0.0f;
bool running_ = false;
};