Torque Joystick Fix
by James Lupiani · 03/16/2002 (1:12 pm) · 7 comments
Download Code File
The changes are relatively minor. If you're a control freak, you can go through this list and make the changes yourself. If you're more pragmatic, just download the attached file, which should work with Torque releases up to this date.
The only problems I've had (and only after an OS reinstall) were errors that cropped up with setting the keyboard's data format (which shouldn't really have to be done anyway, but evidently using the predefined constructs it won't work anyway.)
You should probably copy dinput8.lib from the DX8 SDK to the lib/directx8 directory in the Torque SDK. Add it to the project's library list.
The first changes are in winDirectInput.h under platformWin32. To prevent DirectX from giving errors, add the following right above #include:
#define DIRECTINPUT_VERSION DIRECTINPUT_HEADER_VERSION
This will prevent warnings from the DX8 headers.
For the DInputManager class, we're not accessing the DInput library at runtime, so we don't need the HMODULE. Also, the structure should be redefined for version 8.
Change
That's it for this file. Now let's move on to the implementation (winDirectInput.cc).
As before, we're not linking at runtime, so we don't need that stuff. Remove the typedef at the beginning of the file, and all references to mDInputLib.
The last change for this file is in DInputManager::enable. Basically, remove everything from "mDInputLib = LoadLibrary( "DInput.dll" );" and the if block directly beneath it. Replace it with the following code:
Now, on to the device class (winDInputDevice.h) itself. Like the manager class, the changes here involve removing unneeded variables and changing the struct versions. As before, put "#define DIRECTINPUT_VERSION DIRECTINPUT_HEADER_VERSION" above the dinput.h include.
Change:
and further down:
And finally, in winDInputDevice.cc:
Remove references to mDevice2 in the constructor and destroy() function. In the processImmediate() function:
And in DInputDevice::create():
That's it! The engine should now work just fine with the joystick. On the script side, I should note that I had to add some code to my game's init.cs. It was necessary to enable it here instead of when the game starts so that the joystick could be configured from the options dialog.
Enjoy!
The changes are relatively minor. If you're a control freak, you can go through this list and make the changes yourself. If you're more pragmatic, just download the attached file, which should work with Torque releases up to this date.
The only problems I've had (and only after an OS reinstall) were errors that cropped up with setting the keyboard's data format (which shouldn't really have to be done anyway, but evidently using the predefined constructs it won't work anyway.)
You should probably copy dinput8.lib from the DX8 SDK to the lib/directx8 directory in the Torque SDK. Add it to the project's library list.
The first changes are in winDirectInput.h under platformWin32. To prevent DirectX from giving errors, add the following right above #include
#define DIRECTINPUT_VERSION DIRECTINPUT_HEADER_VERSION
This will prevent warnings from the DX8 headers.
For the DInputManager class, we're not accessing the DInput library at runtime, so we don't need the HMODULE. Also, the structure should be redefined for version 8.
Change
HMODULE mDInputLib;
LPDIRECTINPUT mDInputInterface;toLPDIRECTINPUT8 mDInputInterface;
That's it for this file. Now let's move on to the implementation (winDirectInput.cc).
As before, we're not linking at runtime, so we don't need that stuff. Remove the typedef at the beginning of the file, and all references to mDInputLib.
The last change for this file is in DInputManager::enable. Basically, remove everything from "mDInputLib = LoadLibrary( "DInput.dll" );" and the if block directly beneath it. Replace it with the following code:
hr = DirectInput8Create( winState.appInstance, DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&mDInputInterface, NULL );
if ( DI_OK == hr )
{
enumerateDevices();
mEnabled = true;
return true;
}Now, on to the device class (winDInputDevice.h) itself. Like the manager class, the changes here involve removing unneeded variables and changing the struct versions. As before, put "#define DIRECTINPUT_VERSION DIRECTINPUT_HEADER_VERSION" above the dinput.h include.
Change:
static LPDIRECTINPUT smDInputInterface;
static bool smIsDX5;tostatic LPDIRECTINPUT8 smDInputInterface;
and further down:
LPDIRECTINPUTDEVICE mDevice;
LPDIRECTINPUTDEVICE2 mDevice2;toLPDIRECTINPUTDEVICE8 mDevice;
And finally, in winDInputDevice.cc:
// Static class data: LPDIRECTINPUT DInputDevice::smDInputInterface; bool DInputDevice::smIsDX5;should be changed to
LPDIRECTINPUT8 DInputDevice::smDInputInterface;
Remove references to mDevice2 in the constructor and destroy() function. In the processImmediate() function:
if ( mDevice2 )
mDevice2->Poll();can now bemDevice->Poll();
And in DInputDevice::create():
mDevice->QueryInterface( IID_IDirectInputDevice2, (void**) &mDevice2 );
mDeviceCaps.dwSize = ( smIsDX5 ? sizeof( DIDEVCAPS ) : sizeof( DIDEVCAPS_DX3 ) );boils down tomDeviceCaps.dwSize = sizeof( DIDEVCAPS );
That's it! The engine should now work just fine with the joystick. On the script side, I should note that I had to add some code to my game's init.cs. It was necessary to enable it here instead of when the game starts so that the joystick could be configured from the options dialog.
$enableDirectInput = "1"; activateDirectInput(); enableJoystick();
Enjoy!
About the author
Programmer for Sickhead Games
Recent Blogs
• Updated zlib (Security Fix)• Export Material Flags to Console
• Plan for James Lupiani
• Star Rendering
#2
03/17/2002 (2:38 pm)
it seems to work fine, keyboad and mouse all handle as before.
#3
03/19/2002 (4:20 am)
Oy, one-upped again. +)
#4
03/19/2002 (3:37 pm)
The DX checkin I made yesterday is just a quick fix; the input code still needs to be updated to support DX8 natively and for that I'll use your stuff.
#5
03/20/2002 (2:42 am)
Woohoo!
#6
winDirectInput.obj : error LNK2001: unresolved external symbol _DirectInput8Create@20
../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
torqueDemo_DEBUG.exe - 2 error(s), 1 warning(s)
what did i do wrong?
08/27/2002 (1:16 pm)
i just downloaded the files and placed them in platformWin32. they replaced the files there. Then i compiled the program and it came up with 2 linking errors.winDirectInput.obj : error LNK2001: unresolved external symbol _DirectInput8Create@20
../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
torqueDemo_DEBUG.exe - 2 error(s), 1 warning(s)
what did i do wrong?
#7
To do this in Visual Studios 6 its 'project->setting->link and add dinput8.lib to the project options box down the bottom. I thought adding dxguid.lib to projects covered the whole library but i guess not. :/
03/01/2005 (6:25 pm)
Michael Heining: i got the same error as you and fixed it by adding the dinput8.lib to my project.To do this in Visual Studios 6 its 'project->setting->link and add dinput8.lib to the project options box down the bottom. I thought adding dxguid.lib to projects covered the whole library but i guess not. :/
Torque Owner Rick Overman
--Rick