// ----------------------------------------------------------------------------- bool DeviceManager::initialize() { GamepadConfig *gamepadConfig = NULL; GamePadDevice *gamepadDevice = NULL; m_map_fire_to_select = false; bool created = false; // Shutdown in case the device manager is being re-initialized shutdown(); if(UserConfigParams::logMisc()) { Log::info("Device manager","Initializing Device Manager"); Log::info("-","---------------------------"); } load(); // Assign a configuration to the keyboard, or create one if we haven't yet if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing keyboard support."); if (m_keyboard_configs.size() == 0) { if(UserConfigParams::logMisc()) Log::info("Device manager","No keyboard configuration exists, creating one."); m_keyboard_configs.push_back(new KeyboardConfig()); created = true; } const int keyboard_amount = m_keyboard_configs.size(); for (int n = 0; n < keyboard_amount; n++) { m_keyboards.push_back(new KeyboardDevice(m_keyboard_configs.get(n))); } if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing gamepad support."); irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads); int num_gamepads = m_irrlicht_gamepads.size(); if(UserConfigParams::logMisc()) { Log::info("Device manager","Irrlicht reports %d gamepads are attached to the system.", num_gamepads); } // Create GamePadDevice for each physical gamepad and find a GamepadConfig to match for (int id = 0; id < num_gamepads; id++) { core::stringc name = m_irrlicht_gamepads[id].Name; // Some systems report a disk accelerometer as a gamepad, skip that if (name.find("LIS3LV02DL") != -1) continue; if (name == "applesmc") continue; if(m_irrlicht_gamepads[id].HasGenericName) { // On Windows all gamepads are given the same name ('microsoft // pc-joystick driver'). Irrlicht now tries to get a better name // from the registry, but in case this should fail we still have // all gamepads with the same name shown in the GUI. This makes // configuration totally useless, so append an ID to the name. name = name + " " + StringUtils::toString(id).c_str(); } if (UserConfigParams::logMisc()) { Log::info("Device manager","#%d: %s detected...", id, name.c_str()); } // Returns true if new configuration was created if (getConfigForGamepad(id, name.c_str(), &gamepadConfig) == true) { if(UserConfigParams::logMisc()) Log::info("Device manager","creating new configuration."); created = true; } else { if(UserConfigParams::logMisc()) Log::info("Device manager","using existing configuration."); } gamepadConfig->setPlugged(); gamepadDevice = new GamePadDevice(id, name.c_str(), m_irrlicht_gamepads[id].Axes, m_irrlicht_gamepads[id].Buttons, gamepadConfig ); addGamepad(gamepadDevice); } // end for if (UserConfigParams::m_multitouch_enabled) { m_multitouch_device = new MultitouchDevice(); } if (created) save(); return created; } // initialize
// ----------------------------------------------------------------------------- bool DeviceManager::initialize() { GamepadConfig *gamepadConfig = NULL; GamePadDevice *gamepadDevice = NULL; m_map_fire_to_select = false; bool created = false; // Shutdown in case the device manager is being re-initialized shutdown(); if(UserConfigParams::logMisc()) { Log::info("Device manager","Initializing Device Manager"); Log::info("-","---------------------------"); } deserialize(); // Assign a configuration to the keyboard, or create one if we haven't yet if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing keyboard support."); if (m_keyboard_configs.size() == 0) { if(UserConfigParams::logMisc()) Log::info("Device manager","No keyboard configuration exists, creating one."); m_keyboard_configs.push_back(new KeyboardConfig()); created = true; } const int keyboard_amount = m_keyboard_configs.size(); for (int n=0; n<keyboard_amount; n++) { m_keyboards.push_back(new KeyboardDevice(m_keyboard_configs.get(n))); } if(UserConfigParams::logMisc()) Log::info("Device manager","Initializing gamepad support."); irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads); int num_gamepads = m_irrlicht_gamepads.size(); if(UserConfigParams::logMisc()) { Log::info("Device manager","Irrlicht reports %d gamepads are attached to the system.", num_gamepads); } // Create GamePadDevice for each physical gamepad and find a GamepadConfig to match for (int id = 0; id < num_gamepads; id++) { core::stringc name = m_irrlicht_gamepads[id].Name; // Some linux systems report a disk accelerometer as a gamepad, skip that if (name.find("LIS3LV02DL") != -1) continue; #ifdef WIN32 // On Windows, unless we use DirectInput, all gamepads are given the // same name ('microsoft pc-joystick driver'). This makes configuration // totally useless, so append an ID to the name. We can't test for the // name, since the name is even translated. name = name + " " + StringUtils::toString(id).c_str(); #endif if (UserConfigParams::logMisc()) { Log::info("Device manager","#%d: %s detected...", id, name.c_str()); } // Returns true if new configuration was created if (getConfigForGamepad(id, name, &gamepadConfig) == true) { if(UserConfigParams::logMisc()) Log::info("Device manager","creating new configuration."); created = true; } else { if(UserConfigParams::logMisc()) Log::info("Device manager","using existing configuration."); } gamepadConfig->setPlugged(); gamepadDevice = new GamePadDevice(id, name.c_str(), m_irrlicht_gamepads[id].Axes, m_irrlicht_gamepads[id].Buttons, gamepadConfig ); addGamepad(gamepadDevice); } // end for if (created) serialize(); return created; } // initialize
void SDL_Event_Handler::joyDeviceAdded(const SDL_Event *event) { addGamepad(event->cdevice.which); }