| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #ifndef TIMER_HPP
- #define TIMER_HPP
- #include <cstddef>
- #include <functional>
- #include <memory>
- #include <ncurses.h>
- #include <string>
- #include <vector>
- class timer;
- 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;
- public:
- void addtimer(std::unique_ptr<timer> input_timer);
- void updatetimers(double dtime);
- };
- 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);
- };
- #endif
- /*
- externalize state
- */
|