Hello Guest

Understanding the Gamepad-Mapping

  • 1 Replies
  • 1387 Views
Understanding the Gamepad-Mapping
« 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

Re: Understanding the Gamepad-Mapping
« Reply #1 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.

Code: [Select]
mDataByteBuffer = MemoryUtil.memAlloc(GLFWGamepadState.SIZEOF);
mGamepadState = new GLFWGamepadState(mDataByteBuffer);

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

Code: [Select]
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