Skip to content

Commit

Permalink
Controls: extract init_joysticks (#15597)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrrrzr authored Dec 28, 2024
1 parent 35bc217 commit cca65fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,29 @@ void ClientLauncher::init_input()
else
input = new RealInputHandler(receiver);

if (g_settings->getBool("enable_joysticks")) {
irr::core::array<irr::SJoystickInfo> infos;
std::vector<irr::SJoystickInfo> 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)) {
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;
}
if (g_settings->getBool("enable_joysticks"))
init_joysticks();
}

void ClientLauncher::init_joysticks()
{
irr::core::array<irr::SJoystickInfo> infos;
std::vector<irr::SJoystickInfo> 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)
Expand Down
1 change: 1 addition & 0 deletions src/client/clientlauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ClientLauncher
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();
Expand Down

0 comments on commit cca65fd

Please sign in to comment.