diff options
Diffstat (limited to 'src/libjin/Time/Timer.h')
-rw-r--r-- | src/libjin/Time/Timer.h | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/src/libjin/Time/Timer.h b/src/libjin/Time/Timer.h index 9458215..173cd95 100644 --- a/src/libjin/Time/Timer.h +++ b/src/libjin/Time/Timer.h @@ -4,31 +4,71 @@ #if JIN_MODULES_TIME #include "SDL2/SDL.h" +#include <vector> namespace jin { namespace time { + + class Timers + { + public: + typedef void(*timer_callback)(void* prameters); + + Timers(); + ~Timers(); + + void update(int ms); + + void every(int ms, timer_callback callback, void* paramters); + void after(int ms, timer_callback callback, void* paramters); + void repeat(int ms, int count, timer_callback callback, void* paramters); + private: + 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; + }; + inline void sleep(int ms) { -#if JIN_TIME_SDL + #if JIN_TIME_SDL SDL_Delay(ms); -#endif + #endif } inline double getSecond() { -#if JIN_TIME_SDL + #if JIN_TIME_SDL return SDL_GetTicks() / 1000.f; -#endif + #endif } inline double getMilliSecond() { -#if JIN_TIME_SDL + #if JIN_TIME_SDL return SDL_GetTicks(); -#endif + #endif } } // time |