app now just coordinates the components initialized in main
reduced responsibilities of constructors started using more pointers. sessions through app rather than app itself. mostly split view away from app (still hard coded) haven't decoupled sorts from timers as their actuator yet
This commit is contained in:
+14
-13
@@ -1,39 +1,40 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "timer.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
Timer::Timer(size_t triggeramount, function<bool()> myaction, milliseconds triggerinterval)
|
||||
:triggeramount(triggeramount), timeraction(myaction), triggerinterval(triggerinterval) {}
|
||||
:triggeramount(triggeramount)
|
||||
, timeraction(myaction)
|
||||
, triggerinterval(triggerinterval) {}
|
||||
|
||||
void Timer::add_time(milliseconds deltatime) {
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
timeraction();
|
||||
triggercount++;
|
||||
triggercount++;
|
||||
if (!isinfinite && triggercount >= triggeramount){
|
||||
isexpired=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void TimerManager::add_timer(size_t triggeramount, function<bool()> myaction, std::chrono::milliseconds triggerinterval) {
|
||||
Timer mynewtimer(triggeramount, myaction, triggerinterval);
|
||||
timers.push_back(mynewtimer);
|
||||
timers.push_back(std::move(mynewtimer));
|
||||
};
|
||||
|
||||
void TimerManager::update_timers() {
|
||||
steady_clock::time_point currenttime =
|
||||
steady_clock::time_point currenttime =
|
||||
steady_clock::now();
|
||||
milliseconds deltatime = duration_cast<milliseconds>(currenttime-previoustime);
|
||||
for(Timer &mytimer: timers){
|
||||
milliseconds deltatime = duration_cast<milliseconds>(currenttime-previoustime);
|
||||
for(Timer &mytimer: timers){
|
||||
mytimer.add_time(deltatime);
|
||||
}
|
||||
}
|
||||
previoustime = currenttime;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user