Skip to content

Commit

Permalink
[core] Change axisCount to be an array (#3421)
Browse files Browse the repository at this point in the history
* Update `PLATFORM_DRM` implementation of `GetGamepadAxisCount`

* Update

* Update `PLATFORM_DRM` implementation of `GetGamepadName`

* Add example to test gamepad info functions
Fix typo

* Update new gamepad info example

* Move axis count update out of GamepadThread - race condition

* Remove pointless if statement

* Start integrating stuff from the mikesinput lib

* Add more logging

* Add semicolon

* Add forgotten static

* More fixes

* Update axisCount to be array

* More debugging

* Add forgotten index to ready check

* Add path logging

* Missing parenthesis

* Add missing slash

* Fix axis count being reset to 0

* Fix missing paren

* Test polling joystick button events

* Major updates

* Fix missing array index

* Fix another missing array index

* Update example

* dumb logging

* Wrong constant for ev.code handling

* More dumb logging

* Remove some logging

* Add FPS to gamepad info example and try for max FPS

* tweak

* Revert example

* Add fps back

* Clean up after merge

* Switch axisCount to be an array
  • Loading branch information
michaelfiber committed Oct 14, 2023
1 parent 781f717 commit 18bedbd
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
20 changes: 17 additions & 3 deletions examples/core/core_input_gamepad_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,29 @@ int main(void)

ClearBackground(RAYWHITE);

for (int i = 0; i < 4; i++) // by default rcore.h has a MAX_GAMEPADS of 4 so mimmic that here.
for (int i = 0; i < 4; i++) // by default rcore.h has a MAX_GAMEPADS of 4 so mimmic that here.
{
if (IsGamepadAvailable(i))
{
DrawText(TextFormat("Gamepad:\n\tName: %s\n\tAxes: %d", GetGamepadName(i), GetGamepadAxisCount(i)), 10, y, 20, BLACK);
y += 40;
DrawText(TextFormat("Gamepad name: %s", GetGamepadName(i)), 10, y, 20, BLACK);
y += 30;
DrawText(TextFormat("\tAxis count: %d", GetGamepadAxisCount(i)), 10, y, 20, BLACK);
y += 30;
for (int axis = 0; axis < GetGamepadAxisCount(i); axis++)
{
DrawText(TextFormat("\tAxis %d = %f", axis, GetGamepadAxisMovement(i, axis)), 10, y, 20, BLACK);
y += 30;
}
for (int button = 0; button < 32; button++)
{
DrawText(TextFormat("\tButton %d = %d", button, IsGamepadButtonDown(i, button)), 10, y, 20, BLACK);
y += 30;
}
}
}

DrawFPS(GetScreenWidth() - 100, 100);

EndDrawing();
}

Expand Down
2 changes: 1 addition & 1 deletion src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ int GetGamepadButtonPressed(void)
// Get gamepad axis count
int GetGamepadAxisCount(int gamepad)
{
return CORE.Input.Gamepad.axisCount;
return CORE.Input.Gamepad.axisCount[gamepad];
}

// Get axis movement vector for a gamepad
Expand Down
2 changes: 1 addition & 1 deletion src/rcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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
Expand Down
2 changes: 1 addition & 1 deletion src/rcore_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void PollInputEvents(void)

// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
//CORE.Input.Gamepad.axisCount = 0;

// Register previous touch states
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
Expand Down
4 changes: 2 additions & 2 deletions src/rcore_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ void PollInputEvents(void)

// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
//CORE.Input.Gamepad.axisCount = 0;
// Keyboard/Mouse input polling (automatically managed by GLFW3 through callback)

// Register previous keys states
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void PollInputEvents(void)
CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1f);
CORE.Input.Gamepad.currentButtonState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1f);

CORE.Input.Gamepad.axisCount = GLFW_GAMEPAD_AXIS_LAST + 1;
CORE.Input.Gamepad.axisCount[i] = GLFW_GAMEPAD_AXIS_LAST + 1;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void PollInputEvents(void)

// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
//CORE.Input.Gamepad.axisCount = 0;

// Register previous keys states
for (int i = 0; i < MAX_KEYBOARD_KEYS; i++)
Expand Down Expand Up @@ -1847,7 +1847,7 @@ static void InitGamepad(void)
}

ioctl(platform.gamepadStreamFd[i], JSIOCGNAME(64), &CORE.Input.Gamepad.name[i]);
ioctl(platform.gamepadStreamFd[i], JSIOCGAXES, &CORE.Input.Gamepad.axisCount);
ioctl(platform.gamepadStreamFd[i], JSIOCGAXES, &CORE.Input.Gamepad.axisCount[i]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rcore_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ void PollInputEvents(void)

// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
//CORE.Input.Gamepad.axisCount = 0;

// Register previous touch states
for (int i = 0; i < MAX_TOUCH_POINTS; i++) CORE.Input.Touch.previousTouchState[i] = CORE.Input.Touch.currentTouchState[i];
Expand Down
4 changes: 2 additions & 2 deletions src/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void PollInputEvents(void)

// Reset last gamepad button/axis registered state
CORE.Input.Gamepad.lastButtonPressed = 0; // GAMEPAD_BUTTON_UNKNOWN
CORE.Input.Gamepad.axisCount = 0;
//CORE.Input.Gamepad.axisCount = 0;
// Keyboard/Mouse input polling (automatically managed by GLFW3 through callback)

// Register previous keys states
Expand Down Expand Up @@ -799,7 +799,7 @@ void PollInputEvents(void)
CORE.Input.Gamepad.axisState[i][j] = gamepadState.axis[j];
}

CORE.Input.Gamepad.axisCount = gamepadState.numAxes;
CORE.Input.Gamepad.axisCount[i] = gamepadState.numAxes;
}
}
}
Expand Down

0 comments on commit 18bedbd

Please sign in to comment.