3 * - By John Hodge (thePowersGang)
13 typedef struct sTimer {
15 void (*Callback)(void*);
20 void Timer_CallTimers();
24 Sint64 giTimestamp = 0;
25 Uint64 giPartMiliseconds = 0;
26 tTimer gTimers[NUM_TIMERS];
31 * \brief Return the current timestamp
39 * \fn void Timer_CallTimers()
41 void Timer_CallTimers()
44 void (*callback)(void *);
50 if(gTimers[i].Callback == NULL) continue;
51 if(giTimestamp < gTimers[i].FiresAfter) continue;
52 callback = gTimers[i].Callback;
53 gTimers[i].Callback = NULL;
54 callback(gTimers[i].Argument);
59 * \fn int Time_CreateTimer(int Delta, void *Callback, void *Argument)
61 int Time_CreateTimer(int Delta, void *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);