prosperon/source/engine/timer.c

32 lines
451 B
C
Raw Permalink Normal View History

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
for (int i = 0; i < arrlen(timers); i++) {
if (timers[i] == t) {
arrdelswap(timers,i);
break;
}
}
free(t);
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
}