mirror of https://github.com/encounter/SDL.git
emscripten: Remove use of EM_ASM from SDL_timer code.
Instead use the native emscripten timer API. See https://github.com/emscripten-core/emscripten/issues/17941
This commit is contained in:
parent
a97d2e6958
commit
cfab203f91
|
@ -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 \
|
||||
|
|
|
@ -375,11 +375,15 @@ SDL_RemoveTimer(SDL_TimerID id)
|
|||
#else
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/eventloop.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue