Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 22, 2009, 11:16:34 PM (15 years ago)
Author:
rgrieder
Message:

Updated OIS library (still 1.2, but CVS version).
There have been some little fixes and support for force feedback on Linux (but this doesn't concern us for now…)

Location:
code/branches/resource2/src/ois/win32
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/ois/win32/Win32ForceFeedback.cpp

    r1505 r5668  
    2525#include <Math.h>
    2626
    27 #if defined (_DEBUG)
     27// 0 = No trace; 1 = Important traces; 2 = Debug traces
     28#define OIS_WIN32_JOYFF_DEBUG 1
     29
     30#if (defined (_DEBUG) || defined(OIS_WIN32_JOYFF_DEBUG))
     31  #include <iostream>
    2832  #include <sstream>
     33  using namespace std;
    2934#endif
    3035
     
    3237
    3338//--------------------------------------------------------------//
    34 Win32ForceFeedback::Win32ForceFeedback(IDirectInputDevice8* joy) :
    35         mHandles(0), mJoyStick(joy)
    36 {
     39Win32ForceFeedback::Win32ForceFeedback(IDirectInputDevice8* pDIJoy, const DIDEVCAPS* pDIJoyCaps) :
     40  mHandles(0), mJoyStick(pDIJoy), mFFAxes(0), mpDIJoyCaps(pDIJoyCaps)
     41{
     42#if (OIS_WIN32_JOYFF_DEBUG > 0)
     43  cout << "FFSamplePeriod      : " << mpDIJoyCaps->dwFFSamplePeriod << " mu-s, "
     44           << "FFMinTimeResolution : " << mpDIJoyCaps->dwFFMinTimeResolution << " mu-s,"
     45           << "" << endl;
     46#endif
    3747}
    3848
     
    4555                LPDIRECTINPUTEFFECT dxEffect = i->second;
    4656                if( dxEffect )
     57                {
    4758                        dxEffect->Unload();
     59                        dxEffect->Release();
     60                }
    4861        }
    4962
    5063        mEffectList.clear();
     64}
     65
     66//--------------------------------------------------------------//
     67short Win32ForceFeedback::getFFAxesNumber()
     68{
     69        return mFFAxes;
     70}
     71
     72//--------------------------------------------------------------//
     73unsigned short Win32ForceFeedback::getFFMemoryLoad()
     74{
     75    DIPROPDWORD dipdw;  // DIPROPDWORD contains a DIPROPHEADER structure.
     76        dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
     77        dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
     78        dipdw.diph.dwObj        = 0; // device property
     79        dipdw.diph.dwHow        = DIPH_DEVICE;
     80        dipdw.dwData            = 0; // In case of any error.
     81
     82        const HRESULT hr = mJoyStick->GetProperty(DIPROP_FFLOAD, &dipdw.diph);
     83        if(FAILED(hr))
     84        {
     85            if (hr == DIERR_NOTEXCLUSIVEACQUIRED)
     86                    OIS_EXCEPT(E_General, "Can't query FF memory load as device was not acquired in exclusive mode");
     87                else
     88                    OIS_EXCEPT(E_General, "Unknown error querying FF memory load ->..");
     89        }
     90
     91        return (unsigned short)dipdw.dwData;
    5192}
    5293
     
    86127                        //have been unlaoded
    87128                        if( SUCCEEDED(dxEffect->Unload()) )
     129                        {
     130                            dxEffect->Release();
    88131                                mEffectList.erase(i);
     132                        }
    89133                }
    90134                else
     
    111155        DIPropGain.dwData            = gain_level;
    112156
    113         mJoyStick->SetProperty(DIPROP_FFGAIN, &DIPropGain.diph);
     157#if (OIS_WIN32_JOYFF_DEBUG > 0)
     158        cout << "Win32ForceFeedback("<< mJoyStick << ") : Setting master gain to "
     159                 << level << " => " << DIPropGain.dwData << endl;
     160#endif
     161
     162        const HRESULT hr = mJoyStick->SetProperty(DIPROP_FFGAIN, &DIPropGain.diph);
     163
     164#if defined (_DEBUG)
     165        if(FAILED(hr))
     166            cout << "Failed to change master gain" << endl;
     167#endif
    114168}
    115169
     
    117171void Win32ForceFeedback::setAutoCenterMode( bool auto_on )
    118172{
    119         //DI Property DIPROPAUTOCENTER_OFF = 0, 1 is on
    120173        DIPROPDWORD DIPropAutoCenter;
    121174        DIPropAutoCenter.diph.dwSize       = sizeof(DIPropAutoCenter);
     
    123176        DIPropAutoCenter.diph.dwObj        = 0;
    124177        DIPropAutoCenter.diph.dwHow        = DIPH_DEVICE;
    125         DIPropAutoCenter.dwData            = auto_on;
    126 
    127         //hr =
    128         mJoyStick->SetProperty(DIPROP_AUTOCENTER, &DIPropAutoCenter.diph);
     178        DIPropAutoCenter.dwData            = (auto_on ? DIPROPAUTOCENTER_ON : DIPROPAUTOCENTER_OFF);
     179
     180#if (OIS_WIN32_JOYFF_DEBUG > 0)
     181        cout << "Win32ForceFeedback("<< mJoyStick << ") : Setting auto-center mode to "
     182                 << auto_on << " => " << DIPropAutoCenter.dwData << endl;
     183#endif
     184
     185        const HRESULT hr = mJoyStick->SetProperty(DIPROP_AUTOCENTER, &DIPropAutoCenter.diph);
     186
     187#if defined (_DEBUG)
     188        if(FAILED(hr))
     189            cout << "Failed to change auto-center mode" << endl;
     190#endif
    129191}
    130192
     
    132194void Win32ForceFeedback::_updateConstantEffect( const Effect* effect )
    133195{
     196        ConstantEffect *eff = static_cast<ConstantEffect*>(effect->getForceEffect());
     197
    134198        DWORD           rgdwAxes[2]     = { DIJOFS_X, DIJOFS_Y };
    135199        LONG            rglDirection[2] = { 0, 0 };
     200        DIENVELOPE      diEnvelope;
    136201        DICONSTANTFORCE cf;
    137202        DIEFFECT        diEffect;
     
    139204        //Currently only support 1 axis
    140205        //if( effect->getNumAxes() == 1 )
    141         cf.lMagnitude = static_cast<ConstantEffect*>(effect->getForceEffect())->level;
    142 
    143         _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICONSTANTFORCE), &cf, effect);
     206        cf.lMagnitude = eff->level;
     207
     208#if (OIS_WIN32_JOYFF_DEBUG > 1)
     209        cout << "  Level : " << eff->level
     210                 << " => " << cf.lMagnitude << endl;
     211#endif
     212
     213        _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICONSTANTFORCE), &cf, effect, &eff->envelope);
    144214        _upload(GUID_ConstantForce, &diEffect, effect);
    145215}
     
    148218void Win32ForceFeedback::_updateRampEffect( const Effect* effect )
    149219{
     220        RampEffect *eff = static_cast<RampEffect*>(effect->getForceEffect());
     221
    150222        DWORD           rgdwAxes[2]     = { DIJOFS_X, DIJOFS_Y };
    151223        LONG            rglDirection[2] = { 0, 0 };
     224        DIENVELOPE      diEnvelope;
    152225        DIRAMPFORCE     rf;
    153226        DIEFFECT        diEffect;
    154227
    155228        //Currently only support 1 axis
    156         rf.lStart = static_cast<RampEffect*>(effect->getForceEffect())->startLevel;
    157         rf.lEnd = static_cast<RampEffect*>(effect->getForceEffect())->endLevel;
    158 
    159         _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DIRAMPFORCE), &rf, effect);
     229        rf.lStart = eff->startLevel;
     230        rf.lEnd = eff->endLevel;
     231
     232        _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DIRAMPFORCE), &rf, effect, &eff->envelope );
    160233        _upload(GUID_RampForce, &diEffect, effect);
    161234}
     
    164237void Win32ForceFeedback::_updatePeriodicEffect( const Effect* effect )
    165238{
     239        PeriodicEffect *eff = static_cast<PeriodicEffect*>(effect->getForceEffect());
     240
    166241        DWORD           rgdwAxes[2]     = { DIJOFS_X, DIJOFS_Y };
    167242        LONG            rglDirection[2] = { 0, 0 };
     243        DIENVELOPE      diEnvelope;
    168244        DIPERIODIC      pf;
    169245        DIEFFECT        diEffect;
    170246
    171247        //Currently only support 1 axis
    172         pf.dwMagnitude = static_cast<PeriodicEffect*>(effect->getForceEffect())->magnitude;
    173         pf.lOffset = static_cast<PeriodicEffect*>(effect->getForceEffect())->offset;
    174         pf.dwPhase = static_cast<PeriodicEffect*>(effect->getForceEffect())->phase;
    175         pf.dwPeriod = static_cast<PeriodicEffect*>(effect->getForceEffect())->period;
    176 
    177         _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DIPERIODIC), &pf, effect);
     248        pf.dwMagnitude = eff->magnitude;
     249        pf.lOffset = eff->offset;
     250        pf.dwPhase = eff->phase;
     251        pf.dwPeriod = eff->period;
     252
     253        _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DIPERIODIC), &pf, effect, &eff->envelope );
    178254
    179255        switch( effect->type )
     
    191267void Win32ForceFeedback::_updateConditionalEffect( const Effect* effect )
    192268{
     269        ConditionalEffect *eff = static_cast<ConditionalEffect*>(effect->getForceEffect());
     270
    193271        DWORD           rgdwAxes[2]     = { DIJOFS_X, DIJOFS_Y };
    194272        LONG            rglDirection[2] = { 0, 0 };
     273        DIENVELOPE      diEnvelope;
    195274        DICONDITION     cf;
    196275        DIEFFECT        diEffect;
    197276
    198         cf.lOffset = static_cast<ConditionalEffect*>(effect->getForceEffect())->deadband;
    199         cf.lPositiveCoefficient = static_cast<ConditionalEffect*>(effect->getForceEffect())->rightCoeff;
    200         cf.lNegativeCoefficient = static_cast<ConditionalEffect*>(effect->getForceEffect())->leftCoeff;
    201         cf.dwPositiveSaturation = static_cast<ConditionalEffect*>(effect->getForceEffect())->rightSaturation;
    202         cf.dwNegativeSaturation = static_cast<ConditionalEffect*>(effect->getForceEffect())->leftSaturation;
    203         cf.lDeadBand = static_cast<ConditionalEffect*>(effect->getForceEffect())->deadband;
    204 
    205         _setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICONDITION), &cf, effect);
     277        cf.lOffset = eff->deadband;
     278        cf.lPositiveCoefficient = eff->rightCoeff;
     279        cf.lNegativeCoefficient = eff->leftCoeff;
     280        cf.dwPositiveSaturation = eff->rightSaturation;
     281        cf.dwNegativeSaturation = eff->leftSaturation;
     282        cf.lDeadBand = eff->deadband;
     283
     284        _setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICONDITION), &cf, effect, 0 );
    206285
    207286        switch( effect->type )
     
    218297void Win32ForceFeedback::_updateCustomEffect( const Effect* /*effect*/ )
    219298{
     299    //CustomEffect *eff = static_cast<CustomEffect*>(effect->getForceEffect());
     300    //
    220301        //DWORD           rgdwAxes[2]     = { DIJOFS_X, DIJOFS_Y };
    221302        //LONG            rglDirection[2] = { 0, 0 };
     303        //DIENVELOPE      diEnvelope;
    222304        //DICUSTOMFORCE cf;
    223305        //DIEFFECT        diEffect;
     
    226308        //cf.cSamples = 0;
    227309        //cf.rglForceData = 0;
    228         //_setCommonProperties(&diEffect, rgdwAxes, rglDirection, sizeof(DICUSTOMFORCE), &cf, effect);
     310        //_setCommonProperties(&diEffect, rgdwAxes, rglDirection, &diEnvelope, sizeof(DICUSTOMFORCE), &cf, effect, &eff->envelope);
    229311        //_upload(GUID_CustomForce, &diEffect, effect);
    230312}
     
    233315void Win32ForceFeedback::_setCommonProperties(
    234316                DIEFFECT* diEffect, DWORD* rgdwAxes,
    235                 LONG* rglDirection, DWORD struct_size,
    236                 LPVOID struct_type, const Effect* effect )
     317                LONG* rglDirection, DIENVELOPE* diEnvelope, DWORD struct_size,
     318                LPVOID struct_type, const Effect* effect, const Envelope* envelope )
    237319{
    238320        ZeroMemory(diEffect, sizeof(DIEFFECT));
     
    240322        diEffect->dwSize                  = sizeof(DIEFFECT);
    241323        diEffect->dwFlags                 = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
     324        diEffect->dwGain                  = DI_FFNOMINALMAX;
     325
     326        diEffect->dwTriggerButton         = DIEB_NOTRIGGER; // effect->trigger_button; // TODO: Conversion
     327        diEffect->dwTriggerRepeatInterval = effect->trigger_interval;
     328
     329#if (OIS_WIN32_JOYFF_DEBUG > 1)
     330        cout << "  Trigger :" << endl
     331                 << "    Button   : " << effect->trigger_button
     332                 << " => " << diEffect->dwTriggerButton << endl
     333                 << "    Interval : " << effect->trigger_interval
     334                 << " => " << diEffect->dwTriggerRepeatInterval << endl;
     335#endif
     336
     337        diEffect->cAxes                   = 1; // effect->getNumAxes();
     338        diEffect->rgdwAxes                = rgdwAxes;
     339
     340        diEffect->rglDirection            = rglDirection; // TODO: conversion from effect->direction
     341
     342#if (OIS_WIN32_JOYFF_DEBUG > 1)
     343        cout << "  Direction : " << Effect::getDirectionName(effect->direction)
     344                 << " => {";
     345        for (int iDir=0; iDir < (int)diEffect->cAxes; iDir++)
     346          cout << " " << diEffect->rglDirection[iDir];
     347        cout << "}" << endl;
     348#endif
     349
     350        if (diEnvelope && envelope && envelope->isUsed())
     351        {
     352            diEnvelope->dwSize = sizeof(DIENVELOPE);
     353            diEnvelope->dwAttackLevel = envelope->attackLevel;
     354            diEnvelope->dwAttackTime  = envelope->attackLength;
     355            diEnvelope->dwFadeLevel   = envelope->fadeLevel;
     356            diEnvelope->dwFadeTime    = envelope->fadeLength;
     357            diEffect->lpEnvelope = diEnvelope;
     358        }
     359        else
     360            diEffect->lpEnvelope = 0;
     361
     362#if (OIS_WIN32_JOYFF_DEBUG > 1)
     363        if (diEnvelope && envelope && envelope->isUsed())
     364        {
     365                cout << "  Enveloppe :" << endl
     366                         << "    AttackLen : " << envelope->attackLength
     367                         << " => " << diEnvelope->dwAttackTime << endl
     368                         << "    AttackLvl : " << envelope->attackLevel
     369                         << " => " << diEnvelope->dwAttackLevel << endl
     370                         << "    FadeLen   : " << envelope->fadeLength
     371                         << " => " << diEnvelope->dwFadeTime << endl
     372                         << "    FadeLvl   : " << envelope->fadeLevel
     373                         << " => " << diEnvelope->dwFadeLevel << endl;
     374        }
     375#endif
     376
     377        diEffect->dwSamplePeriod          = 0;
    242378        diEffect->dwDuration              = effect->replay_length;
    243         diEffect->dwSamplePeriod          = 0;
    244         diEffect->dwGain                  = DI_FFNOMINALMAX;
    245         diEffect->dwTriggerButton         = DIEB_NOTRIGGER;
    246         diEffect->dwTriggerRepeatInterval = 0;
    247         diEffect->cAxes                   = effect->getNumAxes();
    248         diEffect->rgdwAxes                = rgdwAxes;
    249         diEffect->rglDirection            = rglDirection;
    250         diEffect->lpEnvelope              = 0;
     379        diEffect->dwStartDelay            = effect->replay_delay;
     380
     381#if (OIS_WIN32_JOYFF_DEBUG > 1)
     382        cout << "  Replay :" << endl
     383                 << "    Length : " << effect->replay_length
     384                 << " => " << diEffect->dwDuration << endl
     385                 << "    Delay  : " << effect->replay_delay
     386                 << " => " << diEffect->dwStartDelay << endl;
     387#endif
     388
    251389        diEffect->cbTypeSpecificParams    = struct_size;
    252390        diEffect->lpvTypeSpecificParams   = struct_type;
    253         diEffect->dwStartDelay            = effect->replay_delay;
    254391}
    255392
     
    295432void Win32ForceFeedback::_addEffectSupport( LPCDIEFFECTINFO pdei )
    296433{
    297         //Determine what the effect is and how it corresponds to our OIS's Enums
    298         //We could save the GUIDs too, however, we will just use the predefined
    299         //ones later
     434#if (OIS_WIN32_JOYFF_DEBUG > 0)
     435    // Dump some usefull information about the effect type.
     436    cout << "Adding support for '" << pdei->tszName << "' effect type" << endl;
     437        cout << "  Supported static params: ";
     438        if (pdei->dwStaticParams & DIEP_AXES) cout << " Axes";
     439        if (pdei->dwStaticParams & DIEP_DIRECTION) cout << " Direction";
     440        if (pdei->dwStaticParams & DIEP_DURATION) cout << " Duration";
     441        if (pdei->dwStaticParams & DIEP_ENVELOPE) cout << " Envelope";
     442        if (pdei->dwStaticParams & DIEP_GAIN) cout << " Gain";
     443        if (pdei->dwStaticParams & DIEP_SAMPLEPERIOD) cout << " SamplePeriod";
     444        if (pdei->dwStaticParams & DIEP_STARTDELAY) cout << " StartDelay";
     445        if (pdei->dwStaticParams & DIEP_TRIGGERBUTTON) cout << " TriggerButton";
     446        if (pdei->dwStaticParams & DIEP_TRIGGERREPEATINTERVAL) cout << " TriggerRepeatInterval";
     447        if (pdei->dwStaticParams & DIEP_TYPESPECIFICPARAMS) cout << " TypeSpecificParams";
     448        cout << endl;
     449        cout << "  Supported dynamic params: ";
     450        if (pdei->dwDynamicParams & DIEP_AXES) cout << " Axes";
     451        if (pdei->dwDynamicParams & DIEP_DIRECTION) cout << " Direction";
     452        if (pdei->dwDynamicParams & DIEP_DURATION) cout << " Duration";
     453        if (pdei->dwDynamicParams & DIEP_ENVELOPE) cout << " Envelope";
     454        if (pdei->dwDynamicParams & DIEP_GAIN) cout << " Gain";
     455        if (pdei->dwDynamicParams & DIEP_SAMPLEPERIOD) cout << " SamplePeriod";
     456        if (pdei->dwDynamicParams & DIEP_STARTDELAY) cout << " StartDelay";
     457        if (pdei->dwDynamicParams & DIEP_TRIGGERBUTTON) cout << " TriggerButton";
     458        if (pdei->dwDynamicParams & DIEP_TRIGGERREPEATINTERVAL) cout << " TriggerRepeatInterval";
     459        if (pdei->dwDynamicParams & DIEP_TYPESPECIFICPARAMS) cout << " TypeSpecificParams";
     460        cout << endl;
     461        cout << "  More details about supported parameters support: ";
     462        if (pdei->dwEffType & DIEFT_STARTDELAY) cout << " StartDelay";
     463        if (pdei->dwEffType & DIEFT_FFATTACK) cout << " Attack";
     464        if (pdei->dwEffType & DIEFT_FFFADE) cout << " Fade";
     465        if (pdei->dwEffType & DIEFT_DEADBAND) cout << " DeadBand";
     466        if (pdei->dwEffType & DIEFT_SATURATION) cout << " Saturation";
     467        if (pdei->dwEffType & DIEFT_POSNEGSATURATION) cout << " PosNegaturation";
     468        if (pdei->dwEffType & DIEFT_POSNEGCOEFFICIENTS) cout << " PosNegCoefficients";
     469        if (pdei->dwEffType & DIEFT_HARDWARE) cout << " HardwareSpecific";
     470        cout << endl;
     471#endif
     472
     473    Effect::EForce eForce;
     474        switch (DIEFT_GETTYPE(pdei->dwEffType))
     475        {
     476            case DIEFT_CONSTANTFORCE:
     477                    eForce = Effect::ConstantForce;
     478                        break;
     479            case DIEFT_RAMPFORCE:
     480                    eForce = Effect::RampForce;
     481                        break;
     482            case DIEFT_PERIODIC:
     483                    eForce = Effect::PeriodicForce;
     484                        break;
     485            case DIEFT_CONDITION:
     486                    eForce = Effect::ConditionalForce;
     487                        break;
     488            case DIEFT_CUSTOMFORCE:
     489                    eForce = Effect::CustomForce;
     490                        break;
     491            default:
     492                    eForce = Effect::UnknownForce;
     493#if defined (_DEBUG)
     494                        cout << "Win32ForceFeedback: DirectInput8 Effect type support not implemented: "
     495                                 << "DIEFT_GETTYPE="<< (int)DIEFT_GETTYPE(pdei->dwEffType) << endl;
     496#endif
     497                        return;
     498        }
     499
     500        //Determine what the effect type is and how it corresponds to our OIS's Enums
     501        //We could save the GUIDs too, however, we will just use the predefined ones later
    300502        if( pdei->guid == GUID_ConstantForce )
    301                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Constant );
     503                _addEffectTypes(eForce, Effect::Constant );
    302504        else if( pdei->guid == GUID_Triangle )
    303                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Triangle );
     505                _addEffectTypes(eForce, Effect::Triangle );
    304506        else if( pdei->guid == GUID_Spring )
    305                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Spring );
     507                _addEffectTypes(eForce, Effect::Spring );
    306508        else if( pdei->guid == GUID_Friction )
    307                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Friction );
     509                _addEffectTypes(eForce, Effect::Friction );
    308510        else if( pdei->guid == GUID_Square )
    309                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Square );
     511                _addEffectTypes(eForce, Effect::Square );
    310512        else if( pdei->guid == GUID_Sine )
    311                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Sine );
     513                _addEffectTypes(eForce, Effect::Sine );
    312514        else if( pdei->guid == GUID_SawtoothUp )
    313                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::SawToothUp );
     515                _addEffectTypes(eForce, Effect::SawToothUp );
    314516        else if( pdei->guid == GUID_SawtoothDown )
    315                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::SawToothDown );
     517                _addEffectTypes(eForce, Effect::SawToothDown );
    316518        else if( pdei->guid == GUID_Damper )
    317                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Damper );
     519                _addEffectTypes(eForce, Effect::Damper );
    318520        else if( pdei->guid == GUID_Inertia )
    319                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Inertia );
     521                _addEffectTypes(eForce, Effect::Inertia );
    320522        else if( pdei->guid == GUID_CustomForce )
    321                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Custom );
     523                _addEffectTypes(eForce, Effect::Custom );
    322524        else if( pdei->guid == GUID_RampForce )
    323                 _addEffectTypes((Effect::EForce)DIEFT_GETTYPE(pdei->dwEffType), Effect::Ramp );
     525                _addEffectTypes(eForce, Effect::Ramp );
     526
    324527#if defined (_DEBUG)
    325528        //Only care about this for Debugging Purposes
     
    333536#endif
    334537}
     538
     539//--------------------------------------------------------------//
     540void Win32ForceFeedback::_addFFAxis()
     541{
     542        mFFAxes++;
     543}
  • code/branches/resource2/src/ois/win32/Win32ForceFeedback.h

    r1505 r5668  
    3434                Win32ForceFeedback() {}
    3535        public:
    36                 Win32ForceFeedback(IDirectInputDevice8* joy);
     36                Win32ForceFeedback(IDirectInputDevice8* pDIJoy, const DIDEVCAPS* pDIJoyCaps);
    3737                ~Win32ForceFeedback();
    3838
     
    5252                void setAutoCenterMode( bool auto_on );
    5353
    54                 /** @copydoc ForceFeedback::getFFAxesNumber
    55                         xxx todo - Actually return correct number
    56                 */
    57                 short getFFAxesNumber() {return 1;}
     54                /** @copydoc ForceFeedback::getFFAxesNumber */
     55                short getFFAxesNumber();
     56
     57                /** @copydoc ForceFeedback::getFFMemoryLoad */
     58                unsigned short getFFMemoryLoad();
    5859
    5960                /**
     
    6465                void _addEffectSupport( LPCDIEFFECTINFO pdei );
    6566
     67                /**
     68                        @remarks
     69                        Internal use.. Used during axis enumeration to get number of FF axes
     70                        support effects.
     71                */
     72                void _addFFAxis();
     73
    6674        protected:
     75
    6776                //Specific Effect Settings
    6877                void _updateConstantEffect( const Effect* effect );
     
    7180                void _updateConditionalEffect( const Effect* effect );
    7281                void _updateCustomEffect( const Effect* effect );
     82
    7383                //Sets the common properties to all effects
    7484                void _setCommonProperties( DIEFFECT* diEffect, DWORD* rgdwAxes,
    75                                                                         LONG* rglDirection, DWORD struct_size,
    76                                                                         LPVOID struct_type, const Effect* effect );
     85                                                                        LONG* rglDirection, DIENVELOPE* diEnvelope, DWORD struct_size,
     86                                                                        LPVOID struct_type, const Effect* effect, const Envelope* envelope );
    7787                //Actually do the upload
    7888                void _upload( GUID, DIEFFECT*, const Effect* );
    7989
     90                // Map of currently uploaded effects (handle => effect)
    8091                typedef std::map<int,LPDIRECTINPUTEFFECT> EffectList;
    8192                EffectList mEffectList;
    82                 //Simple unique handle creation - allows for upto 2+ million effects
     93
     94                //Simple unique handle creation - allows for upto 2+ billion effects
    8395                //during the lifetime of application. Hopefully, that is enough.
    8496                int mHandles;
    8597
     98                // Joystick device descriptor.
    8699                IDirectInputDevice8* mJoyStick;
     100               
     101                // Joystick capabilities.
     102                const DIDEVCAPS* mpDIJoyCaps;
     103
     104                // Number of axis supporting FF.
     105                short mFFAxes;
    87106        };
    88107}
  • code/branches/resource2/src/ois/win32/Win32InputManager.cpp

    r1505 r5668  
    7575        hInst = GetModuleHandle(0);
    7676
    77         //Create the device
     77        //Create the input system
    7878        hr = DirectInput8Create( hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&mDirectInput, NULL );
    7979    if (FAILED(hr))     
     
    8282        //Ok, now we have DirectInput, parse whatever extra settings were sent to us
    8383        _parseConfigSettings( paramList );
     84
     85        // Enumerate devices ...
    8486        _enumerateDevices();
    8587}
     
    116118{
    117119        //Enumerate all attached devices
    118         mDirectInput->EnumDevices(NULL, _DIEnumKbdCallback, this, DIEDFL_ATTACHEDONLY);
    119 }
    120 
    121 //--------------------------------------------------------------------------------//
    122 BOOL CALLBACK Win32InputManager::_DIEnumKbdCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
     120        mDirectInput->EnumDevices(NULL , _DIEnumDevCallback, this, DIEDFL_ATTACHEDONLY);
     121}
     122
     123//--------------------------------------------------------------------------------//
     124BOOL CALLBACK Win32InputManager::_DIEnumDevCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
    123125{
    124126        Win32InputManager *_this_ = static_cast<Win32InputManager*>(pvRef);
     127
     128        // Register only game devices (keyboard and mouse are managed differently).
    125129        if( GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK ||
    126130                GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD ||
  • code/branches/resource2/src/ois/win32/Win32InputManager.h

    r1505 r5668  
    8181
    8282                //! Used during device enumeration
    83                 static BOOL CALLBACK _DIEnumKbdCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
     83                static BOOL CALLBACK _DIEnumDevCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
    8484
    8585                //! Keep a list of all joysticks enumerated, but not in use
  • code/branches/resource2/src/ois/win32/Win32JoyStick.cpp

    r1505 r5668  
    8282        mState.mAxes.clear();
    8383
    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.
    87104        DIPROPDWORD dipdw;
    88 
    89105        dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
    90106        dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
     
    93109        dipdw.dwData            = JOYSTICK_DX_BUFFERSIZE;
    94110
    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 
    106111        if( FAILED(mJoyStick->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)) )
    107                 OIS_EXCEPT( E_General, "Win32Mouse::Win32Mouse >> Failed to set buffer size property" );
    108 
    109         //Enumerate all axes/buttons/sliders/etc before aquiring
     112                OIS_EXCEPT( E_General, "Win32JoyStick::_initialize >> Failed to set buffer size property" );
     113
     114        // Enumerate all axes/buttons/sliders/force feedback/etc before aquiring
    110115        _enumerate();
    111116
     
    118123void Win32JoyStick::_enumerate()
    119124{
    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);
    129139
    130140        //Reset the axis mapping enumeration value
    131141        _AxisNumber = 0;
    132142
    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)
    137144        mJoyStick->EnumObjects(DIEnumDeviceObjectsCallback, this, DIDFT_AXIS);
    138145}
     
    181188                OIS_EXCEPT( E_General, "Win32JoyStick::_DIEnumDeviceObjectsCallback >> Failed to set min/max range property" );
    182189
    183         //Check if FF Axes
     190        //Check if FF Axes, and if so, increment counter
    184191        if((lpddoi->dwFlags & DIDOI_FFACTUATOR) != 0 )
    185192        {
    186193                if( _this->ff_device )
    187194                {
    188                         //todo - increment force feedback axis count
     195                        _this->ff_device->_addFFAxis();
    189196                }
    190197        }
    191198
     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
    192208        return DIENUM_CONTINUE;
    193209}
     
    198214        Win32JoyStick* _this = (Win32JoyStick*)pvRef;
    199215
    200         //Create the FF class after we know there is at least one effect type
     216        //Create the FF instance only after we know there is at least one effect type
    201217        if( _this->ff_device == 0 )
    202                 _this->ff_device = new Win32ForceFeedback(_this->mJoyStick);
     218          _this->ff_device = new Win32ForceFeedback(_this->mJoyStick, &_this->mDIJoyCaps);
    203219
    204220        _this->ff_device->_addEffectSupport( pdei );
  • code/branches/resource2/src/ois/win32/Win32JoyStick.h

    r1505 r5668  
    6060                IDirectInput8* mDirectInput;
    6161                IDirectInputDevice8* mJoyStick;
     62                DIDEVCAPS mDIJoyCaps;
     63
    6264                DWORD coopSetting;
    6365                GUID deviceGuid;
  • code/branches/resource2/src/ois/win32/Win32KeyBoard.cpp

    r1505 r5668  
    238238                return 0;
    239239
    240         unsigned char buff[3] = {0,0,0};
    241         int ascii = ToAsciiEx(vk, kc, keyState, (LPWORD) buff, 0, layout);
    242         //WCHAR wide[3];
    243         //int ascii = ToUnicodeEx(vk, kc, keyState, wide, 3, 0, layout);
     240        WCHAR buff[3] = {0};
     241        int ascii = ToUnicodeEx(vk, kc, keyState, buff, 3, 0, layout);
     242
    244243        if(ascii == 1 && deadKey != '\0' )
    245244        {
Note: See TracChangeset for help on using the changeset viewer.