aboutsummaryrefslogtreecommitdiff
path: root/CruUI/timer.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-18 01:38:02 +0800
committercrupest <crupest@outlook.com>2018-09-18 01:38:02 +0800
commit4710715102df3806479985679bd8048631ccaab5 (patch)
tree0f18f3c1d278aace11521a93abad97c97eb4ae54 /CruUI/timer.h
parent94c066a34900845297c41c134a9a910124a5833d (diff)
downloadcru-4710715102df3806479985679bd8048631ccaab5.tar.gz
cru-4710715102df3806479985679bd8048631ccaab5.tar.bz2
cru-4710715102df3806479985679bd8048631ccaab5.zip
I think I can't sleep well after this commit.
Still a lot of bugs!!!
Diffstat (limited to 'CruUI/timer.h')
-rw-r--r--CruUI/timer.h26
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);
}