Files
exc/cpp/ui/ncurses/hw/timer.hpp
T
lyrgb 37c919df90 interval was being ignored because of type error
size_t interval should've been a double, but was being implicitly
converted, so it worked, compiled. but not like I intended.
2026-07-17 00:41:46 +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, double interval_input,
std::unique_ptr<timeraction> action_input
);
//limited timer
timer(std::string name, double 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
*/