-
Notifications
You must be signed in to change notification settings - Fork 64
SDL_AddTimer doesn't work properly #67
Comments
I think that's what the SDL API says, though: that it will be called once? https://wiki.libsdl.org/SDL_AddTimer Or maybe I'm misreading that... For reference emscripten's SDL1 support also just calls it once, but maybe that's wrong too... |
To be honest, setInterval is still not correct. So, I think the correct implementation may be: // Cause I'm new to emscripten, I wrote it in pure js :)
mapping = {};
next_id = 0;
function SDL_AddTimer(interval, callback, param) {
var id = next_id++;
var internal_callback = function(interval) {
var ret = callback(interval, param);
if (ret == 0) {
del mapping[id];
return;
}
mapping[id] = setTimeout(function() { internal_callback(ret) }, ret);
};
mapping[id] = setTimeout(function() { internal_callback(interval) }, interval);
return id;
}
function SDL_RemoveTimer(id) {
if (!(id in mapping))
return false;
clearTimeout(mapping[id]);
del mapping[id];
return true;
} |
09b829b should be it. |
FYI 09b829b broke RenPyWeb. In addition there's no SDL_SetError, so I got an unrelated error which was quite confusing. |
Oops, looks like I need to init |
Or just move two characters... a8a4fde |
This appears to work, thanks a lot! |
SetTimeout only emit the callback once, it should be setInterval.
The text was updated successfully, but these errors were encountered: