Mercurial > wgsdk
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 9:07f0e2f43204 | 10:42ac054c0231 | 
|---|---|
| 1 #include <assert.h> | |
| 2 #ifndef WIN32_LEAN_AND_MEAN | |
| 3 # define WIN32_LEAN_AND_MEAN | |
| 4 #endif | |
| 5 #include <windows.h> | |
| 6 #include "timer.h" | 1 #include "timer.h" | 
| 7 | 2 | 
| 8 void timer_init(struct timer* restrict timer, HWND winampClientWindow, TIMERPROC timer_proc) { | 3 #include <assert.h> | 
| 9 timer->winampClientWindow = winampClientWindow; | 4 | 
| 5 void timer_init(struct timer* restrict timer, UINT interval, TIMERPROC timer_proc) { | |
| 6 timer->id = 0; | |
| 7 timer->interval = interval; | |
| 10 timer->timer_proc = timer_proc; | 8 timer->timer_proc = timer_proc; | 
| 11 timer->initialized = 1; | |
| 12 } | 9 } | 
| 13 | 10 | 
| 14 void timer_set(struct timer* restrict timer, HWND winampClientWindow) { | 11 int timer_set(struct timer* restrict timer) { | 
| 15 assert(timer->initialized); | 12 assert(!timer->id); | 
| 16 | 13 | 
| 17 if (timer->is_timer_alive) | 14 return !!(timer->id = SetTimer(NULL, timer->id, timer->interval, timer->timer_proc)); | 
| 18 return; | |
| 19 | |
| 20 timer->is_timer_alive = 1; | |
| 21 SetTimer(winampClientWindow, 1, timer->interval, timer->timer_proc); | |
| 22 } | 15 } | 
| 23 | 16 | 
| 24 void timer_stop(struct timer* restrict timer, HWND winampClientWindow) { | 17 int timer_stop(struct timer* restrict timer) { | 
| 25 assert(timer->initialized); | 18 assert(timer->id); | 
| 26 | 19 | 
| 27 if (!timer->is_timer_alive) | 20 BOOL ret = KillTimer(NULL, timer->id); | 
| 28 return; | 21 timer->id = 0; | 
| 29 | 22 return ret; | 
| 30 timer->is_timer_alive = 0; | |
| 31 KillTimer(winampClientWindow, 1); | |
| 32 } | 23 } | 
