breakhack/src/timer.c

40 lines
509 B
C
Raw Normal View History

2017-12-05 08:30:08 +01:00
#include <SDL2/SDL.h>
2017-12-21 11:57:12 +01:00
#include <stdlib.h>
2017-12-05 08:30:08 +01:00
#include "util.h"
#include "timer.h"
Timer* timer_create()
{
Timer *t = ec_malloc(sizeof(Timer));
t->startTime = 0;
return t;
}
void timer_start(Timer *t)
{
t->startTime = SDL_GetTicks();
}
void timer_stop(Timer *t)
{
t->startTime = 0;
}
2017-12-08 14:40:33 +01:00
bool timer_started(Timer *t)
{
return t->startTime != 0;
}
2017-12-05 08:30:08 +01:00
unsigned int timer_get_ticks(Timer *t)
{
if (!t->startTime)
return 0;
return SDL_GetTicks() - t->startTime;
}
void timer_destroy(Timer *t)
{
free(t);
}