Timer now contains an invoker instead of inheriting
the idea is that an invoker holds a weak_ptr to a steppable. and anything with an invoker can advance a steppable app::add_sort has become too heavy because of the way timer and invoker are initialized now.
This commit is contained in:
+7
-4
@@ -1,21 +1,24 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "timer.hpp"
|
||||
#include "Invoker.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
|
||||
Timer::Timer(size_t triggeramount, milliseconds triggerinterval)
|
||||
Timer::Timer(size_t triggeramount, std::unique_ptr<Invoker> invoker, milliseconds triggerinterval)
|
||||
:triggeramount(triggeramount)
|
||||
, triggerinterval(triggerinterval) {}
|
||||
, invoker(std::move(invoker))
|
||||
, triggerinterval(triggerinterval){}
|
||||
|
||||
void Timer::add_time(milliseconds deltatime) {
|
||||
accumulator += deltatime;
|
||||
if (accumulator >= triggerinterval) {
|
||||
accumulator -= triggerinterval;
|
||||
cout << "request in timer\n";
|
||||
request();
|
||||
invoker->request();
|
||||
triggercount++;
|
||||
if (triggeramount != 0 && triggercount >= triggeramount){
|
||||
isexpired=true;
|
||||
@@ -24,7 +27,7 @@ void Timer::add_time(milliseconds deltatime) {
|
||||
}
|
||||
|
||||
void TimerManager::add_timer(Timer timer){
|
||||
timers.push_back(timer);
|
||||
timers.push_back(std::move(timer));
|
||||
}
|
||||
|
||||
void TimerManager::update_timers() {
|
||||
|
||||
Reference in New Issue
Block a user