00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __MX_TIMERX_H_X
00015 #define __MX_TIMERX_H_X
00016
00017 #include "SDL.h"
00018
00019 namespace mx
00020 {
00021 unsigned int timer_exec(unsigned int val, void *param);
00022 unsigned int timer_execution(unsigned int val, void *param);
00026 class mxTimer_Exec {
00027
00028 public:
00030 virtual ~mxTimer_Exec() { }
00032 mxTimer_Exec() { }
00036 virtual unsigned int timerExecution(unsigned int x) = 0;
00037 };
00039 class mxTimer : public mxTimer_Exec {
00040
00041 public:
00043 mxTimer();
00045 virtual ~mxTimer() { stopTimer(); }
00049 void setTimer(unsigned int interval);
00052 void stopTimer();
00053 protected:
00054 SDL_TimerID tid;
00055
00056 };
00058 template<typename Class>
00059 class mxTimerObject : public mxTimer_Exec {
00060
00061 public:
00066 mxTimerObject(Class *ptr, unsigned int (Class::*timer)(unsigned int mil))
00067 {
00068 ptr = cls;
00069 timer_func = timer;
00070 tid = 0;
00071 }
00072
00076 void setTimer(unsigned int interval);
00078 void stopTimer();
00082 virtual unsigned int timerExecution(unsigned int x);
00083 protected:
00084 Class *cls;
00085 unsigned int (Class::*timer_func)(unsigned int mili);
00086 SDL_TimerID tid;
00087 };
00088
00089 template<typename Class>
00090 void mxTimerObject<Class>::setTimer(unsigned int interval)
00091 {
00092 tid = SDL_AddTimer(interval, timer_execution, (void*)this);
00093 }
00094
00095
00096 template<typename Class>
00097 void mxTimerObject<Class>::stopTimer()
00098 {
00099
00100 SDL_RemoveTimer(tid);
00101 tid = 0;
00102
00103 }
00104
00105 template<typename Class>
00106 unsigned int mxTimerObject<Class>::timerExecution(unsigned int x)
00107 {
00108 return (*cls.*timer_func)(x);
00109 }
00110
00111 }
00112
00113 #endif
00114