diff --git a/Config/FFBPlugin.ini b/Config/FFBPlugin.ini index d381983..f3c506a 100644 --- a/Config/FFBPlugin.ini +++ b/Config/FFBPlugin.ini @@ -257,6 +257,7 @@ AlternativeMinForceRight=0 AlternativeMaxForceRight=100 SpringStrength=100 FrictionStrength=0 +JointsAndStripesStrength=100 CollisionsStrength=100 TiresSlipStrength=100 HighhSpeedVibrationsStrength=100 diff --git a/DllMain.cpp b/DllMain.cpp index 4b8cd32..0fc4680 100644 --- a/DllMain.cpp +++ b/DllMain.cpp @@ -1090,8 +1090,8 @@ std::chrono::milliseconds timeOfLastSineEffect = duration_cast(sys std::chrono::milliseconds timeOfLastSpringEffect = duration_cast(system_clock::now().time_since_epoch()); std::string lastConstantEffectHash = ""; std::string lastFrictionEffectHash = ""; -std::string lastSineEffectHash = ""; double lastSineEffectStrength = 0; +double lastSineEffectPeriod = 0; std::string lastSpringEffectHash = ""; void TriggerConstantEffect(int direction, double strength) { @@ -1464,12 +1464,6 @@ void TriggerSineEffect(UINT16 period, UINT16 fadePeriod, double strength) { std::chrono::milliseconds now = duration_cast(system_clock::now().time_since_epoch()); long long elapsedTime = (std::chrono::duration_cast(now - timeOfLastSineEffect)).count(); - std::string effectHash = std::to_string(effects.effect_sine_id) + "_" + std::to_string(period) + "_" + std::to_string(fadePeriod) + "_" + std::to_string(strength); - - // if the effect is the same as the last effect that was sent AND enough time hasn't elapsed, do nothing - if (effectHash.compare(lastSineEffectHash) == 0 && elapsedTime < configFeedbackLength) { - return; // same effect, do nothing. - } int direction = 1; if (strength <= -0.001) { @@ -1477,19 +1471,19 @@ void TriggerSineEffect(UINT16 period, UINT16 fadePeriod, double strength) direction = -1; } - if (strength < (lastSineEffectStrength / 2.0) && elapsedTime < configFeedbackLength) { - return; // we prevent interruption of previous vibrations by a vibration a lot less strong. + // we ignore new effect until the last one is completed, unless the new one is significantly stronger + if (elapsedTime < lastSineEffectPeriod && strength < (lastSineEffectStrength * 2.0)) { + return; } - // TODO: investigate if we need this - if (configResetFeedback || strength <= 0.001) { + // if no strength, we do nothing + if (strength <= 0.001) { + return; + } + + // stop previous sine if not completed + if (configResetFeedback) { SDL_HapticStopEffect(haptic, effects.effect_sine_id); - if (strength <= 0.01) { - timeOfLastSineEffect = now; - lastSineEffectHash = effectHash; - lastSineEffectStrength = strength; - return; - } } SDL_HapticEffect tempEffect; @@ -1530,7 +1524,7 @@ void TriggerSineEffect(UINT16 period, UINT16 fadePeriod, double strength) } tempEffect.periodic.magnitude = (SHORT)(magnitude); - tempEffect.periodic.length = configFeedbackLength; + tempEffect.periodic.length = period; tempEffect.periodic.attack_length = fadePeriod; tempEffect.periodic.fade_length = fadePeriod; @@ -1541,8 +1535,8 @@ void TriggerSineEffect(UINT16 period, UINT16 fadePeriod, double strength) hlp.log((char *)std::to_string(supported).c_str());*/ timeOfLastSineEffect = now; - lastSineEffectHash = effectHash; lastSineEffectStrength = strength; + lastSineEffectPeriod = period; } void TriggerSpringEffectWithDefaultOption(double strength, bool isDefault) { diff --git a/Game Files/WMMT5.cpp b/Game Files/WMMT5.cpp index 2cc24f4..d966459 100644 --- a/Game Files/WMMT5.cpp +++ b/Game Files/WMMT5.cpp @@ -15,8 +15,10 @@ along with FFB Arcade Plugin.If not, see < https://www.gnu.org/licenses/>. #include "WMMT5.h" wchar_t* settingsWMMT5 = TEXT(".\\FFBPlugin.ini"); +bool gameFfbStarted = false; int SpringStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("SpringStrength"), 0, settingsWMMT5); int FrictionStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("FrictionStrength"), 0, settingsWMMT5); +int JointsAndStripesStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("JointsAndStripesStrength"), 0, settingsWMMT5); int CollisionsStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("CollisionsStrength"), 0, settingsWMMT5); int TiresSlipStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("TiresSlipStrength"), 0, settingsWMMT5); int HighhSpeedVibrationsStrengthWMMT5 = GetPrivateProfileInt(TEXT("Settings"), TEXT("HighhSpeedVibrationsStrength"), 0, settingsWMMT5); @@ -38,59 +40,87 @@ void WMMT5::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers ffs = "tires slip: " + std::to_string(tiresSlip); helpers->log((char*)ffs.c_str()); + double percentForce; if (0 < spring) { - double percentForce = (1.0 * spring) * SpringStrengthWMMT5 / 100.0; + if (!gameFfbStarted) + { + helpers->log("game's FFB started"); + gameFfbStarted = true; + } + percentForce = (1.0 * spring) * SpringStrengthWMMT5 / 100.0; triggers->Spring(percentForce); } + else if (!gameFfbStarted) + { + helpers->log("fake spring/friction until game's FFB starts"); + percentForce = 0.4 * SpringStrengthWMMT5 / 100.0; + triggers->Spring(percentForce); + percentForce = 0.5 * FrictionStrengthWMMT5 / 100.0; + triggers->Friction(percentForce); + } if (0 < friction) { - double percentForce = (1.0 * friction) * FrictionStrengthWMMT5 / 100.0; + percentForce = (1.0 * friction) * FrictionStrengthWMMT5 / 100.0; triggers->Friction(percentForce); } if (0 < collisions) { - helpers->log("collision on the left"); - double percentForce = (1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0; - triggers->Sine(100, 120, percentForce); - - double percentLength = (150); - triggers->LeftRight(0, percentForce, percentLength); + if (0.209 <= collisions && 0.311 >= collisions) + { + helpers->log("joint/stripe on the right"); + percentForce = (1.0 * collisions) * JointsAndStripesStrengthWMMT5 / 100.0; + triggers->Sine(80, 80, percentForce); + triggers->LeftRight(0, percentForce, 150); + } + else + { + helpers->log("collision on the right"); + percentForce = (1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0; + triggers->Constant(constants->DIRECTION_FROM_RIGHT, percentForce); + triggers->LeftRight(0, percentForce, 150); + } } else if (0 > collisions) { - helpers->log("collision on the right"); - double percentForce = (1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0; - triggers->Sine(100, 120, percentForce); + if (-0.209 >= collisions && -0.311 <= collisions) + { + helpers->log("joint/stripe on the left"); + percentForce = (1.0 * collisions) * JointsAndStripesStrengthWMMT5 / 100.0; + triggers->Sine(80, 80, percentForce); + triggers->LeftRight(0, -1.0 * percentForce, 150); + } + else + { + helpers->log("collision on the left"); + percentForce = (-1.0 * collisions) * CollisionsStrengthWMMT5 / 100.0; + triggers->Constant(constants->DIRECTION_FROM_LEFT, percentForce); + triggers->LeftRight(0, percentForce, 150); + } - double percentLength = (150); - triggers->LeftRight(0, -1.0 * percentForce, percentLength); } if (0 < tiresSlip) { helpers->log("tires slip left"); bool highSpeedVibrations = (1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlipWMMT5 / 1000.0); - double percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighhSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0; - triggers->Sine(highSpeedVibrations ? 100 : 120, 120, percentForce); + percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighhSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0; + triggers->Sine(100, 100, percentForce); - if (0 == CollisionsStrengthWMMT5 || (0.001 > collisions && -0.001 < collisions)) + if ((0 == JointsAndStripesStrengthWMMT5 && 0 == CollisionsStrengthWMMT5) || (0.001 > collisions && -0.001 < collisions)) { - percentForce *= -1.0; - double percentLength = (150); - triggers->LeftRight(highSpeedVibrations ? percentForce : 0, highSpeedVibrations ? 0 : percentForce, percentLength); + triggers->LeftRight(highSpeedVibrations ? (-1.0 * percentForce) : 0, highSpeedVibrations ? 0 : (-1.0 * percentForce), 150); } } else if (0 > tiresSlip) { helpers->log("tires slip right"); bool highSpeedVibrations = (-1.0 * tiresSlip) < (LimitBetweenHighSpeedVibrationsAndTiresSlipWMMT5 / 1000.0); - double percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighhSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0; - triggers->Sine(highSpeedVibrations ? 100 : 120, 120, percentForce); + percentForce = (-1.0 * tiresSlip) * (highSpeedVibrations ? HighhSpeedVibrationsStrengthWMMT5 : TiresSlipStrengthWMMT5) / 100.0; + triggers->Sine(100, 100, percentForce); - if (0 == CollisionsStrengthWMMT5 || (0.001 > collisions && -0.001 < collisions)) + if ((0 == JointsAndStripesStrengthWMMT5 && 0 == CollisionsStrengthWMMT5) || (0.001 > collisions && -0.001 < collisions)) { - double percentLength = (150); - triggers->LeftRight(highSpeedVibrations ? percentForce : 0, highSpeedVibrations ? 0 : percentForce, percentLength); + triggers->LeftRight(highSpeedVibrations ? percentForce : 0, highSpeedVibrations ? 0 : percentForce, 150); } } } \ No newline at end of file