aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Time/je_timer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-05 07:33:41 +0800
committerchai <chaifix@163.com>2018-11-05 07:33:41 +0800
commit1d1210d7932b287d66e27157701b92df764528cb (patch)
tree0f6ff1178abb3eec2976cfdee80e201283d949b5 /src/libjin/Time/je_timer.h
parent91641bccdf744e0dc29f015fbffc64be46d2ad2c (diff)
+状态机测试代码
Diffstat (limited to 'src/libjin/Time/je_timer.h')
-rw-r--r--src/libjin/Time/je_timer.h73
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