refactored into class, some cleanup

This commit is contained in:
2026-07-07 02:12:41 +02:00
parent 69a943371c
commit 76c7281b84
+13 -56
View File
@@ -27,48 +27,6 @@
centralize into event sender and subscriber
*/
struct printhelloswithupdate {
int numofhellos = 0;
int maxhellos = 10;
int xloc = 8;
int yloc = 8;
void updatehello() {
if (numofhellos < maxhellos) {
mvprintw(xloc, yloc, "hello: %d", numofhellos);
numofhellos++, xloc++, yloc++;
}
}
};
struct updater {
};
struct secondsdisplay {
double accumulator = 0;
size_t interval = 2;//only display every 2 seconds
int currenttime = 10;
int minutex = 5;
int minutey = 5;
void updatedisplay() {
printf("time: %d\n", currenttime);
// mvprintw(minutex, minutey, "time: %d", currenttime);
// refresh();
}
void updatetime(double DeltaTime) {
accumulator += DeltaTime;
if (accumulator >= interval) {
currenttime -= 1;
accumulator = 0;
updatedisplay();
}
if (currenttime < 1) {
currenttime = 10;
}
}
};
struct mysecondsdisplay {
int currenttime = 10;
void myupdatedisplay() {
@@ -80,10 +38,13 @@ struct mysecondsdisplay {
}
};
struct timer {
//calls callbackfunc on specified interval based on accumulated deltatime
class timer {
public:
std::function<void()> callbackfunc;
double accumulator = 0;
size_t interval = 2; // only display every 2 seconds
timer(size_t interval_input): interval(interval_input){}
void updatetime(double DeltaTime) {
accumulator += DeltaTime;
@@ -93,8 +54,11 @@ struct timer {
accumulator = 0;
callbackfunc();
}
}
private:
double accumulator = 0;
size_t interval = 1; // only display every 1 seconds
};
int main() {
@@ -104,22 +68,15 @@ int main() {
// printw("Hello curses");
// refresh();
printf("verification\n");
std::cout << "couttest\n";
//secondsdisplay mymindisp = {};
printhelloswithupdate myhelloprinter = {};
auto starttime =
std::chrono::system_clock::now();
timer clocktimer = {};
auto starttime = std::chrono::system_clock::now();
timer clocktimer(1);
mysecondsdisplay secdisp;
clocktimer.callbackfunc = [&]() { secdisp.myupdatedisplay(); };
while (true) {
auto currenttime =
std::chrono::system_clock::now();
auto currenttime = std::chrono::system_clock::now();
std::chrono::duration<double> myDeltaTime = currenttime - starttime;
double DoubleDeltaTime = myDeltaTime.count();
clocktimer.updatetime(DoubleDeltaTime);
//mymindisp.updatetime(DoubleDeltaTime);
myhelloprinter.updatehello();
printf("deltatime:%f\n", DoubleDeltaTime);
starttime = currenttime;
std::this_thread::sleep_for(std::chrono::milliseconds(250));