From 6346188a643df6d3a659250d9d363088ac0f2b4a Mon Sep 17 00:00:00 2001 From: auria Date: Wed, 13 Apr 2011 01:47:06 +0000 Subject: [PATCH] Hat support is now believed to be there git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8323 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/config/device_config.cpp | 7 +- src/guiengine/event_handler.cpp | 67 ++++++++++++++++++++ src/input/binding.cpp | 25 +++++--- src/input/device_manager.cpp | 2 +- src/input/input.hpp | 5 +- src/input/input_device.cpp | 2 +- src/input/input_manager.cpp | 35 +++++----- src/states_screens/options_screen_input2.cpp | 7 +- 8 files changed, 112 insertions(+), 38 deletions(-) diff --git a/src/config/device_config.cpp b/src/config/device_config.cpp index ef2a89028..0fb1cef9c 100644 --- a/src/config/device_config.cpp +++ b/src/config/device_config.cpp @@ -65,12 +65,7 @@ irr::core::stringw DeviceConfig::getMappingIdString (const PlayerAction action) returnString += "stkbt_"; returnString += id; break; - - case Input::IT_STICKHAT: - returnString += "stkht_"; - returnString += id; - break; - + case Input::IT_MOUSEMOTION: returnString += "mousemo_"; returnString += id; diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index f50e8a7f3..5fba6cebb 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -48,6 +48,73 @@ EventHandler::~EventHandler() bool EventHandler::OnEvent (const SEvent &event) { + // TO DEBUG HATS (when you don't actually have a hat) + /* + if (event.EventType == EET_KEY_INPUT_EVENT) + { + if (event.KeyInput.Key == 'W') + { + printf("Sending hat up event %i\n", event.KeyInput.PressedDown); + SEvent evt2; + evt2.EventType = EET_JOYSTICK_INPUT_EVENT; + for (int n=0; n= m_axis_count) return false; // this gamepad doesn't even have that many axes + if (id >= m_axis_count && id != Input::HAT_H_ID && id != Input::HAT_V_ID) return false; // this gamepad doesn't even have that many axes if (player != NULL) { diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 2f88843da..d6f23cdfe 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -331,17 +331,6 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int button, break; } - case Input::IT_STICKHAT: - if (value > Input::MAX_VALUE/2) - { - Input sensed_input; - sensed_input.m_type = Input::IT_STICKHAT; - sensed_input.m_device_id = deviceID; - sensed_input.m_button_id = button; - sensed_input.m_character = deviceID; - OptionsScreenInput2::getInstance()->gotSensedInput(sensed_input); - break; - } case Input::IT_NONE: case Input::IT_MOUSEMOTION: case Input::IT_MOUSEBUTTON: @@ -525,8 +514,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int button // early menus where we accept every input because players are not set-up yet if (m_master_player_only && player == NULL) { - if (type == Input::IT_STICKMOTION || type == Input::IT_STICKBUTTON || - type == Input::IT_STICKHAT) + if (type == Input::IT_STICKMOTION || type == Input::IT_STICKBUTTON) { GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(deviceID); @@ -621,9 +609,26 @@ EventPropagation InputManager::input(const SEvent& event) event.JoystickEvent.Joystick, axis_id, value); } - dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, axis_id, Input::AD_NEUTRAL, value); + dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, axis_id, + Input::AD_NEUTRAL, value); } - + + if (event.JoystickEvent.POV == 65535) + { + dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, Input::HAT_H_ID, Input::AD_NEUTRAL, + 0); + dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, Input::HAT_V_ID, Input::AD_NEUTRAL, + 0); + } + else + { + // *0.017453925f is to convert degrees to radians + dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, Input::HAT_H_ID, Input::AD_NEUTRAL, + cos(event.JoystickEvent.POV*0.017453925f/100.0f)*Input::MAX_VALUE); + dispatchInput(Input::IT_STICKMOTION, event.JoystickEvent.Joystick, Input::HAT_V_ID, Input::AD_NEUTRAL, + sin(event.JoystickEvent.POV*0.017453925f/100.0f)*Input::MAX_VALUE); + } + GamePadDevice* gp = getDeviceList()->getGamePadFromIrrID(event.JoystickEvent.Joystick); if (gp == NULL) diff --git a/src/states_screens/options_screen_input2.cpp b/src/states_screens/options_screen_input2.cpp index 18813dcd2..c131c5b74 100644 --- a/src/states_screens/options_screen_input2.cpp +++ b/src/states_screens/options_screen_input2.cpp @@ -292,8 +292,7 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input) const bool keyboard = (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD && sensed_input.m_type == Input::IT_KEYBOARD); const bool gamepad = (sensed_input.m_type == Input::IT_STICKMOTION || - sensed_input.m_type == Input::IT_STICKBUTTON || - sensed_input.m_type == Input::IT_STICKHAT) && + sensed_input.m_type == Input::IT_STICKBUTTON) && m_config->getType() == DEVICE_CONFIG_TYPE_GAMEPAD; if (keyboard) @@ -332,10 +331,6 @@ void OptionsScreenInput2::gotSensedInput(const Input& sensed_input) { std::cout << "button " << sensed_input.m_button_id<< "\n\n"; } - else if (sensed_input.m_type == Input::IT_STICKHAT) - { - std::cout << "Hat " << sensed_input.m_button_id << "\n\n"; - } else { std::cout << "Sensed unknown gamepad event type??\n";