timer.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef TIMER_HPP
  2. #define TIMER_HPP
  3. #include <chrono>
  4. #include <cstddef>
  5. #include <functional>
  6. #include <memory>
  7. #include <ncurses.h>
  8. #include <string>
  9. #include <vector>
  10. class timer;
  11. struct balkjes {
  12. int startx;
  13. int starty;
  14. int yhight;
  15. };
  16. class timeraction {
  17. public:
  18. virtual ~timeraction() = default;
  19. virtual void update(const timer &t) = 0;
  20. };
  21. class timer {
  22. private:
  23. double accumulator = 0;
  24. int triggeramount = 0;
  25. double time_interval = 1; // only display every 1 seconds
  26. public:
  27. std::string name;
  28. int triggercounter = 0;
  29. bool is_infinite = false;
  30. std::unique_ptr<timeraction> action;
  31. bool is_expired = false;
  32. //infinite timer
  33. timer(std::string name_input, double interval_input,
  34. std::unique_ptr<timeraction> action_input
  35. );
  36. //limited timer
  37. timer(std::string name, double interval_input, int triggeramount,
  38. std::unique_ptr<timeraction> action
  39. );
  40. // callbackfunc once enough time has accumulated
  41. void updatetime(double DeltaTime);
  42. };
  43. // manage collection of timers
  44. class timermanager {
  45. std::vector<std::unique_ptr<timer>> timers;
  46. std::chrono::steady_clock::time_point prevtime; // initial starttime
  47. public:
  48. timermanager();
  49. void addtimer(std::unique_ptr<timer> input_timer);
  50. void updatetimers();
  51. };
  52. #endif
  53. /*
  54. externalize state
  55. */