Search Tips Advanced Search |
| Delphi Graphics and Game Programming Exposed with DirectX 7.0 by John Ayres Wordware Publishing, Inc. ISBN: 1556226373 Pub Date: 12/01/99
Search this book:
Previous | Table of Contents | Next
### Additional Effect Considerations While this is not meant to be a complete reference to DirectX, there are several more force feedback specific methods that have not been discussed, but may be very useful to applications that incorporate force feedback functionality. In particular, applications may need to determine the status of an effect or the state of the overall force feedback system, send a command to the force feedback system, or modify effect parameters on the fly. #### Retrieving Effect Status There may be times when the application needs to determine if an effect is currently playing or not. This is easily accomplished by calling the GetEffectStatus method of the IDirectInputEffect interface. The GetEffectStatus method is defined as:
    function GetEffectStatus(

    var pdwFlags : DWORD                   // flags indicating the effect status

    ) : HResult;                           // returns a DirectX error code
The only parameter to this method is a variable that will be initialized to one or more flags. The effect is currently playing if the DIEGES_PLAYING flag is present in the pdwFlags variable. #### Retrieving the Force Feedback System State Another useful method of the IDirectInputDevice2 interface is the GetForceFeedbackState method. This method returns a series of flags which indicate the overall state of the force feedback device. The GetForceFeedbackState method is defined as:

    function GetForceFeedbackState(

    var pdwOut: DWORD                      // flags indicating overall device state

    ) : HResult;                           // returns a DirectX error code

    The pdwOut parameter is simply a variable that, upon return, will be initialized with the flags that indicate the overall force feedback system status. This can be a combination of one or more flags from the following table.
Table 8-3: Force feedback state flags Flag | Description
--- | ---
DIGFFS_EMPTY DIGFFS_STOPPED DIGFFS_PAUSED DIGFFS_ACTUATORSON DIGFFS_ACTUATORSOFF DIGFFS_POWERON DIGFFS_POWEROFF DIGFFS_SAFETYSWITCHON DIGFFS_SAFETYSWITCHOFF DIGFFS_USERFFSWITCHON DIGFFS_USERFFSWITCHOFF DIGFFS_DEVICELOST | The device has no downloaded effects. No effects are playing. All active effects are paused. Force feedback actuators are enabled. Force feedback actuators are disabled. Power to the force feedback device is available. Power to the force feedback device is not available. The safety switch is on. The safety switch is off, and the device cannot operate. The force feedback switch is on. The force feedback switch is off, and force feedback effects cannot be played. The device has been unacquired and must be reacquired.
#### Sending Commands to the Force Feedback System There are times when it is necessary to send global commands to the force feedback system. For example, if the user pauses the game, it would be nice to pause all playing effects without having to enumerate them all and call Stop for each one, and then restart them when the user resumes play. This can be accomplished through the SendForceFeedbackCommand method of the IDirectInputDevice2 interface. The SendForceFeedbackCommand method is defined as:
    function SendForceFeedbackCommand(

    dwFlags: DWORD                                // the command value

    ) : HResult;                                  // returns a DirectX error code
The single parameter of this function takes one value from the following table. Table 8-4: Force feedback system commands Command | Description
--- | ---
DISFFC_RESET DISFFC_STOPALL DISFFC_PAUSE DISFFC_CONTINUE DISFFC_SETACTUATORSON DISFFC_SETACTUATORSOFF | Resets the entire device. All effects are destroyed and must be re-created. All actively playing effects are stopped. All actively playing effects are paused. When restarted, they continue playing to the remainder of their duration. New effects cannot be started. Continues playing from a paused state. Turns force feedback actuators on. Turns force feedback actuators off. Effects can still be played but will be ignored by the device.
#### Modifying an Effect at Run Time In order to further customize an effect to reflect changes in the game world, an effect can be modified while it is playing, provided that this is supported by the driver. As we examined earlier, we can use the GetEffectInfo method to determine which parameters can be dynamically changed during effect playback. In practice, we can change any of the parameters at any time; the parameters listed in dwDynamicParams indicate those parameters that can be changed without restarting the effect. Changing a parameter that is not included in dwDynamicParams will cause the force feedback system to stop and then restart the effect. To change an effect’s parameters during playback, call the SetParameters method of the IDirectInputEffect interface. The SetParameters method is defined as:
    function SetParameters(

    var peff: TDIEffect;               // a TDIEffect structure with new parameters

    dwFlags: DWORD                     // control flags

    ) : HResult;                       // returns a DirectX error code
The first parameter contains a TDIEffect structure that contains the new values for the effect parameters to be changed. It is not necessary to initialize the entire structure, only those members containing the new effect parameters. The second parameter contains a series of flags that indicate which members of the TDIEffect structure contain the new information. These are the same flags as returned by the GetEffectInfo method, and are listed in Table 8-1. Some additional flags available with this method control the behavior of the force feedback system when the effect is modified. For example, calling the SetParameters method automatically downloads the effect. This can be disabled by including the DIEP_NODOWNLOAD flag in the second parameter. These additional flags are listed below. Table 8-5: Parameter flags Flag | Description
--- | ---
DIEP_NODOWNLOAD DIEP_NORESTART DIEP_START DIEP_TYPESPECIFICPARAMS | Effect parameters are updated but not downloaded to the device. Suppresses restart of an effect. If the effect must be restarted, an error code of DIERR_EFFECTPLAYING is returned, and the effect continues to play with the original parameters. Starts playing the effect if it is not playing already. Indicates that the lpvTypeSpecificParams and cbTypeSpecificParams members of the TDIEffect structure contain new data.
The following listing demonstrates changing an effect’s direction at run time.
Previous | Table of Contents | Next

Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.