Game Development Reference
In-Depth Information
For that reason, I focus on
Windows since it is an easy platform to own and experiment with.
First, we
mind numbing
category a bit more than
interesting.
'
ll play with the hardware.
Getting the Device State
No matter what platform you are on or what type of device you use
keyboard,
mouse, joystick, and so on
ll need to understand the techniques and subtleties
of getting and controlling the state of your input devices. We
you
'
'
ll start by working at
the lowest level, and then we
ll work our way up the input device food chain. The
interfaces to input devices are completely dependent on the platforms you use and
to some extent any middleware you might be using. Many 3D graphics engines also
provide APIs to all the input hardware. Regardless of the API used or devices they
control, there are two schemes for processing user input:
'
n Polling: This method minimizes the layers of code between you and the hard-
ware, and it requires an application to query each device to find out its state.
Your code should react to the state accordingly, usually comparing it against a
previous state and calling an input handler if anything changed. The APIs to
accomplish this are typically unique to the hardware.
n Callbacks or messages: This method is more common in advanced game
engines that handle the low level stuff for you. Here you just register input
device callbacks based on which devices you care about, and when they change
state, your callback will get control. They poll at the low level just like DirectX
would, but state changes are detected for you, which launches your callback.
Meaningful changes in hardware state should be translated into a game event,
whether you use a polling method or callback method. With a little work you can
structure your code to do this.
Of course, every platform operates a little differently, but the code looks very similar;
mouse buttons still go up and down, and the entire device moves on a two-
dimensional plane. It ' s not crazy to assume that most device-handling code reflects
the nature of the specific device.
n Buttons: Theywillhaveupanddownstates.Thedownstatemighthaveananalog
component. Most game controllers support button pressure as an 8-bit value.
n One-axis controllers: They will have a single analog state, with zero represent-
ing the unpressed state. Game controllers usually have analog triggers for use in
features such as accelerators in driving games.
 
 
Search WWH ::




Custom Search