?/TD>
Microsoft DirectX 9.0

Buffered and Immediate Data


Microsoft?DirectInput?supplies two types of data: buffered and immediate. Buffered data is a record of events that are stored until an application retrieves them. Immediate data is a snapshot of the current state of a device.

You might use immediate data in an application that is concerned only with the current state of a device—for example, a flight combat simulation that responds to the current position of the joystick and the state of one or more buttons. Buffered data might be the better choice where events are more important than states—for example, in an application that responds to movement of the mouse and button clicks. You can also use both types of data, as you might, for example, if you wanted to get immediate data for joystick axes but buffered data for the buttons.

Note  If you are using Action Mapping, you will want to retrieve buffered data because the buffered data packets contain the application-defined data associated with the input. Doing so means that you are responsible for tracking the position of absolute axes, since events but not states are reported in buffered data packets.

An application retrieves immediate data by calling the IDirectInputDevice8::GetDeviceState method. As the name implies, this method returns the current state of the device—for example, whether each button is up or down. The method provides no data about what has happened with the device since the last call, apart from implicit information that you can derive by comparing the current state with the last one. For example, if a user presses and releases a button between two calls to IDirectInputDevice8::GetDeviceState, your application will never be given this input. On the other hand, if the user is holding a button down, IDirectInputDevice8::GetDeviceState continues reporting that fact until the user releases it.

This way of reporting the device state is different from the way Microsoft Windows?reports events with one-time messages such as WM_LBUTTONDOWN. It is more like the results from the Microsoft Win32® GetKeyboardState function. If you are polling a device with IDirectInputDevice8::GetDeviceState, you are responsible for determining what constitutes a button click, a double-click, a single keystroke, and so on, and for ensuring that your application does not keep responding to a button-down or key-down state when it's not appropriate to do so.

With buffered data, events are stored until you are ready to deal with them. Every time a button or key is pressed or an axis is moved, information about the event is placed in a DIDEVICEOBJECTDATA structure in the buffer. If the buffer overflows, new data is lost. Your application reads the buffer with a call to IDirectInputDevice8::GetDeviceData. You can read any number of items at a time.

Reading an item normally deletes it from the buffer, but you also have the choice of peeking without deleting.

To get buffered data, you must first set the buffer size with the IDirectInputDevice8::SetProperty or IDirectInputDevice8::SetActionMap method. (See the example under Device Properties.) Set the buffer size before acquiring the device for the first time. For reasons of efficiency, the default size of the buffer is 0, and you cannot obtain buffered data unless you change this value. The size of the buffer is measured in items of data for that type of device, not in bytes.

Check the value of the pdwInOut parameter after a call to the IDirectInputDevice8::GetDeviceData method. The number of items retrieved from the buffer is returned in this variable.

Note  For devices that do not generate interrupts, such as analog joysticks, DirectInput does not obtain any data until you call the IDirectInputDevice8::Poll method. For more information, see Polling and Event Notification.

For examples of retrieving buffered data, see IDirectInputDevice8::GetDeviceData.

See also:



© 2002 Microsoft Corporation. All rights reserved.