From 1d1210d7932b287d66e27157701b92df764528cb Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 5 Nov 2018 07:33:41 +0800 Subject: =?UTF-8?q?+=E7=8A=B6=E6=80=81=E6=9C=BA=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Time/je_timer.h | 73 ++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'src/libjin/Time/je_timer.h') diff --git a/src/libjin/Time/je_timer.h b/src/libjin/Time/je_timer.h index b558a55..d0e5513 100644 --- a/src/libjin/Time/je_timer.h +++ b/src/libjin/Time/je_timer.h @@ -14,68 +14,77 @@ namespace JinEngine /// /// /// - class Timers + class Timer { public: - typedef void(*timer_callback)(void* prameters); + + typedef void(*TimerCallback)(void* prameters); /// /// /// - Timers(); + class Handler + { + private: + friend class Timer; + enum Type + { + EVERY, + AFTER, + REPEAT, + }; + Handler(Type type, int duration, int count = 0, TimerCallback callback = nullptr, void* paramters = nullptr); + virtual ~Handler(); + void process(int ms); + + int duration; + int count; + int tickdown; + int countdown; + Type type; + TimerCallback callback; + void* paramters; + bool canceled; + }; /// /// /// - ~Timers(); + Timer(); /// /// /// - void update(int ms); + ~Timer(); /// /// /// - void every(int ms, timer_callback callback, void* paramters); + void update(int ms); /// /// /// - void after(int ms, timer_callback callback, void* paramters); + Handler* every(int ms, TimerCallback callback, void* paramters); /// /// /// - void repeat(int ms, int count, timer_callback callback, void* paramters); + Handler* after(int ms, TimerCallback callback, void* paramters); - private: + /// + /// + /// + Handler* repeat(int ms, int count, TimerCallback callback, void* paramters); /// /// /// - class Timer - { - public: - enum Type - { - EVERY, - AFTER, - REPEAT, - }; - Timer(Type type, int duration, int count = 0, timer_callback callback = nullptr, void* paramters = nullptr); - virtual ~Timer(); - bool process(int ms); - private: - int duration; - int count; - int tickdown; - int countdown; - Type type; - timer_callback callback; - void* paramters; - }; - std::vector timers; + void cancel(Handler* handler = nullptr); + + private: + + std::vector mHandlers; }; @@ -114,4 +123,4 @@ namespace JinEngine #endif // defined(jin_time) -#endif // __JE_TIMER_H__ +#endif // __JE_TIMER_H__ \ No newline at end of file -- cgit v1.1-26-g67d0