From 0529e067f23307fb06a8a4ce14a24977e5f37081 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 2 Aug 2013 15:50:36 +0000 Subject: [PATCH] input: fix a problem with the SDLK_WORLD_0 macro; arrow keys weren't handled properly. --- src/input/inputdevice.cpp | 4 +++- src/platform/sdl/sdlinput.cpp | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/input/inputdevice.cpp b/src/input/inputdevice.cpp index b944e526..fbabd6b7 100644 --- a/src/input/inputdevice.cpp +++ b/src/input/inputdevice.cpp @@ -45,7 +45,9 @@ void InputDeviceInternal::AddCursor(const char* name) InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard() { InputDeviceInternal* keyboard = new InputDeviceInternal("Keyboard"); -# define KEY_FUNC(key, value) keyboard->AddKey(#key); + /* "value" is unused, what matters is the index. */ +# define KEY_FUNC(key, value) \ + keyboard->AddKey(#key); # include "input/keys.h" # undef KEY_FUNC return keyboard; diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index d88f17dd..c7bdc114 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -61,6 +61,7 @@ private: Array m_joysticks; InputDeviceInternal* m_mouse; InputDeviceInternal* m_keyboard; + ivec2 m_prevmouse; float m_app_w; float m_app_h; @@ -126,10 +127,10 @@ SdlInput::SdlInput() # ifdef LOL_INPUT_V2 InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C()); - for (int i = 0; i < SDL_JoystickNumAxes(sdlstick); ++i) - stick->AddAxis(String::Printf("Axis%d", i+1).C()); - for (int i = 0; i < SDL_JoystickNumButtons(sdlstick); ++i) - stick->AddKey(String::Printf("Button%d", i+1).C()); + for (int j = 0; j < SDL_JoystickNumAxes(sdlstick); ++j) + stick->AddAxis(String::Printf("Axis%d", j + 1).C()); + for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) + stick->AddKey(String::Printf("Button%d", j + 1).C()); m_data->m_joysticks.Push(sdlstick, stick); # else // !LOL_INPUT_V2 @@ -290,7 +291,7 @@ void SdlInputData::Tick(float seconds) # else // !LOL_INPUT_V2 Input::SetMousePos(mouse); -# endif // LOL_INPUT_V2 +# endif // LOL_INPUT_V2 # if SDL_VERSION_ATLEAST(1,3,0) Uint8 *sdlstate = SDL_GetKeyboardState(nullptr); @@ -299,14 +300,14 @@ void SdlInputData::Tick(float seconds) # endif int keyindex = 0; -# ifdef LOL_INPUT_V2 -# define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0); -# if !defined SDLK_WORLD_0 -# define KEY_DISABLE_WORLD -# endif // !SDLK_WORLD_0 -# include "input/keys.h" -# undef KEY_FUNC -# else // !LOL_INPUT_V2 +# ifdef LOL_INPUT_V2 +# define KEY_FUNC(name, index) \ + m_keyboard->SetKey(keyindex++, sdlstate[index] != 0); + /* FIXME: we ignore SDLK_WORLD_0, which means our list of + * keys and SDL's list of keys could be out of sync. */ +# include "input/keys.h" +# undef KEY_FUNC +# else // !LOL_INPUT_V2 /* Send the whole keyboard state to the input system */ Array &lolstate = Input::GetKeyboardState();