3 * - By John Hodge (thePowersGang)
13 typedef struct sTimer {
15 void (*Callback)(void*);
20 void Timer_CallTimers(void);
23 volatile Uint64 giTicks = 0;
24 volatile Sint64 giTimestamp = 0;
25 volatile Uint64 giPartMiliseconds = 0;
26 tTimer gTimers[NUM_TIMERS]; // TODO: Replace by a ring-list timer
30 * \fn void Timer_CallTimers()
32 void Timer_CallTimers()
35 void (*callback)(void *);
38 for(i = 0; i < NUM_TIMERS; i ++)
40 if(gTimers[i].Callback == NULL) continue;
41 if(giTimestamp < gTimers[i].FiresAfter) continue;
42 callback = gTimers[i].Callback; arg = gTimers[i].Argument;
43 gTimers[i].Callback = NULL;
49 * \fn int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
51 int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
55 if(Callback == NULL) return -1;
61 if(gTimers[ret].Callback != NULL) continue;
62 gTimers[ret].Callback = Callback;
63 gTimers[ret].FiresAfter = giTimestamp + Delta;
64 gTimers[ret].Argument = Argument;
65 //Log("Callback = %p", Callback);
66 //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter);
73 * \fn void Time_RemoveTimer(int ID)
75 void Time_RemoveTimer(int ID)
77 if(ID < 0 || ID >= NUM_TIMERS) return;
78 gTimers[ID].Callback = NULL;
82 * \fn void Time_Delay(int Delay)
83 * \brief Delay for a small ammount of time
85 void Time_Delay(int Delay)
87 Sint64 dest = now() + Delay;
88 //Log("Time_Delay: dest = %lli", dest);
89 while(dest > now()) Threads_Yield();
90 //Log("Time_Delay: giTimestamp = %lli", giTimestamp);
94 EXPORT(Time_CreateTimer);
95 EXPORT(Time_RemoveTimer);