MCPcopy Create free account
hub / github.com/defold/defold / NewGamepadBinding

Function NewGamepadBinding

engine/input/src/input.cpp:203–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201 }
202
203 static GamepadBinding* NewGamepadBinding(HBinding binding, uint32_t gamepad_index)
204 {
205 dmHID::HGamepad gamepad = dmHID::GetGamepad(binding->m_Context->m_HidContext, gamepad_index);
206
207 // For now, by default they are legacy mappings
208 dmHID::SetGamepadLayoutLegacy(gamepad, true);
209
210 // TODO: Get the gamepad guid + SDL name
211
212 GamepadConfig* selected_config = 0;
213
214 // TODO: Get the gamepad sdk mapping (if any)
215
216 if (!selected_config)
217 {
218 char device_name_out[dmHID::MAX_GAMEPAD_NAME_LENGTH];
219 selected_config = GetGamepadConfig(binding, gamepad, device_name_out);
220 }
221
222 if (selected_config)
223 {
224 GamepadBinding* gamepad_binding = new GamepadBinding();
225 memset(gamepad_binding, 0, sizeof(*gamepad_binding));
226 gamepad_binding->m_Gamepad = gamepad;
227
228 if (selected_config->m_DeviceId == UNKNOWN_GAMEPAD_CONFIG_ID)
229 {
230 char device_name[dmHID::MAX_GAMEPAD_NAME_LENGTH];
231 dmHID::GetGamepadDeviceName(binding->m_Context->m_HidContext, gamepad, device_name);
232 dmLogWarning("No gamepad map found for gamepad %d (%s). The raw gamepad map will be used.", gamepad_index, device_name);
233 gamepad_binding->m_Unknown = 1;
234 }
235 ResetGamepadBindings(binding, gamepad_binding, gamepad_index);
236 return gamepad_binding;
237 }
238 else
239 {
240 char device_name[dmHID::MAX_GAMEPAD_NAME_LENGTH];
241 dmHID::GetGamepadDeviceName(binding->m_Context->m_HidContext, gamepad, device_name);
242
243 if (device_name[0])
244 {
245 dmLogWarning("No gamepad map found for gamepad %d (%s). Ignored.", gamepad_index, device_name);
246 }
247 }
248 return 0x0;
249 }
250
251 static void SetupGamepadBindings(HBinding binding)
252 {

Callers 2

SetupGamepadBindingsFunction · 0.85
MapGamePadFunction · 0.85

Calls 5

GetGamepadFunction · 0.85
SetGamepadLayoutLegacyFunction · 0.85
GetGamepadConfigFunction · 0.85
ResetGamepadBindingsFunction · 0.85
GetGamepadDeviceNameFunction · 0.50

Tested by

no test coverage detected