view src/timer.c @ 10:42ac054c0231

*: huge refactoring dirtools now uses wchar (wayyy overdue) the timer doesn't have a stupid design anymore we don't use windows.h at all now ...
author Paper <paper@paper.us.eu.org>
date Sun, 11 Feb 2024 19:43:31 -0500
parents 07f0e2f43204
children e6a594f16403
line wrap: on
line source

#include "timer.h"

#include <assert.h>

void timer_init(struct timer* restrict timer, UINT interval, TIMERPROC timer_proc) {
	timer->id = 0;
	timer->interval = interval;
	timer->timer_proc = timer_proc;
}

int timer_set(struct timer* restrict timer) {
	assert(!timer->id);

	return !!(timer->id = SetTimer(NULL, timer->id, timer->interval, timer->timer_proc));
}

int timer_stop(struct timer* restrict timer) {
	assert(timer->id);

	BOOL ret = KillTimer(NULL, timer->id);
	timer->id = 0;
	return ret;
}