timermanager now creates its own timers
This commit is contained in:
+7
-8
@@ -11,9 +11,9 @@
|
||||
|
||||
using namespace std;
|
||||
//check if the timer is still valid, check if enough time has passed and if so, actuate action
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
string name;
|
||||
size_t triggeramount;
|
||||
|
||||
bool isexpired = false;
|
||||
@@ -21,22 +21,21 @@ public:
|
||||
size_t triggercount = 0;
|
||||
function<bool()> timeraction;
|
||||
|
||||
Timer(string name, int triggercount, function<bool()> myaction, std::chrono::milliseconds triggerinterval);
|
||||
Timer(size_t triggeramount, function<bool()> myaction, std::chrono::milliseconds triggerinterval);
|
||||
void add_time(std::chrono::milliseconds deltatime);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::chrono::milliseconds accumulator = std::chrono::milliseconds(0);
|
||||
std::chrono::milliseconds triggerinterval = std::chrono::milliseconds(1000); //default to 1 sec
|
||||
};
|
||||
|
||||
|
||||
//CRUD timers and give them dt on update
|
||||
class TimerManager {
|
||||
public:
|
||||
vector<unique_ptr<Timer>> timers;
|
||||
TimerManager() { previoustime = std::chrono::steady_clock::now(); }
|
||||
void add_timer(unique_ptr<Timer> newtimer);
|
||||
vector<Timer> timers;
|
||||
TimerManager(){previoustime = std::chrono::steady_clock::now();}
|
||||
void add_timer(size_t triggeramount, function<bool()> myaction, std::chrono::milliseconds triggerinterval);
|
||||
void delete_timer();
|
||||
void update_timers();
|
||||
|
||||
@@ -44,4 +43,4 @@ private:
|
||||
std::chrono::steady_clock::time_point previoustime;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user