#pragma once #include #include class Timer{ friend struct std::hash; public: enum class TimerType{ REPEAT, MANUAL, }; using enum TimerType; private: std::string timerName; float originalVal; float timer; TimerType autoRepeat; std::functioncallback; public: Timer(const std::string timerName,const float timer,const std::functioncallback,const TimerType autoRepeat=MANUAL); const bool Update(const float fElapsedTime); //Returns false when the timer is completed. void Reset(); //Resets the timer to the original given time it had. void Reset(const float newTime); //Resets the timer to the specified time. void Cancel(); //Stops the timer such that it is no longer running. (Doesn't invoke the callback) const bool IsRunning()const; const bool IsDone()const; const float RemainingTime()const; bool operator==(const Timer&timer){return timerName==timer.timerName;}; }; template <> struct std::hash { std::size_t operator()(const Timer&timer) const { return std::hash()(timer.timerName); } };