diff options
author | chai <chaifix@163.com> | 2018-11-16 00:24:51 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-16 00:24:51 +0800 |
commit | 831e814ce9bdb84e86c06c4a52008f6bdaaa00d6 (patch) | |
tree | f91fccc7d2628d6e0a39886134b2bb174f5eede4 /src/libjin/Time/je_timer.h | |
parent | 6dc75930fe5fe02f1af5489917752d315cf9e48f (diff) |
*合并master到minimal分支
Diffstat (limited to 'src/libjin/Time/je_timer.h')
-rw-r--r-- | src/libjin/Time/je_timer.h | 88 |
1 files changed, 54 insertions, 34 deletions
diff --git a/src/libjin/Time/je_timer.h b/src/libjin/Time/je_timer.h index b6b4b9e..31cd322 100644 --- a/src/libjin/Time/je_timer.h +++ b/src/libjin/Time/je_timer.h @@ -1,9 +1,11 @@ -#ifndef __JE_TIMER_H -#define __JE_TIMER_H +#ifndef __JE_TIMER_H__ +#define __JE_TIMER_H__ #include "../core/je_configuration.h" #if defined(jin_time) #include <vector> +#include <functional> + #include "SDL2/SDL.h" namespace JinEngine @@ -14,68 +16,86 @@ namespace JinEngine /// /// /// - class Timers + class Timer { public: - typedef void(*timer_callback)(void* prameters); + + typedef std::function<void(void*)> TimerCallback; + + typedef std::function<void(void*)> FinishCallback; /// /// /// - Timers(); + class Handler + { + public: + friend class Timer; + enum Type + { + EVERY, + AFTER, + REPEAT, + }; + Handler(Type type, float duration, int count = 0, TimerCallback callback = nullptr, void* paramters = nullptr, FinishCallback finishcallback = nullptr); + virtual ~Handler(); + void process(float dt); + + protected: + int count; + int countdown; + float duration; + float tickdown; + Type type; + TimerCallback callback; + FinishCallback finishCallback; + void* paramters; + bool canceled; + }; /// /// /// - ~Timers(); + Timer(); /// /// /// - void update(int ms); + ~Timer(); /// /// /// - void every(int ms, timer_callback callback, void* paramters); + void update(float dt); /// /// /// - void after(int ms, timer_callback callback, void* paramters); + Handler* every(float dt, TimerCallback callback, void* paramters, FinishCallback finish); /// /// /// - void repeat(int ms, int count, timer_callback callback, void* paramters); + Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish); - private: + /// + /// + /// + Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish); /// /// /// - 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<Timer*> timers; + void cancel(Handler* handler); + + /// + /// + /// + void cancelAll(); + + private: + + std::vector<Handler*> mHandlers; }; @@ -114,4 +134,4 @@ namespace JinEngine #endif // defined(jin_time) -#endif // __JE_TIMER_H
\ No newline at end of file +#endif // __JE_TIMER_H__
\ No newline at end of file |