From 0c4f93897f270515c7c5e81d362c17ba9b13b269 Mon Sep 17 00:00:00 2001 From: Nik Henson Date: Sun, 25 Sep 2011 22:46:58 +0000 Subject: [PATCH] Force feedback fixes in DirectInputSystem.cpp: - Fixed bug which meant right constant force was not being capped to DI_EFFECTS_MAX - Made sure all values are being clamped to sensible ranges --- Src/OSD/Windows/DirectInputSystem.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Src/OSD/Windows/DirectInputSystem.cpp b/Src/OSD/Windows/DirectInputSystem.cpp index 019a4b9..5997d6a 100644 --- a/Src/OSD/Windows/DirectInputSystem.cpp +++ b/Src/OSD/Windows/DirectInputSystem.cpp @@ -1811,13 +1811,19 @@ bool CDirectInputSystem::ProcessForceFeedbackCmd(int joyNum, int axisNum, ForceF eff.lpEnvelope = NULL; // Set command specific parameters + LONG lFFMag; + DWORD dFFMag; switch (ffCmd.id) { case FFConstantForce: //printf("FFConstantForce %0.2f\n", 100.0f * ffCmd.force); if (g_Config.dInputConstForceMax == 0) return false; - dicf.lMagnitude = min(-ffCmd.force * (float)(g_Config.dInputConstForceMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); // Invert sign for DirectInput effect + lFFMag = (LONG)(-ffCmd.force * (float)(g_Config.dInputConstForceMax * DI_EFFECTS_SCALE)); // Invert sign for DirectInput effect + if (lFFMag >= 0) + dicf.lMagnitude = min(lFFMag, DI_EFFECTS_MAX); + else + dicf.lMagnitude = max(lFFMag, -DI_EFFECTS_MAX); eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE); eff.lpvTypeSpecificParams = &dicf; @@ -1827,9 +1833,10 @@ bool CDirectInputSystem::ProcessForceFeedbackCmd(int joyNum, int axisNum, ForceF //printf("FFSelfCenter %0.2f\n", 100.0f * ffCmd.force); if (g_Config.dInputSelfCenterMax == 0) return false; + lFFMag = (LONG)(ffCmd.force * (float)(g_Config.dInputSelfCenterMax * DI_EFFECTS_SCALE)); dic.lOffset = 0; - dic.lPositiveCoefficient = min(ffCmd.force * (float)(g_Config.dInputSelfCenterMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); - dic.lNegativeCoefficient = min(ffCmd.force * (float)(g_Config.dInputSelfCenterMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); + dic.lPositiveCoefficient = max(0, min(lFFMag, DI_EFFECTS_MAX)); + dic.lNegativeCoefficient = max(0, min(lFFMag, DI_EFFECTS_MAX)); dic.dwPositiveSaturation = DI_FFNOMINALMAX; dic.dwNegativeSaturation = DI_FFNOMINALMAX; dic.lDeadBand = (LONG)(0.05 * DI_FFNOMINALMAX); @@ -1842,9 +1849,10 @@ bool CDirectInputSystem::ProcessForceFeedbackCmd(int joyNum, int axisNum, ForceF //printf("FFFriction %0.2f\n", 100.0f * ffCmd.force); if (g_Config.dInputFrictionMax == 0) return false; + lFFMag = (LONG)(ffCmd.force * (float)(g_Config.dInputFrictionMax * DI_EFFECTS_SCALE)); dic.lOffset = 0; - dic.lPositiveCoefficient = min(ffCmd.force * (float)(g_Config.dInputFrictionMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); - dic.lNegativeCoefficient = min(ffCmd.force * (float)(g_Config.dInputFrictionMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); + dic.lPositiveCoefficient = max(0, min(lFFMag, DI_EFFECTS_MAX)); + dic.lNegativeCoefficient = max(0, min(lFFMag, DI_EFFECTS_MAX)); dic.dwPositiveSaturation = DI_FFNOMINALMAX; dic.dwNegativeSaturation = DI_FFNOMINALMAX; dic.lDeadBand = 0; @@ -1857,7 +1865,8 @@ bool CDirectInputSystem::ProcessForceFeedbackCmd(int joyNum, int axisNum, ForceF //printf("FFVibrate %0.2f\n", 100.0f * ffCmd.force); if (g_Config.dInputVibrateMax == 0) return false; - dip.dwMagnitude = min(ffCmd.force * (float)(g_Config.dInputVibrateMax * DI_EFFECTS_SCALE), DI_EFFECTS_MAX); + dFFMag = (DWORD)(ffCmd.force * (float)(g_Config.dInputVibrateMax * DI_EFFECTS_SCALE)); + dip.dwMagnitude = max(0, min(dFFMag, DI_EFFECTS_MAX)); dip.lOffset = 0; dip.dwPhase = 0; dip.dwPeriod = (DWORD)(0.05 * DI_SECONDS); // 1/20th second