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
+23 -12
View File
@@ -1,4 +1,5 @@
#include "timer.hpp"
#include "timeractions.hpp"
#include <chrono>
#include <clocale>
#include <cstdio>
@@ -24,16 +25,18 @@ void myupdatedisplay(const timer &timer_input) {
"test: █");
}
void createbalk(const timer &timer_input, cchar_t &input_char) {
int ticnt = timer_input.triggercounter;
mvwvline_set(stdscr, LINES - ticnt, ticnt, &input_char, ticnt);
}
std::vector<int> mynumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<int> myothernumbers = {1, 4, 9, 8, 6, 2, 3, 5, 7};
void displaynumbers(int myy, std::vector<int> &input_numbers) {
void displaynumbers(int startx, int starty, std::vector<int> &input_numbers, cchar_t &input_char) {
for (size_t i = 0; i < input_numbers.size(); i++) {
mvprintw(myy, 10 + i, "%d,", input_numbers[i]);
/**
I make a horizontal line of i chars, which are supposed to represent mynumbers
above that, I want a line of bars.
_all_ bars stretch from LINES-1 to LINES-1-numbervalue
**/
mvprintw(LINES -1 - starty, i + startx, "%d,", input_numbers[i]);
mvwvline_set(stdscr, LINES-1-input_numbers[i]-starty, i+startx, &input_char, input_numbers[i]);
}
}
@@ -53,20 +56,28 @@ void myinitialize() {
int main() {
myinitialize();
cchar_t my_c_char = {.attr= A_NORMAL, .chars={L''}, .ext_color = 0};
//create actions, then put them in timers, then put them into the timermanager
auto myaction = std::make_unique<swapaction>(mynumbers);
auto clocktimer = std::make_unique<timer>("secondsprinter", 1, 10, std::move(myaction));
auto clocktimer =
std::make_unique<timer>("secondsprinter", 1, 10, std::move(myaction));
auto myothersort = std::make_unique<sortaction>(myothernumbers);
auto sorttimer =
std::make_unique<timer>("sorttimer", 0.1, std::move(myothersort));
timermanager mytimermanager;
mytimermanager.addtimer(std::move(clocktimer));
displaynumbers(2, mynumbers);
// calculate delta between current and previous time
mytimermanager.addtimer(std::move(sorttimer));
while (true) {
erase();
mytimermanager.updatetimers();
displaynumbers(3, mynumbers);
displaynumbers(0,0,mynumbers, my_c_char);
displaynumbers(10, 10, myothernumbers, my_c_char);
refresh();
std::this_thread::sleep_for(std::chrono::milliseconds(500));