Game Development Reference
In-Depth Information
HAL. While there is nothing for DirectInput to hardware accelerate, it does provide
an important service, which is to expose the capabilities of the user input hardware.
For example, a USB game controller might have a rumble or force-feedback feature.
If it does, DirectInput will give your game a way to detect it and use it to make your
game more interesting.
XInput is Microsoft
s answer to DirectInput, but it is a simpler and somewhat less capa-
ble system. It has a few limitations that DirectInput never had, such as only supporting
certain controllers, a four controller limit, limited support for force feedback, no support
for keyboards or mice, and others. While I ' m certainly for simplification of APIs, I
never like to lose functionality, even if I have to dig into the lower layers a bit more.
Windows can certainly grab user input with DirectInput or XInput. Mouse and key-
board messages are well understood by a Win32 programmer the moment he creates
his first Win32 application. You might not be aware that the Win32 Multimedia Plat-
form SDK has everything you need to accept messages from your joystick. You don
'
t
even need DirectInput for that, so why bother? Straight Win32 code does not expose
every feature of all varieties of joysticks or PC game controller pads. For example, you
can grab input from a Logitech PC gamepad without DirectInput with this code:
'
bool CheckForJoystick(HWND hWnd)
{
JOYINFO joyinfo;
UINT wNumDevs, wDeviceID;
BOOL bDev1Attached, bDev2Attached;
if((wNumDevs = joyGetNumDevs()) == 0)
return false;
bDev1Attached = joyGetPos(JOYSTICKID1,&joyinfo) != JOYERR_UNPLUGGED;
bDev2Attached = joyGetPos(JOYSTICKID2,&joyinfo) != JOYERR_UNPLUGGED;
if(bDev1Attached)
joySetCapture(hWnd, JOYSTICKID1, 1000/30, true);
if (bDev2Attached)
joySetCapture(hWnd, JOYSTICKID2, 1000/30, true);
return true;
}
After this code runs, Windows will begin sending messages to your game such as
MM_JOY1MOVE and MM_JOY2BUTTONDOWN . You might feel that this simple code is
preferable to the much larger initialization and required polling needed by DirectInput,
but DirectInput gives you access to the entire device
all the buttons, the rumble, force
feedback, and so on. The Windows Multimedia Platform SDK only gives you the most
basic access to joystick messages.
 
Search WWH ::




Custom Search