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 *);
52 if(gTimers[i].Callback == NULL) continue;
53 if(giTimestamp < gTimers[i].FiresAfter) continue;
54 callback = gTimers[i].Callback; arg = gTimers[i].Argument;
55 gTimers[i].Callback = NULL;
61 * \fn int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
63 int Time_CreateTimer(int Delta, tTimerCallback *Callback, void *Argument)
67 if(Callback == NULL) return -1;
73 if(gTimers[ret].Callback != NULL) continue;
74 gTimers[ret].Callback = Callback;
75 gTimers[ret].FiresAfter = giTimestamp + Delta;
76 gTimers[ret].Argument = Argument;
77 //Log("Callback = %p", Callback);
78 //Log("Timer %i fires at %lli", ret, gTimers[ret].FiresAfter);
85 * \fn void Time_RemoveTimer(int ID)
87 void Time_RemoveTimer(int ID)
89 if(ID < 0 || ID >= NUM_TIMERS) return;
90 gTimers[ID].Callback = NULL;
94 * \fn void Time_Delay(int Delay)
95 * \brief Delay for a small ammount of time
97 void Time_Delay(int Delay)
99 Sint64 dest = giTimestamp + Delay;
100 while(dest < giTimestamp) Threads_Yield();
105 EXPORT(Time_CreateTimer);
106 EXPORT(Time_RemoveTimer);