3 * - By John Hodge (thePowersGang)
13 typedef struct sTimer {
15 void (*Callback)(void*);
21 void Timer_CallTimers(void);
25 Sint64 giTimestamp = 0;
26 Uint64 giPartMiliseconds = 0;
27 tTimer gTimers[NUM_TIMERS];
32 * \brief Return the current timestamp
40 * \fn void Timer_CallTimers()
42 void Timer_CallTimers()
45 void (*callback)(void *);
51 if(gTimers[i].Callback == NULL) continue;
52 if(giTimestamp < gTimers[i].FiresAfter) continue;
53 callback = gTimers[i].Callback;
54 gTimers[i].Callback = NULL;
55 callback(gTimers[i].Argument);
60 * \fn int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
62 int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
66 if(Callback == NULL) return -1;
72 if(gTimers[ret].Callback != NULL) continue;
73 gTimers[ret].Callback = Callback;
74 gTimers[ret].FiresAfter = giTimestamp + Delta;
75 gTimers[ret].Argument = Argument;
76 //Log("Callback = %p", Callback);
77 //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter);
84 * \fn void Time_RemoveTimer(int ID)
86 void Time_RemoveTimer(int ID)
88 if(ID < 0 || ID >= NUM_TIMERS) return;
89 gTimers[ID].Callback = NULL;
93 * \fn void Time_Delay(int Delay)
94 * \brief Delay for a small ammount of time
96 void Time_Delay(int Delay)
98 Sint64 dest = giTimestamp + Delay;
99 while(dest < giTimestamp) Threads_Yield();
104 EXPORT(Time_CreateTimer);
105 EXPORT(Time_RemoveTimer);