Joystick Support in PrBoom 2.5.0
Posted by postfuturist on 2009-04-25 13:08:22

PrBoom is a fairly conservative port of the original Doom source code for modern computers. It is very stable, incorporates a lot of improvements and additions to the Doom engine from other ports. It has one shortcoming, however. The joystick support is awful. You can only use the first four buttons on your joystick in a fixed configuration and one pair of axes for walking forward and backward and turning. This makes playing the game with a joystick not a compelling experience.
I recently picked up a Logitech Dual Action USB game controller. It's a fantastic controller, especially for the sub $20 range. It is in a standard modern console configuration with a D-Pad, two analog sticks, and 12 buttons (4 face buttons, 4 trigger buttons, "start" and "select" style buttons, and two buttons activated by depressing the analog sticks). The joystick is perfect for using with console emulators. I am somewhat more of a console gamer than a traditional PC gamer. I enjoy the modern game controller layout quite a bit. I actually enjoy playing first person shooters, like Doom, as much with a good controller as I do with the keyboard/mouse combination.
I decided to do something about the poor joystick / game controller support in PrBoom. Instead of 4 buttons with fixed functions, I changed the code to treat the buttons (as many as you want) as key presses and so can be configured for any function. I also changed the analog stick controls to be in a more modern console style where the left stick is for moving (backward and forward and side to side) while the right stick is for turning. It took a couple hours to get into the source code, figure out what's going on and implement the changes. At first I tried using Code::Blocks as the IDE, but that proved to be an unsatisfactory experience, so I switched over to Netbeans 6.7 M3. Netbeans has fantastic autocomplete support for code written in C. It's basically flawless.
I have a few more changes I'd like to make. I would like to add some configuration for the behavior of the various joystick axes so people can set up the controls however they like. Also, I would like the option of using the various axes like buttons, too. This would allow, for example, using the various directions on the D-Pad for different functions. PrBoom is missing the ability to assign a key/button to cycle through the available weapons. This is not a problem on the keyboard, as there are so many keys, but it is not ideal for a game controller, even one with 12 buttons. The sensitivity of the analog control for movement that I added is linear which turns out to be not ideal for fine-grained aiming and careful movement.
Once I've brought the game controller integration of PrBoom into the 21st century, I will try to get my changes merged upstream with PrBoom.


Comment from Tom Maneiro:
Mind you to share your current changes until now? I also would care about better support for gamepads on PrBoom, and well, PrBoom development is pretty much dead these days. I have a couple of cheap Genius MaxFire G-08XU USB pads (ULTRA cheap, but does the job, it's comfortable, and it lasts pretty much forever - plug and frag!). Unfortunately, it's annoying to only be able to use four buttons (this pad has 8 buttons and two axes, more than enough for me, i'm not a "big" gamer), and even more annoying is to play with a LAPTOP keyboard. The idea is to have the laptop plugged to a fat TV (because Ninten-God says "thou shall not play games on a supermarket laptop"), and control Doom entirely with the pad (like the old console ports: i liked the 6-button layout of Sega 32X port), fragging demons and barons in the big screen. Anyway, keep up the hacking effort! I hope to see that code soon. I would not mind to become a betatester or something like that :)
Comment from postfuturist:
I was afraid after posting this that somebody would ask for the changes. Since it is open source, I decided to take the opportunity to create a GitHub account. My changes to prboom can be found here: <a href="http://github.com/deliciousrobots/prboom-joystick" target="_blank" rel="nofollow">http://github.com/deliciousrobots/prboom-joystick</a> . I haven't tested this out in awhile, so you've been warned. Enjoy.
Comment from Tom Maneiro:
Hey, thanks! I'm already used to test "broken"/"untested" things: FFmpeg is my personal favorite :) Let's compile the thing and see what happens...
Comment from Tom Maneiro:
Just compiled and tested the thing... i'm lovin' it! However, one minor issue: joystick axis default mappings are not remappable (useless for those that use el-cheapo 2-axis gamepads, not X-360 pads or better pads, because axis 0 is locked to strafe, NOT to turn), and they're loced in "autorun" mode. There is an easy fix: find the following lines in g_game.c (line 386), and comment out them! <pre> forward -= ((joyaxes[1] * maxforwardmove) / 255); side += ((joyaxes[0] * maxsidemove) / 255); cmd-&gt;angleturn -= ((joyaxes[2] * maxangleturn) / 255);</pre> After rebuilding, just remap the directional keys to your gamepad D-pad, and presto! The perfect setup for a cheap console pad. Thanks again!
Comment from postfuturist:
Awesome, I'm really glad you like it. I'll probably incorporate your changes when I get home. There are a couple other small things I want to fix. I'd also like to make it more configurable, but that would be a lot of work.
Comment from Flandry:
This is good stuff; it's exactly what i need to make the accelerometer -&gt; joystick wrapper in Maemo more useful for the PrBoom port. Two questions: Which exact version did you start with? Do you have a diff from that version to your changes? I used the December svn for the port because of a fix that went in at the time, so i need to know where i'll be starting at for the base. Thanks for sharing.
Comment from postfuturist:
The initial commit on github is vanilla PrBoom 2.5.0. I haven't made changes since my last commit. Got distracted with other things, you know.

    Leave a comment: