time keeping / deltatime now handled by timermanager instead of main
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// calls callbackfunc on specified interval based on accumulated deltatime
|
||||
#include "timer.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
@@ -39,9 +39,13 @@ void timermanager::addtimer(std::unique_ptr<timer> input_timer) {
|
||||
timers.push_back(std::move(input_timer));
|
||||
}
|
||||
|
||||
void timermanager::updatetimers(double dtime) {
|
||||
void timermanager::updatetimers() {
|
||||
for (auto &mytimer : timers) {
|
||||
auto currenttime = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> myDeltaTime = currenttime - prevtime;
|
||||
double dtime = myDeltaTime.count();
|
||||
mytimer->updatetime(dtime);
|
||||
prevtime = currenttime;
|
||||
mvprintw(12, 0, "updated timer %s", mytimer->name.c_str());
|
||||
}
|
||||
timers.erase(std::remove_if(timers.begin(), timers.end(),
|
||||
@@ -51,6 +55,8 @@ void timermanager::updatetimers(double dtime) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
timermanager::timermanager(): prevtime(std::chrono::steady_clock::now()){}
|
||||
|
||||
swapaction::swapaction(std::vector<int> &input_vector): input_vector(input_vector){}
|
||||
|
||||
void swapaction::update(const timer &input_timer){
|
||||
@@ -62,3 +68,16 @@ void swapaction::update(const timer &input_timer){
|
||||
if(it_i>=input_vector.size() / 2){iscomplete=true;}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printaction::printaction(std::vector<balkjes> &input_vector): input_vector(input_vector) {}
|
||||
|
||||
void printaction::update(const timer &input_timer) {
|
||||
if(!iscomplete) {
|
||||
// for each it_i add a balkje then eventually print it
|
||||
if (it_i>=10) {
|
||||
iscomplete=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user