diff options
Diffstat (limited to 'src/libjin/Time/je_timer.h')
-rw-r--r-- | src/libjin/Time/je_timer.h | 73 |
1 files changed, 41 insertions, 32 deletions
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<Timer*> timers; + void cancel(Handler* handler = nullptr); + + private: + + std::vector<Handler*> 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 |