Racing Wheel, Flight Stick and Gamepad Support for Torque (Windows)
by Nick "Dig" Koirala · 06/18/2003 (9:56 am) · 49 comments
Download Code File
These files just need to be added to the engine, overwriting the existsing files and then do a build of the engine. This code implements each input device seperately so you can use multiple devices at the same time. Make sure to check your prefs.cs file and enable the relavant input devices if necessary. In scripts the input devices are referenced as follows.
Standard
--------
keyboard0
mouse0
joystick0
Additional
----------
gamepad0
driving0
flight0
More information in the readme.txt file.
Based on Kurtis Seebaldt's resource for adding Gamepad Support.
I'm working on an updated options dialog to make use of this support, I'll upload that as a resource if its useful.
These files just need to be added to the engine, overwriting the existsing files and then do a build of the engine. This code implements each input device seperately so you can use multiple devices at the same time. Make sure to check your prefs.cs file and enable the relavant input devices if necessary. In scripts the input devices are referenced as follows.
Standard
--------
keyboard0
mouse0
joystick0
Additional
----------
gamepad0
driving0
flight0
More information in the readme.txt file.
Based on Kurtis Seebaldt's resource for adding Gamepad Support.
I'm working on an updated options dialog to make use of this support, I'll upload that as a resource if its useful.
About the author
#2
06/19/2003 (2:42 pm)
um, I've compiled these files in, but how do I enable the joysticks (Wheel in my case)? Do I have to put enableDriving(); somewhere?
#3
you also might need to put enableDriving(); in your code before you can access the wheel.
It works on my system without an explicit call to enableDriving();
check to console to ensure that its all working use echoInputState();
ALSO make sure that the wheel is mapped to something, check in ~/client/config.cs and make sure some binding is using the wheel (like yaw).
To work properly the default.bind.cs file needs slightly different actions to those of the mouse, I'm updating that along with the control options gui and should put it up in a few days. In the meantime look here the last to blocks of code might help with adding the right actions....
I hope that helps, as I said I'll add another resource soon which might help clarify things further...
06/19/2003 (7:23 pm)
in your prefs.cs file you need $pref::Input::DrivingEnabled = 1you also might need to put enableDriving(); in your code before you can access the wheel.
It works on my system without an explicit call to enableDriving();
check to console to ensure that its all working use echoInputState();
ALSO make sure that the wheel is mapped to something, check in ~/client/config.cs and make sure some binding is using the wheel (like yaw).
To work properly the default.bind.cs file needs slightly different actions to those of the mouse, I'm updating that along with the control options gui and should put it up in a few days. In the meantime look here the last to blocks of code might help with adding the right actions....
I hope that helps, as I said I'll add another resource soon which might help clarify things further...
#4
- Keyboard is Enabled and active.
...
- Driving Wheel is Enabled but inactive.
and my binds are
vehicleDriverMap.bind( driving0, "xaxis", yaw );
vehicleDriverMap.bind( driving0, "yaxis", pitch );
06/19/2003 (7:55 pm)
Yeah, I tried all of that. I get- Keyboard is Enabled and active.
...
- Driving Wheel is Enabled but inactive.
and my binds are
vehicleDriverMap.bind( driving0, "xaxis", yaw );
vehicleDriverMap.bind( driving0, "yaxis", pitch );
#5
I'll keep looking into it....
06/19/2003 (8:07 pm)
hmmmm.... try enableDriving(); in the console once the game has started, if that works then you'll need to script it in somewhere.I'll keep looking into it....
#6
- directInput Driving Wheel failed to enable!
when I do that. The steering wheel works in the control panel with no problems.
If I setup the joystick0 then the wheel actually affects it a little. It doesn't behave like the steering wheel should though.
06/19/2003 (8:13 pm)
I get - directInput Driving Wheel failed to enable!
when I do that. The steering wheel works in the control panel with no problems.
If I setup the joystick0 then the wheel actually affects it a little. It doesn't behave like the steering wheel should though.
#7
You probably need to modify the code in default.bind.cs to get a proper analogue input device working properly....
06/19/2003 (9:10 pm)
What kind of wheel do you have? Maybe its being reported to DirectX as a Joystick instead of a wheel.You probably need to modify the code in default.bind.cs to get a proper analogue input device working properly....
#8
I have a Thrustmaster Modena 360 USB wheel. DXDiag doesn't give me much info beyond "Controller ID 1" and the port that it's attached to. It shows a picture of the wheel and foot pedals in the control panel, so I'm assuming it's picking it up as a wheel.
When the Wheel is setup as Joystick0 to turn the corner I have to move it all the way to the left and the wheel turns a little bit. Recenter the wheel and turn it all the way to the left again and it turns a little more. Recenter it and go back to the left again... etc etc until it turns all the way to the left.
06/20/2003 (8:17 am)
Alrighty then... GarageGames just ate my reply. Never seen that before.I have a Thrustmaster Modena 360 USB wheel. DXDiag doesn't give me much info beyond "Controller ID 1" and the port that it's attached to. It shows a picture of the wheel and foot pedals in the control panel, so I'm assuming it's picking it up as a wheel.
When the Wheel is setup as Joystick0 to turn the corner I have to move it all the way to the left and the wheel turns a little bit. Recenter the wheel and turn it all the way to the left again and it turns a little more. Recenter it and go back to the left again... etc etc until it turns all the way to the left.
#9
06/20/2003 (4:26 pm)
That happens if you use the mouse code to yaw instead of the joystick code in default.bind.cs, take a look at the flight stick resource which has how to edit default.bind.cs to qork properly with anagloue input devices...
#10
-- I just backed out this code and did a clean build. This patch is affecting the frame rate.
06/20/2003 (5:42 pm)
Great! It's now working, BUT my frame rate is dropping from 50 to 20FPS when I turn the wheel. I've also determined that it isn't due to the yaw2/pitch2 functions. It's either torque or this code. I'm going to copy the old joystick functions back and see if the frame rate drops then.-- I just backed out this code and did a clean build. This patch is affecting the frame rate.
#11
06/20/2003 (9:16 pm)
Oh dear, I"ll check through it, I don't notice any slow down on my pitiful machine but I'll have a look and see if anythign could be causing it...
#12
Not much I can change about it then!
Still working on the options Dialog changes, I've got a bit distracted lately, they should be up soon though...
07/17/2003 (9:21 pm)
I don't think this code is causing any significant change in frame rate on any of the machine I could test it on...Not much I can change about it then!
Still working on the options Dialog changes, I've got a bit distracted lately, they should be up soon though...
#13
(c:\torque\torque\engine\console\consoletypes.h(11) : warning C4005: 'Offset' : macro redefinition
c:\torque\torque\engine\platform\event.h(14) : see previous definition of 'Offset')
I am use version 1.1.2
07/30/2003 (10:21 am)
I get 48 warnings and they are all the same.(c:\torque\torque\engine\console\consoletypes.h(11) : warning C4005: 'Offset' : macro redefinition
c:\torque\torque\engine\platform\event.h(14) : see previous definition of 'Offset')
I am use version 1.1.2
#14
07/30/2003 (10:12 pm)
If it still compiles I don't think it matters, I get hundreds of warnings compiling Torque under MingW and it has no effect on the exe as far as I can tell. If its not compiling at all it might need the HEAD version...
#15
An old game-port style wheel, flight stick, etc. will cause the kind of slowdown that you're talking about. The technology hasn't changed since the Apple II's were out -- the only difference between the Apple II joysticks and the gameport joysticks were the connector, and later Apple's used the same connector...
The traditional mechanism for reading a gameport joystick looks like this (this is either for borland or watcom, not sure how old the code is I lifted this out of):
This is the traditional (Apple II, pre-Windows era) mechanism to read the game port, you write out what axis you are interested in, and you time it until they clear out. Once they clear out, you know the value on the axis. It is necessary to read each axis separately or else you get interference -- this is what lead to the move the joystick to all the corners, so the interference could be figured in and you could poll more than one axis simultaneously.
A USB controller doesn't have this 'keep polling the port' bit. An interupt arrives, the computer processes it, the data that arrived on the USB port has the stick's position. For a poll, the computer might have to send a message out first. At any rate, the joystick does all the work and just reports "this is where I am." There should be virtually no performance hit from a USB device, because of how it works. Should be the same as for a mouse or keyboard.
Some of the "hybrid" wheels/sticks still do the stupid poll routine; you can identify these sticks by the presence of a "joystick to usb" wire... Most of these still work correctly USB, but some manufacturers were stupid about it.
08/23/2003 (7:02 pm)
Neil: How old is the wheel?An old game-port style wheel, flight stick, etc. will cause the kind of slowdown that you're talking about. The technology hasn't changed since the Apple II's were out -- the only difference between the Apple II joysticks and the gameport joysticks were the connector, and later Apple's used the same connector...
The traditional mechanism for reading a gameport joystick looks like this (this is either for borland or watcom, not sure how old the code is I lifted this out of):
unsigned short int ReadStick(unsigned char axis)
{
register unsigned short int count = 0xFFFF;
register unsigned char mask = 1 << (axis - 1);
if (!(joystickcap & mask)) return -1;
_disable();
outp(0x201,mask);
while ((++count != 0xFFFF) && (inp(0x201) & mask)) {};
while (inp(0x201) & joystickcap) {};
_enable();
return count;
}This is the traditional (Apple II, pre-Windows era) mechanism to read the game port, you write out what axis you are interested in, and you time it until they clear out. Once they clear out, you know the value on the axis. It is necessary to read each axis separately or else you get interference -- this is what lead to the move the joystick to all the corners, so the interference could be figured in and you could poll more than one axis simultaneously.
A USB controller doesn't have this 'keep polling the port' bit. An interupt arrives, the computer processes it, the data that arrived on the USB port has the stick's position. For a poll, the computer might have to send a message out first. At any rate, the joystick does all the work and just reports "this is where I am." There should be virtually no performance hit from a USB device, because of how it works. Should be the same as for a mouse or keyboard.
Some of the "hybrid" wheels/sticks still do the stupid poll routine; you can identify these sticks by the presence of a "joystick to usb" wire... Most of these still work correctly USB, but some manufacturers were stupid about it.
#16
08/23/2003 (7:12 pm)
It's about 2 years old. It's a gameport with a usb adapter on it. I'm using the usb ending.
#17
10/24/2004 (10:13 pm)
What's a good value to use for $pref::Input::DeadZone and $pref::Input::Sensitivity? The gamepad seems to be working but yaw2 and pitch2 don't seem to respond very well to the analog controller.
#18
First off I just bought the torque sdk so im rather new to it.. though I am by far not new to game dev... I think I might be able to fix this problem but we will see what you guys think..
I have a joystick and after some tinkering went into the binds and changed the yaxis and xaxis to the analog buttons.... but now when i hold the button like up or what ever it does not repeat the function... so basicly i have to tap up alot just to get my character to do anything..... any help here?
11/10/2004 (6:58 am)
Well this is my first responce in the toque comm... so lols here it goes....First off I just bought the torque sdk so im rather new to it.. though I am by far not new to game dev... I think I might be able to fix this problem but we will see what you guys think..
I have a joystick and after some tinkering went into the binds and changed the yaxis and xaxis to the analog buttons.... but now when i hold the button like up or what ever it does not repeat the function... so basicly i have to tap up alot just to get my character to do anything..... any help here?
#19
but i have to press it each time to get a little movement cant just hold it
11/10/2004 (7:06 am)
Let me rephrase some of that.. I have changed my zaxis and Rzaxis to the yaw and pitch functions...but i have to press it each time to get a little movement cant just hold it
#20
Look there for a better explanation of the code involved with this fix. You may not
be using yaw2 and pitch2...
11/10/2004 (8:27 am)
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=3780Look there for a better explanation of the code involved with this fix. You may not
be using yaw2 and pitch2...

Torque Owner Gilles Jr Lafrance
Really nice job... all in one. Your "updated controls options dialog" will be really usefull too. Thanks !