Implemented GetGamepadName() for emscripten (#1986)

* implemented GetGamepadName for emscripten

* updated gamepad to use existing name as arary

* removed unnecessary platform_web check
This commit is contained in:
Neil Barkhina 2021-09-12 12:02:54 -04:00 committed by GitHub
parent 024adc2538
commit e9d3d4fa1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -456,10 +456,10 @@ typedef struct CoreData {
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
char previousButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
float axisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM) || defined(PLATFORM_WEB)
pthread_t threadId; // Gamepad reading thread id
int streamId[MAX_GAMEPADS]; // Gamepad device file descriptor
char name[64]; // Gamepad name holder
char name[MAX_GAMEPADS][64]; // Gamepad name holder
#endif
} Gamepad;
} Input;
@ -3273,8 +3273,11 @@ const char *GetGamepadName(int gamepad)
else return NULL;
#endif
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
if (CORE.Input.Gamepad.ready[gamepad]) ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name);
return CORE.Input.Gamepad.name;
if (CORE.Input.Gamepad.ready[gamepad]) ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name[gamepad]);
return CORE.Input.Gamepad.name[gamepad];
#endif
#if defined(PLATFORM_WEB)
return CORE.Input.Gamepad.name[gamepad];
#endif
return NULL;
}
@ -5400,7 +5403,11 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
for (int i = 0; i < gamepadEvent->numButtons; ++i) TRACELOGD("Button %d: Digital: %d, Analog: %g", i, gamepadEvent->digitalButton[i], gamepadEvent->analogButton[i]);
*/
if ((gamepadEvent->connected) && (gamepadEvent->index < MAX_GAMEPADS)) CORE.Input.Gamepad.ready[gamepadEvent->index] = true;
if ((gamepadEvent->connected) && (gamepadEvent->index < MAX_GAMEPADS))
{
CORE.Input.Gamepad.ready[gamepadEvent->index] = true;
sprintf(CORE.Input.Gamepad.name[gamepadEvent->index],"%s",gamepadEvent->id);
}
else CORE.Input.Gamepad.ready[gamepadEvent->index] = false;
// TODO: Test gamepadEvent->index