What's the best way to access DirectInput from inside a Godot program?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gemini

So… The more research I do on how joysticks work in Godot by default, the more convinced I am that if I want my flight-sim inspired project to work out and work with as many joystick configurations as possible, I need to write my own joystick handler to handle special cases where players have elaborate joystick setups. (I can still use the built-in handling for simpler joysticks and gamepads.)

I’ve done this before back on Windows 98 and since DirectInput hasn’t changed much over the years I imagine the process will be similar. Heck, my old code may even still work! But, the real trick is integrating this into a Godot project, so my question is: What would be the best approach for doing this? Can this be done entirely with GDScript? Will I need to write a separate C/C++ module? C# even? Could it be done using plugins? Or heck, is doing this even possible given how anything integrates with Godot?

I’m just looking for advice on the best approach to integrate such a thing into a Godot project so that I know where to focus my efforts.

:bust_in_silhouette: Reply From: ConnyOnny

Generally it is possible to integrate your own C/C++ code into a Godot game. Start here: GDNative — Godot Engine (3.0) documentation in English
It takes some serious work though.

I wonder what special setups you have in mind that cannot be handled by the Godot engine’s joystick handling code. I found it to be quite flexible.

Also if possible, I recommend to first create your game with Godot’s input handling mechanisms and then at some point look into this topic again (think version 1.1 of your game).

Well, the initial trouble I ran into is that Godot uses SDL-style mapping for joysticks, which is fine for the majority of joysticks out there, but for advanced flightsticks or setups with proper rudder pedals and everything, it simply can’t handle it all since it has to map everything to common gamepad mappings.

For instance, I’m using a Thrustmaster T.Flight HOTAS X joystick which has FIVE axes, a hat, and 12 buttons. Godot recognizes only four of the axes by default and if I attempt to manually map in the fifth one as analog triggers I end up unable to map two of the buttons. In short, I cannot use the entire joystick with Godot’s built-in handling. :frowning:

The game I’m developing will work with keyboard+mouse or a gamepad, but because it’s steeped with flight-sim aspects, I absolutely do not want to leave out people who want to play the game with advanced joystick setups so that they can have total control of their craft without having to rely on things working automatically or at a simpler level.

The plus side is I do still have my old DirectInput joystick code which I wrote years ago. With a little luck, all I’ll have to do is go through the Godot integration process and then just copy-paste the whole thing!

Gemini | 2018-07-27 23:14