#ifndef INPUT_LAG_H_DF16F381 #define INPUT_LAG_H_DF16F381 /** * Helper class that handles key repeat. */ class InputLag { public: bool isActive() const { return active_; } void reset() { accum_ = 0.0; active_ = false; repeat_ = false; } void accumulate(double dt) { accum_ += dt; } bool step() { if (!active_) { active_ = true; return true; } else if (!repeat_) { if (accum_ > delay_) { accum_ -= delay_; repeat_ = true; return true; } } else { if (accum_ > tick_) { accum_ -= tick_; return true; } } return false; } private: double tick_ = 1.0 / 15.0; double delay_ = tick_ * 3.0; double accum_ = 0.0; bool active_ = false; bool repeat_ = false; }; #endif /* end of include guard: INPUT_LAG_H_DF16F381 */