diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index 91f02487c..217336b6f 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -57,6 +57,9 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0) m_device_manager = new DeviceManager(); + m_timer_in_use = false; + m_timer = 0; + bool something_new_to_write = false; if(!m_device_manager->deserialize()) @@ -87,6 +90,15 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0) if(something_new_to_write) m_device_manager->serialize(); } +// ----------------------------------------------------------------------------- +void InputManager::update(float dt) +{ + if(m_timer_in_use) + { + m_timer -= dt; + if(m_timer < 0) m_timer_in_use = false; + } +} // ----------------------------------------------------------------------------- /** Initialises joystick/gamepad info. @@ -327,6 +339,8 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2, const bool action_found = m_device_manager->mapInputToPlayerAndAction( type, id0, id1, id2, value, &player, &action ); if(!action_found) return; + if(m_timer_in_use) return; // time between keys not elapsed yet + if(action == PA_FIRE || action == PA_NITRO) evt.Key = irr::KEY_RETURN; else if(action == PA_ACCEL) @@ -341,6 +355,10 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2, return; // only those bindings are accepted in menus for now. evt.PressedDown = abs(value) > MAX_VALUE/2; + + // minimum time between two gamepad events in menu + m_timer_in_use = true; + m_timer = 500; } // send event to irrLicht diff --git a/src/input/input_manager.hpp b/src/input/input_manager.hpp index b6daa17d5..68d20672f 100644 --- a/src/input/input_manager.hpp +++ b/src/input/input_manager.hpp @@ -44,6 +44,10 @@ public: BOOTSTRAP }; + // to put a delay before a new gamepad axis move is considered in menu + bool m_timer_in_use; + float m_timer; + private: Input *m_sensed_input; @@ -62,7 +66,7 @@ private: * makes the mouse behave like an analog axis on a gamepad/joystick. */ 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); @@ -74,6 +78,9 @@ public: void input(); void setMode(InputDriverMode); bool isInMode(InputDriverMode); + + void update(float dt); + Input &getSensedInput(); }; diff --git a/src/main_loop.cpp b/src/main_loop.cpp index c59c9ea00..564f2a91a 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -214,6 +214,8 @@ void MainLoop::run() sound_manager->update(dt); + input_manager->update(dt); + #ifdef HAVE_IRRLICHT if(!user_config->m_bullet_debug) irr_driver->update(dt);