GLFW Joystick / Controller input questions

Started by Cornix, June 05, 2018, 21:16:59

Previous topic - Next topic

Cornix

Hi everybody,

I have a small question about the implementation of the GLFW Joystick API. When reading the documentation about glfwGetJoystickAxes it appears to me, that a game would only need to call this function once. A reference to the returned array could simply be kept and its values would be updated automatically. Is this correct?
I am asking because in LWJGL3 the values within the FloatBuffer that is returned by the binding do not update. I have to call the glfwGetJoystickAxes continuously. Is this the intended behaviour? Is this generating garbage? What is the preferred way to poll joystick inputs?

Thanks for the answers!

KaiHH

It would work that way iff there was some other function in GLFW which updated the joystick axes state, such as glfwPollEvents(), but there isn't. Joystick axes state is not sent to the application via window message events, but has to be polled from the device manually and continuously.
I am sure that Escape Analysis will eliminate the allocation of the FloatBuffer instance that is merely mapped to the returned pointer address of the GLFW call if you have the call in a tight loop/method.
You should not be too worried about repeatedly calling that method.