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:
+19
-12
@@ -4,30 +4,37 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include "timer.hpp"
|
||||
Timer::Timer(std::string name, int triggercount, std::function<void(Timer &t)> myaction, std::chrono::milliseconds triggerinterval)
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
Timer::Timer(string name, int triggercount, function<bool()> myaction, milliseconds triggerinterval)
|
||||
: name(name), triggeramount(triggercount), timeraction(myaction), triggerinterval(triggerinterval) {}
|
||||
|
||||
void Timer::add_time(std::chrono::milliseconds deltatime) {
|
||||
void Timer::add_time(milliseconds deltatime) {
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
timeraction(*this);
|
||||
if (timeraction()==true){
|
||||
isdone = true;
|
||||
};
|
||||
triggercounter++;
|
||||
if (!isinfinite && triggercounter >= triggeramount){
|
||||
isexpired=true;
|
||||
}
|
||||
if (!isinfinite && triggercounter >= triggeramount){
|
||||
isexpired=true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void TimerManager::add_timer(std::unique_ptr<Timer> newtimer) {
|
||||
void TimerManager::add_timer(unique_ptr<Timer> newtimer) {
|
||||
timers.push_back(std::move(newtimer));
|
||||
};
|
||||
|
||||
void TimerManager::update_timers() {
|
||||
std::chrono::steady_clock::time_point currenttime =
|
||||
std::chrono::steady_clock::now();
|
||||
std::chrono::milliseconds deltatime = std::chrono::duration_cast<std::chrono::milliseconds>(currenttime-previoustime);
|
||||
for(std::unique_ptr<Timer> &mytimer: timers){
|
||||
mytimer->add_time(deltatime);
|
||||
steady_clock::time_point currenttime =
|
||||
steady_clock::now();
|
||||
milliseconds deltatime = duration_cast<milliseconds>(currenttime-previoustime);
|
||||
for(unique_ptr<Timer> &mytimer: timers){
|
||||
mytimer->add_time(deltatime);
|
||||
}
|
||||
previoustime = currenttime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user