diff options
Diffstat (limited to 'CruUI/timer.h')
-rw-r--r-- | CruUI/timer.h | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/CruUI/timer.h b/CruUI/timer.h index 1a512a44..70913775 100644 --- a/CruUI/timer.h +++ b/CruUI/timer.h @@ -12,31 +12,29 @@ namespace cru { - using TimerAction = std::function<void()>; - class TimerManager : public Object { - friend class cru::Application; - private: - static TimerManager* instance_; - public: - static TimerManager* GetInstance(); + static TimerManager* GetInstance() + { + return Application::GetInstance()->GetTimerManager(); + } public: - TimerManager(); + TimerManager() = default; TimerManager(const TimerManager& other) = delete; TimerManager(TimerManager&& other) = delete; TimerManager& operator=(const TimerManager& other) = delete; TimerManager& operator=(TimerManager&& other) = delete; - ~TimerManager() override; + ~TimerManager() override = default; - UINT_PTR CreateTimer(UINT microseconds, bool loop, const TimerAction& action); + UINT_PTR CreateTimer(UINT milliseconds, bool loop, std::shared_ptr<Action<>> action); void KillTimer(UINT_PTR id); - std::optional<TimerAction> GetAction(UINT_PTR id); + std::shared_ptr<Action<>> GetAction(UINT_PTR id); private: - std::map<UINT_PTR, TimerAction> map_{}; + std::map<UINT_PTR, std::shared_ptr<Action<>>> map_{}; + UINT_PTR current_count_ = 0; }; struct ITimerTask : virtual Interface @@ -44,6 +42,6 @@ namespace cru virtual void Cancel() = 0; }; - std::shared_ptr<ITimerTask> SetTimeout(double seconds, const TimerAction& action); - std::shared_ptr<ITimerTask> SetInterval(double seconds, const TimerAction& action); + std::shared_ptr<ITimerTask> SetTimeout(double seconds, std::shared_ptr<Action<>> action); + std::shared_ptr<ITimerTask> SetInterval(double seconds, std::shared_ptr<Action<>> action); } |