| 149 | } |
| 150 | |
| 151 | static GamepadConfig* GetGamepadConfig(HBinding binding, dmHID::HGamepad gamepad, char device_name_out[dmHID::MAX_GAMEPAD_NAME_LENGTH]) |
| 152 | { |
| 153 | char device_name[dmHID::MAX_GAMEPAD_NAME_LENGTH]; |
| 154 | dmHID::GetGamepadDeviceName(binding->m_Context->m_HidContext, gamepad, device_name); |
| 155 | |
| 156 | /* |
| 157 | * NOTE: We used to log a warning here but the warning is removed for the following reasons: |
| 158 | * - The input-binding file covers several platforms and certain platforms |
| 159 | * doesn't have support for e.g. pads. But more importantly, sometimes you might have |
| 160 | * a device connected but sometimes not. It should be up to the user and we shouldn't |
| 161 | * spam out warnings in such cases. In other words. It's impossible to tell whether the |
| 162 | * warning is appropriate or not. |
| 163 | * - We should also have support dynamic pad-connections. Whether a pad is connected |
| 164 | * or not should be up to the game-ui. |
| 165 | */ |
| 166 | if (device_name[0] == 0) |
| 167 | return 0x0; |
| 168 | |
| 169 | GamepadConfig* best_config = 0x0; |
| 170 | uint32_t best_config_name_index = 0; |
| 171 | |
| 172 | uint32_t num_names = 1; |
| 173 | char* device_names[] = { device_name, 0 }; |
| 174 | |
| 175 | #ifdef _WIN32 |
| 176 | // for backwards compatability with GLFW 2.7 |
| 177 | device_names[num_names++] = "XBox 360 Controller"; |
| 178 | #endif |
| 179 | |
| 180 | for (uint32_t i = 0; i < num_names; ++i) |
| 181 | { |
| 182 | GamepadConfig* config = GetGamepadConfigFromDeviceName(binding, dmHashString32(device_names[i])); |
| 183 | if (!config) |
| 184 | continue; |
| 185 | |
| 186 | best_config = config; |
| 187 | best_config_name_index = i; |
| 188 | |
| 189 | // if we have found a config with a valid gamepad id, we don't look further. |
| 190 | if (best_config->m_DeviceId != UNKNOWN_GAMEPAD_CONFIG_ID) |
| 191 | { |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (best_config) |
| 197 | { |
| 198 | dmStrlCpy(device_name_out, device_names[best_config_name_index], dmHID::MAX_GAMEPAD_NAME_LENGTH); |
| 199 | } |
| 200 | return best_config; |
| 201 | } |
| 202 | |
| 203 | static GamepadBinding* NewGamepadBinding(HBinding binding, uint32_t gamepad_index) |
| 204 | { |
no test coverage detected