emscripten: Fixed compiling on C89 compilers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c
index b772249..ee38e53 100644
--- a/src/audio/emscripten/SDL_emscriptenaudio.c
+++ b/src/audio/emscripten/SDL_emscriptenaudio.c
@@ -328,6 +328,9 @@ EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscaptu
static int
EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
{
+ int available;
+ int capture_available;
+
/* Set the function pointers */
impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
@@ -339,7 +342,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
/* check availability */
- const int available = EM_ASM_INT_V({
+ available = EM_ASM_INT_V({
if (typeof(AudioContext) !== 'undefined') {
return 1;
} else if (typeof(webkitAudioContext) !== 'undefined') {
@@ -352,7 +355,7 @@ EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
SDL_SetError("No audio context available");
}
- const int capture_available = available && EM_ASM_INT_V({
+ capture_available = available && EM_ASM_INT_V({
if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
return 1;
} else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 3fd3616..85f56f4 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -490,6 +490,8 @@ static EM_BOOL
Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
{
Uint32 scancode;
+ SDL_bool prevent_default;
+ SDL_bool is_nav_key;
/* .keyCode is deprecated, but still the most reliable way to get keys */
if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
@@ -517,17 +519,17 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
}
}
- SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
+ prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
* we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
*/
- SDL_bool is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
- keyEvent->keyCode == 9 /* tab */ ||
- keyEvent->keyCode == 37 /* left */ ||
- keyEvent->keyCode == 38 /* up */ ||
- keyEvent->keyCode == 39 /* right */ ||
- keyEvent->keyCode == 40 /* down */;
+ is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
+ keyEvent->keyCode == 9 /* tab */ ||
+ keyEvent->keyCode == 37 /* left */ ||
+ keyEvent->keyCode == 38 /* up */ ||
+ keyEvent->keyCode == 39 /* right */ ||
+ keyEvent->keyCode == 40 /* down */;
if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
prevent_default = SDL_FALSE;
@@ -629,6 +631,8 @@ Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChang
void
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
{
+ const char *keyElement;
+
/* There is only one window and that window is the canvas */
emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
@@ -651,7 +655,7 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
emscripten_set_pointerlockchange_callback(NULL, data, 0, Emscripten_HandlePointerLockChange);
/* Keyboard events are awkward */
- const char *keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+ keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
if (!keyElement) keyElement = "#window";
emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
@@ -668,6 +672,8 @@ Emscripten_RegisterEventHandlers(SDL_WindowData *data)
void
Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
{
+ const char *target;
+
/* only works due to having one window */
emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
@@ -689,7 +695,7 @@ Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
emscripten_set_pointerlockchange_callback(NULL, NULL, 0, NULL);
- const char *target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
+ target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
if (!target) {
target = "#window";
}