Changeset 5695 for code/trunk/src/ois/win32/Win32JoyStick.cpp
- Timestamp:
- Aug 30, 2009, 2:22:00 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/resource2 (added) merged: 3373-3374,5594,5597,5610-5611,5614,5624,5641,5644-5646,5650-5664,5667-5672,5682-5684,5688-5691,5694
- Property svn:mergeinfo changed
-
code/trunk/src/ois/win32/Win32JoyStick.cpp
r1505 r5695 82 82 mState.mAxes.clear(); 83 83 84 delete ff_device; 85 ff_device = 0; 86 84 if (ff_device) 85 { 86 delete ff_device; 87 ff_device = 0; 88 } 89 90 // Create direct input joystick device. 91 if(FAILED(mDirectInput->CreateDevice(deviceGuid, &mJoyStick, NULL))) 92 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> Could not initialize joy device!"); 93 94 // Set DIJoystick2 data format. 95 if(FAILED(mJoyStick->SetDataFormat(&c_dfDIJoystick2))) 96 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> data format error!"); 97 98 // Set cooperative level as specified when creating input manager. 99 HWND hwin = ((Win32InputManager*)mCreator)->getWindowHandle(); 100 if(FAILED(mJoyStick->SetCooperativeLevel( hwin, coopSetting))) 101 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> failed to set cooperation level!"); 102 103 // Set buffer size. 87 104 DIPROPDWORD dipdw; 88 89 105 dipdw.diph.dwSize = sizeof(DIPROPDWORD); 90 106 dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); … … 93 109 dipdw.dwData = JOYSTICK_DX_BUFFERSIZE; 94 110 95 if(FAILED(mDirectInput->CreateDevice(deviceGuid, &mJoyStick, NULL)))96 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> Could not initialize joy device!");97 98 if(FAILED(mJoyStick->SetDataFormat(&c_dfDIJoystick2)))99 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> data format error!");100 101 HWND hwin = ((Win32InputManager*)mCreator)->getWindowHandle();102 103 if(FAILED(mJoyStick->SetCooperativeLevel( hwin, coopSetting)))104 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize() >> failed to set cooperation level!");105 106 111 if( FAILED(mJoyStick->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)) ) 107 OIS_EXCEPT( E_General, "Win32 Mouse::Win32Mouse >> Failed to set buffer size property" );108 109 // Enumerate all axes/buttons/sliders/etc before aquiring112 OIS_EXCEPT( E_General, "Win32JoyStick::_initialize >> Failed to set buffer size property" ); 113 114 // Enumerate all axes/buttons/sliders/force feedback/etc before aquiring 110 115 _enumerate(); 111 116 … … 118 123 void Win32JoyStick::_enumerate() 119 124 { 120 //We can check force feedback here too 121 DIDEVCAPS DIJoyCaps; 122 DIJoyCaps.dwSize = sizeof(DIDEVCAPS); 123 mJoyStick->GetCapabilities(&DIJoyCaps); 124 125 mPOVs = (short)DIJoyCaps.dwPOVs; 126 127 mState.mButtons.resize(DIJoyCaps.dwButtons); 128 mState.mAxes.resize(DIJoyCaps.dwAxes); 125 // Get joystick capabilities. 126 mDIJoyCaps.dwSize = sizeof(DIDEVCAPS); 127 if( FAILED(mJoyStick->GetCapabilities(&mDIJoyCaps)) ) 128 OIS_EXCEPT( E_General, "Win32JoyStick::_enumerate >> Failed to get capabilities" ); 129 130 // => Number of POVs 131 mPOVs = (short)mDIJoyCaps.dwPOVs; 132 133 // => Number of buttons and axes. 134 mState.mButtons.resize(mDIJoyCaps.dwButtons); 135 mState.mAxes.resize(mDIJoyCaps.dwAxes); 136 137 // Enumerate all Force Feedback effects (if any) 138 mJoyStick->EnumEffects(DIEnumEffectsCallback, this, DIEFT_ALL); 129 139 130 140 //Reset the axis mapping enumeration value 131 141 _AxisNumber = 0; 132 142 133 //Enumerate Force Feedback (if any) 134 mJoyStick->EnumEffects(DIEnumEffectsCallback, this, DIEFT_ALL); 135 136 //Enumerate and set axis constraints (and check FF Axes) 143 // Enumerate and set axis constraints (and check FF Axes) 137 144 mJoyStick->EnumObjects(DIEnumDeviceObjectsCallback, this, DIDFT_AXIS); 138 145 } … … 181 188 OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set min/max range property" ); 182 189 183 //Check if FF Axes 190 //Check if FF Axes, and if so, increment counter 184 191 if((lpddoi->dwFlags & DIDOI_FFACTUATOR) != 0 ) 185 192 { 186 193 if( _this->ff_device ) 187 194 { 188 //todo - increment force feedback axis count195 _this->ff_device->_addFFAxis(); 189 196 } 190 197 } 191 198 199 //Force the flags for gain and auto-center support to true, 200 //as DInput has no API to query the device for these capabilities 201 //(the only way to know is to try them ...) 202 if( _this->ff_device ) 203 { 204 _this->ff_device->_setGainSupport(true); 205 _this->ff_device->_setAutoCenterSupport(true); 206 } 207 192 208 return DIENUM_CONTINUE; 193 209 } … … 198 214 Win32JoyStick* _this = (Win32JoyStick*)pvRef; 199 215 200 //Create the FF classafter we know there is at least one effect type216 //Create the FF instance only after we know there is at least one effect type 201 217 if( _this->ff_device == 0 ) 202 _this->ff_device = new Win32ForceFeedback(_this->mJoyStick);218 _this->ff_device = new Win32ForceFeedback(_this->mJoyStick, &_this->mDIJoyCaps); 203 219 204 220 _this->ff_device->_addEffectSupport( pdei );
Note: See TracChangeset
for help on using the changeset viewer.