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]; // TODO: Replace by a ring-list timer
32 * \brief Return the current timestamp
40 * \fn void Timer_CallTimers()
42 void Timer_CallTimers()
45 void (*callback)(void *);
48 for(i = 0; i < NUM_TIMERS; i ++)
50 if(gTimers[i].Callback == NULL) continue;
51 if(giTimestamp < gTimers[i].FiresAfter) continue;
52 callback = gTimers[i].Callback; arg = gTimers[i].Argument;
53 gTimers[i].Callback = NULL;
59 * \fn int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
61 int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
65 if(Callback == NULL) return -1;
71 if(gTimers[ret].Callback != NULL) continue;
72 gTimers[ret].Callback = Callback;
73 gTimers[ret].FiresAfter = giTimestamp + Delta;
74 gTimers[ret].Argument = Argument;
75 //Log("Callback = %p", Callback);
76 //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter);
83 * \fn void Time_RemoveTimer(int ID)
85 void Time_RemoveTimer(int ID)
87 if(ID < 0 || ID >= NUM_TIMERS) return;
88 gTimers[ID].Callback = NULL;
92 * \fn void Time_Delay(int Delay)
93 * \brief Delay for a small ammount of time
95 void Time_Delay(int Delay)
97 Sint64 dest = giTimestamp + Delay;
98 while(dest > giTimestamp) Threads_Yield();
103 EXPORT(Time_CreateTimer);
104 EXPORT(Time_RemoveTimer);