| 214 | } |
| 215 | |
| 216 | void InputManager::createGamepadMap() |
| 217 | { |
| 218 | auto cKey = m_inputs.begin(); |
| 219 | while (cKey != m_inputs.end()) |
| 220 | { |
| 221 | if (cKey->first.rfind("GP_", 0) == 0) |
| 222 | cKey = m_inputs.erase(cKey); |
| 223 | else |
| 224 | ++cKey; |
| 225 | } |
| 226 | sf::Joystick::update(); |
| 227 | for (int gamepadIndex = 0; gamepadIndex < sf::Joystick::Count; gamepadIndex++) |
| 228 | { |
| 229 | for (unsigned int buttonIndex = 0; |
| 230 | buttonIndex < sf::Joystick::getButtonCount(gamepadIndex); buttonIndex++) |
| 231 | { |
| 232 | std::string gamepadButtonName = "GP_" + std::to_string(gamepadIndex) |
| 233 | + "_BTN_" + std::to_string(buttonIndex); |
| 234 | m_inputs[gamepadButtonName] = std::make_unique<InputButton>( |
| 235 | gamepadIndex, buttonIndex, gamepadButtonName); |
| 236 | } |
| 237 | auto addHorizontalAxis = [&gamepadIndex, this](sf::Joystick::Axis axis, |
| 238 | const std::string& axisName) { |
| 239 | if (sf::Joystick::hasAxis(gamepadIndex, axis)) |
| 240 | { |
| 241 | const std::string gamepadAxisName |
| 242 | = "GP_" + std::to_string(gamepadIndex) + "_AXIS_" + axisName; |
| 243 | std::pair<AxisThresholdDirection, float> leftX( |
| 244 | AxisThresholdDirection::Less, -80); |
| 245 | std::pair<AxisThresholdDirection, float> rightX( |
| 246 | AxisThresholdDirection::More, 80); |
| 247 | m_inputs[gamepadAxisName + "_LEFT"] = std::make_unique<InputButton>( |
| 248 | gamepadIndex, axis, leftX, gamepadAxisName + "_LEFT"); |
| 249 | m_inputs[gamepadAxisName + "_RIGHT"] = std::make_unique<InputButton>( |
| 250 | gamepadIndex, axis, rightX, gamepadAxisName + "_RIGHT"); |
| 251 | } |
| 252 | }; |
| 253 | auto addVerticalAxis = [&gamepadIndex, this](sf::Joystick::Axis axis, |
| 254 | const std::string& axisName) { |
| 255 | if (sf::Joystick::hasAxis(gamepadIndex, axis)) |
| 256 | { |
| 257 | const std::string gamepadAxisName |
| 258 | = "GP_" + std::to_string(gamepadIndex) + "_AXIS_" + axisName; |
| 259 | std::pair<AxisThresholdDirection, float> upY( |
| 260 | AxisThresholdDirection::Less, -80); |
| 261 | std::pair<AxisThresholdDirection, float> downY( |
| 262 | AxisThresholdDirection::More, 80); |
| 263 | m_inputs[gamepadAxisName + "_UP"] = std::make_unique<InputButton>( |
| 264 | gamepadIndex, axis, upY, gamepadAxisName + "_UP"); |
| 265 | m_inputs[gamepadAxisName + "_DOWN"] = std::make_unique<InputButton>( |
| 266 | gamepadIndex, axis, downY, gamepadAxisName + "_DOWN"); |
| 267 | } |
| 268 | }; |
| 269 | addHorizontalAxis(sf::Joystick::Axis::X, "X"); |
| 270 | addVerticalAxis(sf::Joystick::Axis::Y, "Y"); |
| 271 | addHorizontalAxis(sf::Joystick::Axis::PovX, "PovX"); |
| 272 | addVerticalAxis(sf::Joystick::Axis::PovY, "PovY"); |
| 273 | addHorizontalAxis(sf::Joystick::Axis::U, "U"); |
no test coverage detected