| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #ifndef TIMER_HPP
- #define TIMER_HPP
- #include <cstddef>
- #include <functional>
- #include <memory>
- #include <ncurses.h>
- #include <string>
- #include <vector>
- 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::function<void(const timer&)> callbackfunc;
- bool is_expired = false;
- //infinite timer
- timer(std::string name_input, size_t interval_input,
- std::function<void(const timer &)> callback_input);
-
- //limited timer
- timer(std::string name, size_t interval_input, int triggeramount,
- std::function<void(const timer &)> callback);
- // 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);
- };
- #endif
|