From 1ffa61c5729aa9412468fc0fe63a52537a948a5e Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 8 Apr 2013 00:29:13 +0000 Subject: [PATCH] input: activate SDL input with Emscripten. --- src/platform/sdl/sdlapp.cpp | 2 -- src/platform/sdl/sdlinput.cpp | 36 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 658069fd..dee374f2 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -101,9 +101,7 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : new D3d9Input(); # endif -# if !defined EMSCRIPTEN new SdlInput(); -# endif #endif } diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index 9e493e58..22fef12e 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -8,12 +8,12 @@ // http://www.wtfpl.net/ for more details. // -#if defined HAVE_CONFIG_H +#if HAVE_CONFIG_H # include "config.h" #endif -#if defined USE_SDL -# if defined HAVE_SDL_SDL_H +#if USE_SDL +# if HAVE_SDL_SDL_H # include # else # include @@ -42,7 +42,7 @@ private: void Tick(float seconds); static ivec2 GetMousePos(); -#if defined USE_SDL +#if USE_SDL Array m_joysticks; #endif }; @@ -54,17 +54,18 @@ private: SdlInput::SdlInput() : m_data(new SdlInputData()) { -#if defined USE_SDL +#if USE_SDL /* Enable Unicode translation of keyboard events */ SDL_EnableUNICODE(1); SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); -# if SDL_FORCE_POLL_JOYSTICK +# if !EMSCRIPTEN +# if SDL_FORCE_POLL_JOYSTICK SDL_JoystickEventState(SDL_QUERY); -# else +# else SDL_JoystickEventState(SDL_ENABLE); -# endif +# endif /* Register all the joysticks we can find, and let the input * system decide what it wants to track. */ @@ -78,9 +79,9 @@ SdlInput::SdlInput() * it won't think there is only one trigger axis. */ char const *name = SDL_JoystickName(i); if (strstr(name, "HDAPS") -# if defined USE_XINPUT +# if USE_XINPUT || strstr(name, "XBOX 360 For Windows") -# endif +# endif || false) { SDL_JoystickClose(sdlstick); @@ -97,6 +98,7 @@ SdlInput::SdlInput() m_data->m_joysticks.Push(sdlstick, stick); } +# endif #endif m_gamegroup = GAMEGROUP_BEFORE; @@ -104,7 +106,7 @@ SdlInput::SdlInput() SdlInput::~SdlInput() { -#if defined USE_SDL +#if USE_SDL && !EMSCRIPTEN /* Unregister all the joysticks we added */ while (m_data->m_joysticks.Count()) { @@ -120,7 +122,7 @@ void SdlInput::TickGame(float seconds) { Entity::TickGame(seconds); -#if !defined _WIN32 +#if !_WIN32 m_data->Tick(seconds); #endif } @@ -129,19 +131,19 @@ void SdlInput::TickDraw(float seconds) { Entity::TickDraw(seconds); -#if defined _WIN32 +#if _WIN32 m_data->Tick(seconds); #endif } void SdlInputData::Tick(float seconds) { -#if defined USE_SDL +#if USE_SDL /* Handle mouse input */ ivec2 mouse = SdlInputData::GetMousePos();; Input::SetMousePos(mouse); -# if SDL_FORCE_POLL_JOYSTICK +# if SDL_FORCE_POLL_JOYSTICK && EMSCRIPTEN /* Pump all joystick events because no event is coming to us. */ SDL_JoystickUpdate(); for (int j = 0; j < m_joysticks.Count(); j++) @@ -210,8 +212,10 @@ ivec2 SdlInputData::GetMousePos() { ivec2 ret(-1, -1); -#if defined USE_SDL +#if USE_SDL +# if !EMSCRIPTEN if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) +# endif { SDL_GetMouseState(&ret.x, &ret.y); ret.y = Video::GetSize().y - 1 - ret.y;