The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
#pragma once
|
|
#include <functional>
|
|
#include <string>
|
|
|
|
class Timer{
|
|
friend struct std::hash<Timer>;
|
|
public:
|
|
enum class TimerType{
|
|
REPEAT,
|
|
MANUAL,
|
|
};
|
|
|
|
using enum TimerType;
|
|
private:
|
|
std::string timerName;
|
|
float originalVal;
|
|
float timer;
|
|
TimerType autoRepeat;
|
|
std::function<void()>callback;
|
|
public:
|
|
Timer(const std::string timerName,const float timer,const std::function<void()>callback,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<Timer>
|
|
{
|
|
std::size_t operator()(const Timer&timer) const
|
|
{
|
|
return std::hash<std::string>()(timer.timerName);
|
|
}
|
|
}; |