21 #ifndef GRT_TIMER_HEADER
22 #define GRT_TIMER_HEADER
24 #include "GRTVersionInfo.h"
25 #include "GRTTypedefs.h"
28 #if defined(__GRT_WINDOWS_BUILD__)
33 #if defined(__GRT_OSX_BUILD__)
37 #if defined(__GRT_LINUX_BUILD__)
49 timerMode = NORMAL_MODE;
50 timerState = NOT_RUNNING;
67 timerMode = NORMAL_MODE;
81 bool start(
unsigned long countDownTime,
unsigned long prepTime = 0){
82 if( countDownTime > 0 ){
85 this->countDownTime = countDownTime;
86 this->prepTime = prepTime;
87 timerMode = COUNTDOWN_MODE;
90 timerState = PREP_STATE;
92 timerState = COUNTDOWN_STATE;
106 timerRunning =
false;
107 timerState = NOT_RUNNING;
118 if( !timerRunning )
return 0;
124 return (now-startTime);
127 if( timerState == PREP_STATE ){
128 if( now-startTime >= prepTime ){
129 timerState = COUNTDOWN_STATE;
131 return countDownTime;
133 return countDownTime;
135 if( timerState == COUNTDOWN_STATE )
return (countDownTime - (now-startTime));
154 if( !timerRunning )
return 0;
191 bool getInPrepState()
const {
192 return timerState == PREP_STATE;
195 bool getInCountdownState()
const {
196 return timerState == COUNTDOWN_STATE;
212 #ifdef __GRT_OSX_BUILD__
214 gettimeofday( &now, NULL );
215 return now.tv_usec/1000 + now.tv_sec*1000;
217 #ifdef __GRT_WINDOWS_BUILD__
218 SYSTEMTIME systemTime;
219 GetSystemTime(&systemTime);
220 return (systemTime.wHour*60*60*1000) + (systemTime.wMinute*60*1000) + (systemTime.wSecond*1000) + systemTime.wMilliseconds;
222 #ifdef __GRT_LINUX_BUILD__
224 gettimeofday( &now, NULL );
225 return now.tv_usec/1000 + now.tv_sec*1000;
231 enum TimerMode {NORMAL_MODE=0,COUNTDOWN_MODE};
232 enum TimerState {NOT_RUNNING=0,RUNNING,COUNTDOWN_STATE,PREP_STATE};
234 unsigned long startTime;
235 unsigned long countDownTime;
236 unsigned long prepTime;
239 TimerState timerState;
245 #endif //GRT_TIMER_HEADER
signed long getMilliSeconds()
static unsigned long getSystemTime()
bool start(unsigned long countDownTime, unsigned long prepTime=0)