This commit is contained in:
Benau 2021-02-08 08:25:48 +08:00
parent 6e3744157d
commit d2b98456a7
2 changed files with 13 additions and 14 deletions

View File

@ -86,9 +86,7 @@ InputManager::InputManager() : m_mode(BOOTSTRAP),
m_device_manager = new DeviceManager(); m_device_manager = new DeviceManager();
m_device_manager->initialize(); m_device_manager->initialize();
m_timer_in_use = false;
m_master_player_only = false; m_master_player_only = false;
m_timer = 0;
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0)
{ {
@ -153,6 +151,8 @@ void InputManager::handleJoystick(SDL_Event& event)
} }
case SDL_JOYDEVICEREMOVED: case SDL_JOYDEVICEREMOVED:
{ {
m_gamepads_timer.erase(
m_sdl_controller.at(event.jdevice.which)->getInstanceID());
m_sdl_controller.erase(event.jdevice.which); m_sdl_controller.erase(event.jdevice.which);
break; break;
} }
@ -202,11 +202,15 @@ void InputManager::update(float dt)
wiimote_manager->update(); wiimote_manager->update();
#endif #endif
if(m_timer_in_use) for (auto it = m_gamepads_timer.begin(); it != m_gamepads_timer.end();)
{ {
m_timer -= dt; it->second -= dt;
if(m_timer < 0) m_timer_in_use = false; if (it->second < 0)
it = m_gamepads_timer.erase(it);
else
it++;
} }
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
for (auto& controller : m_sdl_controller) for (auto& controller : m_sdl_controller)
controller.second->checkPowerLevel(); controller.second->checkPowerLevel();
@ -968,10 +972,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
{ {
// reset timer when released // reset timer when released
if (abs(value) == 0 && type == Input::IT_STICKMOTION) if (abs(value) == 0 && type == Input::IT_STICKMOTION)
{ m_gamepads_timer.erase(deviceID);
m_timer_in_use = false;
m_timer = 0;
}
// When in master-only mode, we can safely assume that players // When in master-only mode, we can safely assume that players
// are set up, contrarly to early menus where we accept every // are set up, contrarly to early menus where we accept every
@ -998,13 +999,12 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID,
} }
// menu input // menu input
if (!m_timer_in_use) if (m_gamepads_timer.find(deviceID) == m_gamepads_timer.end())
{ {
if (type == Input::IT_STICKMOTION && if (type == Input::IT_STICKMOTION &&
abs(value) > Input::MAX_VALUE * 2 / 3) abs(value) > Input::MAX_VALUE * 2 / 3)
{ {
m_timer_in_use = true; m_gamepads_timer[deviceID] = 0.25f;
m_timer = 0.25;
} }
if (is_nw_spectator) if (is_nw_spectator)

View File

@ -54,8 +54,7 @@ public:
}; };
// to put a delay before a new gamepad axis move is considered in menu // to put a delay before a new gamepad axis move is considered in menu
bool m_timer_in_use; std::map<int, float> m_gamepads_timer;
float m_timer;
private: private: