diff --git a/.github/workflows/emscripten.yml b/.github/workflows/emscripten.yml index 06aee9e3a..3e8647c41 100644 --- a/.github/workflows/emscripten.yml +++ b/.github/workflows/emscripten.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/checkout@v2 - uses: mymindstorm/setup-emsdk@v10 with: - version: 2.0.31 + version: 2.0.32 - name: Configure CMake run: | emcmake cmake -S . -B build \ diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 7b7692df0..6741e97cb 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -375,11 +375,15 @@ SDL_RemoveTimer(SDL_TimerID id) #else #include +#include typedef struct _SDL_TimerMap { int timerID; int timeoutID; + Uint32 interval; + SDL_TimerCallback callback; + void *param; struct _SDL_TimerMap *next; } SDL_TimerMap; @@ -391,18 +395,14 @@ typedef struct { static SDL_TimerData SDL_timer_data; static void -SDL_Emscripten_TimerHelper(SDL_TimerMap *entry, Uint32 interval, SDL_TimerCallback callback, void *param) +SDL_Emscripten_TimerHelper(void *userdata) { - Uint32 new_timeout; - - new_timeout = callback(interval, param); - - if (new_timeout != 0) { - entry->timeoutID = EM_ASM_INT({ - return Browser.safeSetTimeout(function() { - dynCall('viiii', $0, [$1, $2, $3, $4]); - }, $2); - }, &SDL_Emscripten_TimerHelper, entry, interval, callback, param); + SDL_TimerMap *entry = (SDL_TimerMap*)userdata; + entry->interval = entry->callback(entry->interval, entry->param); + if (entry->interval > 0) { + entry->timeoutID = emscripten_set_timeout(&SDL_Emscripten_TimerHelper, + entry->interval, + entry); } } @@ -437,12 +437,13 @@ SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param) return 0; } entry->timerID = ++data->nextID; + entry->callback = callback; + entry->param = param; + entry->interval = interval; - entry->timeoutID = EM_ASM_INT({ - return Browser.safeSetTimeout(function() { - dynCall('viiii', $0, [$1, $2, $3, $4]); - }, $2); - }, &SDL_Emscripten_TimerHelper, entry, interval, callback, param); + entry->timeoutID = emscripten_set_timeout(&SDL_Emscripten_TimerHelper, + entry->interval, + entry); entry->next = data->timermap; data->timermap = entry; @@ -470,9 +471,7 @@ SDL_RemoveTimer(SDL_TimerID id) } if (entry) { - EM_ASM_({ - window.clearTimeout($0); - }, entry->timeoutID); + emscripten_clear_timeout(entry->timeoutID); SDL_free(entry); return SDL_TRUE;