From b8f2ef6c16a4b1c363060f608089adee86dd7e4a Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 28 Jun 2009 23:24:58 +0000 Subject: [PATCH] Some cleanup in input sensing code + fixed a totally stupid bug git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3671 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/gui/options_screen.cpp | 17 ++++-- src/input/input_device.cpp | 2 +- src/input/input_manager.cpp | 114 +++++++++++++++++------------------- src/input/input_manager.hpp | 2 +- 4 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/gui/options_screen.cpp b/src/gui/options_screen.cpp index 586123acd..10edd3047 100644 --- a/src/gui/options_screen.cpp +++ b/src/gui/options_screen.cpp @@ -411,7 +411,7 @@ namespace StateManager RibbonGridWidget* devices = getCurrentScreen()->getWidget("devices"); assert( devices != NULL ); - std::cout << "-------\nentering sensing mode for " << devices->getSelectionIDString().c_str() << std::endl; + std::cout << "\n% Entering sensing mode for " << devices->getSelectionIDString().c_str() << std::endl; new PressAKeyDialog(0.4f, 0.4f); @@ -455,7 +455,7 @@ namespace StateManager if(keyboard) { - std::cout << "received some keyboard input\n"; + std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to keyboard key " << sensedInput->btnID << " \n\n"; KeyboardDevice* keyboard = input_manager->getDeviceList()->getKeyboard(0); keyboard->editBinding(binding_to_set, sensedInput->btnID); @@ -465,13 +465,18 @@ namespace StateManager } else if(gamepad) { - std::cout << "received some gamepad input on device " << sensedInput->deviceID << " : "; + std::cout << "% Binding " << KartActionStrings[binding_to_set] << " : setting to gamepad #" << sensedInput->deviceID << " : "; if(sensedInput->type == Input::IT_STICKMOTION) - std::cout << "axis\n"; + { + std::cout << "axis " << sensedInput->btnID << " direction " << + (sensedInput->axisDirection == Input::AD_NEGATIVE ? "-" : "+") << "\n\n"; + } else if(sensedInput->type == Input::IT_STICKBUTTON) - std::cout << "button " << sensedInput->btnID << "\n"; + { + std::cout << "button " << sensedInput->btnID << "\n\n"; + } else - std::cout << "WTF?\n"; + std::cout << "Sensed unknown gamepad event type??\n"; int gamepadID = -1; diff --git a/src/input/input_device.cpp b/src/input/input_device.cpp index fda4ce3a3..8f97b20b1 100644 --- a/src/input/input_device.cpp +++ b/src/input/input_device.cpp @@ -283,7 +283,7 @@ void GamePadDevice::editBinding(const PlayerAction action, const Input::InputTyp { m_bindings[action].type = type; m_bindings[action].id = id; - m_bindings[PA_ACCEL].dir = direction; + m_bindings[action].dir = direction; } // ----------------------------------------------------------------------------- void GamePadDevice::resetAxisDirection(const int axis, Input::AxisDirection direction, const int player) diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 26b9614b8..6ea593a27 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -164,7 +164,55 @@ void InputManager::handleStaticAction(int key, int value) } - +/** + * Handles input when an input sensing mode (when configuring input) + */ +void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID, int axisDirection, int value) +{ + // See if the new input should be stored. This happens if: + // 1) the value is larger + // 2) nothing has been saved yet + // 3) the new event has the preferred type : TODO - reimplement + // The latter is necessary since some gamepads have analog + // buttons that can return two different events when pressed + bool store_new = abs(value) > m_max_sensed_input || + m_max_sensed_type == Input::IT_NONE; + + // don't store if we're trying to do something like bindings keyboard keys on a gamepad + if(m_mode == INPUT_SENSE_KEYBOARD && type != Input::IT_KEYBOARD) store_new = false; + if(m_mode == INPUT_SENSE_GAMEPAD && type != Input::IT_STICKMOTION && type != Input::IT_STICKBUTTON) store_new = false; + + // only store axes when they're pushed quite far + if(m_mode == INPUT_SENSE_GAMEPAD && type == Input::IT_STICKMOTION && abs(value) < MAX_VALUE *2/3) store_new = false; + + if(store_new) + { + m_sensed_input->type = type; + if(type == Input::IT_STICKMOTION) + { + std::cout << "%% storing new axis binding, value=" << value << + " deviceID=" << deviceID << " btnID=" << btnID << " axisDirection=" << + (axisDirection == Input::AD_NEGATIVE ? "-" : "+") << "\n"; + } + else if(type == Input::IT_STICKBUTTON) + { + std::cout << "%% storing new gamepad button binding\n"; + } + + m_sensed_input->deviceID = deviceID; + m_sensed_input->btnID = btnID; + m_sensed_input->axisDirection = axisDirection; + + m_max_sensed_input = abs(value); + m_max_sensed_type = type; + } + + // Notify the completion of the input sensing if the key/stick/... is released. + if(value==0) + { + StateManager::gotSensedInput(m_sensed_input); + } +} //----------------------------------------------------------------------------- /** Handles the conversion from some input to a GameAction and its distribution @@ -211,73 +259,17 @@ void InputManager::input(Input::InputType type, int deviceID, int btnID, int axi if (m_mode == INPUT_SENSE_KEYBOARD || m_mode == INPUT_SENSE_GAMEPAD) { - - //if(type == Input::IT_STICKMOTION) - // std::cout << "sensing input detected an axis event\n"; - //if(type == Input::IT_STICKBUTTON) - // std::cout << "sensing input detected a button event\n"; - - // Input sensing should be canceled. (TODO) - //if (ga == GA_LEAVE && m_sensed_input->type==Input::IT_KEYBOARD) - //{ - // StateManager::gotSensedInput(NULL); - //} - // Stores the sensed input when the button/key/axes/ is - // released only and is not used in a fixed mapping. - //else - //if (!UserConfigParams::isFixedInput(type, id0, id1, id2) ) // ignore static actions (TODO) - { - // See if the new input should be stored. This happens if: - // 1) the value is larger - // 2) nothing has been saved yet - // 3) the new event has the preferred type : TODO - reimplement - // The latter is necessary since some gamepads have analog - // buttons that can return two different events when pressed - bool store_new = abs(value) > m_max_sensed_input || - m_max_sensed_type == Input::IT_NONE; - - // (m_mode == INPUT_SENSE_GAMEPAD && (type == Input::IT_STICKMOTION || - // type == Input::IT_STICKBUTTON) && - // abs(value) > m_max_sensed_input); - - // don't store if we're trying to do something like bindings keyboard keys on a gamepad - if(m_mode == INPUT_SENSE_KEYBOARD && type != Input::IT_KEYBOARD) store_new = false; - if(m_mode == INPUT_SENSE_GAMEPAD && type != Input::IT_STICKMOTION && type != Input::IT_STICKBUTTON) store_new = false; - - // only store axes when they're pushed quite far - if(m_mode == INPUT_SENSE_GAMEPAD && type == Input::IT_STICKMOTION && abs(value) < MAX_VALUE *2/3) store_new = false; - - if(store_new) - { - m_sensed_input->type = type; - if(type == Input::IT_STICKMOTION) - std::cout << "storing new axis binding, value=" << value << - " deviceID=" << deviceID << " btnID=" << btnID << "\n"; - if(type == Input::IT_STICKBUTTON) - std::cout << "storing new button binding\n"; - - m_sensed_input->deviceID = deviceID; - m_sensed_input->btnID = btnID; - m_sensed_input->axisDirection = axisDirection; - - m_max_sensed_input = abs(value); - m_max_sensed_type = type; - } - - // Notify the completion of the input sensing if the key/stick/ - // ... is released. - if(value==0) - { - StateManager::gotSensedInput(m_sensed_input); - } - } + inputSensing(type, deviceID, btnID, axisDirection, value); } + // Otherwise, do something with the key if it matches a binding else if (action_found) { + // ... when in-game if(StateManager::isGameState()) { RaceManager::getWorld()->getLocalPlayerKart(player)->action(action, abs(value)); } + // ... when in menus else { // reset timer when released diff --git a/src/input/input_manager.hpp b/src/input/input_manager.hpp index 635fc5302..a054444e6 100644 --- a/src/input/input_manager.hpp +++ b/src/input/input_manager.hpp @@ -68,9 +68,9 @@ private: int m_mouse_val_x, m_mouse_val_y; void input(Input::InputType, int, int, int, int); - //void postIrrLichtMouseEvent(irr::EMOUSE_INPUT_EVENT type, const int x, const int y); void handleStaticAction(int id0, int value); void handlePlayerAction(PlayerAction pa, const int playerNo, int value); + void inputSensing(Input::InputType type, int deviceID, int btnID, int axisDirection, int value); public: InputManager(); ~InputManager();