cleanup, timermanager in App is a dependency that takes timers again.
App now adds already constructed Timers Timer is now an Invoker that takes a weak_ptr to a steppable with a request()rather than a bool callback. should eventually be changed to composition
This commit is contained in:
+7
-13
@@ -1,37 +1,31 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
|
||||
#include "timer.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
Timer::Timer(size_t triggeramount, function<bool()> myaction, milliseconds triggerinterval)
|
||||
Timer::Timer(size_t triggeramount, milliseconds triggerinterval)
|
||||
:triggeramount(triggeramount)
|
||||
, callback(myaction)
|
||||
, triggerinterval(triggerinterval) {}
|
||||
|
||||
void Timer::add_time(milliseconds deltatime) {
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
cout << "request in timer\n";
|
||||
request();
|
||||
triggercount++;
|
||||
if (!isinfinite && triggercount >= triggeramount){
|
||||
if (triggeramount != 0 && triggercount >= triggeramount){
|
||||
isexpired=true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void Timer::request() {
|
||||
callback();
|
||||
}
|
||||
|
||||
void TimerManager::add_timer(size_t triggeramount, function<bool()> myaction, std::chrono::milliseconds triggerinterval) {
|
||||
Timer mynewtimer(triggeramount, myaction, triggerinterval);
|
||||
timers.push_back(std::move(mynewtimer));
|
||||
};
|
||||
void TimerManager::add_timer(Timer timer){
|
||||
timers.push_back(timer);
|
||||
}
|
||||
|
||||
void TimerManager::update_timers() {
|
||||
steady_clock::time_point currenttime =
|
||||
|
||||
Reference in New Issue
Block a user