| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #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
- */
|