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

Function RegisterGamepads

engine/input/src/input.cpp:488–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

486 }
487
488 void RegisterGamepads(HContext context, const dmInputDDF::GamepadMaps* ddf)
489 {
490 int count = 0;
491 for (uint32_t i = 0; i < ddf->m_Driver.m_Count; ++i)
492 {
493 const dmInputDDF::GamepadMap& gamepad_map = ddf->m_Driver[i];
494 if (SupportsPlatform(gamepad_map.m_Platform))
495 {
496 count++;
497 }
498 }
499
500 context->m_GamepadMaps.SetCapacity(dmMath::Max(1, (count + 1) / 3), count + 1);
501
502 // Add a gamepad config that will be used when an unidentified gamepad
503 // is connected. This will allow developers to at least read raw button,
504 // axis and hat data and do their own mappings.
505 GamepadConfig unknownGamepadConfig;
506 unknownGamepadConfig.m_DeadZone = 0.0;
507 unknownGamepadConfig.m_DeviceId = UNKNOWN_GAMEPAD_CONFIG_ID;
508 memset(unknownGamepadConfig.m_Inputs, 0, sizeof(unknownGamepadConfig.m_Inputs));
509 for (uint32_t j = 0; j < (sizeof(unknownGamepadConfig.m_Inputs) / sizeof(struct GamepadInput)); ++j)
510 {
511 unknownGamepadConfig.m_Inputs[j].m_Index = INVALID_INDEX;
512 }
513 context->m_GamepadMaps.Put(UNKNOWN_GAMEPAD_CONFIG_ID, unknownGamepadConfig);
514
515 if (count == 0)
516 {
517 dmLogInfo("No gamepads found in the gamepad map for this platform");
518 return;
519 }
520
521 for (uint32_t i = 0; i < ddf->m_Driver.m_Count; ++i)
522 {
523 const dmInputDDF::GamepadMap& gamepad_map = ddf->m_Driver[i];
524 if (SupportsPlatform(gamepad_map.m_Platform))
525 {
526 uint32_t device_id = dmHashString32(gamepad_map.m_Device);
527 if (context->m_GamepadMaps.Get(device_id) == 0x0)
528 {
529 GamepadConfig config;
530 config.m_DeadZone = gamepad_map.m_DeadZone;
531 config.m_DeviceId = device_id;
532 memset(config.m_Inputs, 0, sizeof(config.m_Inputs));
533 for (uint32_t j = 0; j < (sizeof(config.m_Inputs) / sizeof(struct GamepadInput)); ++j)
534 {
535 config.m_Inputs[j].m_Index = INVALID_INDEX;
536 }
537
538 for (uint32_t j = 0; j < gamepad_map.m_Map.m_Count; ++j)
539 {
540 const dmInputDDF::GamepadMapEntry& entry = gamepad_map.m_Map[j];
541 GamepadInput& input = config.m_Inputs[entry.m_Input];
542 input.m_Index = (uint16_t)entry.m_Index;
543 input.m_Type = entry.m_Type;
544 if (entry.m_Type == dmInputDDF::GAMEPAD_TYPE_HAT)
545 {

Callers 3

LoadBootstrapContentFunction · 0.85
SetUpMethod · 0.85
SetUpMethod · 0.85

Calls 5

SupportsPlatformFunction · 0.85
MaxFunction · 0.50
SetCapacityMethod · 0.45
PutMethod · 0.45
GetMethod · 0.45

Tested by 2

SetUpMethod · 0.68
SetUpMethod · 0.68