/****************************************************************** Function: RomClosed Purpose: This function is called when a rom is closed. input: none output: none *******************************************************************/ EXPORT void CALL RomClosed(void) { int i; XInputEnable( FALSE ); // disables xinput --tecnicors DebugWriteA("CALLED: RomClosed\n"); EnterCriticalSection( &g_critical ); if (g_sysMouse.didHandle) g_sysMouse.didHandle->SetCooperativeLevel(g_strEmuInfo.hMainWindow, DIB_KEYBOARD); // unlock the mouse, just in case for( i = 0; i < ARRAYSIZE(g_pcControllers); ++i ) { if( g_pcControllers[i].pPakData ) { SaveControllerPak( i ); CloseControllerPak( i ); } // freePakData( &g_pcControllers[i] ); already done by CloseControllerPak --rabid // DON'T free the modifiers! // ZeroMemory( &g_pcControllers[i], sizeof(CONTROLLER) ); } for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) ReleaseEffect( g_apdiEffect[i] ); ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); g_bRunning = false; LeaveCriticalSection( &g_critical ); return; }
void ReleaseImg() { // 释放贴图列表 for(int i=0;i<65535;i++) { texlist *sch = texlist_headp[i]; while(sch) { sch->tex->tex->Release(); texlist *tmp = sch; sch = sch->next; delete tmp; } } // 释放顶点缓存 if( lpVB != NULL ) lpVB->Release(); // 释放化着色器资源 ReleaseEffect(); }
// release our DirectInput effects and devices, our DirectInput handle, and then unload dinput library void FreeDirectInput () { int i; // release effects for( i = 0; i < ARRAYSIZE( g_apdiEffect ); ++i ) ReleaseEffect( g_apdiEffect[i] ); ZeroMemory( g_apdiEffect, sizeof(g_apdiEffect) ); // release FF devices for( i = 0; i << ARRAYSIZE(g_apFFDevice); ++i ) ReleaseDevice( g_apFFDevice[i] ); ZeroMemory( g_apFFDevice, sizeof(g_apFFDevice) ); // release normal devices for( i = 0; i < g_nDevices; i++ ) ReleaseDevice( g_devList[i].didHandle ); ZeroMemory( g_devList, sizeof(g_devList) ); g_nDevices = 0; // release mouse device ReleaseDevice( g_sysMouse.didHandle ); ZeroMemory( &g_sysMouse, sizeof(g_sysMouse) ); // Release any DirectInput handles. if( g_pDIHandle != NULL ) { g_pDIHandle->Release(); g_pDIHandle = NULL; } // Unload the library. if( g_hDirectInputDLL != NULL ) { FreeLibrary( g_hDirectInputDLL ); g_hDirectInputDLL = NULL; } return; }
// Create a force feedback effect handle and downloads the effect. Parameters are self-explanatory. bool CreateEffectHandle( HWND hWnd, LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LPDIRECTINPUTEFFECT &pDIEffect, BYTE bRumbleTyp, long lStrength ) { if( pDIEffect ) ReleaseEffect( pDIEffect ); if( !lpDirectInputDevice || bRumbleTyp == RUMBLE_DIRECT ) return false; DWORD nAxes = 0; DWORD rgdwAxes[] = { DIJOFS_X, DIJOFS_Y }; HRESULT hResult; // count the FF - axes of the joystick lpDirectInputDevice->EnumObjects( EnumCountFFAxes, &nAxes, DIDFT_FFACTUATOR | DIDFT_AXIS ); if( nAxes == 0 ) return false; nAxes = min( nAxes, 2 ); // Must be unaquired for setting stuff like Co-op Level hResult = lpDirectInputDevice->Unacquire(); //FF Requires EXCLUSIVE LEVEL, took me hours to find the reason why it wasnt working hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, DIB_FF ); // fail if we can't set coop level --rabid if (hResult != DI_OK) { DebugWriteA("CreateEffectHandle: couldn't set coop level: %08X\n", hResult); return false; } // Since we will be playing force feedback effects, we should disable the // auto-centering spring. DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = FALSE; hResult = lpDirectInputDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ); long rglDirection[] = { 1, 1 }; LPGUID EffectGuid; DIEFFECT eff; ZeroMemory( &eff, sizeof(eff) ); eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwGain = lStrength * 100; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = nAxes; //Number of Axes eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = NULL; eff.dwStartDelay = 0; DICONSTANTFORCE cf; DIRAMPFORCE rf; DIPERIODIC pf; switch( bRumbleTyp ) { case RUMBLE_CONSTANT: EffectGuid = (GUID*)&GUID_ConstantForce; eff.dwDuration = 150000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); eff.lpvTypeSpecificParams = &cf; cf.lMagnitude = 10000; break; case RUMBLE_RAMP: EffectGuid = (GUID*)&GUID_RampForce; eff.dwDuration = 300000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); eff.lpvTypeSpecificParams = &rf; rf.lStart = 10000; rf.lEnd = 2000; break; case RUMBLE_CONDITION: case RUMBLE_PERIODIC: EffectGuid = (GUID*)&GUID_Sine; eff.dwDuration = 150000; // microseconds eff.dwSamplePeriod = 0; eff.cbTypeSpecificParams = sizeof(DIPERIODIC); eff.lpvTypeSpecificParams = &pf; pf.dwMagnitude = 10000; pf.lOffset = 0; pf.dwPhase = 0; pf.dwPeriod = 2000; break; case RUMBLE_NONE: case RUMBLE_CUSTOM: default: return false; } hResult = lpDirectInputDevice->CreateEffect( *EffectGuid, &eff, &pDIEffect, NULL ); if (hResult == DI_OK) { hResult = lpDirectInputDevice->Acquire(); hResult = pDIEffect->Download(); } else { DebugWriteA("CreateEffectHandle: didn't CreateEffect: %08X\n", hResult); } return SUCCEEDED( hResult ); }
// PrepareInputDevices rewritten --rabid bool PrepareInputDevices() { bool fKeyboard = false; bool fMouse = false; bool fGamePad = false; for( int i = 0; i < ARRAYSIZE( g_pcControllers ); ++i ) { fGamePad = false; if( g_pcControllers[i].fPlugged ) { CountControllerStructDevs( &g_pcControllers[i] ); fKeyboard = g_pcControllers[i].fKeyboard != 0; fMouse = g_pcControllers[i].fMouse != 0; fGamePad = ( g_pcControllers[i].fGamePad != 0); // we'll assume for now that there's a gamepad to go with those buttons } ReleaseEffect( g_apdiEffect[i] ); if( g_pcControllers[i].guidFFDevice != GUID_NULL && GetInputDevice( g_strEmuInfo.hMainWindow, g_apFFDevice[i], g_pcControllers[i].guidFFDevice, DI8DEVTYPE_JOYSTICK, DIB_FF )) // not necessarily a joystick type device, but we don't use the data anyway { DIDEVICEINSTANCE diDev; diDev.dwSize = sizeof( DIDEVICEINSTANCE ); g_apFFDevice[i]->GetDeviceInfo( &diDev ); if( !lstrcmp( diDev.tszProductName, _T( STRING_ADAPTOID ))) { g_pcControllers[i].fIsAdaptoid = true; DebugWriteA("FF device on controller %d is of type Adaptoid\n", i+1); } else { g_pcControllers[i].fIsAdaptoid = false; } if ( CreateEffectHandle( i, g_pcControllers[i].bRumbleTyp, g_pcControllers[i].bRumbleStrength ) ) { AcquireDevice( g_apFFDevice[i] ); DebugWriteA("Got FF device %d\n", i); } else DebugWriteA("Couldn't get FF device: CreateEffectHandle failed!\n"); } else { g_apFFDevice[i] = NULL; DebugWriteA("Didn't get FF device %d\n", i); } } if( fMouse ) { if( !g_sysMouse.didHandle ) { if( GetInputDevice( g_strEmuInfo.hMainWindow, g_sysMouse.didHandle, GUID_SysMouse, DI8DEVTYPE_MOUSE, g_bExclusiveMouse ? DIB_MOUSE : DIB_KEYBOARD )) { AcquireDevice( g_sysMouse.didHandle ); } } } else { g_bExclusiveMouse = false; } return true; }