From 029a0639704ee4fac10712d8226173a8df85b933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=B3lik=20Uszasty?= Date: Fri, 19 Feb 2021 22:14:05 +0100 Subject: [PATCH] Better sound of retarder --- DynObj.cpp | 4 ++-- McZapkie/MOVER.h | 4 ++++ McZapkie/Mover.cpp | 22 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index 19a79059..ca0982be 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -7618,13 +7618,13 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub } if (Vehicle.hydro_R) { - float speed = std::abs(Vehicle.hydro_R_Fill * Vehicle.hydro_R_n); + float speed = std::abs(Vehicle.hydro_R_n); retarder .pitch(retarder.m_frequencyoffset + speed * retarder.m_frequencyfactor) .gain(retarder.m_amplitudeoffset + Vehicle.hydro_R_Fill * retarder.m_amplitudefactor); - if (retarder.gain() > 0.01) { + if ((retarder.gain() > 0.01)&&(speed > 1)&&(Vehicle.hydro_R_ClutchActive)) { retarder.play(sound_flags::exclusive | sound_flags::looping); } else { diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 5b44f128..c1ed8f04 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1269,6 +1269,9 @@ public: double hydro_R_FillRateDec = 1.0; /*szybkosc oprozniania sprzegla*/ double hydro_R_MinVel = 1.0; /*minimalna predkosc, przy ktorej retarder dziala*/ double hydro_R_EngageVel = 1.0; /*minimalna predkosc hamowania, przy ktorej sprzeglo jest wciaz wlaczone*/ + bool hydro_R_Clutch = false; /*czy retarder ma rozłączalne sprzęgło*/ + double hydro_R_ClutchSpeed = 10.0; /*szybkość narastania obrotów po włączeniu sprzęgła retardera*/ + bool hydro_R_WithIndividual = false; /*czy dla autobusów jest to łączone*/ /*- dla lokomotyw spalinowo-elektrycznych -*/ double AnPos = 0.0; // pozycja sterowania dokladnego (analogowego) bool AnalogCtrl = false; // @@ -1567,6 +1570,7 @@ public: double hydro_R_Torque = 0.0; /*moment*/ double hydro_R_Request = 0.0; /*zadanie sily hamowania*/ double hydro_R_n = 0.0; /*predkosc obrotowa retardera*/ + bool hydro_R_ClutchActive = false; /*czy retarder jest napędzany*/ /*- zmienne dla lokomotyw z silnikami indukcyjnymi -*/ double eimic = 0; /*aktualna pozycja zintegrowanego sterowania jazda i hamowaniem*/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index f612f759..4c60d90b 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -7829,6 +7829,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt) double TMoverParameters::dizel_MomentumRetarder(double n, double dt) { double RetarderRequest = (Mains ? std::max(0.0, -eimic_real) : 0); + if (hydro_R_WithIndividual) RetarderRequest = LocalBrakeRatio(); if (Vel < hydro_R_MinVel) RetarderRequest = 0; if ((hydro_R_Placement == 2) && (enrot < dizel_nmin)) @@ -7836,7 +7837,21 @@ double TMoverParameters::dizel_MomentumRetarder(double n, double dt) RetarderRequest = 0; } - hydro_R_n = n * 60; + hydro_R_ClutchActive = (!hydro_R_Clutch) || (RetarderRequest > 0); + if ((!hydro_R_Clutch) + || ((hydro_R_ClutchActive) && (hydro_R_ClutchSpeed == 0))) + { + hydro_R_n = n * 60; + } + else if (hydro_R_ClutchActive) + { + hydro_R_n = sign(n)*std::min(std::abs(hydro_R_n + hydro_R_ClutchSpeed * dt), std::abs(n * 60)); + } + else + { + hydro_R_n = 0; + } + n = hydro_R_n / 60.f; if (hydro_R_Fill < RetarderRequest) //gdy zadane hamowanie { @@ -7848,7 +7863,7 @@ double TMoverParameters::dizel_MomentumRetarder(double n, double dt) } double Moment = hydro_R_MaxTorque; - double pwr = Moment * n * M_PI * 2 * 0.001; + double pwr = Moment * std::abs(n) * M_PI * 2 * 0.001; if (pwr > hydro_R_MaxPower) Moment = Moment * hydro_R_MaxPower / pwr; double moment_in = n*n*hydro_R_TorqueInIn; @@ -10653,6 +10668,9 @@ void TMoverParameters::LoadFIZ_Engine( std::string const &Input ) { extract_value(hydro_R_FillRateDec, "R_FRD", Input, ""); extract_value(hydro_R_MinVel, "R_MinVel", Input, ""); extract_value(hydro_R_EngageVel, "R_EngageVel", Input, ""); + extract_value(hydro_R_Clutch, "R_IsClutch", Input, ""); + extract_value(hydro_R_ClutchSpeed, "R_ClutchSpeed", Input, ""); + extract_value(hydro_R_WithIndividual, "R_WithIndividual", Input, ""); } } break;