| 4206 | } |
| 4207 | |
| 4208 | static void onConnected(std::string_view deviceName, int deviceId) |
| 4209 | { |
| 4210 | // Check whether the controller is already registered |
| 4211 | auto iter = findController(deviceId); |
| 4212 | if (iter != Controller::s_allController.end()) |
| 4213 | return; |
| 4214 | |
| 4215 | // It's a new controller being connected. |
| 4216 | auto controller = new ax::Controller(); |
| 4217 | controller->_deviceId = deviceId; |
| 4218 | controller->_deviceName = deviceName; |
| 4219 | Controller::s_allController.emplace_back(controller); |
| 4220 | |
| 4221 | // Check if we already have an available input controller profile. If so, attach it it to the controller. |
| 4222 | for (const auto& it : s_controllerProfiles) |
| 4223 | { |
| 4224 | if (deviceName.compare(it.first) == 0) |
| 4225 | { |
| 4226 | // Found controller profile. Attach it to the controller: |
| 4227 | AXLOGD("ControllerImpl: Found input profile for controller: {}", deviceName); |
| 4228 | controller->_buttonInputMap = it.second.first; |
| 4229 | controller->_axisInputMap = it.second.second; |
| 4230 | |
| 4231 | // Show a one-time warning in debug mode for every button that's currently not matched in the input profile. |
| 4232 | // This will let the developers know that the mapping must be included in the constructor of ControllerImpl located |
| 4233 | // above. |
| 4234 | # ifdef _AX_DEBUG |
| 4235 | int count; |
| 4236 | glfwGetJoystickButtons(deviceId, &count); |
| 4237 | for (int i = 0; i < count; ++i) |
| 4238 | { |
| 4239 | // Check the mapping of each button: |
| 4240 | const auto& it = controller->_buttonInputMap.find(i); |
| 4241 | if (it == controller->_buttonInputMap.end()) |
| 4242 | { |
| 4243 | AXLOGD( |
| 4244 | "ControllerImpl: Could not find a button input mapping for controller \"{}\", and keyCode " |
| 4245 | "\"{}\". This keyCode will not match any from Controller::Key", |
| 4246 | controller->getDeviceName(), i); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | glfwGetJoystickAxes(deviceId, &count); |
| 4251 | for (int i = 0; i < count; ++i) |
| 4252 | { |
| 4253 | // Check the mapping of each axis |
| 4254 | const auto& it = controller->_axisInputMap.find(i); |
| 4255 | if (it == controller->_axisInputMap.end()) |
| 4256 | { |
| 4257 | AXLOGD( |
| 4258 | "ControllerImpl: Could not find an axis input mapping for controller \"{}\", and keyCode " |
| 4259 | "\"{}\". This keyCode will not match any from Controller::Key", |
| 4260 | controller->getDeviceName(), i); |
| 4261 | } |
| 4262 | } |
| 4263 | # endif |
| 4264 | |
| 4265 | break; |
no test coverage detected