aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/time/timer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-11 11:29:07 +0800
committerchai <chaifix@163.com>2020-02-11 11:29:07 +0800
commit160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch)
treeabe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/time/timer.h
parente095043485d1d298571af6d9eca7f0db9009ea7a (diff)
*修改 tab大小HEADmaster
Diffstat (limited to 'src/libjin/time/timer.h')
-rw-r--r--src/libjin/time/timer.h278
1 files changed, 139 insertions, 139 deletions
diff --git a/src/libjin/time/timer.h b/src/libjin/time/timer.h
index 48e51ba..e742112 100644
--- a/src/libjin/time/timer.h
+++ b/src/libjin/time/timer.h
@@ -12,145 +12,145 @@
namespace JinEngine
{
- namespace Time
- {
-
- ///
- ///
- ///
- class Timer : public Object
- {
- public:
-
- typedef std::function<void(void*)> TimerCallback;
-
- typedef std::function<void(void*)> FinishCallback;
-
- ///
- ///
- ///
- class Handler : public Object
- {
- 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;
- };
-
- ///
- ///
- ///
- Timer();
-
- ///
- ///
- ///
- ~Timer();
-
- ///
- ///
- ///
- void update(float dt);
-
- ///
- ///
- ///
- Handler* every(float dt, TimerCallback callback, void* paramters = nullptr, FinishCallback finish = nullptr);
-
- ///
- ///
- ///
- Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
-
- ///
- ///
- ///
- Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish);
-
- ///
- ///
- ///
- void cancel(Handler* handler);
-
- ///
- ///
- ///
- void cancelAll();
-
- private:
-
- std::vector<Handler*> mHandlers;
-
- };
-
- ///
- ///
- ///
- inline void sleep(int ms)
- {
- #if jin_time == jin_time_sdl
- SDL_Delay(ms);
- #endif
- }
-
- ///
- ///
- ///
- inline double getSecond()
- {
- #if jin_time == jin_time_sdl
- return SDL_GetTicks() / 1000.f;
- #endif
- }
-
- ///
- ///
- ///
- inline double getMilliSecond()
- {
- #if jin_time == jin_time_sdl
- return SDL_GetTicks();
- #endif
- }
-
- ///
- /// Delta time between frames.
- ///
- extern float deltaTime;
-
- inline void step()
- {
- static float previous = 0;
- static float current = getSecond();
- previous = current;
- current = getSecond();
- deltaTime = current - previous;
- }
-
- inline float getDeltaTime()
- {
- return deltaTime;
- }
-
- } // namespace Time
+ namespace Time
+ {
+
+ ///
+ ///
+ ///
+ class Timer : public Object
+ {
+ public:
+
+ typedef std::function<void(void*)> TimerCallback;
+
+ typedef std::function<void(void*)> FinishCallback;
+
+ ///
+ ///
+ ///
+ class Handler : public Object
+ {
+ 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;
+ };
+
+ ///
+ ///
+ ///
+ Timer();
+
+ ///
+ ///
+ ///
+ ~Timer();
+
+ ///
+ ///
+ ///
+ void update(float dt);
+
+ ///
+ ///
+ ///
+ Handler* every(float dt, TimerCallback callback, void* paramters = nullptr, FinishCallback finish = nullptr);
+
+ ///
+ ///
+ ///
+ Handler* after(float dt, TimerCallback callback, void* paramters, FinishCallback finish);
+
+ ///
+ ///
+ ///
+ Handler* repeat(float dt, int count, TimerCallback callback, void* paramters, FinishCallback finish);
+
+ ///
+ ///
+ ///
+ void cancel(Handler* handler);
+
+ ///
+ ///
+ ///
+ void cancelAll();
+
+ private:
+
+ std::vector<Handler*> mHandlers;
+
+ };
+
+ ///
+ ///
+ ///
+ inline void sleep(int ms)
+ {
+ #if jin_time == jin_time_sdl
+ SDL_Delay(ms);
+ #endif
+ }
+
+ ///
+ ///
+ ///
+ inline double getSecond()
+ {
+ #if jin_time == jin_time_sdl
+ return SDL_GetTicks() / 1000.f;
+ #endif
+ }
+
+ ///
+ ///
+ ///
+ inline double getMilliSecond()
+ {
+ #if jin_time == jin_time_sdl
+ return SDL_GetTicks();
+ #endif
+ }
+
+ ///
+ /// Delta time between frames.
+ ///
+ extern float deltaTime;
+
+ inline void step()
+ {
+ static float previous = 0;
+ static float current = getSecond();
+ previous = current;
+ current = getSecond();
+ deltaTime = current - previous;
+ }
+
+ inline float getDeltaTime()
+ {
+ return deltaTime;
+ }
+
+ } // namespace Time
} // namespace JinEngine
#endif // defined(jin_time)