aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Time/Timer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-06 16:22:00 +0800
committerchai <chaifix@163.com>2018-08-06 16:22:00 +0800
commit89e7a9ecfad9a54633eb3ebbab1d1f13ad78826f (patch)
tree1ba8a806af1b8e7750d6b637c296f08e13cf268e /src/libjin/Time/Timer.h
parentea9769944a2db3abe15f537dab67e16fdfc20bef (diff)
*update
Diffstat (limited to 'src/libjin/Time/Timer.h')
-rw-r--r--src/libjin/Time/Timer.h52
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