2024-08-04 15:20:11 -05:00
|
|
|
#include "timer.h"
|
2024-08-05 15:26:18 -05:00
|
|
|
#include <stdio.h>
|
2024-08-04 15:20:11 -05:00
|
|
|
#include "stb_ds.h"
|
|
|
|
|
2024-08-05 15:26:18 -05:00
|
|
|
timer **timers;
|
2024-08-04 15:20:11 -05:00
|
|
|
|
|
|
|
timer *timer_make()
|
|
|
|
{
|
2024-08-05 15:26:18 -05:00
|
|
|
timer *t = calloc(sizeof(*t),1);
|
|
|
|
arrput(timers, t);
|
|
|
|
return t;
|
2024-08-04 15:20:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_free(timer *t)
|
|
|
|
{
|
2024-08-05 15:26:18 -05:00
|
|
|
printf("before free arrlen if timers is now %d\n", arrlen(timers));
|
|
|
|
for (int i = 0; i < arrlen(timers); i++) {
|
|
|
|
if (timers[i] == t) {
|
|
|
|
arrdelswap(timers,i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(t);
|
|
|
|
printf("arrlen if timers is now %d\n", arrlen(timers));
|
2024-08-04 15:20:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void timer_update(double dt)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < arrlen(timers); i++) {
|
2024-08-05 15:26:18 -05:00
|
|
|
timers[i]->remain -= dt;
|
2024-08-04 15:20:11 -05:00
|
|
|
}
|
2024-08-05 15:26:18 -05:00
|
|
|
}
|