From 69ed995437440c8ba93ee22a0ca55e38100189a6 Mon Sep 17 00:00:00 2001 From: Tomoaki Hayasaka Date: Sat, 29 Mar 2014 01:16:44 +0900 Subject: [PATCH] fix "unknown SDL joystick axes mapped to 'pad.X Axis-'" bug. --- SDL/SDLJoystick.cpp | 47 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/SDL/SDLJoystick.cpp b/SDL/SDLJoystick.cpp index 3a8375637..31a3a598b 100644 --- a/SDL/SDLJoystick.cpp +++ b/SDL/SDLJoystick.cpp @@ -48,35 +48,44 @@ void SDLJoystick::ProcessInput(SDL_Event &event){ switch (event.type) { case SDL_JOYAXISMOTION: { - AxisInput axis; - axis.axisId = SDLJoyAxisMap[event.jaxis.axis]; - // 1.2 to try to approximate the PSP's clamped rectangular range. - axis.value = 1.2 * event.jaxis.value / 32767.0f; - if (axis.value > 1.0f) axis.value = 1.0f; - if (axis.value < -1.0f) axis.value = -1.0f; - axis.deviceId = DEVICE_ID_PAD_0; - axis.flags = 0; - NativeAxis(axis); + std::map::const_iterator i = SDLJoyAxisMap.find(event.jaxis.axis); + if (i != SDLJoyAxisMap.end()) { + AxisInput axis; + axis.axisId = i->second; + // 1.2 to try to approximate the PSP's clamped rectangular range. + axis.value = 1.2 * event.jaxis.value / 32767.0f; + if (axis.value > 1.0f) axis.value = 1.0f; + if (axis.value < -1.0f) axis.value = -1.0f; + axis.deviceId = DEVICE_ID_PAD_0; + axis.flags = 0; + NativeAxis(axis); + } break; } case SDL_JOYBUTTONDOWN: { - KeyInput key; - key.flags = KEY_DOWN; - key.keyCode = SDLJoyButtonMap[event.jbutton.button]; - key.deviceId = DEVICE_ID_PAD_0; - NativeKey(key); + std::map::const_iterator i = SDLJoyButtonMap.find(event.jbutton.button); + if (i != SDLJoyButtonMap.end()) { + KeyInput key; + key.flags = KEY_DOWN; + key.keyCode = i->second; + key.deviceId = DEVICE_ID_PAD_0; + NativeKey(key); + } break; } case SDL_JOYBUTTONUP: { - KeyInput key; - key.flags = KEY_UP; - key.keyCode = SDLJoyButtonMap[event.jbutton.button]; - key.deviceId = DEVICE_ID_PAD_0; - NativeKey(key); + std::map::const_iterator i = SDLJoyButtonMap.find(event.jbutton.button); + if (i != SDLJoyButtonMap.end()) { + KeyInput key; + key.flags = KEY_UP; + key.keyCode = i->second; + key.deviceId = DEVICE_ID_PAD_0; + NativeKey(key); + } break; }