Browse Source

emscripten: resume audio context if necessary.

This will probably end up upstream very soon:
    https://github.com/emscripten-ports/SDL2/pull/104
legacy
Sam Hocevar 5 years ago
parent
commit
944923ae6a
1 changed files with 24 additions and 0 deletions
  1. +24
    -0
      src/ui/sdl-input.cpp

+ 24
- 0
src/ui/sdl-input.cpp View File

@@ -19,6 +19,9 @@
# include <SDL.h> # include <SDL.h>
# endif # endif
#endif #endif
#if HAVE_EMSCRIPTEN_H
# include <emscripten.h>
#endif
#if HAVE_EMSCRIPTEN_HTML5_H #if HAVE_EMSCRIPTEN_HTML5_H
# include <emscripten/html5.h> # include <emscripten/html5.h>
#endif #endif
@@ -123,6 +126,18 @@ void SdlInput::tick_draw(float seconds, Scene &scene)
tick(seconds); tick(seconds);
} }


#if __EMSCRIPTEN__
static void resume_audiocontext(void)
{
EM_ASM(
{
var m = Module['SDL2'];
if (m && m.audioContext && m.audioContext.state == 'suspended')
m.audioContext.resume();
});
}
#endif

void SdlInput::tick(float seconds) void SdlInput::tick(float seconds)
{ {
#if LOL_USE_SDL #if LOL_USE_SDL
@@ -201,11 +216,17 @@ void SdlInput::tick(float seconds)


case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
#if __EMSCRIPTEN__
resume_audiocontext();
#endif
//event.button.which //event.button.which
mouse->internal_set_button((input::button)((int)input::button::BTN_Left + event.button.button - 1), mouse->internal_set_button((input::button)((int)input::button::BTN_Left + event.button.button - 1),
event.type == SDL_MOUSEBUTTONDOWN); event.type == SDL_MOUSEBUTTONDOWN);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
#if __EMSCRIPTEN__
resume_audiocontext();
#endif
mouse_wheel += (float)event.button.y; mouse_wheel += (float)event.button.y;
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
@@ -214,6 +235,9 @@ void SdlInput::tick(float seconds)
{ {
case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
#if __EMSCRIPTEN__
resume_audiocontext();
#endif
mouse->internal_set_button(input::button::BTN_Focus, true); mouse->internal_set_button(input::button::BTN_Focus, true);
break; break;
case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_LEAVE:


Loading…
Cancel
Save