LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: uwi2k2 on November 23, 2022, 12:43:53

Title: Understanding the Gamepad-Mapping
Post by: uwi2k2 on November 23, 2022, 12:43:53
Hello there,

in my game i implemented gamepad controlling.
But different gamepads behave differently.

This is were the MAPPING comes in i guess. But i just donÃ,´t understand how to use it.

in my code i load a mapping txt file with this text in the first line: "# Game Controller DB for SDL in 2.0.16 format".
It has about 1800 controllers listed.

I guess this file is already loaded by default but i was not sure.

Anyway .... all my controllers behave differently.
Button indexes or AnaogStick indexes are all very different form controller to controller.

So my question is: HOW do i make use of this loaded mapping file?
I checked almost all functions about this and just donÃ,´t see any that seem to have something to do with the mapping.

I would be very thankful if someone can explain the basic usage of the mapping to me.

thanks in advance!
cu
kai
Title: Re: Understanding the Gamepad-Mapping
Post by: Lintfordpickle on February 02, 2023, 22:11:06
Hi,
for the functionality which is mapped from other libraries, you'd be better off just using the original documentation. In this case, the glfwGetGamepadState is pretty well described here: https://www.glfw.org/docs/latest/input.html#gamepad

as for how to use it within Java, you just need to instantiate a ByteBuffer object, which will be filled with the state of the gamepad and create a new instance of GLFWGamepadState.


mDataByteBuffer = MemoryUtil.memAlloc(GLFWGamepadState.SIZEOF);
mGamepadState = new GLFWGamepadState(mDataByteBuffer);


You can then poll the gamepad state when you're handling input like this:


if(mGamepadState .buttons(GLFW.GLFW_GAMEPAD_BUTTON_X) == GLFW.GLFW_PRESS)
    shoot();


Not all controllers have a gamepad-mapping available, so you first need to check the availability of the mapping by calling glfwJoystickIsGamepad