ic working example
setup with working timers and timermanager
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
std::string name;
|
||||
std::size_t triggeramount;
|
||||
|
||||
bool isexpired;
|
||||
bool isinfinite;
|
||||
std::size_t triggercounter = 0;
|
||||
|
||||
Timer(std::string name, int triggercount, std::function<void(Timer &t)> myaction, std::chrono::milliseconds triggerinterval);
|
||||
void add_time(std::chrono::milliseconds deltatime);
|
||||
std::function<void(Timer&)> timeraction;
|
||||
|
||||
private:
|
||||
std::chrono::milliseconds accumulator = std::chrono::milliseconds(0);
|
||||
std::chrono::milliseconds triggerinterval = std::chrono::milliseconds(1000); //default to 1 sec
|
||||
};
|
||||
|
||||
class TimerManager {
|
||||
|
||||
|
||||
public:
|
||||
std::vector<std::unique_ptr<Timer>> timers;
|
||||
TimerManager() { previoustime = std::chrono::steady_clock::now(); }
|
||||
void add_timer(std::unique_ptr<Timer> newtimer);
|
||||
void delete_timer();
|
||||
void update_timers();
|
||||
|
||||
private:
|
||||
std::chrono::steady_clock::time_point previoustime;
|
||||
};
|
||||
Reference in New Issue
Block a user