switched from raw lambda to stepable
couldn't figure out how to handle sortstate, eventually put it into bsort class. should be split into timeraction and steppable. and there shouldn't be a random steppedbsort in App
This commit is contained in:
+39
-23
@@ -1,3 +1,5 @@
|
||||
#ifndef _TIMERS_
|
||||
#define _TIMERS_
|
||||
|
||||
#include <cstddef>
|
||||
#include <ctime>
|
||||
@@ -7,34 +9,48 @@
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
std::string name;
|
||||
std::size_t triggeramount;
|
||||
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
|
||||
class Timer {
|
||||
public:
|
||||
string name;
|
||||
size_t triggeramount;
|
||||
|
||||
bool isexpired = false;
|
||||
bool isdone = false;
|
||||
bool isinfinite = false;
|
||||
size_t triggercounter = 0;
|
||||
function<bool()> timeraction;
|
||||
|
||||
Timer(string name, int triggercount, function<bool()> myaction, milliseconds triggerinterval);
|
||||
void add_time(milliseconds deltatime);
|
||||
|
||||
|
||||
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
|
||||
milliseconds accumulator = milliseconds(0);
|
||||
milliseconds triggerinterval = milliseconds(1000); //default to 1 sec
|
||||
};
|
||||
|
||||
//CRUD timers and give them dt
|
||||
class TimerManager {
|
||||
public:
|
||||
vector<unique_ptr<Timer>> timers;
|
||||
TimerManager() { previoustime = steady_clock::now(); }
|
||||
void add_timer(unique_ptr<Timer> newtimer);
|
||||
void delete_timer();
|
||||
void update_timers();
|
||||
|
||||
|
||||
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;
|
||||
private:
|
||||
steady_clock::time_point previoustime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user