Hello Guest

GLFW Joystick / Controller input questions

  • 1 Replies

Offline Cornix

  • *****
  • 488
GLFW Joystick / Controller input questions
« on: June 05, 2018, 21:16:59 »
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!


Offline KaiHH

  • ****
  • 273
Re: GLFW Joystick / Controller input questions
« Reply #1 on: June 05, 2018, 21:38:30 »
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.