summaryrefslogtreecommitdiff
path: root/src/client/clientlauncher.cpp
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2017-04-02 23:00:34 +0100
committerAuke Kok <sofar+github@foo-projects.org>2017-04-06 20:58:52 -0700
commitbce0d458d8cda70c10d78ea9ec476474f0a6f01a (patch)
tree529062ce8f0e7b7fd8f5bd94608af3e36a7860d6 /src/client/clientlauncher.cpp
parent351cc2e79a7d78f7ec97ff9b33e4f0bad4042b19 (diff)
downloadminetest-bce0d458d8cda70c10d78ea9ec476474f0a6f01a.tar.gz
minetest-bce0d458d8cda70c10d78ea9ec476474f0a6f01a.tar.bz2
minetest-bce0d458d8cda70c10d78ea9ec476474f0a6f01a.zip
Add Joystick type detection and Xbox controller support
* Add joystick type detection (with joystick_type setting to override it) * Fix multiple joysticks from interfering with each other by only reading from one (add joystick_id setting) * Add support for Xbox controllers
Diffstat (limited to 'src/client/clientlauncher.cpp')
-rw-r--r--src/client/clientlauncher.cpp51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 3ec7be7d9..249f6727a 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -127,10 +127,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
device->setResizable(true);
- if (random_input)
- input = new RandomInputHandler();
- else
- input = new RealInputHandler(device, receiver);
+ init_input();
smgr = device->getSceneManager();
smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
@@ -337,6 +334,33 @@ bool ClientLauncher::init_engine()
return device != NULL;
}
+void ClientLauncher::init_input()
+{
+ if (random_input)
+ input = new RandomInputHandler();
+ else
+ input = new RealInputHandler(device, 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 (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;
+ }
+ }
+}
+
bool ClientLauncher::launch_game(std::string &error_message,
bool reconnect_requested, GameParams &game_params,
const Settings &cmd_args)
@@ -566,25 +590,8 @@ bool ClientLauncher::create_engine_device()
device = createDeviceEx(params);
- if (device) {
- 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 (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]);
- }
- } else {
- errorstream << "Could not activate joystick support." << std::endl;
- }
- }
+ if (device)
porting::initIrrlicht(device);
- }
return device != NULL;
}