Fix missing joystick if device is reinitialized
This commit is contained in:
parent
2cf5e29272
commit
fa943c70e3
@ -61,7 +61,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
||||
// noparachute prevents SDL from catching fatal errors.
|
||||
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
u32 init_flags = SDL_INIT_TIMER| SDL_INIT_VIDEO| SDL_INIT_GAMECONTROLLER;
|
||||
u32 init_flags = SDL_INIT_TIMER | SDL_INIT_VIDEO;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 9)
|
||||
init_flags |= SDL_INIT_SENSOR;
|
||||
#endif
|
||||
|
@ -1027,6 +1027,9 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
|
||||
// Input manager set first so it recieves SDL joystick event
|
||||
// Re-init GUI engine
|
||||
GUIEngine::init(m_device, m_video_driver, StateManager::get());
|
||||
// If not recreate device we need to add the previous joystick manually
|
||||
if (!recreate_device)
|
||||
input_manager->addJoystick();
|
||||
|
||||
setMaxTextureSize();
|
||||
//material_manager->reInit();
|
||||
|
@ -87,6 +87,38 @@ InputManager::InputManager() : m_mode(BOOTSTRAP),
|
||||
m_timer_in_use = false;
|
||||
m_master_player_only = false;
|
||||
m_timer = 0;
|
||||
#ifndef SERVER_ONLY
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void InputManager::addJoystick()
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
// When irrlicht device is reinitialized the joystick added event may be
|
||||
// lost, we look for them and add it back
|
||||
for (int i = 0; i < SDL_NumJoysticks(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
SDL_Joystick* joystick = SDL_JoystickOpen(i);
|
||||
if (!joystick)
|
||||
continue;
|
||||
SDL_JoystickID id = SDL_JoystickInstanceID(joystick);
|
||||
if (m_sdl_controller.find(id) != m_sdl_controller.end())
|
||||
continue;
|
||||
std::unique_ptr<SDLController> c(
|
||||
new SDLController(i));
|
||||
id = c->getInstanceID();
|
||||
m_sdl_controller[id] = std::move(c);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log::error("SDLController", "%s", e.what());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -126,6 +126,7 @@ public:
|
||||
void dispatchInput(Input::InputType, int deviceID, int btnID,
|
||||
Input::AxisDirection direction, int value,
|
||||
bool shift_mask = false);
|
||||
void addJoystick();
|
||||
};
|
||||
|
||||
extern InputManager *input_manager;
|
||||
|
Loading…
Reference in New Issue
Block a user