LWJGL3 - Precise Gamepad Input

From what I can gather, LWJGL3 (GLFW) only offers polling when checking up on Joystick/Gamepad input, no callbacks.

If I’m not mistaken, this means I need to poll the input data on each frame (update), which means that the precision of button presses will be dependent on how often the polling is made.

I find this is a problem when requiring precise timing of inputs, for, say, a game requiring key combos, like a fighting game or the like.

So far, the best solution I can come up with is to run the gamepad polling in an independent thread so as to try and make it as fast and stable as possible, and then check the input data from the main game thread when processing the game logic.

Is this approach sound? Am I missing something? Should I throw myself out of a window?

:clue:

I don’t think that there is any other possibility (on any OS and/or any device) other than polling. Also DirectX/DirectInput uses this approach. I.e. you must call a specific poll function/query the current state.
Even if there was some framework/library providing an event-based API, it will under the hood realize it via polling of the device.
On Win32 there is joySetCapture (Winmm.dll) to capture a joystick to a Win32 window and have it send joystick messages to the window’s message queue, so that the joystick events which have accumulated during a frame could be processed in GLFW via glfwPollEvents(). But even joySetCapture uses polling internally.

The GLFW joystick handling APIs appear to be full of fail… there is no event-callback way of doing joysticks, so basically a bit useless for most games.

Cas :slight_smile:

So it would be preferable to use an alternate libray for joystick handling then?

Use libgdx I’d say.

Cas :slight_smile:

Looks like, on Windows DirectInput can also be configured to have it record input events into a user-supplied buffer. Which is exactly what libgdx-controller (and the contained OIS library) does, because it also uses DirectInput (and XInput for XBox controllers). GLFW could also implement that, since it also already uses DirectInput/XInput on Windows.
More information on MSDN (section “4. Set up the device.”)
GLFW already has a feature request for that, too: https://github.com/glfw/glfw/issues/601

libGDX looks great, but I’m interested in a lower level approach right now. ;D