Update axisCount to be array

This commit is contained in:
Michael 2023-10-12 17:04:40 -04:00
parent 2503ff9f95
commit 8489d81075
2 changed files with 12 additions and 5 deletions

View File

@ -181,7 +181,7 @@ typedef struct CoreData {
} Touch;
struct {
int lastButtonPressed; // Register last gamepad button pressed
int axisCount; // Register number of available gamepad axis
int axisCount[MAX_GAMEPADS]; // Register number of available gamepad axis
bool ready[MAX_GAMEPADS]; // Flag to know if gamepad is ready
char name[MAX_GAMEPADS][64]; // Gamepad name holder
char currentButtonState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state

View File

@ -763,7 +763,7 @@ const char *GetGamepadName(int gamepad)
// Get gamepad axis count
int GetGamepadAxisCount(int gamepad)
{
return CORE.Input.Gamepad.axisCount;
return CORE.Input.Gamepad.axisCount[gamepad];
}
// Set internal gamepad mappings
@ -861,7 +861,11 @@ void PollInputEvents(void)
// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
for (int i = 0; i < MAX_GAMEPADS; i++)
{
CORE.Input.Gamepad.axisCount[i] = 0;
}
// Register previous keys states
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
@ -1519,16 +1523,19 @@ static void InitDrmJoystick(int index, const char *path)
// Get the bits describing the absolute axes of the device.
unsigned long abs_bits[ABS_MAX / 8 + 1] = {0};
ioctl(platform.gamepadStreamFd[index], EVIOCGBIT(EV_ABS, sizeof(abs_bits)), &abs_bits);
ioctl(platform.gamepadStreamFd[index], EVIOCGNAME(64), &CORE.Input.Gamepad.name[index]);
// Count the axes present on the device.
CORE.Input.Gamepad.axisCount = 0;
CORE.Input.Gamepad.axisCount[index] = 0;
for (int axis = 0; axis < ABS_MAX; axis++)
{
if (MI_IS_BIT_SET(abs_bits, axis)) {
CORE.Input.Gamepad.axisCount++;
CORE.Input.Gamepad.axisCount[index]++;
}
}
TraceLog(LOG_INFO, TextFormat("Gamepad [%d] %s has %d axes", index, CORE.Input.Gamepad.name[index], CORE.Input.Gamepad.axisCount[index]));
CORE.Input.Gamepad.ready[index] = true;
}