annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "timer.h"
1
7abb5d8b20ea Initial commit: part 2
Paper <mrpapersonic@gmail.com>
parents: 0
diff changeset
2
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
3 #include <assert.h>
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
4
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
5 void timer_init(struct timer* restrict timer, UINT interval, TIMERPROC timer_proc) {
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
6 timer->id = 0;
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
7 timer->interval = interval;
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 timer->timer_proc = timer_proc;
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 }
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
11 int timer_set(struct timer* restrict timer) {
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
12 assert(!timer->id);
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
13
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
14 return !!(timer->id = SetTimer(NULL, timer->id, timer->interval, timer->timer_proc));
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 }
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
17 int timer_stop(struct timer* restrict timer) {
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
18 assert(timer->id);
9
07f0e2f43204 *: add the restrict keyword when necessary
Paper
parents: 7
diff changeset
19
10
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
20 BOOL ret = KillTimer(NULL, timer->id);
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
21 timer->id = 0;
42ac054c0231 *: huge refactoring
Paper <paper@paper.us.eu.org>
parents: 9
diff changeset
22 return ret;
0
d91dfd53b8b4 Initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 }