| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #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();
- };
- class swapaction : public timeraction {
- public:
- size_t it_i = 0;
- bool iscomplete = false;
- std::vector<int> &input_vector;
- swapaction(std::vector<int> &input_vector);
- void update(const timer &t);
- };
- class printaction : public timeraction {
- public:
- size_t it_i = 0;
- bool iscomplete = false;
- std::vector<balkjes> &input_vector;
- printaction(std::vector<balkjes> &input_vector);
- void update(const timer &t);
- };
- #endif
- /*
- externalize state
- */
|