From cca65fde08442075bab9344cff0645934c2de21e Mon Sep 17 00:00:00 2001 From: wrrrzr <161970349+wrrrzr@users.noreply.github.com> Date: Sun, 29 Dec 2024 00:05:01 +0300 Subject: [PATCH] Controls: extract init_joysticks (#15597) --- src/client/clientlauncher.cpp | 37 ++++++++++++++++++++--------------- src/client/clientlauncher.h | 1 + 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 9d87ec3fd..b68edb790 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -301,24 +301,29 @@ void ClientLauncher::init_input() else input = new RealInputHandler(receiver); - if (g_settings->getBool("enable_joysticks")) { - irr::core::array infos; - std::vector joystick_infos; + if (g_settings->getBool("enable_joysticks")) + init_joysticks(); +} - // Make sure this is called maximum once per - // irrlicht device, otherwise it will give you - // multiple events for the same joystick. - if (m_rendering_engine->get_raw_device()->activateJoysticks(infos)) { - infostream << "Joystick support enabled" << std::endl; - joystick_infos.reserve(infos.size()); - for (u32 i = 0; i < infos.size(); i++) { - joystick_infos.push_back(infos[i]); - } - input->joystick.onJoystickConnect(joystick_infos); - } else { - errorstream << "Could not activate joystick support." << std::endl; - } +void ClientLauncher::init_joysticks() +{ + irr::core::array infos; + std::vector joystick_infos; + + // Make sure this is called maximum once per + // irrlicht device, otherwise it will give you + // multiple events for the same joystick. + if (!m_rendering_engine->get_raw_device()->activateJoysticks(infos)) { + errorstream << "Could not activate joystick support." << std::endl; + return; } + + infostream << "Joystick support enabled" << std::endl; + joystick_infos.reserve(infos.size()); + for (u32 i = 0; i < infos.size(); i++) { + joystick_infos.push_back(infos[i]); + } + input->joystick.onJoystickConnect(joystick_infos); } void ClientLauncher::setting_changed_callback(const std::string &name, void *data) diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index f349cec57..21e459db7 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -26,6 +26,7 @@ private: void init_args(GameStartData &start_data, const Settings &cmd_args); bool init_engine(); void init_input(); + void init_joysticks(); static void setting_changed_callback(const std::string &name, void *data); void config_guienv();