1 | /* |
---|
2 | The zlib/libpng License |
---|
3 | |
---|
4 | Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) |
---|
5 | |
---|
6 | This software is provided 'as-is', without any express or implied warranty. In no event will |
---|
7 | the authors be held liable for any damages arising from the use of this software. |
---|
8 | |
---|
9 | Permission is granted to anyone to use this software for any purpose, including commercial |
---|
10 | applications, and to alter it and redistribute it freely, subject to the following |
---|
11 | restrictions: |
---|
12 | |
---|
13 | 1. The origin of this software must not be misrepresented; you must not claim that |
---|
14 | you wrote the original software. If you use this software in a product, |
---|
15 | an acknowledgment in the product documentation would be appreciated but is |
---|
16 | not required. |
---|
17 | |
---|
18 | 2. Altered source versions must be plainly marked as such, and must not be |
---|
19 | misrepresented as being the original software. |
---|
20 | |
---|
21 | 3. This notice may not be removed or altered from any source distribution. |
---|
22 | */ |
---|
23 | #include "win32/Win32ForceFeedback.h" |
---|
24 | #include "OISException.h" |
---|
25 | #include <math.h> |
---|
26 | #include <cstddef> |
---|
27 | |
---|
28 | // 0 = No trace; 1 = Important traces; 2 = Debug traces |
---|
29 | #define OIS_WIN32_JOYFF_DEBUG 0 |
---|
30 | |
---|
31 | #if (defined (_DEBUG) || defined(OIS_WIN32_JOYFF_DEBUG)) |
---|
32 | #include <iostream> |
---|
33 | #include <sstream> |
---|
34 | using namespace std; |
---|
35 | #endif |
---|
36 | |
---|
37 | using namespace OIS; |
---|
38 | |
---|
39 | //--------------------------------------------------------------// |
---|
40 | Win32ForceFeedback::Win32ForceFeedback(IDirectInputDevice8* pDIJoy, const DIDEVCAPS* pDIJoyCaps) : |
---|
41 | mHandles(0), mJoyStick(pDIJoy), mFFAxes(0), mpDIJoyCaps(pDIJoyCaps) |
---|
42 | { |
---|
43 | #if (OIS_WIN32_JOYFF_DEBUG > 0) |
---|
44 | cout << "FFSamplePeriod : " << mpDIJoyCaps->dwFFSamplePeriod << " mu-s, " |
---|
45 | << "FFMinTimeResolution : " << mpDIJoyCaps->dwFFMinTimeResolution << " mu-s," |
---|
46 | << "" << endl; |
---|
47 | #endif |
---|
48 | } |
---|
49 | |
---|
50 | //--------------------------------------------------------------// |
---|
51 | Win32ForceFeedback::~Win32ForceFeedback() |
---|
52 | { |
---|
53 | //Get the effect - if it exists |
---|
54 | for(EffectList::iterator i = mEffectList.begin(); i != mEffectList.end(); ++i ) |
---|
55 | { |
---|
56 | LPDIRECTINPUTEFFECT dxEffect = i->second; |
---|
57 | if( dxEffect ) |
---|
58 | { |
---|
59 | dxEffect->Unload(); |
---|
60 | dxEffect->Release(); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | mEffectList.clear(); |
---|
65 | } |
---|
66 | |
---|
67 | //--------------------------------------------------------------// |
---|
68 | short Win32ForceFeedback::getFFAxesNumber() |
---|
69 | { |
---|
70 | return mFFAxes; |
---|
71 | } |
---|
72 | |
---|
73 | //--------------------------------------------------------------// |
---|
74 | unsigned short Win32ForceFeedback::getFFMemoryLoad() |
---|
75 | { |
---|
76 | DIPROPDWORD dipdw; // DIPROPDWORD contains a DIPROPHEADER structure. |
---|
77 | dipdw.diph.dwSize = sizeof(DIPROPDWORD); |
---|
78 | dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); |
---|
79 | dipdw.diph.dwObj = 0; // device property |
---|
80 | dipdw.diph.dwHow = DIPH_DEVICE; |
---|
81 | dipdw.dwData = 0; // In case of any error. |
---|
82 | |
---|
83 | const HRESULT hr = mJoyStick->GetProperty(DIPROP_FFLOAD, &dipdw.diph); |
---|
84 | if(FAILED(hr)) |
---|
85 | { |
---|
86 | if (hr == DIERR_NOTEXCLUSIVEACQUIRED) |
---|
87 | OIS_EXCEPT(E_General, "Can't query FF memory load as device was not acquired in exclusive mode"); |
---|
88 | else |
---|
89 | OIS_EXCEPT(E_General, "Unknown error querying FF memory load ->.."); |
---|
90 | } |
---|
91 | |
---|
92 | return (unsigned short)dipdw.dwData; |
---|
93 | } |
---|
94 | |
---|
95 | //--------------------------------------------------------------// |
---|
96 | void Win32ForceFeedback::upload( const Effect* effect ) |
---|
97 | { |
---|
98 | switch( effect->force ) |
---|
99 | { |
---|
100 | case OIS::Effect::ConstantForce: _updateConstantEffect(effect); break; |
---|
101 | case OIS::Effect::RampForce: _updateRampEffect(effect); break; |
---|
102 | case OIS::Effect::PeriodicForce: _updatePeriodicEffect(effect); break; |
---|
103 | case OIS::Effect::ConditionalForce: _updateConditionalEffect(effect); break; |
---|
104 | //case OIS::Effect::CustomForce: _updateCustomEffect(effect); break; |
---|
105 | default: OIS_EXCEPT(E_NotImplemented, "Requested Force not Implemented yet, sorry!"); break; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | //--------------------------------------------------------------// |
---|
110 | void Win32ForceFeedback::modify( const Effect* eff ) |
---|
111 | { |
---|
112 | //Modifying is essentially the same as an upload, so, just reuse that function |
---|
113 | upload(eff); |
---|
114 | } |
---|
115 | |
---|
116 | //--------------------------------------------------------------// |
---|
117 | void Win32ForceFeedback::remove( const Effect* eff ) |
---|
118 | { |
---|
119 | //Get the effect - if it exists |
---|
120 | EffectList::iterator i = mEffectList.find(eff->_handle); |
---|
121 | if( i != mEffectList.end() ) |
---|
122 | { |
---|
123 | LPDIRECTINPUTEFFECT dxEffect = i->second; |
---|
124 | if( dxEffect ) |
---|
125 | { |
---|
126 | dxEffect->Stop(); |
---|
127 | //We care about the return value - as the effect might not |
---|
128 | //have been unlaoded |
---|
129 | if( SUCCEEDED(dxEffect->Unload()) ) |
---|
130 | { |
---|
131 | dxEffect->Release(); |
---|
132 | mEffectList.erase(i); |
---|
133 | } |
---|
134 | } |
---|
135 | else |
---|
136 | mEffectList.erase(i); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | //--------------------------------------------------------------// |
---|
141 | void Win32ForceFeedback::setMasterGain( float level ) |
---|
142 | { |
---|
143 | //Between 0 - 10,000 |
---|
144 | int gain_level = (int)(10000.0f * level); |
---|
145 | |
---|
146 | if( gain_level > 10000 ) |
---|
147 | gain_level = 10000; |
---|
148 | else if( gain_level < 0 ) |
---|
149 | gain_level = 0; |
---|
150 | |
---|
151 | DIPROPDWORD DIPropGain; |
---|
152 | DIPropGain.diph.dwSize = sizeof(DIPropGain); |
---|
153 | DIPropGain.diph.dwHeaderSize = sizeof(DIPROPHEADER); |
---|
154 | DIPropGain.diph.dwObj = 0; |
---|
155 | DIPropGain.diph.dwHow = DIPH_DEVICE; |
---|
156 | DIPropGain.dwData = gain_level; |
---|
157 | |
---|
158 | #if (OIS_WIN32_JOYFF_DEBUG > 0) |
---|
159 | cout << "Win32ForceFeedback("<< mJoyStick << ") : Setting master gain to " |
---|
160 | << level << " => " << DIPropGain.dwData << endl; |
---|
161 | #endif |
---|
162 | |
---|
163 | const HRESULT hr = mJoyStick->SetProperty(DIPROP_FFGAIN, &DIPropGain.diph); |
---|
164 | |
---|
165 | #if defined (_DEBUG) |
---|
166 | if(FAILED(hr)) |
---|
167 | cout << "Failed to change master gain" << endl; |
---|
168 | #endif |
---|
169 | } |
---|
170 | |
---|
171 | //--------------------------------------------------------------// |
---|
172 | void Win32ForceFeedback::setAutoCenterMode( bool auto_on ) |
---|
173 | { |
---|
174 | DIPROPDWORD DIPropAutoCenter; |
---|
175 | DIPropAutoCenter.diph.dwSize = sizeof(DIPropAutoCenter); |
---|
176 | DIPropAutoCenter.diph.dwHeaderSize = sizeof(DIPROPHEADER); |
---|
177 | DIPropAutoCenter.diph.dwObj = 0; |
---|
178 | DIPropAutoCenter.diph.dwHow = DIPH_DEVICE; |
---|
179 | DIPropAutoCenter.dwData = (auto_on ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF); |
---|
180 | |
---|
181 | #if (OIS_WIN32_JOYFF_DEBUG > 0) |
---|
182 | cout << "Win32ForceFeedback("<< mJoyStick << ") : Setting auto-center mode to " |
---|
183 | << auto_on << " => " << DIPropAutoCenter.dwData << endl; |
---|
184 | #endif |
---|
185 | |
---|
186 | const HRESULT hr = mJoyStick->SetProperty(DIPROP_AUTOCENTER, &DIPropAutoCenter.diph); |
---|
187 | |
---|
188 | #if defined (_DEBUG) |
---|
189 | if(FAILED(hr)) |
---|
190 | cout << "Failed to change auto-center mode" << endl; |
---|
191 | #endif |
---|
192 | } |
---|
193 | |
---|
194 | //--------------------------------------------------------------// |
---|
195 | void Win32ForceFeedback::_updateConstantEffect( const Effect* effect ) |
---|
196 | { |
---|
197 | ConstantEffect *eff = static_cast<ConstantEffect*>(effect->getForceEffect()); |
---|
198 | |
---|
199 | DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; |
---|
200 | LONG rglDirection[2] = { 0, 0 }; |
---|
201 | DIENVELOPE diEnvelope; |
---|
202 | DICONSTANTFORCE cf; |
---|
203 | DIEFFECT diEffect; |
---|
204 | |
---|
205 | //Currently only support 1 axis |
---|
206 | //if( effect->getNumAxes() == 1 ) |
---|
207 | cf.lMagnitude = eff->level; |
---|
208 | |
---|
209 | #if (OIS_WIN32_JOYFF_DEBUG > 1) |
---|
210 | cout << " Level : " << eff->level |
---|
211 | << " => " << cf.lMagnitude << endl; |
---|
212 | #endif |
---|
213 | |
---|
214 | _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICONSTANTFORCE), &cf, effect, &eff->envelope); |
---|
215 | _upload(GUID_ConstantForce, &diEffect, effect); |
---|
216 | } |
---|
217 | |
---|
218 | //--------------------------------------------------------------// |
---|
219 | void Win32ForceFeedback::_updateRampEffect( const Effect* effect ) |
---|
220 | { |
---|
221 | RampEffect *eff = static_cast<RampEffect*>(effect->getForceEffect()); |
---|
222 | |
---|
223 | DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; |
---|
224 | LONG rglDirection[2] = { 0, 0 }; |
---|
225 | DIENVELOPE diEnvelope; |
---|
226 | DIRAMPFORCE rf; |
---|
227 | DIEFFECT diEffect; |
---|
228 | |
---|
229 | //Currently only support 1 axis |
---|
230 | rf.lStart = eff->startLevel; |
---|
231 | rf.lEnd = eff->endLevel; |
---|
232 | |
---|
233 | _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DIRAMPFORCE), &rf, effect, &eff->envelope ); |
---|
234 | _upload(GUID_RampForce, &diEffect, effect); |
---|
235 | } |
---|
236 | |
---|
237 | //--------------------------------------------------------------// |
---|
238 | void Win32ForceFeedback::_updatePeriodicEffect( const Effect* effect ) |
---|
239 | { |
---|
240 | PeriodicEffect *eff = static_cast<PeriodicEffect*>(effect->getForceEffect()); |
---|
241 | |
---|
242 | DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; |
---|
243 | LONG rglDirection[2] = { 0, 0 }; |
---|
244 | DIENVELOPE diEnvelope; |
---|
245 | DIPERIODIC pf; |
---|
246 | DIEFFECT diEffect; |
---|
247 | |
---|
248 | //Currently only support 1 axis |
---|
249 | pf.dwMagnitude = eff->magnitude; |
---|
250 | pf.lOffset = eff->offset; |
---|
251 | pf.dwPhase = eff->phase; |
---|
252 | pf.dwPeriod = eff->period; |
---|
253 | |
---|
254 | _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DIPERIODIC), &pf, effect, &eff->envelope ); |
---|
255 | |
---|
256 | switch( effect->type ) |
---|
257 | { |
---|
258 | case OIS::Effect::Square: _upload(GUID_Square, &diEffect, effect); break; |
---|
259 | case OIS::Effect::Triangle: _upload(GUID_Triangle, &diEffect, effect); break; |
---|
260 | case OIS::Effect::Sine: _upload(GUID_Sine, &diEffect, effect); break; |
---|
261 | case OIS::Effect::SawToothUp: _upload(GUID_SawtoothUp, &diEffect, effect); break; |
---|
262 | case OIS::Effect::SawToothDown: _upload(GUID_SawtoothDown, &diEffect, effect); break; |
---|
263 | default: break; |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | //--------------------------------------------------------------// |
---|
268 | void Win32ForceFeedback::_updateConditionalEffect( const Effect* effect ) |
---|
269 | { |
---|
270 | ConditionalEffect *eff = static_cast<ConditionalEffect*>(effect->getForceEffect()); |
---|
271 | |
---|
272 | DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; |
---|
273 | LONG rglDirection[2] = { 0, 0 }; |
---|
274 | DIENVELOPE diEnvelope; |
---|
275 | DICONDITION cf; |
---|
276 | DIEFFECT diEffect; |
---|
277 | |
---|
278 | cf.lOffset = eff->deadband; |
---|
279 | cf.lPositiveCoefficient = eff->rightCoeff; |
---|
280 | cf.lNegativeCoefficient = eff->leftCoeff; |
---|
281 | cf.dwPositiveSaturation = eff->rightSaturation; |
---|
282 | cf.dwNegativeSaturation = eff->leftSaturation; |
---|
283 | cf.lDeadBand = eff->deadband; |
---|
284 | |
---|
285 | _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICONDITION), &cf, effect, 0 ); |
---|
286 | |
---|
287 | switch( effect->type ) |
---|
288 | { |
---|
289 | case OIS::Effect::Friction: _upload(GUID_Friction, &diEffect, effect); break; |
---|
290 | case OIS::Effect::Damper: _upload(GUID_Damper, &diEffect, effect); break; |
---|
291 | case OIS::Effect::Inertia: _upload(GUID_Inertia, &diEffect, effect); break; |
---|
292 | case OIS::Effect::Spring: _upload(GUID_Spring, &diEffect, effect); break; |
---|
293 | default: break; |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | //--------------------------------------------------------------// |
---|
298 | void Win32ForceFeedback::_updateCustomEffect( const Effect* /*effect*/ ) |
---|
299 | { |
---|
300 | //CustomEffect *eff = static_cast<CustomEffect*>(effect->getForceEffect()); |
---|
301 | // |
---|
302 | //DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; |
---|
303 | //LONG rglDirection[2] = { 0, 0 }; |
---|
304 | //DIENVELOPE diEnvelope; |
---|
305 | //DICUSTOMFORCE cf; |
---|
306 | //DIEFFECT diEffect; |
---|
307 | //cf.cChannels = 0; |
---|
308 | //cf.dwSamplePeriod = 0; |
---|
309 | //cf.cSamples = 0; |
---|
310 | //cf.rglForceData = 0; |
---|
311 | //_setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICUSTOMFORCE), &cf, effect, &eff->envelope); |
---|
312 | //_upload(GUID_CustomForce, &diEffect, effect); |
---|
313 | } |
---|
314 | |
---|
315 | //--------------------------------------------------------------// |
---|
316 | void Win32ForceFeedback::_setCommonProperties( |
---|
317 | DIEFFECT* diEffect, DWORD* rgdwAxes, |
---|
318 | LONG* rglDirection, DIENVELOPE* diEnvelope, DWORD struct_size, |
---|
319 | LPVOID struct_type, const Effect* effect, const Envelope* envelope ) |
---|
320 | { |
---|
321 | ZeroMemory(diEffect, sizeof(DIEFFECT)); |
---|
322 | |
---|
323 | diEffect->dwSize = sizeof(DIEFFECT); |
---|
324 | diEffect->dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; |
---|
325 | diEffect->dwGain = DI_FFNOMINALMAX; |
---|
326 | |
---|
327 | diEffect->dwTriggerButton = DIEB_NOTRIGGER; // effect->trigger_button; // TODO: Conversion |
---|
328 | diEffect->dwTriggerRepeatInterval = effect->trigger_interval; |
---|
329 | |
---|
330 | #if (OIS_WIN32_JOYFF_DEBUG > 1) |
---|
331 | cout << " Trigger :" << endl |
---|
332 | << " Button : " << effect->trigger_button |
---|
333 | << " => " << diEffect->dwTriggerButton << endl |
---|
334 | << " Interval : " << effect->trigger_interval |
---|
335 | << " => " << diEffect->dwTriggerRepeatInterval << endl; |
---|
336 | #endif |
---|
337 | |
---|
338 | diEffect->cAxes = 1; // effect->getNumAxes(); |
---|
339 | diEffect->rgdwAxes = rgdwAxes; |
---|
340 | |
---|
341 | diEffect->rglDirection = rglDirection; // TODO: conversion from effect->direction |
---|
342 | |
---|
343 | #if (OIS_WIN32_JOYFF_DEBUG > 1) |
---|
344 | cout << " Direction : " << Effect::getDirectionName(effect->direction) |
---|
345 | << " => {"; |
---|
346 | for (int iDir=0; iDir < (int)diEffect->cAxes; iDir++) |
---|
347 | cout << " " << diEffect->rglDirection[iDir]; |
---|
348 | cout << "}" << endl; |
---|
349 | #endif |
---|
350 | |
---|
351 | if (diEnvelope && envelope && envelope->isUsed()) |
---|
352 | { |
---|
353 | diEnvelope->dwSize = sizeof(DIENVELOPE); |
---|
354 | diEnvelope->dwAttackLevel = envelope->attackLevel; |
---|
355 | diEnvelope->dwAttackTime = envelope->attackLength; |
---|
356 | diEnvelope->dwFadeLevel = envelope->fadeLevel; |
---|
357 | diEnvelope->dwFadeTime = envelope->fadeLength; |
---|
358 | diEffect->lpEnvelope = diEnvelope; |
---|
359 | } |
---|
360 | else |
---|
361 | diEffect->lpEnvelope = 0; |
---|
362 | |
---|
363 | #if (OIS_WIN32_JOYFF_DEBUG > 1) |
---|
364 | if (diEnvelope && envelope && envelope->isUsed()) |
---|
365 | { |
---|
366 | cout << " Enveloppe :" << endl |
---|
367 | << " AttackLen : " << envelope->attackLength |
---|
368 | << " => " << diEnvelope->dwAttackTime << endl |
---|
369 | << " AttackLvl : " << envelope->attackLevel |
---|
370 | << " => " << diEnvelope->dwAttackLevel << endl |
---|
371 | << " FadeLen : " << envelope->fadeLength |
---|
372 | << " => " << diEnvelope->dwFadeTime << endl |
---|
373 | << " FadeLvl : " << envelope->fadeLevel |
---|
374 | << " => " << diEnvelope->dwFadeLevel << endl; |
---|
375 | } |
---|
376 | #endif |
---|
377 | |
---|
378 | diEffect->dwSamplePeriod = 0; |
---|
379 | diEffect->dwDuration = effect->replay_length; |
---|
380 | diEffect->dwStartDelay = effect->replay_delay; |
---|
381 | |
---|
382 | #if (OIS_WIN32_JOYFF_DEBUG > 1) |
---|
383 | cout << " Replay :" << endl |
---|
384 | << " Length : " << effect->replay_length |
---|
385 | << " => " << diEffect->dwDuration << endl |
---|
386 | << " Delay : " << effect->replay_delay |
---|
387 | << " => " << diEffect->dwStartDelay << endl; |
---|
388 | #endif |
---|
389 | |
---|
390 | diEffect->cbTypeSpecificParams = struct_size; |
---|
391 | diEffect->lpvTypeSpecificParams = struct_type; |
---|
392 | } |
---|
393 | |
---|
394 | //--------------------------------------------------------------// |
---|
395 | void Win32ForceFeedback::_upload( GUID guid, DIEFFECT* diEffect, const Effect* effect) |
---|
396 | { |
---|
397 | LPDIRECTINPUTEFFECT dxEffect = 0; |
---|
398 | |
---|
399 | //Get the effect - if it exists |
---|
400 | EffectList::iterator i = mEffectList.find(effect->_handle); |
---|
401 | //It has been created already |
---|
402 | if( i != mEffectList.end() ) |
---|
403 | dxEffect = i->second; |
---|
404 | else //This effect has not yet been created - generate a handle |
---|
405 | effect->_handle = mHandles++; |
---|
406 | |
---|
407 | if( dxEffect == 0 ) |
---|
408 | { |
---|
409 | //This effect has not yet been created, so create it |
---|
410 | HRESULT hr = mJoyStick->CreateEffect(guid, diEffect, &dxEffect, NULL); |
---|
411 | if(SUCCEEDED(hr)) |
---|
412 | { |
---|
413 | mEffectList[effect->_handle] = dxEffect; |
---|
414 | dxEffect->Start(INFINITE,0); |
---|
415 | } |
---|
416 | else if( hr == DIERR_DEVICEFULL ) |
---|
417 | OIS_EXCEPT(E_DeviceFull, "Remove an effect before adding more!"); |
---|
418 | else |
---|
419 | OIS_EXCEPT(E_General, "Unknown error creating effect->.."); |
---|
420 | } |
---|
421 | else |
---|
422 | { |
---|
423 | //ToDo -- Update the Effect |
---|
424 | HRESULT hr = dxEffect->SetParameters( diEffect, DIEP_DIRECTION | |
---|
425 | DIEP_DURATION | DIEP_ENVELOPE | DIEP_STARTDELAY | DIEP_TRIGGERBUTTON | |
---|
426 | DIEP_TRIGGERREPEATINTERVAL | DIEP_TYPESPECIFICPARAMS | DIEP_START ); |
---|
427 | |
---|
428 | if(FAILED(hr)) OIS_EXCEPT(E_InvalidParam, "Error updating device!"); |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | //--------------------------------------------------------------// |
---|
433 | void Win32ForceFeedback::_addEffectSupport( LPCDIEFFECTINFO pdei ) |
---|
434 | { |
---|
435 | #if (OIS_WIN32_JOYFF_DEBUG > 0) |
---|
436 | // Dump some usefull information about the effect type. |
---|
437 | cout << "Adding support for '" << pdei->tszName << "' effect type" << endl; |
---|
438 | cout << " Supported static params: "; |
---|
439 | if (pdei->dwStaticParams & DIEP_AXES) cout << " Axes"; |
---|
440 | if (pdei->dwStaticParams & DIEP_DIRECTION) cout << " Direction"; |
---|
441 | if (pdei->dwStaticParams & DIEP_DURATION) cout << " Duration"; |
---|
442 | if (pdei->dwStaticParams & DIEP_ENVELOPE) cout << " Envelope"; |
---|
443 | if (pdei->dwStaticParams & DIEP_GAIN) cout << " Gain"; |
---|
444 | if (pdei->dwStaticParams & DIEP_SAMPLEPERIOD) cout << " SamplePeriod"; |
---|
445 | if (pdei->dwStaticParams & DIEP_STARTDELAY) cout << " StartDelay"; |
---|
446 | if (pdei->dwStaticParams & DIEP_TRIGGERBUTTON) cout << " TriggerButton"; |
---|
447 | if (pdei->dwStaticParams & DIEP_TRIGGERREPEATINTERVAL) cout << " TriggerRepeatInterval"; |
---|
448 | if (pdei->dwStaticParams & DIEP_TYPESPECIFICPARAMS) cout << " TypeSpecificParams"; |
---|
449 | cout << endl; |
---|
450 | cout << " Supported dynamic params: "; |
---|
451 | if (pdei->dwDynamicParams & DIEP_AXES) cout << " Axes"; |
---|
452 | if (pdei->dwDynamicParams & DIEP_DIRECTION) cout << " Direction"; |
---|
453 | if (pdei->dwDynamicParams & DIEP_DURATION) cout << " Duration"; |
---|
454 | if (pdei->dwDynamicParams & DIEP_ENVELOPE) cout << " Envelope"; |
---|
455 | if (pdei->dwDynamicParams & DIEP_GAIN) cout << " Gain"; |
---|
456 | if (pdei->dwDynamicParams & DIEP_SAMPLEPERIOD) cout << " SamplePeriod"; |
---|
457 | if (pdei->dwDynamicParams & DIEP_STARTDELAY) cout << " StartDelay"; |
---|
458 | if (pdei->dwDynamicParams & DIEP_TRIGGERBUTTON) cout << " TriggerButton"; |
---|
459 | if (pdei->dwDynamicParams & DIEP_TRIGGERREPEATINTERVAL) cout << " TriggerRepeatInterval"; |
---|
460 | if (pdei->dwDynamicParams & DIEP_TYPESPECIFICPARAMS) cout << " TypeSpecificParams"; |
---|
461 | cout << endl; |
---|
462 | cout << " More details about supported parameters support: "; |
---|
463 | if (pdei->dwEffType & DIEFT_STARTDELAY) cout << " StartDelay"; |
---|
464 | if (pdei->dwEffType & DIEFT_FFATTACK) cout << " Attack"; |
---|
465 | if (pdei->dwEffType & DIEFT_FFFADE) cout << " Fade"; |
---|
466 | if (pdei->dwEffType & DIEFT_DEADBAND) cout << " DeadBand"; |
---|
467 | if (pdei->dwEffType & DIEFT_SATURATION) cout << " Saturation"; |
---|
468 | if (pdei->dwEffType & DIEFT_POSNEGSATURATION) cout << " PosNegaturation"; |
---|
469 | if (pdei->dwEffType & DIEFT_POSNEGCOEFFICIENTS) cout << " PosNegCoefficients"; |
---|
470 | if (pdei->dwEffType & DIEFT_HARDWARE) cout << " HardwareSpecific"; |
---|
471 | cout << endl; |
---|
472 | #endif |
---|
473 | |
---|
474 | Effect::EForce eForce; |
---|
475 | switch (DIEFT_GETTYPE(pdei->dwEffType)) |
---|
476 | { |
---|
477 | case DIEFT_CONSTANTFORCE: |
---|
478 | eForce = Effect::ConstantForce; |
---|
479 | break; |
---|
480 | case DIEFT_RAMPFORCE: |
---|
481 | eForce = Effect::RampForce; |
---|
482 | break; |
---|
483 | case DIEFT_PERIODIC: |
---|
484 | eForce = Effect::PeriodicForce; |
---|
485 | break; |
---|
486 | case DIEFT_CONDITION: |
---|
487 | eForce = Effect::ConditionalForce; |
---|
488 | break; |
---|
489 | case DIEFT_CUSTOMFORCE: |
---|
490 | eForce = Effect::CustomForce; |
---|
491 | break; |
---|
492 | default: |
---|
493 | eForce = Effect::UnknownForce; |
---|
494 | #if defined (_DEBUG) |
---|
495 | cout << "Win32ForceFeedback: DirectInput8 Effect type support not implemented: " |
---|
496 | << "DIEFT_GETTYPE="<< (int)DIEFT_GETTYPE(pdei->dwEffType) << endl; |
---|
497 | #endif |
---|
498 | return; |
---|
499 | } |
---|
500 | |
---|
501 | //Determine what the effect type is and how it corresponds to our OIS's Enums |
---|
502 | //We could save the GUIDs too, however, we will just use the predefined ones later |
---|
503 | if( pdei->guid == GUID_ConstantForce ) |
---|
504 | _addEffectTypes(eForce, Effect::Constant ); |
---|
505 | else if( pdei->guid == GUID_Triangle ) |
---|
506 | _addEffectTypes(eForce, Effect::Triangle ); |
---|
507 | else if( pdei->guid == GUID_Spring ) |
---|
508 | _addEffectTypes(eForce, Effect::Spring ); |
---|
509 | else if( pdei->guid == GUID_Friction ) |
---|
510 | _addEffectTypes(eForce, Effect::Friction ); |
---|
511 | else if( pdei->guid == GUID_Square ) |
---|
512 | _addEffectTypes(eForce, Effect::Square ); |
---|
513 | else if( pdei->guid == GUID_Sine ) |
---|
514 | _addEffectTypes(eForce, Effect::Sine ); |
---|
515 | else if( pdei->guid == GUID_SawtoothUp ) |
---|
516 | _addEffectTypes(eForce, Effect::SawToothUp ); |
---|
517 | else if( pdei->guid == GUID_SawtoothDown ) |
---|
518 | _addEffectTypes(eForce, Effect::SawToothDown ); |
---|
519 | else if( pdei->guid == GUID_Damper ) |
---|
520 | _addEffectTypes(eForce, Effect::Damper ); |
---|
521 | else if( pdei->guid == GUID_Inertia ) |
---|
522 | _addEffectTypes(eForce, Effect::Inertia ); |
---|
523 | else if( pdei->guid == GUID_CustomForce ) |
---|
524 | _addEffectTypes(eForce, Effect::Custom ); |
---|
525 | else if( pdei->guid == GUID_RampForce ) |
---|
526 | _addEffectTypes(eForce, Effect::Ramp ); |
---|
527 | |
---|
528 | #if defined (_DEBUG) |
---|
529 | //Only care about this for Debugging Purposes |
---|
530 | //else |
---|
531 | //{ |
---|
532 | // std::ostringstream ss; |
---|
533 | // ss << "Win32ForceFeedback, DirectInput8 Effect not found. Reported as: " |
---|
534 | // << pdei->tszName; |
---|
535 | // OIS_EXCEPT( E_General, ss.str().c_str()); |
---|
536 | //} |
---|
537 | #endif |
---|
538 | } |
---|
539 | |
---|
540 | //--------------------------------------------------------------// |
---|
541 | void Win32ForceFeedback::_addFFAxis() |
---|
542 | { |
---|
543 | mFFAxes++; |
---|
544 | } |
---|