Improved texture handling

This commit is contained in:
2022-08-25 20:48:15 +00:00
parent 3040dc1f7f
commit ff4168d279
11 changed files with 227 additions and 142 deletions

View File

@@ -1,16 +1,12 @@
#include "timer.h"
#include <GLFW/glfw3.h>
#include <stdlib.h>
#include "vec.h"
#include <stb_ds.h>;
static double time;
struct vec timers;
void timer_init() {
time = glfwGetTime();
timers = vec_init(sizeof(struct timer), 10);
}
struct timer *timers;
void check_timer(struct timer *t)
{
@@ -33,51 +29,60 @@ void check_timer(struct timer *t)
void timer_update(double s) {
time = s;
vec_walk(&timers, check_timer);
for (int i = 0; i < arrlen(timers); i++)
check_timer(&timers[i]);
}
struct timer *timer_make(double interval, void (*callback)(void *param), void *param) {
struct timer *new = calloc(sizeof(*new),1);
struct timer new;
new.remain_time = interval;
new.interval = interval;
new.cb = callback;
new.data = param;
new.repeat = 1;
new.timerid = arrlen(timers);
new->remain_time = interval;
new->interval = interval;
new->cb = callback;
new->data = param;
new->repeat = 1;
timer_start(&new);
arrput(timers, new);
timer_start(new);
struct timer *nn = vec_add(&timers, new);
free(new);
nn->timerid = timers.len-1;
return nn;
return &arrlast(timers);
}
void timer_pause(struct timer *t) {
if (!t->on) return;
t->on = 0;
t->remain_time = t->fire_time - time;
}
void timer_stop(struct timer *t) {
if (!t->on) return;
t->on = 0;
t->remain_time = t->interval;
}
void timer_start(struct timer *t) {
if (t->on) return;
t->on = 1;
t->fire_time = time + t->remain_time;
}
void timer_remove(struct timer *t) {
vec_delete(&timers, t->timerid);
int i = t->timerid;
arrdelswap(timers, i);
timers[i].timerid = i;
}
void timer_settime(struct timer *t, double interval) {
double elapsed = time - (t->fire_time - t->interval);
//double elapsed = time - (t->fire_time - t->interval);
t->interval = interval;
t->remain_time = time + t->interval - elapsed;
t->remain_time = t->interval;
// TODO: timer_settime reacts to elapsed time
}