headers, split steppable
This commit is contained in:
+11
-20
@@ -1,5 +1,5 @@
|
||||
#ifndef _TIMERS_
|
||||
#define _TIMERS_
|
||||
#ifndef TIMER_HPP
|
||||
#define TIMER_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
@@ -9,48 +9,39 @@
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
class Steppable {
|
||||
public:
|
||||
bool is_finished = 0;
|
||||
virtual bool step() = 0;
|
||||
};
|
||||
|
||||
//check if the timer is valid, check if enough time has passed and if so, actuate
|
||||
//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;
|
||||
bool isdone = false;
|
||||
bool isinfinite = false;
|
||||
size_t triggercounter = 0;
|
||||
size_t triggercount = 0;
|
||||
function<bool()> timeraction;
|
||||
|
||||
Timer(string name, int triggercount, function<bool()> myaction, milliseconds triggerinterval);
|
||||
void add_time(milliseconds deltatime);
|
||||
Timer(string name, int triggercount, function<bool()> myaction, std::chrono::milliseconds triggerinterval);
|
||||
void add_time(std::chrono::milliseconds deltatime);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
milliseconds accumulator = milliseconds(0);
|
||||
milliseconds triggerinterval = milliseconds(1000); //default to 1 sec
|
||||
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
|
||||
//CRUD timers and give them dt on update
|
||||
class TimerManager {
|
||||
public:
|
||||
vector<unique_ptr<Timer>> timers;
|
||||
TimerManager() { previoustime = steady_clock::now(); }
|
||||
TimerManager() { previoustime = std::chrono::steady_clock::now(); }
|
||||
void add_timer(unique_ptr<Timer> newtimer);
|
||||
void delete_timer();
|
||||
void update_timers();
|
||||
|
||||
private:
|
||||
steady_clock::time_point previoustime;
|
||||
std::chrono::steady_clock::time_point previoustime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user