visualization of bsort, manager now responsible for updates and time

split timeractions from timers into seperate header
integrated the experiments into an improved displaynumbers, which
includes the vector as well as bars above them
outsourced the calculation of delta time to the manager to clean up main()
This commit is contained in:
2026-07-17 00:04:28 +02:00
parent db8fc15560
commit 9dbc24efc1
5 changed files with 120 additions and 63 deletions
+12 -32
View File
@@ -11,14 +11,14 @@
// infinite timer
timer::timer(std::string name_input, size_t interval_input,
std::unique_ptr<timeraction> action_input)
: time_interval(interval_input), name(name_input), is_infinite(true),
action(std::move(action_input)) {}
: time_interval(interval_input), name(name_input), is_infinite(true),
action(std::move(action_input)) {}
// limited timer
timer::timer(std::string name, size_t interval_input, int triggeramount,
std::unique_ptr<timeraction> action_input)
: triggeramount(triggeramount), time_interval(interval_input), name(name),
action(std::move(action_input)) {}
: triggeramount(triggeramount), time_interval(interval_input), name(name),
action(std::move(action_input)) {}
// callbackfunc once enough time has accumulated
void timer::updatetime(double DeltaTime) {
@@ -40,14 +40,18 @@ void timermanager::addtimer(std::unique_ptr<timer> input_timer) {
}
void timermanager::updatetimers() {
//get dtime
auto currenttime = std::chrono::steady_clock::now();
std::chrono::duration<double> myDeltaTime = currenttime - prevtime;
double dtime = myDeltaTime.count();
//update timers with dtime
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());
}
//reset for next tick
prevtime = currenttime;
timers.erase(std::remove_if(timers.begin(), timers.end(),
[](auto &timer) { return timer->is_expired; }),
timers.end());
@@ -56,28 +60,4 @@ void timermanager::updatetimers() {
}
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){
if (!iscomplete) {
int temp = input_vector[it_i];
input_vector[it_i] = input_vector[input_vector.size() -1 - it_i];
input_vector[input_vector.size() - 1 - it_i] = temp;
it_i++;
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;
}
}
}