Files
exc/cpp/ui/ncurses/hw/timer.hpp
T
lyrgb 9dbc24efc1 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()
2026-07-17 00:04:28 +02:00

71 lines
1.3 KiB
C++

#ifndef TIMER_HPP
#define TIMER_HPP
#include <chrono>
#include <cstddef>
#include <functional>
#include <memory>
#include <ncurses.h>
#include <string>
#include <vector>
class timer;
struct balkjes {
int startx;
int starty;
int yhight;
};
class timeraction {
public:
virtual ~timeraction() = default;
virtual void update(const timer &t) = 0;
};
class timer {
private:
double accumulator = 0;
int triggeramount = 0;
double time_interval = 1; // only display every 1 seconds
public:
std::string name;
int triggercounter = 0;
bool is_infinite = false;
std::unique_ptr<timeraction> action;
bool is_expired = false;
//infinite timer
timer(std::string name_input, size_t interval_input,
std::unique_ptr<timeraction> action_input
);
//limited timer
timer(std::string name, size_t interval_input, int triggeramount,
std::unique_ptr<timeraction> action
);
// callbackfunc once enough time has accumulated
void updatetime(double DeltaTime);
};
// manage collection of timers
class timermanager {
std::vector<std::unique_ptr<timer>> timers;
std::chrono::steady_clock::time_point prevtime; // initial starttime
public:
timermanager();
void addtimer(std::unique_ptr<timer> input_timer);
void updatetimers();
};
#endif
/*
externalize state
*/