emscripten: Fixed compiling on C89 compilers.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 26 May 2017 22:45:40 +0200
changeset 11034fcb1f3161d2e
parent 11033 3b8bfd13c61f
child 11035 10552ae634ca
emscripten: Fixed compiling on C89 compilers.
src/audio/emscripten/SDL_emscriptenaudio.c
src/video/emscripten/SDL_emscriptenevents.c
     1.1 --- a/src/audio/emscripten/SDL_emscriptenaudio.c	Thu May 25 23:01:59 2017 +0200
     1.2 +++ b/src/audio/emscripten/SDL_emscriptenaudio.c	Fri May 26 22:45:40 2017 +0200
     1.3 @@ -328,6 +328,9 @@
     1.4  static int
     1.5  EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl * impl)
     1.6  {
     1.7 +    int available;
     1.8 +    int capture_available;
     1.9 +
    1.10      /* Set the function pointers */
    1.11      impl->OpenDevice = EMSCRIPTENAUDIO_OpenDevice;
    1.12      impl->CloseDevice = EMSCRIPTENAUDIO_CloseDevice;
    1.13 @@ -339,7 +342,7 @@
    1.14      impl->ProvidesOwnCallbackThread = 1;
    1.15  
    1.16      /* check availability */
    1.17 -    const int available = EM_ASM_INT_V({
    1.18 +    available = EM_ASM_INT_V({
    1.19          if (typeof(AudioContext) !== 'undefined') {
    1.20              return 1;
    1.21          } else if (typeof(webkitAudioContext) !== 'undefined') {
    1.22 @@ -352,7 +355,7 @@
    1.23          SDL_SetError("No audio context available");
    1.24      }
    1.25  
    1.26 -    const int capture_available = available && EM_ASM_INT_V({
    1.27 +    capture_available = available && EM_ASM_INT_V({
    1.28          if ((typeof(navigator.mediaDevices) !== 'undefined') && (typeof(navigator.mediaDevices.getUserMedia) !== 'undefined')) {
    1.29              return 1;
    1.30          } else if (typeof(navigator.webkitGetUserMedia) !== 'undefined') {
     2.1 --- a/src/video/emscripten/SDL_emscriptenevents.c	Thu May 25 23:01:59 2017 +0200
     2.2 +++ b/src/video/emscripten/SDL_emscriptenevents.c	Fri May 26 22:45:40 2017 +0200
     2.3 @@ -490,6 +490,8 @@
     2.4  Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
     2.5  {
     2.6      Uint32 scancode;
     2.7 +    SDL_bool prevent_default;
     2.8 +    SDL_bool is_nav_key;
     2.9  
    2.10      /* .keyCode is deprecated, but still the most reliable way to get keys */
    2.11      if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
    2.12 @@ -517,17 +519,17 @@
    2.13          }
    2.14      }
    2.15  
    2.16 -    SDL_bool prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
    2.17 +    prevent_default = SDL_GetEventState(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_KEYDOWN : SDL_KEYUP) == SDL_ENABLE;
    2.18  
    2.19      /* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
    2.20       * we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
    2.21       */
    2.22 -    SDL_bool is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
    2.23 -                          keyEvent->keyCode == 9 /* tab */ ||
    2.24 -                          keyEvent->keyCode == 37 /* left */ ||
    2.25 -                          keyEvent->keyCode == 38 /* up */ ||
    2.26 -                          keyEvent->keyCode == 39 /* right */ ||
    2.27 -                          keyEvent->keyCode == 40 /* down */;
    2.28 +    is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
    2.29 +                 keyEvent->keyCode == 9 /* tab */ ||
    2.30 +                 keyEvent->keyCode == 37 /* left */ ||
    2.31 +                 keyEvent->keyCode == 38 /* up */ ||
    2.32 +                 keyEvent->keyCode == 39 /* right */ ||
    2.33 +                 keyEvent->keyCode == 40 /* down */;
    2.34  
    2.35      if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
    2.36          prevent_default = SDL_FALSE;
    2.37 @@ -629,6 +631,8 @@
    2.38  void
    2.39  Emscripten_RegisterEventHandlers(SDL_WindowData *data)
    2.40  {
    2.41 +    const char *keyElement;
    2.42 +
    2.43      /* There is only one window and that window is the canvas */
    2.44      emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
    2.45  
    2.46 @@ -651,7 +655,7 @@
    2.47      emscripten_set_pointerlockchange_callback(NULL, data, 0, Emscripten_HandlePointerLockChange);
    2.48  
    2.49      /* Keyboard events are awkward */
    2.50 -    const char *keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
    2.51 +    keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
    2.52      if (!keyElement) keyElement = "#window";
    2.53  
    2.54      emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
    2.55 @@ -668,6 +672,8 @@
    2.56  void
    2.57  Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
    2.58  {
    2.59 +    const char *target;
    2.60 +
    2.61      /* only works due to having one window */
    2.62      emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
    2.63  
    2.64 @@ -689,7 +695,7 @@
    2.65  
    2.66      emscripten_set_pointerlockchange_callback(NULL, NULL, 0, NULL);
    2.67  
    2.68 -    const char *target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
    2.69 +    target = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
    2.70      if (!target) {
    2.71          target = "#window";
    2.72      }