InputManager.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:24k
源码类别:

游戏

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. // File: InputManager.cpp
  3. //
  4. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  5. //-----------------------------------------------------------------------------
  6. #include "stdafx.h"
  7. //-----------------------------------------------------------------------------
  8. // Game actions (using DInput semantic mapper). The definitions here are kind
  9. // of the whole point of this sample. The game uses these actions to map
  10. // physical input like, "the user pressed the 'W' key", to a more useable
  11. // constant for the game, like "if( dwInput == INPUT_CHANGEWEAPONS )...".
  12. //-----------------------------------------------------------------------------
  13. // Input semantics used by this game
  14. enum INPUT_SEMANTICS
  15. {
  16.     // Gameplay semantics
  17.     INPUT_AXIS_LR=1,     INPUT_AXIS_UD,       
  18.     INPUT_TURNLEFT,      INPUT_TURNRIGHT,     INPUT_FORWARDTHRUST,
  19.     INPUT_REVERSETHRUST, INPUT_FIREWEAPONS,   
  20.     INPUT_CHANGEWEAPONS, INPUT_DISPLAYGAMEMENU,
  21.     INPUT_QUITGAME,      INPUT_START,         INPUT_MOVELEFT,
  22.     INPUT_MOVERIGHT,     INPUT_MOVE_LR,
  23.     INPUT_CTRL,          INPUT_SHIFT,         
  24.     INPUT_FLYDOWN,       INPUT_FLYUP,         INPUT_DEBUGMODE,
  25.     // Menu semantics
  26.     INPUT_MENU_UD,       INPUT_MENU_WHEEL,
  27.     INPUT_MENU_UP,       INPUT_MENU_DOWN,     
  28.     INPUT_MENU_SELECT,   INPUT_MENU_QUIT,
  29. };
  30. // Game actions used by this game.
  31. DIACTION g_rgGameAction[] =
  32. {
  33.     // delete x:Program FilesCommon FilesDirectXDirectInputUser Maps*.ini
  34.     // after changing this, otherwise settings won't reset and will be read 
  35.     // from the out of date ini files 
  36.     // Mouse input mappings
  37.     { INPUT_AXIS_LR,         DIMOUSE_XAXIS,      0, TEXT("Look Left/Right"), },
  38.     { INPUT_AXIS_UD,         DIMOUSE_YAXIS,      0, TEXT("Look Up/Down"), },
  39.     { INPUT_FIREWEAPONS,     DIMOUSE_BUTTON0,    0, TEXT("Fire weapons"), },
  40.     // Keyboard input mappings
  41.     { INPUT_MOVELEFT,        DIKEYBOARD_LEFT,    0, TEXT("Strafe left"), },
  42.     { INPUT_MOVERIGHT,       DIKEYBOARD_RIGHT,   0, TEXT("Strafe right"), },
  43.     { INPUT_FORWARDTHRUST,   DIKEYBOARD_UP,      0, TEXT("Forward"), },
  44.     { INPUT_REVERSETHRUST,   DIKEYBOARD_DOWN,    0, TEXT("Reverse"), },
  45.     { INPUT_MOVELEFT,        DIKEYBOARD_A,       0, TEXT("Strafe left"), },
  46.     { INPUT_MOVERIGHT,       DIKEYBOARD_D,       0, TEXT("Strafe right"), },
  47.     { INPUT_FORWARDTHRUST,   DIKEYBOARD_W,       0, TEXT("Forward"), },
  48.     { INPUT_REVERSETHRUST,   DIKEYBOARD_S,       0, TEXT("Reverse"), },
  49.     { INPUT_FIREWEAPONS,     DIKEYBOARD_SPACE,   0, TEXT("Fire weapons"), },
  50.     { INPUT_DISPLAYGAMEMENU, DIKEYBOARD_F1,      DIA_APPFIXED, TEXT("Display game menu"), },
  51.     { INPUT_START,           DIKEYBOARD_PAUSE,   0, TEXT("Start/pause"), },
  52.     { INPUT_DISPLAYGAMEMENU, DIKEYBOARD_ESCAPE,  DIA_APPFIXED, TEXT("Quit game"), },
  53.     { INPUT_CTRL,            DIKEYBOARD_RCONTROL,DIA_APPFIXED, TEXT("Ctrl"), },
  54.     { INPUT_SHIFT,           DIKEYBOARD_RSHIFT,  DIA_APPFIXED, TEXT("Shift"), },
  55.     { INPUT_CTRL,            DIKEYBOARD_LCONTROL,DIA_APPFIXED, TEXT("Ctrl"), },
  56.     { INPUT_SHIFT,           DIKEYBOARD_LSHIFT,  DIA_APPFIXED, TEXT("Shift"), },
  57.     { INPUT_DEBUGMODE,       DIKEYBOARD_GRAVE,   DIA_APPFIXED, TEXT("Debug Mode"), },
  58.     { INPUT_FLYUP,           DIKEYBOARD_PRIOR,   DIA_APPFIXED, TEXT("Debug Fly Up"), },
  59.     { INPUT_FLYDOWN,         DIKEYBOARD_NEXT,    DIA_APPFIXED, TEXT("Debug Fly Down"), },
  60. };
  61. // Game actions used by this game.
  62. DIACTION g_rgBrowserAction[] =
  63. {
  64.     // delete x:Program FilesCommon FilesDirectXDirectInputUser Maps*.ini
  65.     // after changing this, otherwise settings won't reset and will be read 
  66.     // from the out of date ini files 
  67.     // Device input (joystick, etc.) that is pre-defined by DInput, according
  68.     // to genre type. The genre for this app is space simulators.
  69.     { INPUT_MENU_UD,         DIAXIS_BROWSER_MOVE,       0, TEXT("Up/down"), },
  70.     { INPUT_MENU_UP,         DIBUTTON_BROWSER_PREVIOUS, 0, TEXT("Up"), },
  71.     { INPUT_MENU_DOWN,       DIBUTTON_BROWSER_NEXT,     0, TEXT("Down"), },
  72.     { INPUT_MENU_SELECT,     DIBUTTON_BROWSER_SELECT,   0, TEXT("Select"), },
  73.     { INPUT_MENU_QUIT,       DIBUTTON_BROWSER_DEVICE,   0, TEXT("Quit menu"), },
  74.     // Keyboard input mappings
  75.     { INPUT_MENU_UP,         DIKEYBOARD_UP,          0, TEXT("Up"), },
  76.     { INPUT_MENU_DOWN,       DIKEYBOARD_DOWN,        0, TEXT("Down"), },
  77.     { INPUT_MENU_SELECT,     DIKEYBOARD_SPACE,       0, TEXT("Select"), },
  78.     { INPUT_MENU_SELECT,     DIKEYBOARD_RETURN,      0, TEXT("Select"), },
  79.     { INPUT_MENU_SELECT,     DIKEYBOARD_NUMPADENTER, 0, TEXT("Select"), },
  80.     { INPUT_MENU_QUIT,       DIKEYBOARD_ESCAPE,      0, TEXT("Quit menu"), },
  81.     // Mouse input mappings
  82.     { INPUT_MENU_WHEEL,      DIMOUSE_WHEEL,      0, TEXT("Up/down"), },
  83.     { INPUT_MENU_SELECT,     DIMOUSE_BUTTON0,    0, TEXT("Select"), },
  84. };
  85. // Number of actions
  86. #define NUMBER_OF_GAMEACTIONS    (sizeof(g_rgGameAction)/sizeof(DIACTION))
  87. #define NUMBER_OF_BROWSERACTIONS (sizeof(g_rgBrowserAction)/sizeof(DIACTION))
  88. CInputManager::UserInput* g_pUserInput = NULL;              
  89. //-----------------------------------------------------------------------------
  90. // Name: CInputManager()
  91. // Desc:
  92. //-----------------------------------------------------------------------------
  93. CInputManager::CInputManager( CMyApplication* pApp )
  94. {
  95.     m_pApp                  = pApp;
  96.     m_pInputDeviceManager   = NULL;
  97.     m_pMouseDeviceState     = NULL;
  98.     m_pConfigSurface        = NULL; 
  99.     ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
  100.     g_pUserInput = &m_UserInput;
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Name: ~CInputManager()
  104. // Desc:
  105. //-----------------------------------------------------------------------------
  106. CInputManager::~CInputManager(void)
  107. {
  108.     FinalCleanup();
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Name: OneTimeSceneInit()
  112. // Desc:
  113. //-----------------------------------------------------------------------------
  114. HRESULT CInputManager::OneTimeSceneInit( HWND hWnd, GUID* pGuidApp )
  115. {
  116.     HRESULT hr;
  117.     m_hWndMain = hWnd;
  118.     // Setup action format for the acutal gameplay
  119.     ZeroMemory( &m_diafGame, sizeof(DIACTIONFORMAT) );
  120.     m_diafGame.dwSize          = sizeof(DIACTIONFORMAT);
  121.     m_diafGame.dwActionSize    = sizeof(DIACTION);
  122.     m_diafGame.dwDataSize      = NUMBER_OF_GAMEACTIONS * sizeof(DWORD);
  123.     m_diafGame.guidActionMap   = *pGuidApp;
  124.     m_diafGame.dwGenre         = DIVIRTUAL_SPACESIM;
  125.     m_diafGame.dwNumActions    = NUMBER_OF_GAMEACTIONS;
  126.     m_diafGame.rgoAction       = g_rgGameAction;
  127.     m_diafGame.lAxisMin        = -10;
  128.     m_diafGame.lAxisMax        = 10;
  129.     m_diafGame.dwBufferSize    = 16;
  130.     _tcscpy( m_diafGame.tszActionMap, _T("Donuts4") );
  131.     // Setup action format for the in-game menus
  132.     ZeroMemory( &m_diafBrowser, sizeof(DIACTIONFORMAT) );
  133.     m_diafBrowser.dwSize          = sizeof(DIACTIONFORMAT);
  134.     m_diafBrowser.dwActionSize    = sizeof(DIACTION);
  135.     m_diafBrowser.dwDataSize      = NUMBER_OF_BROWSERACTIONS * sizeof(DWORD);
  136.     m_diafBrowser.guidActionMap   = *pGuidApp;
  137.     m_diafBrowser.dwGenre         = DIVIRTUAL_BROWSER_CONTROL;
  138.     m_diafBrowser.dwNumActions    = NUMBER_OF_BROWSERACTIONS;
  139.     m_diafBrowser.rgoAction       = g_rgBrowserAction;
  140.     m_diafBrowser.lAxisMin        = -10;
  141.     m_diafBrowser.lAxisMax        = 10;
  142.     m_diafBrowser.dwBufferSize    = 16;
  143.     _tcscpy( m_diafBrowser.tszActionMap, _T("Donuts4 Menu") );
  144.     // Create a new input device manager
  145.     m_pInputDeviceManager = new CInputDeviceManager();
  146.     if( NULL == m_pInputDeviceManager )
  147.         return E_OUTOFMEMORY;
  148.     if( FAILED( hr = m_pInputDeviceManager->Create( hWnd, NULL, m_diafGame,
  149.                                                     StaticInputAddDeviceCB, this ) ) )
  150.         return hr;
  151.     return S_OK;
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Name: RestoreDeviceObjects()
  155. // Desc:
  156. //-----------------------------------------------------------------------------
  157. HRESULT CInputManager::RestoreDeviceObjects( D3DFORMAT d3dfmtFullscreen )
  158. {
  159. /*
  160.     HRESULT hr;
  161.     // Create a surface for confguring DInput devices
  162.     hr = g_pd3dDevice->CreateImageSurface( 640, 480, d3dfmtFullscreen, &m_pConfigSurface );
  163.     if( FAILED(hr) )
  164.         return hr;
  165. */   
  166.     return S_OK;
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Name: InvalidateDeviceObjects()
  170. // Desc:
  171. //-----------------------------------------------------------------------------
  172. HRESULT CInputManager::InvalidateDeviceObjects()
  173. {
  174.     SAFE_RELEASE( m_pConfigSurface );
  175.     return S_OK;
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Name: DeleteDeviceObjects()
  179. // Desc:
  180. //-----------------------------------------------------------------------------
  181. HRESULT CInputManager::DeleteDeviceObjects()
  182. {
  183.     return S_OK;
  184. }
  185. //-----------------------------------------------------------------------------
  186. // Name: StaticInputAddDeviceCB()
  187. // Desc: Static callback helper to call into CMyApplication class
  188. //-----------------------------------------------------------------------------
  189. HRESULT CALLBACK CInputManager::StaticInputAddDeviceCB( 
  190.                                          CInputDeviceManager::DeviceInfo* pDeviceInfo, 
  191.                                          const DIDEVICEINSTANCE* pdidi, 
  192.                                          LPVOID pParam )
  193. {
  194.     CInputManager* pInputManager = (CInputManager*) pParam;
  195.     return pInputManager->InputAddDeviceCB( pDeviceInfo, pdidi );
  196. }
  197. //-----------------------------------------------------------------------------
  198. // Name: InputAddDeviceCB()
  199. // Desc: Called from CInputDeviceManager whenever a device is added. 
  200. //       Set the dead zone, and creates a new InputDeviceState for each device
  201. //-----------------------------------------------------------------------------
  202. HRESULT CInputManager::InputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, 
  203.                                          const DIDEVICEINSTANCE* pdidi )
  204. {
  205.     // Setup the deadzone 
  206.     DIPROPDWORD dipdw;
  207.     dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
  208.     dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
  209.     dipdw.diph.dwObj        = 0;
  210.     dipdw.diph.dwHow        = DIPH_DEVICE;
  211.     dipdw.dwData            = 500;
  212.     pDeviceInfo->pdidDevice->SetProperty( DIPROP_DEADZONE, &dipdw.diph );
  213.     // Create a new InputDeviceState for each device so the 
  214.     // app can record its state 
  215.     InputDeviceState* pNewInputDeviceState = new InputDeviceState;
  216.     ZeroMemory( pNewInputDeviceState, sizeof(InputDeviceState) );
  217.     pDeviceInfo->pParam = (LPVOID) pNewInputDeviceState;
  218.     if( GET_DIDEVICE_TYPE(pdidi->dwDevType) == DI8DEVTYPE_MOUSE )
  219.     {
  220.         pDeviceInfo->pdidDevice->SetCooperativeLevel( m_hWndMain, DISCL_EXCLUSIVE|DISCL_FOREGROUND );
  221.         m_pMouseDeviceState = pNewInputDeviceState;
  222.     }
  223.     return S_OK;
  224. }
  225. //-----------------------------------------------------------------------------
  226. // Name: FinalCleanup()
  227. // Desc:
  228. //-----------------------------------------------------------------------------
  229. VOID CInputManager::FinalCleanup()
  230. {
  231.     if( m_pInputDeviceManager == NULL )
  232.         return;
  233.     
  234.     // Get access to the list of semantically-mapped input devices
  235.     // to delete all InputDeviceState structs
  236.     CInputDeviceManager::DeviceInfo* pDeviceInfos;
  237.     DWORD dwNumDevices;
  238.     m_pInputDeviceManager->GetDevices( &pDeviceInfos, &dwNumDevices );
  239.     for( DWORD i=0; i<dwNumDevices; i++ )
  240.     {
  241.         InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam;
  242.         SAFE_DELETE( pInputDeviceState );
  243.         pDeviceInfos[i].pParam = NULL;
  244.     }
  245.     // Delete input device manager
  246.     SAFE_DELETE( m_pInputDeviceManager );
  247. }
  248. //-----------------------------------------------------------------------------
  249. // Name: StaticConfigureInputDevicesCB()
  250. // Desc: Static callback helper to call into CMyD3DApplication class
  251. //-----------------------------------------------------------------------------
  252. BOOL CALLBACK CInputManager::StaticConfigureInputDevicesCB( IUnknown* pUnknown, VOID* pUserData )
  253. {
  254.     CInputManager* pInputManager = (CInputManager*) pUserData;
  255.     return pInputManager->ConfigureInputDevicesCB( pUnknown );
  256. }
  257. //-----------------------------------------------------------------------------
  258. // Name: ConfigureInputDevicesCB()
  259. // Desc: Callback function for configuring input devices. This function is
  260. //       called in fullscreen modes, so that the input device configuration
  261. //       window can update the screen.
  262. //-----------------------------------------------------------------------------
  263. BOOL CInputManager::ConfigureInputDevicesCB( IUnknown* pUnknown )
  264. {
  265. /*
  266.     if( m_pApp->IsFullScreen() )
  267.     {
  268.         // Get access to the surface
  269.         LPDIRECT3DSURFACE9 pConfigSurface;
  270.         if( FAILED( pUnknown->QueryInterface( IID_IDirect3DSurface9,
  271.                                             (VOID**)&pConfigSurface ) ) )
  272.             return TRUE;
  273.         // Draw the scene, with the config surface blitted on top
  274.         m_pApp->RenderFrame();
  275.         RECT  rcSrc;
  276.         SetRect( &rcSrc, 0, 0, 640, 480 );
  277.         POINT ptDst;
  278.         ptDst.x = (m_pApp->GetScreenWidth()-640)/2;
  279.         ptDst.y = (m_pApp->GetScreenHeight()-480)/2;
  280.         LPDIRECT3DSURFACE9 pBackBuffer;
  281.         g_pd3dDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
  282.         g_pd3dDevice->CopyRects( pConfigSurface, &rcSrc, 1, pBackBuffer, &ptDst );
  283.         pBackBuffer->Release();
  284.         g_pd3dDevice->Present( 0, 0, 0, 0 );
  285.         // Release the surface
  286.         pConfigSurface->Release();
  287.     }
  288. */
  289.     return TRUE;
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Name: UpdateInput()
  293. // Desc: Processes data from the input device.  Uses GetDeviceState().
  294. //-----------------------------------------------------------------------------
  295. void CInputManager::UpdateInput()
  296. {
  297.     if( NULL == m_pInputDeviceManager )
  298.         return;
  299.     if( m_pMouseDeviceState )
  300.     {
  301.         // Zero all the axis state for the mouse cause
  302.         // these axis are relative so they don't like 
  303.         // to zero on thier own
  304.         m_pMouseDeviceState->fAxisMenuUD = 0.0f;
  305.         m_pMouseDeviceState->fAxisMoveLR = 0.0f;
  306.         m_pMouseDeviceState->fAxisMoveUD = 0.0f;
  307.         m_pMouseDeviceState->fAxisRotateLR = 0.0f;
  308.         m_pMouseDeviceState->fAxisRotateUD = 0.0f;
  309.     }
  310.     // Get access to the list of semantically-mapped input devices
  311.     CInputDeviceManager::DeviceInfo* pDeviceInfos;
  312.     DWORD dwNumDevices;
  313.     m_pInputDeviceManager->GetDevices( &pDeviceInfos, &dwNumDevices );
  314.     // Loop through all devices and check game input
  315.     for( DWORD i=0; i<dwNumDevices; i++ )
  316.     {
  317.         DIDEVICEOBJECTDATA rgdod[10];
  318.         DWORD   dwItems = 10;
  319.         HRESULT hr;
  320.         LPDIRECTINPUTDEVICE8 pdidDevice = pDeviceInfos[i].pdidDevice;
  321.         InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam;
  322.         hr = pdidDevice->Acquire();
  323.         hr = pdidDevice->Poll();
  324.         hr = pdidDevice->GetDeviceData( sizeof(DIDEVICEOBJECTDATA),
  325.                                         rgdod, &dwItems, 0 );
  326.         if( FAILED(hr) )
  327.             continue;
  328.         // Get the sematics codes for the game menu
  329.         for( DWORD j=0; j<dwItems; j++ )
  330.         {
  331.             BOOL  bButtonState = (rgdod[j].dwData==0x80) ? TRUE : FALSE;
  332. //            FLOAT fButtonState = (rgdod[j].dwData==0x80) ? 1.0f : 0.0f;
  333.             FLOAT fAxisState   = (FLOAT)((int)rgdod[j].dwData)/10.0f;
  334.             switch( rgdod[j].uAppData )
  335.             {
  336.                 // Handle semantics for normal game play
  337.                 // Handle relative axis data
  338.                 case INPUT_AXIS_LR: 
  339.                     pInputDeviceState->fAxisRotateLR = fAxisState;
  340.                     break;
  341.                 case INPUT_AXIS_UD: 
  342.                     pInputDeviceState->fAxisRotateUD = -fAxisState;
  343.                     break;
  344.                 // Handle buttons separately so the button state data
  345.                 // doesn't overwrite the axis state data, and handle
  346.                 // each button separately so they don't overwrite each other
  347.                 case INPUT_TURNLEFT:      pInputDeviceState->bButtonRotateLeft    = bButtonState; break;
  348.                 case INPUT_TURNRIGHT:     pInputDeviceState->bButtonRotateRight   = bButtonState; break;
  349.                 case INPUT_MOVELEFT:      pInputDeviceState->bButtonMoveLeft      = bButtonState; break;
  350.                 case INPUT_MOVERIGHT:     pInputDeviceState->bButtonMoveRight     = bButtonState; break;
  351.                 case INPUT_FORWARDTHRUST: pInputDeviceState->bButtonForwardThrust = bButtonState; break;
  352.                 case INPUT_REVERSETHRUST: pInputDeviceState->bButtonReverseThrust = bButtonState; break;
  353.                 case INPUT_FIREWEAPONS:   pInputDeviceState->bButtonFireWeapons   = bButtonState; break;
  354.                 // Handle one-shot buttons
  355.                 case INPUT_CTRL:          pInputDeviceState->bButtonCtrl  = bButtonState; break;
  356.                 case INPUT_SHIFT:         pInputDeviceState->bButtonShift = bButtonState; break;
  357.                 case INPUT_DEBUGMODE:     if( bButtonState && m_UserInput.bButtonShift ) m_pApp->m_bDebugMode = !m_pApp->m_bDebugMode;  break;
  358.                 case INPUT_START:         if( bButtonState )                             m_pApp->m_bPaused    = !m_pApp->m_bPaused; break;
  359.                 case INPUT_FLYUP:         pInputDeviceState->bButtonFlyUp         = bButtonState; break;
  360.                 case INPUT_FLYDOWN:       pInputDeviceState->bButtonFlyDown       = bButtonState; break;
  361.                 case INPUT_DISPLAYGAMEMENU:
  362.                     if( bButtonState )
  363.                     {
  364.                         PostMessage( m_hWndMain, WM_CLOSE, 0, 0 );
  365. /*                        
  366.                         PlaySoundEffect( m_pExplosionSphereSound, &g_Profile.ExplosionSphere);
  367.                         m_pCurrentMenu = m_pMainMenu;
  368.                         m_pInputDeviceManager->SetActionFormat( m_diafBrowser, FALSE );
  369. */
  370.                     }
  371.                     break;
  372.                 // Handle semantics for the game menu
  373.                 case INPUT_MENU_UD:     pInputDeviceState->fAxisMenuUD = -fAxisState; break;
  374.                 case INPUT_MENU_UP:     if( bButtonState ) m_UserInput.bDoMenuUp     = TRUE; break;
  375.                 case INPUT_MENU_DOWN:   if( bButtonState ) m_UserInput.bDoMenuDown   = TRUE; break;
  376.                 case INPUT_MENU_SELECT: if( bButtonState ) m_UserInput.bDoMenuSelect = TRUE; break;
  377.                 case INPUT_MENU_QUIT:   if( bButtonState ) m_UserInput.bDoMenuQuit   = TRUE; break;
  378.                 case INPUT_MENU_WHEEL:
  379.                     if( fAxisState > 0.0f )
  380.                         m_UserInput.bDoMenuUp = TRUE; 
  381.                     else
  382.                         m_UserInput.bDoMenuDown = TRUE; 
  383.                     break;
  384.             }
  385.         }
  386.     }
  387.     m_UserInput.bButtonFireWeapons = FALSE; 
  388.     m_UserInput.bButtonCtrl        = FALSE;
  389.     m_UserInput.bButtonShift       = FALSE;
  390.     m_UserInput.fAxisRotateLR = 0.0f;
  391.     m_UserInput.fAxisRotateUD = 0.0f;
  392.     m_UserInput.fAxisMoveUD   = 0.0f;
  393.     m_UserInput.fAxisMoveLR   = 0.0f;
  394.     m_UserInput.fAxisFlyUD    = 0.0f;
  395.     // Accumulate inputs into m_UserInput
  396.     // Concatinate the data from all the DirectInput devices
  397.     for( i=0; i<dwNumDevices; i++ )
  398.     {
  399.         InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam;
  400.         // Use the axis data that is furthest from zero
  401.         if( fabs(pInputDeviceState->fAxisRotateLR) > fabs(m_UserInput.fAxisRotateLR) )
  402.             m_UserInput.fAxisRotateLR = pInputDeviceState->fAxisRotateLR;
  403.         if( fabs(pInputDeviceState->fAxisRotateUD) > fabs(m_UserInput.fAxisRotateUD) )
  404.             m_UserInput.fAxisRotateUD = pInputDeviceState->fAxisRotateUD;
  405.         if( fabs(pInputDeviceState->fAxisMoveUD) > fabs(m_UserInput.fAxisMoveUD) )
  406.             m_UserInput.fAxisMoveUD = pInputDeviceState->fAxisMoveUD;
  407.         if( fabs(pInputDeviceState->fAxisMoveLR) > fabs(m_UserInput.fAxisMoveLR) )
  408.             m_UserInput.fAxisMoveLR = pInputDeviceState->fAxisMoveLR;
  409.         // Process the button data 
  410.         if( pInputDeviceState->bButtonRotateRight )
  411.             m_UserInput.fAxisRotateLR = 1.0f;
  412.         else if( pInputDeviceState->bButtonRotateLeft )
  413.             m_UserInput.fAxisRotateLR = -1.0f;
  414.         if( pInputDeviceState->bButtonForwardThrust )
  415.             m_UserInput.fAxisMoveUD = 1.0f;
  416.         else if( pInputDeviceState->bButtonReverseThrust )
  417.             m_UserInput.fAxisMoveUD = -1.0f;
  418.         if( pInputDeviceState->bButtonMoveLeft )
  419.             m_UserInput.fAxisMoveLR = -1.0f;
  420.         else if( pInputDeviceState->bButtonMoveRight )
  421.             m_UserInput.fAxisMoveLR = 1.0f;
  422.         if( pInputDeviceState->bButtonFlyUp )
  423.             m_UserInput.fAxisFlyUD = 1.0f;
  424.         else if( pInputDeviceState->bButtonFlyDown )
  425.             m_UserInput.fAxisFlyUD = -1.0f;
  426.         if( pInputDeviceState->bButtonFireWeapons )
  427.             m_UserInput.bButtonFireWeapons = TRUE;
  428.         if( pInputDeviceState->bButtonCtrl )
  429.             m_UserInput.bButtonCtrl = TRUE;
  430.         if( pInputDeviceState->bButtonShift )
  431.             m_UserInput.bButtonShift = TRUE;
  432.     }
  433. }
  434. //-----------------------------------------------------------------------------
  435. // Name: ViewDevices()
  436. // Desc: 
  437. //-----------------------------------------------------------------------------
  438. void CInputManager::ViewDevices()
  439. {
  440.     // Put action format to game play actions
  441.     m_pInputDeviceManager->SetActionFormat( m_diafGame, FALSE );
  442.     // Configure the devices (with view capability only)
  443.     if( m_pApp->IsFullScreen() )
  444.         m_pInputDeviceManager->ConfigureDevices( m_hWndMain,
  445.                                                     m_pConfigSurface,
  446.                                                     (VOID*)StaticConfigureInputDevicesCB,
  447.                                                     DICD_DEFAULT, this );
  448.     else
  449.         m_pInputDeviceManager->ConfigureDevices( m_hWndMain, NULL, NULL,
  450.                                                     DICD_DEFAULT, this );
  451. }
  452. //-----------------------------------------------------------------------------
  453. // Name: ConfigDevices()
  454. // Desc: 
  455. //-----------------------------------------------------------------------------
  456. void CInputManager::ConfigDevices()
  457. {
  458.     // Put action format to game play actions
  459.     m_pInputDeviceManager->SetActionFormat( m_diafGame, FALSE );
  460.     // Get access to the list of semantically-mapped input devices
  461.     // to delete all InputDeviceState structs before calling ConfigureDevices()
  462.     CInputDeviceManager::DeviceInfo* pDeviceInfos;
  463.     DWORD dwNumDevices;
  464.     m_pInputDeviceManager->GetDevices( &pDeviceInfos, &dwNumDevices );
  465.     for( DWORD i=0; i<dwNumDevices; i++ )
  466.     {
  467.         InputDeviceState* pInputDeviceState = (InputDeviceState*) pDeviceInfos[i].pParam;
  468.         SAFE_DELETE( pInputDeviceState );
  469.         pDeviceInfos[i].pParam = NULL;
  470.     }
  471.     // Configure the devices (with edit capability)
  472.     if( m_pApp->IsFullScreen() )
  473.         m_pInputDeviceManager->ConfigureDevices( m_hWndMain,
  474.                                                     m_pConfigSurface,
  475.                                                     (VOID*)StaticConfigureInputDevicesCB,
  476.                                                     DICD_EDIT, this );
  477.     else
  478.         m_pInputDeviceManager->ConfigureDevices( m_hWndMain, NULL, NULL,
  479.                                                     DICD_EDIT, this );
  480. }