timer.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef TIMER_HPP
  2. #define TIMER_HPP
  3. #include <cstddef>
  4. #include <functional>
  5. #include <memory>
  6. #include <ncurses.h>
  7. #include <string>
  8. #include <vector>
  9. class timer {
  10. private:
  11. double accumulator = 0;
  12. int triggeramount = 0;
  13. double time_interval = 1; // only display every 1 seconds
  14. public:
  15. std::string name;
  16. int triggercounter = 0;
  17. bool is_infinite = false;
  18. std::function<void(const timer&)> callbackfunc;
  19. bool is_expired = false;
  20. //infinite timer
  21. timer(std::string name_input, size_t interval_input,
  22. std::function<void(const timer &)> callback_input);
  23. //limited timer
  24. timer(std::string name, size_t interval_input, int triggeramount,
  25. std::function<void(const timer &)> callback);
  26. // callbackfunc once enough time has accumulated
  27. void updatetime(double DeltaTime);
  28. };
  29. // manage collection of timers
  30. class timermanager {
  31. std::vector<std::unique_ptr<timer>> timers;
  32. public:
  33. void addtimer(std::unique_ptr<timer> input_timer);
  34. void updatetimers(double dtime);
  35. };
  36. #endif