diff --git a/Console.cpp b/Console.cpp index 82e8d162..741ffa75 100644 --- a/Console.cpp +++ b/Console.cpp @@ -257,7 +257,7 @@ void Console::ValueSet(int x, double y) } if (Global.fCalibrateOutMax[x] > 0) { - y = clamp( y, 0.0, Global.fCalibrateOutMax[x]); + y = std::clamp(y, 0.0, Global.fCalibrateOutMax[x]); if( Global.iCalibrateOutDebugInfo == x ) { WriteLog( " cutted=" + std::to_string( y ) ); } diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 93c03efb..10a5b88f 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -862,7 +862,7 @@ void TMoverParameters::UpdatePantVolume(double dt) // Ra 2013-12: Niebugocław mówi, że w EZT nie ma potrzeby odcinać kurkiem PantPress = ScndPipePress; // ograniczenie ciśnienia do MaxPress (tylko w pantografach!) - PantPress = clamp(ScndPipePress, 0.0, EnginePowerSource.CollectorParameters.MaxPress); + PantPress = std::clamp(ScndPipePress, 0.0, EnginePowerSource.CollectorParameters.MaxPress); PantVolume = (PantPress + 1.0) * 0.1; // objętość, na wypadek odcięcia kurkiem } else @@ -874,7 +874,7 @@ void TMoverParameters::UpdatePantVolume(double dt) // Ra 2013-12: Niebugocław mówi, że w EZT nabija 1.5 raz wolniej niż jak było 0.005 * (TrainType == dt_EZT ? 0.003 : 0.005) / std::max(1.0, PantPress) * (0.45 - ((0.1 / PantVolume / 10) - 0.1)) / 0.45; } - PantPress = clamp((10.0 * PantVolume) - 1.0, 0.0, EnginePowerSource.CollectorParameters.MaxPress); // tu by się przydała objętość zbiornika + PantPress = std::clamp((10.0 * PantVolume) - 1.0, 0.0, EnginePowerSource.CollectorParameters.MaxPress); // tu by się przydała objętość zbiornika } if (!PantCompFlag && (PantVolume > 0.1)) PantVolume -= dt * 0.0003 * std::max(1.0, PantPress * 0.5); // nieszczelności: 0.0003=0.3l/s @@ -1156,7 +1156,7 @@ double TMoverParameters::PipeRatio(void) double TMoverParameters::EngineRPMRatio() const { - return clamp((EngineType == TEngineType::DieselElectric ? ((60.0 * std::abs(enrot)) / DElist[MainCtrlPosNo].RPM) : + return std::clamp((EngineType == TEngineType::DieselElectric ? ((60.0 * std::abs(enrot)) / DElist[MainCtrlPosNo].RPM) : EngineType == TEngineType::DieselEngine ? (std::abs(enrot) / nmax) : 1.0), // shouldn't ever get here but, eh 0.0, 1.0); @@ -1259,7 +1259,7 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) // if( accelerationchange / AccS < 1.0 ) { // HACK: prevent excessive vehicle pinball cases AccS += accelerationchange; - // AccS = clamp( AccS, -2.0, 2.0 ); + // AccS = std::clamp( AccS, -2.0, 2.0 ); V = velocity; // } } @@ -1394,7 +1394,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap auto const AccSprev{AccS}; // przyspieszenie styczne AccS = interpolate(AccSprev, FTotal / TotalMass, 0.5); - // clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) + // std::clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) if (TestFlag(DamageFlag, dtrain_out)) AccS = -Sign(V) * g * 1; // random(0.0, 0.1) @@ -1416,7 +1416,7 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap } // tangential acceleration, from velocity change - AccSVBased = interpolate(AccSVBased, (V - Vprev) / dt, clamp(dt * 3.0, 0.0, 1.0)); + AccSVBased = interpolate(AccSVBased, (V - Vprev) / dt, std::clamp(dt * 3.0, 0.0, 1.0)); // vertical acceleration AccVert = (std::abs(AccVert) < 0.01 ? 0.0 : AccVert * 0.5); @@ -1491,7 +1491,7 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape &Shape auto const AccSprev{AccS}; // przyspieszenie styczne AccS = interpolate(AccSprev, FTotal / TotalMass, 0.5); - // clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) + // std::clamp( dt * 3.0, 0.0, 1.0 ) ); // prawo Newtona ale z wygladzaniem (średnia z poprzednim) if (TestFlag(DamageFlag, dtrain_out)) AccS = -Sign(V) * g * 1; // * random(0.0, 0.1) @@ -2099,7 +2099,7 @@ void TMoverParameters::HeatingCheck(double const Timestep) generator.voltage_min * absrevolutions / generator.revolutions_min : // absrevolutions > generator.revolutions_max ? generator.voltage_max * absrevolutions / generator.revolutions_max : interpolate(generator.voltage_min, generator.voltage_max, - clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) * + std::clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) * sign(generator.revolutions); } break; @@ -2221,7 +2221,7 @@ void TMoverParameters::OilPumpCheck(double const Timestep) { OilPump.pressure = std::max(OilPump.pressure_target, OilPump.pressure - (enrot > 5.0 ? 0.05 : 0.035) * 0.5 * Timestep); } - OilPump.pressure = clamp(OilPump.pressure, 0.f, 1.5f); + OilPump.pressure = std::clamp(OilPump.pressure, 0.f, 1.5f); } void TMoverParameters::MotorBlowersCheck(double const Timestep) @@ -2276,7 +2276,7 @@ void TMoverParameters::MotorBlowersCheck(double const Timestep) if (revolutionstarget > 0.f) { auto const speedincreasecap{std::max(50.f, fan.speed * 0.05f * -1)}; // 5% of fixed revolution speed, or 50 - fan.revolutions += clamp(revolutionstarget - fan.revolutions, speedincreasecap * -2, speedincreasecap) * Timestep; + fan.revolutions += std::clamp(revolutionstarget - fan.revolutions, speedincreasecap * -2, speedincreasecap) * Timestep; } else { @@ -3751,7 +3751,7 @@ bool TMoverParameters::ChangeCompressorPreset(int const State, range_t const Not auto const initialstate{CompressorListPos}; - CompressorListPos = clamp(State, 0, CompressorListPosNo); + CompressorListPos = std::clamp(State, 0, CompressorListPosNo); if (Notify != range_t::local) { @@ -5285,7 +5285,7 @@ double TMoverParameters::CouplerForce(int const End, double dt) if ((coupler.CouplingFlag != coupling::faux) || (initialdistance < 0)) { - coupler.Dist = clamp(newdistance, (coupler.has_adapter() ? 0 : -coupler.DmaxB), coupler.DmaxC); + coupler.Dist = std::clamp(newdistance, (coupler.has_adapter() ? 0 : -coupler.DmaxB), coupler.DmaxC); double BetaAvg = 0; double Fmax = 0; @@ -5425,7 +5425,7 @@ double TMoverParameters::TractionForce(double dt) tmp = std::max(tmp, std::min(EngineMaxRPM(), EngineHeatingRPM) / 60.0); } // NOTE: fake dizel_fill calculation for the sake of smoke emitter which uses this parameter to determine smoke opacity - dizel_fill = clamp(0.2 + 0.35 * (tmp - enrot) + 0.5 * (std::abs(Im) / DElist[MainCtrlPosNo].Imax), 0.05, 1.0); + dizel_fill = std::clamp(0.2 + 0.35 * (tmp - enrot) + 0.5 * (std::abs(Im) / DElist[MainCtrlPosNo].Imax), 0.05, 1.0); } else { @@ -5435,7 +5435,7 @@ double TMoverParameters::TractionForce(double dt) if (enrot != tmp) { - enrot = clamp(enrot + (dt / dizel_AIM) * (enrot < tmp ? 1.0 : -1.0 * dizel_RevolutionsDecreaseRate), // NOTE: revolutions typically drop faster than they rise + enrot = std::clamp(enrot + (dt / dizel_AIM) * (enrot < tmp ? 1.0 : -1.0 * dizel_RevolutionsDecreaseRate), // NOTE: revolutions typically drop faster than they rise 0.0, std::max(tmp, enrot)); if (std::abs(tmp - enrot) < 0.001) { @@ -5537,9 +5537,9 @@ double TMoverParameters::TractionForce(double dt) if (true == Mains) { // TBD, TODO: currently ignores RVentType, fix this? - RventRot += clamp(enrot - RventRot, -100.0, 50.0) * dt; - dizel_heat.rpmw += clamp(dizel_heat.rpmwz - dizel_heat.rpmw, -100.f, 50.f) * dt; - dizel_heat.rpmw2 += clamp(dizel_heat.rpmwz2 - dizel_heat.rpmw2, -100.f, 50.f) * dt; + RventRot += std::clamp(enrot - RventRot, -100.0, 50.0) * dt; + dizel_heat.rpmw += std::clamp(dizel_heat.rpmwz - dizel_heat.rpmw, -100.f, 50.f) * dt; + dizel_heat.rpmw2 += std::clamp(dizel_heat.rpmwz2 - dizel_heat.rpmw2, -100.f, 50.f) * dt; } else { @@ -5555,8 +5555,8 @@ double TMoverParameters::TractionForce(double dt) // NOTE: we update only radiator fans, as vehicles with diesel engine don't have other ventilators if (true == Mains) { - dizel_heat.rpmw += clamp(dizel_heat.rpmwz - dizel_heat.rpmw, -100.f, 50.f) * dt; - dizel_heat.rpmw2 += clamp(dizel_heat.rpmwz2 - dizel_heat.rpmw2, -100.f, 50.f) * dt; + dizel_heat.rpmw += std::clamp(dizel_heat.rpmwz - dizel_heat.rpmw, -100.f, 50.f) * dt; + dizel_heat.rpmw2 += std::clamp(dizel_heat.rpmwz2 - dizel_heat.rpmw2, -100.f, 50.f) * dt; } else { @@ -5935,7 +5935,7 @@ double TMoverParameters::TractionForce(double dt) // charakterystyka pradnicy obcowzbudnej (elipsa) - twierdzenie Pitagorasa EngineVoltage = std::sqrt(std::abs(square(tempUmax) - square(tempUmax * Im / tempImax))) * (tempMCP - 1) + (1.0 - Im / tempImax) * tempUmax * (tempMCPN - tempMCP); EngineVoltage /= (tempMCPN - 1); - EngineVoltage = clamp(EngineVoltage, Im * 0.05, (1000.0 * tmp / std::abs(Im))); + EngineVoltage = std::clamp(EngineVoltage, Im * 0.05, (1000.0 * tmp / std::abs(Im))); } } @@ -5952,7 +5952,7 @@ double TMoverParameters::TractionForce(double dt) if( ( tmpV > 1 ) && ( EnginePower < tmp ) ) { Ft = interpolate( Ft, EnginePower / tmp, - clamp( tmpV - 1.0, 0.0, 1.0 ) ); + std::clamp( tmpV - 1.0, 0.0, 1.0 ) ); } */ } @@ -6076,7 +6076,7 @@ double TMoverParameters::TractionForce(double dt) /* // crude woodward approximation; difference between rpm for consecutive positions is ~5% // so we get full throttle until ~half way between desired and previous position, or zero on rpm reduction - auto const woodward { clamp( + auto const woodward { std::clamp( ( DElist[ MainCtrlPos ].RPM / ( enrot * 60.0 ) - 1.0 ) * 50.0, 0.0, 1.0 ) }; */ @@ -6249,7 +6249,7 @@ double TMoverParameters::TractionForce(double dt) if (eimv[eimv_Fmax] * Sign(V) * DirAbsolute < -1) { PosRatio = -Sign(V) * DirAbsolute * eimv[eimv_Fr] / (eimc[eimc_p_Fh] * std::max(edBCP, std::max(0.01, Hamulec->GetEDBCP())) / MaxBrakePress[0]); - PosRatio = clamp(PosRatio, 0.0, 1.0); + PosRatio = std::clamp(PosRatio, 0.0, 1.0); } else { @@ -7249,25 +7249,25 @@ void TMoverParameters::CheckEIMIC(double dt) switch (MainCtrlPos) { case 0: // B+ - eimic -= clamp(1.0 + eimic, 0.0, dt * 0.14); // odejmuj do -1 + eimic -= std::clamp(1.0 + eimic, 0.0, dt * 0.14); // odejmuj do -1 break; case 1: // B - eimic -= clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0 + eimic -= std::clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0 break; case 2: // B- case 3: // 0 case 4: // T- - eimic -= clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0 - eimic += clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0 + eimic -= std::clamp(0.0 + eimic, 0.0, dt * 0.14); // odejmuj do 0 + eimic += std::clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0 break; case 5: // T - eimic += clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0 + eimic += std::clamp(0.0 - eimic, 0.0, dt * 0.14); // dodawaj do 0 break; case 6: // T+ - eimic += clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1 + eimic += std::clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1 break; case 7: // TMax - eimic += clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1, max + eimic += std::clamp(1.0 - eimic, 0.0, dt * 0.14); // dodawaj do 1, max break; } if (MainCtrlPos >= 3 && eimic < 0) @@ -7283,18 +7283,18 @@ void TMoverParameters::CheckEIMIC(double dt) { case 0: case 1: - eimic -= clamp(1.0 + eimic, 0.0, delta); // odejmuj do -1 + eimic -= std::clamp(1.0 + eimic, 0.0, delta); // odejmuj do -1 if (eimic > 0) eimic = 0; break; case 2: - eimic -= clamp(0.0 + eimic, 0.0, delta); // odejmuj do 0 + eimic -= std::clamp(0.0 + eimic, 0.0, delta); // odejmuj do 0 break; case 3: - eimic += clamp(0.0 - eimic, 0.0, delta); // dodawaj do 0 + eimic += std::clamp(0.0 - eimic, 0.0, delta); // dodawaj do 0 break; case 4: - eimic += clamp(1.0 - eimic, 0.0, delta); // dodawaj do 1 + eimic += std::clamp(1.0 - eimic, 0.0, delta); // dodawaj do 1 if (eimic < 0) eimic = 0; break; @@ -7331,11 +7331,11 @@ void TMoverParameters::CheckEIMIC(double dt) if ((MainCtrlActualPos != MainCtrlPos) || (LastRelayTime > InitialCtrlDelay)) { - eimic -= clamp(-UniCtrlList[MainCtrlPos].SetCtrlVal + eimic, 0.0, + eimic -= std::clamp(-UniCtrlList[MainCtrlPos].SetCtrlVal + eimic, 0.0, (MainCtrlActualPos == MainCtrlPos ? dt * UniCtrlList[MainCtrlPos].SpeedDown : sign(UniCtrlList[MainCtrlPos].SpeedDown) * 0.01)); // odejmuj do X - eimic += clamp(UniCtrlList[MainCtrlPos].SetCtrlVal - eimic, 0.0, + eimic += std::clamp(UniCtrlList[MainCtrlPos].SetCtrlVal - eimic, 0.0, (MainCtrlActualPos == MainCtrlPos ? dt * UniCtrlList[MainCtrlPos].SpeedUp : sign(UniCtrlList[MainCtrlPos].SpeedUp) * 0.01)); // dodawaj do X - eimic = clamp(eimic, UniCtrlList[MainCtrlPos].MinCtrlVal, UniCtrlList[MainCtrlPos].MaxCtrlVal); + eimic = std::clamp(eimic, UniCtrlList[MainCtrlPos].MinCtrlVal, UniCtrlList[MainCtrlPos].MaxCtrlVal); } if (MainCtrlActualPos == MainCtrlPos) LastRelayTime += dt; @@ -7368,7 +7368,7 @@ void TMoverParameters::CheckEIMIC(double dt) if (eim_localbrake < Hamulec->GetEDBCP() / MaxBrakePress[0]) eim_localbrake = 0; } - eim_localbrake = clamp(eim_localbrake, 0.0, 1.0); + eim_localbrake = std::clamp(eim_localbrake, 0.0, 1.0); if (eim_localbrake > 0.04 && eimic > 0) eimic = 0; } @@ -7394,7 +7394,7 @@ void TMoverParameters::CheckEIMIC(double dt) eimic_max = 0.001; } } - eimic = clamp(eimic, -1.0, eimicpowerenabled ? eimic_max : 0.0); + eimic = std::clamp(eimic, -1.0, eimicpowerenabled ? eimic_max : 0.0); } void TMoverParameters::CheckSpeedCtrl(double dt) @@ -7438,7 +7438,7 @@ void TMoverParameters::CheckSpeedCtrl(double dt) } double error = (std::max(SpeedCtrlValue + SpeedCtrlUnit.Offset, 0.0) - Vel); double factorP = error > 0 ? SpeedCtrlUnit.FactorPpos : SpeedCtrlUnit.FactorPneg; - double eSCP = clamp(factorP * error, -1.2, 1.0); // P module + double eSCP = std::clamp(factorP * error, -1.2, 1.0); // P module bool retarder_not_work = (EngineType != TEngineType::DieselEngine) || (Vel < SpeedCtrlUnit.BrakeInterventionVel); if (eSCP < -1.0) { @@ -7451,14 +7451,14 @@ void TMoverParameters::CheckSpeedCtrl(double dt) // TODO: check how to disable integral part when braking in smart way // double factorI = eimicSpeedCtrlIntegral >= 0 ? SpeedCtrlUnit.FactorIpos : SpeedCtrlUnit.FactorIneg; double factorI = eimicSpeedCtrlIntegral >= 0 ? SpeedCtrlUnit.FactorIpos : SpeedCtrlUnit.FactorIneg; - eimicSpeedCtrlIntegral = clamp(eimicSpeedCtrlIntegral + factorI * eSCP * dt, -1.0 + eSCP, 1.0 - eSCP); + eimicSpeedCtrlIntegral = std::clamp(eimicSpeedCtrlIntegral + factorI * eSCP * dt, -1.0 + eSCP, 1.0 - eSCP); } else { eimicSpeedCtrlIntegral = 0; } - auto const DesiredeimicSpeedCtrl{clamp(eimicSpeedCtrlIntegral + eSCP, -SpeedCtrlUnit.DesiredPower, accfactor)}; - eimicSpeedCtrl = clamp(DesiredeimicSpeedCtrl, eimicSpeedCtrl - SpeedCtrlUnit.PowerDownSpeed * dt, eimicSpeedCtrl + SpeedCtrlUnit.PowerUpSpeed * dt); + auto const DesiredeimicSpeedCtrl{std::clamp(eimicSpeedCtrlIntegral + eSCP, -SpeedCtrlUnit.DesiredPower, accfactor)}; + eimicSpeedCtrl = std::clamp(DesiredeimicSpeedCtrl, eimicSpeedCtrl - SpeedCtrlUnit.PowerDownSpeed * dt, eimicSpeedCtrl + SpeedCtrlUnit.PowerUpSpeed * dt); if (Vel < SpeedCtrlUnit.FullPowerVelocity) { eimicSpeedCtrl = std::min(eimicSpeedCtrl, SpeedCtrlUnit.InitialPower); @@ -7480,9 +7480,9 @@ void TMoverParameters::CheckSpeedCtrl(double dt) else { if (Vmax < 250) - eimicSpeedCtrl = clamp(0.5 * (SpeedCtrlValue - Vel), -1.0, 1.0); + eimicSpeedCtrl = std::clamp(0.5 * (SpeedCtrlValue - Vel), -1.0, 1.0); else - eimicSpeedCtrl = clamp(0.5 * (SpeedCtrlValue * 2 - Vel), -1.0, 1.0); + eimicSpeedCtrl = std::clamp(0.5 * (SpeedCtrlValue * 2 - Vel), -1.0, 1.0); } if (((SpeedCtrlAutoTurnOffFlag & 2) == 2) && (Hamulec->GetEDBCP() > 0.25)) { @@ -7906,7 +7906,7 @@ double TMoverParameters::dizel_fillcheck(int mcp, double dt) } } - return clamp(realfill, 0.0, 1.0); + return std::clamp(realfill, 0.0, 1.0); } // ************************************************************************************************* @@ -7965,7 +7965,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt) if (((!IsPower) && (Vel < dizel_maxVelANS)) || (!Mains) || (enrot < dizel_nmin * 0.8)) hydro_TC_Fill -= hydro_TC_FillRateDec * dt; // obcinanie zakresu - hydro_TC_Fill = clamp(hydro_TC_Fill, 0.0, 1.0); + hydro_TC_Fill = std::clamp(hydro_TC_Fill, 0.0, 1.0); // blokowanie sprzegla blokującego if ((Vel > hydro_TC_LockupSpeed) && (Mains) && (enrot > 0.9 * dizel_nmin) && (IsPower)) @@ -7980,7 +7980,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt) hydro_TC_LockupRate -= hydro_TC_FillRateDec * dt; } // obcinanie zakresu - hydro_TC_LockupRate = clamp(hydro_TC_LockupRate, 0.0, 1.0); + hydro_TC_LockupRate = std::clamp(hydro_TC_LockupRate, 0.0, 1.0); } else { @@ -8070,7 +8070,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt) enMoment = 0; double enrot_min = enrot - (std::min(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) - Moment) / dizel_AIM * dt; double enrot_max = enrot + (std::min(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) + Moment) / dizel_AIM * dt; - enrot = clamp(n, enrot_min, enrot_max); + enrot = std::clamp(n, enrot_min, enrot_max); } if ((hydro_R) && (hydro_R_Placement == 1)) gearMoment -= dizel_MomentumRetarder(hydro_TC_nOut, dt); @@ -8363,7 +8363,7 @@ bool TMoverParameters::AssignLoad(std::string const &Name, float const Amount) { LoadTypeChange = (LoadType.name != Name); LoadType = loadattributes; - LoadAmount = clamp(Amount, 0.f, MaxLoad); + LoadAmount = std::clamp(Amount, 0.f, MaxLoad); ComputeMass(); return true; } @@ -8412,7 +8412,7 @@ bool TMoverParameters::LoadingDone(double const LSpeed, std::string const &Loadn { // pusto lub rozładowano żądaną ilość LoadStatus = 4; // skończony rozładunek - LoadAmount = clamp(LoadAmount, 0.f, MaxLoad); // ładunek nie może być ujemny + LoadAmount = std::clamp(LoadAmount, 0.f, MaxLoad); // ładunek nie może być ujemny } if (LoadAmount == 0.f) { @@ -8450,7 +8450,7 @@ bool TMoverParameters::ChangeDoorPermitPreset(int const Change, range_t const No if (false == Doors.permit_presets.empty()) { - Doors.permit_preset = clamp(Doors.permit_preset + Change, 0, Doors.permit_presets.size() - 1); + Doors.permit_preset = std::clamp(Doors.permit_preset + Change, 0, static_cast(Doors.permit_presets.size() - 1)); auto const doors{Doors.permit_presets[Doors.permit_preset]}; auto const permitleft{((doors & 1) != 0)}; auto const permitright{((doors & 2) != 0)}; @@ -10730,7 +10730,7 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line) extract_value(CoupledCtrl, "CoupledCtrl", line, ""); extract_value(HasCamshaft, "Camshaft", line, ""); extract_value(EIMCtrlType, "EIMCtrlType", line, ""); - EIMCtrlType = clamp(EIMCtrlType, 0, 3); + EIMCtrlType = std::clamp(EIMCtrlType, 0, 3); extract_value(LocHandleTimeTraxx, "LocalBrakeTraxx", line, ""); extract_value(EIMCtrlAdditionalZeros, "EIMCtrlAddZeros", line, ""); extract_value(EIMCtrlEmergency, "EIMCtrlEmergency", line, ""); @@ -11959,7 +11959,7 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir) { SecuritySystem.MagnetLocation = Dim.L / 2 - 0.5; } - SecuritySystem.MagnetLocation = clamp(SecuritySystem.MagnetLocation, 0.0, Dim.L); + SecuritySystem.MagnetLocation = std::clamp(SecuritySystem.MagnetLocation, 0.0, Dim.L); return OK; } @@ -12363,7 +12363,7 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV } else if (Command == "CompressorPreset") { - CompressorListPos = clamp(static_cast(CValue1), 0, CompressorListPosNo); + CompressorListPos = std::clamp(static_cast(CValue1), 0, CompressorListPosNo); OK = SendCtrlToNext(Command, CValue1, CValue2, Couplertype); } else if (Command == "DoorPermit") diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index 049e9a5b..c6b172b4 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -1314,7 +1314,7 @@ void TEStEP1::EPCalc(double dt) { double temp = EPS - std::floor(EPS); // część ułamkowa jest hamulcem EP double LBPLim = std::min(MaxBP * LoadC * temp, BrakeRes->P()); // do czego dążymy - double S = 10 * clamp(LBPLim - LBP, -0.1, 0.1); // przymykanie zaworku + double S = 10 * std::clamp(LBPLim - LBP, -0.1, 0.1); // przymykanie zaworku double dv = PF((S > 0 ? BrakeRes->P() : 0), LBP, abs(S) * (0.00053 + 0.00060 * int(S < 0))) * dt; // przepływ LBP = LBP - dv; } @@ -3045,7 +3045,7 @@ double TFV4aM::GetPF(double i_bcp, double PP, double HP, double dt, double ep) } // na wszelki wypadek, zeby nie wyszlo poza zakres - i_bcp = clamp(i_bcp, -1.999, 5.999); + i_bcp = std::clamp(i_bcp, -1.999, 5.999); double DP{0.0}; if (TP > 0.0) diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 096f5d77..5cf8e463 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -663,7 +663,7 @@ debug_panel::render_section_scenario() { command_relay relay; relay.post( user_command::setweather, - clamp( std::exp( fogrange ), 10.0f, 50000.0f ), + std::clamp( std::exp( fogrange ), 10.0f, 50000.0f ), Global.Overcast, GLFW_PRESS, 0 ); } @@ -677,7 +677,7 @@ debug_panel::render_section_scenario() { command_relay relay; relay.post( user_command::settemperature, - clamp(Airtemperature, -35.0f, 40.0f), + std::clamp(Airtemperature, -35.0f, 40.0f), Global.Overcast, GLFW_PRESS, 0 ); } @@ -690,7 +690,7 @@ debug_panel::render_section_scenario() { relay.post( user_command::setweather, Global.fFogEnd, - clamp( Global.Overcast, 0.0f, 2.0f ), + std::clamp( Global.Overcast, 0.0f, 2.0f ), GLFW_PRESS, 0 ); } } @@ -701,7 +701,7 @@ debug_panel::render_section_scenario() { command_relay relay; relay.post( user_command::setdatetime, - clamp( Global.fMoveLight, 0.0f, 365.0f ), + std::clamp( Global.fMoveLight, 0.0f, 365.0f ), simulation::Time.data().wHour * 60 + simulation::Time.data().wMinute, GLFW_PRESS, 0 ); } @@ -730,7 +730,7 @@ debug_panel::render_section_scenario() { relay.post( user_command::setdatetime, Global.fMoveLight, - clamp( time, 0, 1439 ), + std::clamp( time, 0, 1439 ), GLFW_PRESS, 0 ); } } @@ -747,7 +747,7 @@ debug_panel::render_section_scenario() { auto drawrange = std::log(Global.BaseDrawRange); if (ImGui::SliderFloat( (to_string(std::exp(drawrange), 0, 5) + " m###drawrange").c_str(), &drawrange, std::log(100.0f), std::log(50000.0f), "Base drawing range")) { - Global.BaseDrawRange = clamp(std::exp(drawrange), 100.0f, 50000.0f); + Global.BaseDrawRange = std::clamp(std::exp(drawrange), 100.0f, 50000.0f); } } } @@ -1256,7 +1256,7 @@ debug_panel::update_section_scantable( std::vector &Output ) { auto const &mechanik{ *m_input.mechanik }; - std::size_t i = 0; std::size_t const speedtablesize = clamp( static_cast( mechanik.TableSize() ) - 1, 0, 30 ); + std::size_t i = 0; std::size_t const speedtablesize = std::clamp( static_cast( mechanik.TableSize() ) - 1, 0, 30 ); do { auto const scanline = mechanik.TableText( i ); if( scanline.empty() ) { break; } diff --git a/application/scenarioloaderuilayer.cpp b/application/scenarioloaderuilayer.cpp index 31c9f8e8..7b53e543 100644 --- a/application/scenarioloaderuilayer.cpp +++ b/application/scenarioloaderuilayer.cpp @@ -308,7 +308,7 @@ void scenarioloader_ui::generate_gradient_tex() image_data[(y * image_width + x) * 4] = 0; image_data[(y * image_width + x) * 4 + 1] = 0; image_data[(y * image_width + x) * 4 + 2] = 0; - image_data[(y * image_width + x) * 4 + 3] = clamp(static_cast(pow(y / 255.f, 0.7) * 255), 0, 255); + image_data[(y * image_width + x) * 4 + 3] = std::clamp(static_cast(pow(y / 255.f, 0.7) * 255), 0, 255); } // Create a OpenGL texture identifier diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp index 88fd74e8..ba0afe4c 100644 --- a/audio/audiorenderer.cpp +++ b/audio/audiorenderer.cpp @@ -192,8 +192,7 @@ openal_source::sync_with( sound_properties const &State ) { auto const fadedistance { sound_range * 0.75f }; auto const rangefactor { interpolate( - 1.f, 0.f, - clamp( + 1.f, 0.f, std::clamp( ( distancesquared - rangesquared ) / ( fadedistance * fadedistance ), 0.f, 1.f ) ) }; ::alSourcef( id, AL_GAIN, gain * rangefactor ); @@ -203,7 +202,7 @@ openal_source::sync_with( sound_properties const &State ) { // pitch if( State.pitch != properties.pitch ) { // pitch value has changed - ::alSourcef( id, AL_PITCH, clamp( State.pitch * pitch_variation, 0.1f, 10.f ) ); + ::alSourcef( id, AL_PITCH, std::clamp( State.pitch * pitch_variation, 0.1f, 10.f ) ); } // all synced up properties = State; diff --git a/audio/sound.cpp b/audio/sound.cpp index be8d53d6..d7670d41 100644 --- a/audio/sound.cpp +++ b/audio/sound.cpp @@ -185,7 +185,7 @@ sound_source::deserialize_mapping( cParser &Input ) { >> soundproofing[ 5 ]; for( auto & soundproofingelement : soundproofing ) { if( soundproofingelement != -1.f ) { - soundproofingelement = std::sqrt( clamp( soundproofingelement, 0.f, 1.f ) ); + soundproofingelement = std::sqrt( std::clamp( soundproofingelement, 0.f, 1.f ) ); } } m_soundproofing = soundproofing; @@ -206,7 +206,7 @@ sound_source::deserialize_mapping( cParser &Input ) { } else if( key == "pitchvariation:" ) { auto const variation { - clamp( + std::clamp( Input.getToken( false, "\n\r\t ,;" ), 0.0f, 1.0f ) * 100.0f / 2.0f }; @@ -217,7 +217,7 @@ sound_source::deserialize_mapping( cParser &Input ) { } else if( key == "startoffset:" ) { m_startoffset = - clamp( + std::clamp( Input.getToken( false, "\n\r\t ,;" ), 0.0f, 1.0f ); } @@ -240,7 +240,7 @@ sound_source::deserialize_mapping( cParser &Input ) { // for combined sounds, percentage of assigned range allocated to crossfade sections Input.getTokens( 1, "\n\r\t ,;" ); Input >> m_crossfaderange; - m_crossfaderange = clamp( m_crossfaderange, 0, 100 ); + m_crossfaderange = std::clamp( m_crossfaderange, 0, 100 ); } else if( key == "placement:" ) { auto const value { Input.getToken( true, "\n\r\t ,;" ) }; @@ -480,7 +480,7 @@ sound_source::compute_combined_point() const { return ( m_properties.pitch <= 1.f ? // most sounds use 0-1 value range, we clamp these to 0-99 to allow more intuitive sound definition in .mmd files - clamp( m_properties.pitch, 0.f, 0.99f ) : + std::clamp( m_properties.pitch, 0.f, 0.99f ) : std::max( 0.f, m_properties.pitch ) ) * 100.f; } @@ -784,7 +784,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { interpolate( previouschunkdata.pitch / chunkdata.pitch, 1.f, - clamp( + std::clamp( ( soundpoint - previouschunkdata.threshold ) / ( chunkdata.threshold - previouschunkdata.threshold ), 0.f, 1.f ) ); } @@ -799,7 +799,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { interpolate( 1.f, nextchunkdata.pitch / chunkdata.pitch, - clamp( + std::clamp( ( soundpoint - chunkdata.threshold ) / ( nextchunkdata.threshold - chunkdata.threshold ), 0.f, 1.f ) ); } @@ -818,7 +818,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { float lineargain = interpolate( 0.f, 1.f, - clamp( + std::clamp( ( soundpoint - chunkdata.fadein ) / fadeinwidth, 0.f, 1.f ) ); m_properties.gain *= @@ -838,7 +838,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { float lineargain = interpolate( 0.f, 1.f, - clamp( + std::clamp( ( soundpoint - fadeoutstart ) / fadeoutwidth, 0.f, 1.f ) ); m_properties.gain *= (-lineargain + 1) / @@ -852,7 +852,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) { sound_source & sound_source::gain( float const Gain ) { - m_properties.gain = clamp( Gain, 0.f, 2.f ); + m_properties.gain = std::clamp( Gain, 0.f, 2.f ); return *this; } diff --git a/environment/moon.cpp b/environment/moon.cpp index 31d4b493..80e34f70 100644 --- a/environment/moon.cpp +++ b/environment/moon.cpp @@ -81,9 +81,9 @@ void cMoon::setLocation( float const Longitude, float const Latitude ) { // sets current time, overriding one acquired from the system clock void cMoon::setTime( int const Hour, int const Minute, int const Second ) { - m_observer.hour = clamp( Hour, -1, 23 ); - m_observer.minute = clamp( Minute, -1, 59 ); - m_observer.second = clamp( Second, -1, 59 ); + m_observer.hour = std::clamp( Hour, -1, 23 ); + m_observer.minute = std::clamp( Minute, -1, 59 ); + m_observer.second = std::clamp( Second, -1, 59 ); } void cMoon::setTemperature( float const Temperature ) { diff --git a/environment/skydome.cpp b/environment/skydome.cpp index b268fdd4..8c2e465d 100644 --- a/environment/skydome.cpp +++ b/environment/skydome.cpp @@ -134,18 +134,18 @@ bool CSkyDome::SetSunPosition( glm::vec3 const &Direction ) { void CSkyDome::SetTurbidity( float const Turbidity ) { - m_turbidity = clamp( Turbidity, 1.f, 128.f ); + m_turbidity = std::clamp( Turbidity, 1.f, 128.f ); } void CSkyDome::SetExposure( bool const Linearexposure, float const Expfactor ) { m_linearexpcontrol = Linearexposure; - m_expfactor = 1.0f / clamp( Expfactor, 1.0f, std::numeric_limits::infinity() ); + m_expfactor = 1.0f / std::clamp( Expfactor, 1.0f, std::numeric_limits::infinity() ); } void CSkyDome::SetOvercastFactor( float const Overcast ) { - m_overcast = clamp( Overcast, 0.0f, 1.0f ) * 0.75f; // going above 0.65 makes the model go pretty bad, appearance-wise + m_overcast = std::clamp( Overcast, 0.0f, 1.0f ) * 0.75f; // going above 0.65 makes the model go pretty bad, appearance-wise } void CSkyDome::GetPerez( float *Perez, float Distribution[ 5 ][ 2 ], const float Turbidity ) { @@ -185,7 +185,7 @@ float CSkyDome::PerezFunctionO2( float Perezcoeffs[ 5 ], const float Icostheta, void CSkyDome::RebuildColors() { - float twilightfactor = clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; + float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; auto gammacorrection = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); // get zenith luminance @@ -263,7 +263,7 @@ void CSkyDome::RebuildColors() { colorconverter.z = 0.85f + ( colorconverter.z - 0.85f ) * 0.35f; } - colorconverter.y = clamp( colorconverter.y * Global.m_skysaturationcorrection, 0.0f, 1.0f ); + colorconverter.y = std::clamp( colorconverter.y * Global.m_skysaturationcorrection, 0.0f, 1.0f ); // desaturate sky colour, based on overcast level if( colorconverter.y > 0.0f ) { colorconverter.y *= ( 1.0f - 0.5f * m_overcast ); @@ -272,11 +272,11 @@ void CSkyDome::RebuildColors() { // override the hue, based on sun height above the horizon. crude way to deal with model shortcomings // correction begins when the sun is higher than 10 degrees above the horizon, and fully in effect at 10+15 degrees float const degreesabovehorizon = 90.0f - m_thetasun * ( 180.0f / M_PI ); - auto const sunbasedphase = clamp( (1.0f / 15.0f) * ( degreesabovehorizon - 10.0f ), 0.0f, 1.0f ); + auto const sunbasedphase = std::clamp( (1.0f / 15.0f) * ( degreesabovehorizon - 10.0f ), 0.0f, 1.0f ); // correction is applied in linear manner from the bottom, becomes fully in effect for vertices with y = 0.50 - auto const heightbasedphase = clamp( vertex.y * 2.0f, 0.0f, 1.0f ); + auto const heightbasedphase = std::clamp( vertex.y * 2.0f, 0.0f, 1.0f ); // this height-based factor is reduced the farther the sun is up in the sky - float const shiftfactor = clamp( interpolate(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f ); + float const shiftfactor = std::clamp( interpolate(heightbasedphase, sunbasedphase, sunbasedphase), 0.0f, 1.0f ); // h = 210 makes for 'typical' sky tone shiftedcolor = glm::vec3( 210.0f, colorconverter.y, colorconverter.z ); shiftedcolor = colors::HSVtoRGB( shiftedcolor ); @@ -296,7 +296,7 @@ void CSkyDome::RebuildColors() { color.y = 0.65f * color.z; } // simple gradient, darkening towards the top - color *= clamp( ( 1.0f - vertex.y ), 0.f, 1.f ); + color *= std::clamp( ( 1.0f - vertex.y ), 0.f, 1.f ); //color *= ( 0.25f - vertex.y ); // gamma correction color = glm::pow( color, gammacorrection ); diff --git a/environment/sun.cpp b/environment/sun.cpp index fd28f7f3..a4b6edf3 100644 --- a/environment/sun.cpp +++ b/environment/sun.cpp @@ -86,9 +86,9 @@ void cSun::setLocation( float const Longitude, float const Latitude ) { // sets current time, overriding one acquired from the system clock void cSun::setTime( int const Hour, int const Minute, int const Second ) { - m_observer.hour = clamp( Hour, -1, 23 ); - m_observer.minute = clamp( Minute, -1, 59 ); - m_observer.second = clamp( Second, -1, 59 ); + m_observer.hour = std::clamp( Hour, -1, 23 ); + m_observer.minute = std::clamp( Minute, -1, 59 ); + m_observer.second = std::clamp( Second, -1, 59 ); } void cSun::setTemperature( float const Temperature ) { diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index e1184b20..1e115690 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -147,7 +147,7 @@ mouse_slider::on_move( double const Mousex, double const Mousey ) { auto const controledge { Global.window_size.y * 0.5 + controlsize * 0.5 }; auto const stepsize { controlsize / m_valuerange }; - auto mousey = clamp( Mousey, controledge - controlsize, controledge ); + auto mousey = std::clamp( Mousey, controledge - controlsize, controledge ); m_value = ( m_analogue ? ( controledge - mousey ) / controlsize : @@ -303,7 +303,7 @@ drivermouse_input::scroll( double const Xoffset, double const Yoffset ) { if( Global.ctrlState ) { // ctrl + scroll wheel adjusts fov - Global.FieldOfView = clamp( static_cast( Global.FieldOfView - Yoffset * 20.0 / Timer::subsystem.mainloop_total.average() ), 15.0f, 75.0f ); + Global.FieldOfView = std::clamp( static_cast( Global.FieldOfView - Yoffset * 20.0 / Timer::subsystem.mainloop_total.average() ), 15.0f, 75.0f ); } else { // scroll adjusts master controller diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp index 85c29249..f6c95345 100644 --- a/model/AnimModel.cpp +++ b/model/AnimModel.cpp @@ -457,7 +457,7 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) { else opacity -= m_transition ? timedelta / transitionofftime : 1.f; // reduce to zero // Clamp the opacity - opacity = clamp(opacity, 0.f, 1.f); + opacity = std::clamp(opacity, 0.f, 1.f); } // Ra 2F1I: to by można pomijać dla modeli bez animacji, których jest większość @@ -600,7 +600,7 @@ std::optional> > TAnimModel::L void TAnimModel::SkinSet( int const Index, material_handle const Material ) { - m_materialdata.replacable_skins[ clamp( Index, 1, 4 ) ] = Material; + m_materialdata.replacable_skins[ std::clamp( Index, 1, 4 ) ] = Material; } void TAnimModel::AnimUpdate(double dt) diff --git a/model/Model3d.cpp b/model/Model3d.cpp index 8dfa8be4..1e2d5a16 100644 --- a/model/Model3d.cpp +++ b/model/Model3d.cpp @@ -2321,7 +2321,7 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t, fCosHotspotAngle = std::cos(DegToRad(0.5f * fCosHotspotAngle)); } // cap specular values for legacy models - f4Specular = glm::vec4{clamp(f4Specular.r, 0.0f, 1.0f), clamp(f4Specular.g, 0.0f, 1.0f), clamp(f4Specular.b, 0.0f, 1.0f), clamp(f4Specular.a, 0.0f, 1.0f)}; + f4Specular = glm::vec4{std::clamp(f4Specular.r, 0.0f, 1.0f), std::clamp(f4Specular.g, 0.0f, 1.0f), std::clamp(f4Specular.b, 0.0f, 1.0f), std::clamp(f4Specular.a, 0.0f, 1.0f)}; iFlags &= ~0x0200; // wczytano z pliku binarnego (nie jest właścicielem tablic) diff --git a/rendering/opengl33particles.cpp b/rendering/opengl33particles.cpp index 57f93ca4..b869012b 100644 --- a/rendering/opengl33particles.cpp +++ b/rendering/opengl33particles.cpp @@ -67,7 +67,7 @@ opengl33_particles::update( opengl_camera const &Camera ) { vertex.color[ 0 ] = particlecolor.r; vertex.color[ 1 ] = particlecolor.g; vertex.color[ 2 ] = particlecolor.b; - vertex.color.a = clamp(particle.opacity, 0.0f, 1.0f); + vertex.color.a = std::clamp(particle.opacity, 0.0f, 1.0f); auto const offset { glm::vec3{ particle.position - Camera.position() } }; auto const rotation { glm::angleAxis( particle.rotation, glm::vec3{ 0.f, 0.f, 1.f } ) }; diff --git a/rendering/opengl33renderer.cpp b/rendering/opengl33renderer.cpp index 620e64e4..675c2849 100644 --- a/rendering/opengl33renderer.cpp +++ b/rendering/opengl33renderer.cpp @@ -1293,7 +1293,7 @@ bool opengl33_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squ Dynamic->fShade : 1.0 ) ) ) ) }; setup_sunlight_intensity( - clamp( ( + std::clamp( ( Dynamic->fShade > 0.f ? Dynamic->fShade : 1.f ) @@ -1913,20 +1913,20 @@ bool opengl33_renderer::Render(world_environment *Environment) auto const &modelview = OpenGLMatrices.data(GL_MODELVIEW); - auto const fogfactor{clamp(Global.fFogEnd / 2000.f, 0.f, 1.f)}; // stronger fog reduces opacity of the celestial bodies - float const duskfactor = 1.0f - clamp(std::abs(Environment->m_sun.getAngle()), 0.0f, 12.0f) / 12.0f; + auto const fogfactor{std::clamp(Global.fFogEnd / 2000.f, 0.f, 1.f)}; // stronger fog reduces opacity of the celestial bodies + float const duskfactor = 1.0f - std::clamp(std::abs(Environment->m_sun.getAngle()), 0.0f, 12.0f) / 12.0f; glm::vec3 suncolor = interpolate(glm::vec3(255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f), glm::vec3(235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f), duskfactor); // sun { Bind_Texture(0, m_suntexture); - glm::vec4 color(suncolor.x, suncolor.y, suncolor.z, clamp(1.5f - Global.Overcast, 0.f, 1.f) * fogfactor); + glm::vec4 color(suncolor.x, suncolor.y, suncolor.z, std::clamp(1.5f - Global.Overcast, 0.f, 1.f) * fogfactor); auto const sunvector = Environment->m_sun.getDirection(); /*float const size = interpolate( // TODO: expose distance/scale factor from the moon object 0.0325f, 0.0275f, - clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );*/ + std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f );*/ model_ubs.param[0] = color; model_ubs.param[1] = glm::vec4(glm::vec3(modelview * glm::vec4(sunvector, 1.0f)), 0.00463f /* size */); model_ubs.param[2] = glm::vec4(0.0f, 1.0f, 1.0f, 0.0f); @@ -2003,7 +2003,7 @@ bool opengl33_renderer::Render(world_environment *Environment) float const size = interpolate( // TODO: expose distance/scale factor from the moon object 0.0160f, 0.0135f, - clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );*/ + std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f );*/ model_ubs.param[0] = color; model_ubs.param[1] = glm::vec4(glm::vec3(modelview * glm::vec4(moonvector, 1.0f)), 0.00451f /* size */); @@ -2044,7 +2044,7 @@ bool opengl33_renderer::Render(world_environment *Environment) m_sunlight.apply_intensity(); // calculate shadow tone, based on positions of celestial bodies - m_shadowcolor = interpolate(glm::vec4{colors::shadow}, glm::vec4{colors::white}, clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f); + m_shadowcolor = interpolate(glm::vec4{colors::shadow}, glm::vec4{colors::white}, std::clamp(-Environment->m_sun.getAngle(), 0.f, 6.f) / 6.f); if ((Environment->m_sun.getAngle() < -18.f) && (Environment->m_moon.getAngle() > 0.f)) { // turn on moon shadows after nautical twilight, if the moon is actually up @@ -3102,7 +3102,7 @@ bool opengl33_renderer::Render_cab(TDynamicObject const *Dynamic, float const Li auto const luminance { Global.fLuminance * ( Dynamic->fShade > 0.0f ? Dynamic->fShade : 1.0f ) }; if( Lightlevel > 0.f ) { // crude way to light the cabin, until we have something more complete in place - light_ubs.ambient += ( Dynamic->InteriorLight * Lightlevel ) * static_cast( clamp( 1.25 - luminance, 0.0, 1.0 ) ); + light_ubs.ambient += ( Dynamic->InteriorLight * Lightlevel ) * std::clamp( 1.25f - (float)luminance, 0.f, 1.f ); light_ubo->update( light_ubs ); } @@ -3715,7 +3715,7 @@ void opengl33_renderer::Render_precipitation() ::glRotated(m_precipitationrotation, 0.0, 1.0, 0.0); model_ubs.set_modelview(OpenGLMatrices.data(GL_MODELVIEW)); - model_ubs.param[0] = interpolate(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * clamp(Global.fLuminance, 0.f, 1.f)); + model_ubs.param[0] = interpolate(0.5f * (Global.DayLight.diffuse + Global.DayLight.ambient), colors::white, 0.5f * std::clamp((float)Global.fLuminance, 0.f, 1.f)); model_ubs.param[1].x = simulation::Environment.m_precipitation.get_textureoffset(); model_ubo->update(model_ubs); @@ -3891,7 +3891,7 @@ void opengl33_renderer::Render_Alpha(TTraction *Traction) auto const distance{static_cast(std::sqrt(distancesquared))}; auto const linealpha = 20.f * Traction->WireThickness / std::max(0.5f * Traction->radius() + 1.f, distance - (0.5f * Traction->radius())); if (m_widelines_supported) - glLineWidth(clamp(0.5f * linealpha + Traction->WireThickness * Traction->radius() / 1000.f, 1.f, 1.75f)); + glLineWidth(std::clamp(0.5f * linealpha + Traction->WireThickness * Traction->radius() / 1000.f, 1.f, 1.75f)); // render @@ -3929,7 +3929,7 @@ void opengl33_renderer::Render_Alpha(scene::lines_node const &Lines) auto const linealpha = (data.line_width > 0.f ? 10.f * data.line_width / std::max(0.5f * data.area.radius + 1.f, distance - (0.5f * data.area.radius)) : 1.f); // negative width means the lines are always opague if (m_widelines_supported) - glLineWidth(clamp(0.5f * linealpha + data.line_width * data.area.radius / 1000.f, 1.f, 8.f)); + glLineWidth(std::clamp(0.5f * linealpha + data.line_width * data.area.radius / 1000.f, 1.f, 8.f)); model_ubs.param[0] = glm::vec4(glm::vec3(data.lighting.diffuse * m_sunlight.ambient), glm::min(1.0f, linealpha)); @@ -4171,11 +4171,11 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) { // only bother if the viewer is inside the visibility cone // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness' - auto glarelevel{clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight + auto glarelevel{std::clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions 0.f, 1.f)}; // view angle attenuation - float const anglefactor{clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)}; + float const anglefactor{std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)}; glarelevel *= anglefactor; @@ -4226,7 +4226,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) // kąt większy niż maksymalny stożek swiatła float lightlevel = 1.f; // TODO, TBD: parameter to control light strength // view angle attenuation - float const anglefactor = clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f); + float const anglefactor = std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f); lightlevel *= anglefactor; // distance attenuation. NOTE: since it's fixed pipeline with built-in gamma correction we're using linear attenuation @@ -4236,7 +4236,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) // additionally reduce light strength for farther sources in rain or snow if (Global.Overcast > 0.75f) { - float const precipitationfactor{interpolate(interpolate(1.f, 0.25f, clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)}; + float const precipitationfactor{interpolate(interpolate(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)}; lightlevel *= precipitationfactor; } @@ -4263,7 +4263,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel) if (Global.Overcast > 1.0f) { // fake fog halo - float const fogfactor{interpolate(1.5f, 1.f, clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)}; + float const fogfactor{interpolate(1.5f, 1.f, std::clamp(Global.fFogEnd / 2000, 0.f, 1.f)) * std::max(1.f, Global.Overcast)}; model_ubs.param[1].x = pointsize * fogfactor * 4.0f; model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * std::min(1.f, lightlevel) * 0.5f); diff --git a/rendering/opengllight.cpp b/rendering/opengllight.cpp index f29cc5fb..61287d30 100644 --- a/rendering/opengllight.cpp +++ b/rendering/opengllight.cpp @@ -22,7 +22,7 @@ opengl_light::apply_intensity( float const Factor ) { ::glLightfv( id, GL_SPECULAR, glm::value_ptr( specular ) ); } else { - auto const factor{ clamp( Factor, 0.05f, 1.f ) }; + auto const factor{ std::clamp( Factor, 0.05f, 1.f ) }; // temporary light scaling mechanics (ultimately this work will be left to the shaders glm::vec4 scaledambient( ambient.r * factor, ambient.g * factor, ambient.b * factor, ambient.a ); glm::vec4 scaleddiffuse( diffuse.r * factor, diffuse.g * factor, diffuse.b * factor, diffuse.a ); diff --git a/rendering/openglparticles.cpp b/rendering/openglparticles.cpp index cdb0a66f..54db2ddf 100644 --- a/rendering/openglparticles.cpp +++ b/rendering/openglparticles.cpp @@ -65,7 +65,7 @@ opengl_particles::update( opengl_camera const &Camera ) { vertex.color[ 0 ] = static_cast( particlecolor.r ); vertex.color[ 1 ] = static_cast( particlecolor.g ); vertex.color[ 2 ] = static_cast( particlecolor.b ); - vertex.color[ 3 ] = clamp( particle.opacity * 255, 0, 255 ); + vertex.color[ 3 ] = static_cast( std::clamp( particle.opacity * 255, 0.f, 255.f ) ); auto const offset { glm::vec3{ particle.position - Camera.position() } }; auto const rotation { glm::angleAxis( particle.rotation, glm::vec3{ 0.f, 0.f, 1.f } ) }; diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index 75af6723..d91eb8fc 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -821,7 +821,7 @@ bool opengl_renderer::Render_lowpoly( TDynamicObject *Dynamic, float const Squar Dynamic->fShade : 1.0 ) ) ) ) }; m_sunlight.apply_intensity( - clamp( ( + std::clamp( ( Dynamic->fShade > 0.f ? Dynamic->fShade : 1.f ) @@ -923,7 +923,7 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f switch( Mode ) { case rendermode::color: { Config.draw_range = Global.BaseDrawRange * Global.fDistanceFactor; break; } case rendermode::shadows: { Config.draw_range = Global.shadowtune.range; break; } - case rendermode::cabshadows: { Config.draw_range = ( Global.RenderCabShadowsRange > 0 ? clamp( Global.RenderCabShadowsRange, 5, 100 ) : simulation::Train->Occupied()->Dim.L ); break; } + case rendermode::cabshadows: { Config.draw_range = ( Global.RenderCabShadowsRange > 0 ? std::clamp( Global.RenderCabShadowsRange, 5, 100 ) : simulation::Train->Occupied()->Dim.L ); break; } case rendermode::reflections: { Config.draw_range = Global.BaseDrawRange; break; } case rendermode::pickcontrols: { Config.draw_range = 50.f; break; } case rendermode::pickscenery: { Config.draw_range = Global.BaseDrawRange * 0.5f; break; } @@ -1510,7 +1510,7 @@ opengl_renderer::Render( world_environment *Environment ) { m_shadowcolor = interpolate( glm::vec4{ colors::shadow }, glm::vec4{ colors::white }, - clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f ); + std::clamp( -Environment->m_sun.getAngle(), 0.f, 6.f ) / 6.f ); if( ( Environment->m_sun.getAngle() < -18.f ) && ( Environment->m_moon.getAngle() > 0.f ) ) { // turn on moon shadows after nautical twilight, if the moon is actually up @@ -1568,8 +1568,8 @@ opengl_renderer::Render( world_environment *Environment ) { auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW ); - auto const fogfactor { clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies - float const duskfactor = 1.0f - clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f; + auto const fogfactor { std::clamp( Global.fFogEnd / 2000.f, 0.f, 1.f ) }; // closer/denser fog reduces opacity of the celestial bodies + float const duskfactor = 1.0f - std::clamp( std::abs( Environment->m_sun.getAngle() ), 0.0f, 12.0f ) / 12.0f; glm::vec3 suncolor = interpolate( glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ), glm::vec3( 235.0f / 255.0f, 140.0f / 255.0f, 36.0f / 255.0f ), @@ -1578,7 +1578,7 @@ opengl_renderer::Render( world_environment *Environment ) { if (!m_isATI) { Bind_Texture( m_suntexture ); - ::glColor4f( suncolor.x, suncolor.y, suncolor.z, clamp( 1.5f - Global.Overcast, 0.f, 1.f ) * fogfactor ); + ::glColor4f( suncolor.x, suncolor.y, suncolor.z, std::clamp( 1.5f - Global.Overcast, 0.f, 1.f ) * fogfactor ); auto const sunvector = Environment->m_sun.getDirection(); auto const sunposition = modelview * glm::vec4( sunvector.x, sunvector.y, sunvector.z, 1.0f ); @@ -1589,7 +1589,7 @@ opengl_renderer::Render( world_environment *Environment ) { float const size = interpolate( // TODO: expose distance/scale factor from the moon object 0.0325f, 0.0275f, - clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f ); + std::clamp( Environment->m_sun.getAngle(), 0.f, 90.f ) / 90.f ); ::glBegin( GL_TRIANGLE_STRIP ); ::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 1.f ); ::glVertex3f( -size, size, 0.f ); ::glMultiTexCoord2f( m_diffusetextureunit, 1.f, 0.f ); ::glVertex3f( -size, -size, 0.f ); @@ -1622,7 +1622,7 @@ opengl_renderer::Render( world_environment *Environment ) { float const size = interpolate( // TODO: expose distance/scale factor from the moon object 0.0160f, 0.0135f, - clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f ); + std::clamp( Environment->m_moon.getAngle(), 0.f, 90.f ) / 90.f ); // choose the moon appearance variant, based on current moon phase // NOTE: implementation specific, 8 variants are laid out in 3x3 arrangement // from new moon onwards, top left to right bottom (last spot is left for future use, if any) @@ -2609,7 +2609,7 @@ opengl_renderer::Render_cab( TDynamicObject const *Dynamic, float const Lightlev GL_LIGHT_MODEL_AMBIENT, glm::value_ptr( glm::vec3( m_baseambient ) - + ( Dynamic->InteriorLight * Lightlevel ) * static_cast( clamp( 1.25 - luminance, 0.0, 1.0 ) ) ) ); + + ( Dynamic->InteriorLight * Lightlevel ) * static_cast( std::clamp( 1.25 - luminance, 0.0, 1.0 ) ) ) ); } // render if( true == Alpha ) { @@ -2765,7 +2765,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { // textures... Bind_Material( material ); // ...colors and opacity... - auto const opacity { clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) }; + auto const opacity { std::clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) }; if( Submodel->fVisible < 1.f ) { // setup ::glAlphaFunc( GL_GREATER, 0.f ); @@ -2921,7 +2921,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { // kąt większy niż maksymalny stożek swiatła float lightlevel = 1.f; // TODO, TBD: parameter to control light strength // view angle attenuation - float const anglefactor = clamp( + float const anglefactor = std::clamp( ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ), 0.f, 1.f ); lightlevel *= anglefactor; @@ -2934,7 +2934,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { if( Global.Overcast > 0.75f ) { float const precipitationfactor{ interpolate( - interpolate( 1.f, 0.25f, clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ), + interpolate( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ), 1.f, distancefactor ) }; lightlevel *= precipitationfactor; @@ -2970,7 +2970,7 @@ opengl_renderer::Render( TSubModel *Submodel ) { float const fogfactor { interpolate( 2.f, 1.f, - clamp( Global.fFogEnd / 2000, 0.f, 1.f ) ) + std::clamp( Global.fFogEnd / 2000, 0.f, 1.f ) ) * std::max( 1.f, Global.Overcast ) }; ::glPointSize( pointsize * fogfactor ); @@ -3346,7 +3346,7 @@ opengl_renderer::Render_precipitation() { interpolate( 0.5f * ( Global.DayLight.diffuse + Global.DayLight.ambient ), colors::white, - 0.5f * clamp( Global.fLuminance, 0.f, 1.f ) ) ) ); + 0.5f * std::clamp( (float)Global.fLuminance, 0.f, 1.f ) ) ) ); ::glPushMatrix(); // tilt the precipitation cone against the camera movement vector for crude motion blur // include current wind vector while at it @@ -3587,14 +3587,14 @@ opengl_renderer::Render_Alpha( TTraction *Traction ) { 0.5f * Traction->radius() + 1.f, distance - ( 0.5f * Traction->radius() ) ) }; ::glLineWidth( - clamp( + std::clamp( 0.5f * linealpha + Traction->WireThickness * Traction->radius() / 1000.f, 1.f, 1.75f ) ); // McZapkie-261102: kolor zalezy od materialu i zasniedzenia ::glColor4fv( glm::value_ptr( glm::vec4{ - Traction->wire_color() /* * ( DebugModeFlag ? 1.f : clamp( m_sunandviewangle, 0.25f, 1.f ) ) */, + Traction->wire_color() /* * ( DebugModeFlag ? 1.f : std::clamp( m_sunandviewangle, 0.25f, 1.f ) ) */, linealpha } ) ); // render m_geometry.draw( Traction->m_geometry ); @@ -3637,7 +3637,7 @@ opengl_renderer::Render_Alpha( scene::lines_node const &Lines ) { distance - ( 0.5f * data.area.radius ) ) : 1.f ); // negative width means the lines are always opague ::glLineWidth( - clamp( + std::clamp( 0.5f * linealpha + data.line_width * data.area.radius / 1000.f, 1.f, 8.f ) ); ::glColor4fv( @@ -3839,7 +3839,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { // textures... Bind_Material( material ); // ...colors and opacity... - auto const opacity { clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) }; + auto const opacity { std::clamp( Material( material )->get_or_guess_opacity(), 0.f, 1.f ) }; if( Submodel->fVisible < 1.f ) { ::glColor4f( Submodel->f4Diffuse.r, @@ -3944,13 +3944,13 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) { if( Submodel->fCosViewAngle > Submodel->fCosFalloffAngle ) { // only bother if the viewer is inside the visibility cone // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness' - auto glarelevel { clamp( + auto glarelevel { std::clamp( std::max( 0.6f - Global.fLuminance, // reduce the glare in bright daylight Global.Overcast - 1.f ), // ensure some glare in rainy/foggy conditions 0.f, 1.f ) }; // view angle attenuation - float const anglefactor { clamp( + float const anglefactor { std::clamp( ( Submodel->fCosViewAngle - Submodel->fCosFalloffAngle ) / ( Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle ), 0.f, 1.f ) }; glarelevel *= anglefactor; @@ -4146,8 +4146,8 @@ glm::dvec3 opengl_renderer::Update_Mouse_Position() { glm::ivec2 mousepos = Global.cursor_pos * Global.fb_size / Global.window_size; - mousepos.x = clamp( mousepos.x, 0, Global.fb_size.x - 1 ); - mousepos.y = clamp( Global.fb_size.y - mousepos.y, 0, Global.fb_size.y - 1 ) ; + mousepos.x = std::clamp( mousepos.x, 0, Global.fb_size.x - 1 ); + mousepos.y = std::clamp(Global.fb_size.y - mousepos.y, 0, Global.fb_size.y - 1); GLfloat pointdepth; ::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth ); diff --git a/rendering/openglskydome.cpp b/rendering/openglskydome.cpp index 1ff66548..cc689a05 100644 --- a/rendering/openglskydome.cpp +++ b/rendering/openglskydome.cpp @@ -59,7 +59,7 @@ void opengl_skydome::update() { ::glBindBuffer( GL_ARRAY_BUFFER, m_coloursbuffer ); auto &colors{ skydome.colors() }; /* - float twilightfactor = clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; + float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f; auto gamma = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor ); for( auto & color : colors ) { color = glm::pow( color, gamma ); diff --git a/scene/scene.cpp b/scene/scene.cpp index 9780b593..1bc8674a 100644 --- a/scene/scene.cpp +++ b/scene/scene.cpp @@ -999,8 +999,8 @@ basic_section::cell( glm::dvec3 const &Location, const glm::ivec2 &offset ) { return m_cells[ - clamp( row, 0, ( EU07_SECTIONSIZE / EU07_CELLSIZE ) - 1 ) * ( EU07_SECTIONSIZE / EU07_CELLSIZE ) - + clamp( column, 0, ( EU07_SECTIONSIZE / EU07_CELLSIZE ) - 1 ) ] ; + std::clamp( row, 0, ( EU07_SECTIONSIZE / EU07_CELLSIZE ) - 1 ) * ( EU07_SECTIONSIZE / EU07_CELLSIZE ) + + std::clamp( column, 0, ( EU07_SECTIONSIZE / EU07_CELLSIZE ) - 1 ) ] ; } @@ -1694,8 +1694,8 @@ basic_region::section( glm::dvec3 const &Location ) { auto §ion = m_sections[ - clamp( row, 0, EU07_REGIONSIDESECTIONCOUNT - 1 ) * EU07_REGIONSIDESECTIONCOUNT - + clamp( column, 0, EU07_REGIONSIDESECTIONCOUNT - 1 ) ] ; + std::clamp( row, 0, EU07_REGIONSIDESECTIONCOUNT - 1 ) * EU07_REGIONSIDESECTIONCOUNT + + std::clamp( column, 0, EU07_REGIONSIDESECTIONCOUNT - 1 ) ] ; if( section == nullptr ) { // there's no guarantee the section exists at this point, so check and if needed, create it diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp index 38fe7f02..fcd6b450 100644 --- a/scene/scenenode.cpp +++ b/scene/scenenode.cpp @@ -255,8 +255,8 @@ shape_node::import( cParser &Input, scene::node_data const &Nodedata ) { >> vertex.texture.s >> vertex.texture.t; // clamp texture coordinates if texture wrapping is off - if( true == clamps ) { vertex.texture.s = clamp( vertex.texture.s, 0.001f, 0.999f ); } - if( true == clampt ) { vertex.texture.t = clamp( vertex.texture.t, 0.001f, 0.999f ); } + if( true == clamps ) { vertex.texture.s = std::clamp( vertex.texture.s, 0.001f, 0.999f ); } + if( true == clampt ) { vertex.texture.t = std::clamp( vertex.texture.t, 0.001f, 0.999f ); } // convert all data to gl_triangles to allow data merge for matching nodes switch( nodetype ) { case triangles: { diff --git a/simulation/simulation.cpp b/simulation/simulation.cpp index 390970df..51b7945f 100644 --- a/simulation/simulation.cpp +++ b/simulation/simulation.cpp @@ -140,11 +140,11 @@ state_manager::update_scripting_interface() { if( simulation::is_ready ) { // potentially adjust weather if( weather->Value1() != m_scriptinginterface.weather->Value1() ) { - Global.Overcast = clamp( weather->Value1(), 0, 2 ); + Global.Overcast = std::clamp( (float)weather->Value1(), 0.f, 2.f ); simulation::Environment.compute_weather(); } if( weather->Value2() != m_scriptinginterface.weather->Value2() ) { - Global.fFogEnd = clamp( weather->Value2(), 10, 25000 ); + Global.fFogEnd = std::clamp( (float)weather->Value2(), 10.f, 25000.f ); } } else { @@ -324,7 +324,7 @@ void state_manager::process_commands() { simulation::Environment.compute_season(yearday); if( weather != Global.Weather ) { // HACK: force re-calculation of precipitation - Global.Overcast = clamp( Global.Overcast - 0.0001f, 0.0f, 2.0f ); + Global.Overcast = std::clamp( Global.Overcast - 0.0001f, 0.0f, 2.0f ); } simulation::Environment.update_moon(); diff --git a/simulation/simulationenvironment.cpp b/simulation/simulationenvironment.cpp index e7bae9ca..e1c2138f 100644 --- a/simulation/simulationenvironment.cpp +++ b/simulation/simulationenvironment.cpp @@ -48,7 +48,7 @@ world_environment::compute_season( int const Yearday ) { auto const lookup = std::lower_bound( std::begin( seasonsequence ), std::end( seasonsequence ), - clamp( Yearday, 1, seasonsequence.back().first ), + std::clamp( Yearday, 1, seasonsequence.back().first ), []( dayseasonpair const &Left, const int Right ) { return Left.first < Right; } ); @@ -117,7 +117,7 @@ world_environment::update() { m_moon.update(); // ...determine source of key light and adjust global state accordingly... // diffuse (sun) intensity goes down after twilight, and reaches minimum 18 degrees below horizon - float twilightfactor = clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f; + float twilightfactor = std::clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f; // NOTE: sun light receives extra padding to prevent moon from kicking in too soon auto const sunlightlevel = m_sun.getIntensity() + 0.05f * ( 1.f - twilightfactor ); auto const moonlightlevel = m_moon.getIntensity() * 0.65f; // scaled down by arbitrary factor, it's pretty bright otherwise @@ -127,8 +127,8 @@ world_environment::update() { // turbidity varies from 2-3 during the day based on overcast, 3-4 after sunset to deal with sunlight bleeding too much into the sky from below horizon m_skydome.SetTurbidity( 2.25f - + clamp( Global.Overcast, 0.f, 1.f ) - + interpolate( 0.f, 1.f, clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) ); + + std::clamp( Global.Overcast, 0.f, 1.f ) + + interpolate( 0.f, 1.f, std::clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) ); m_skydome.SetOvercastFactor( Global.Overcast ); m_skydome.Update( m_sun.getDirection() ); @@ -155,7 +155,7 @@ world_environment::update() { keylightintensity = sunlightlevel; m_lightintensity = 1.0f; // include 'golden hour' effect in twilight lighting - float const duskfactor = 1.25f - clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f; + float const duskfactor = 1.25f - std::clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f; keylightcolor = interpolate( glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ), glm::vec3( 235.0f / 255.0f, 120.0f / 255.0f, 36.0f / 255.0f ), @@ -180,8 +180,8 @@ world_environment::update() { // tonal impact of skydome color is inversely proportional to how high the sun is above the horizon // (this is pure conjecture, aimed more to 'look right' than be accurate) - float const ambienttone = clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f ); - float const ambientintensitynightfactor = 1.f - 0.75f * clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f; + float const ambienttone = std::clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f ); + float const ambientintensitynightfactor = 1.f - 0.75f * std::clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f; Global.DayLight.ambient[ 0 ] = interpolate( skydomehsv.z, skydomecolour.r, ambienttone ) * ambientintensitynightfactor; Global.DayLight.ambient[ 1 ] = interpolate( skydomehsv.z, skydomecolour.g, ambienttone ) * ambientintensitynightfactor; Global.DayLight.ambient[ 2 ] = interpolate( skydomehsv.z, skydomecolour.b, ambienttone ) * ambientintensitynightfactor; @@ -191,7 +191,7 @@ world_environment::update() { // update the fog. setting it to match the average colour of the sky dome is cheap // but quite effective way to make the distant items blend with background better Global.FogColor = ((m_skydome.GetAverageHorizonColor()) * keylightcolor) * - clamp(Global.fLuminance, 0.0f, 1.f); + std::clamp((float)Global.fLuminance, 0.f, 1.f); // weather-related simulation factors @@ -255,7 +255,7 @@ world_environment::update_wind() { // TBD, TODO: wind configuration m_wind.azimuth = clamp_circular( m_wind.azimuth + m_wind.azimuth_change * timedelta ); // HACK: negative part of range allows for some quiet periods, without active wind - m_wind.velocity = clamp( m_wind.velocity + m_wind.velocity_change * timedelta, -2, 4 ); + m_wind.velocity = std::clamp( m_wind.velocity + m_wind.velocity_change * timedelta, -2.f, 4.f ); // convert to force vector auto const polarangle { glm::radians( 90.f ) }; // theta auto const azimuthalangle{ glm::radians( m_wind.azimuth ) }; // phi diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp index 32fbd962..0b2a9a8d 100644 --- a/simulation/simulationstateserializer.cpp +++ b/simulation/simulationstateserializer.cpp @@ -225,7 +225,7 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch } Global.fFogEnd = - clamp( + std::clamp( Random( std::min( fograngestart, fograngeend ), std::max( fograngestart, fograngeend ) ), 10.0, 25000.0 ); } @@ -238,7 +238,7 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch // negative overcast means random value in range 0-abs(specified range) Global.Overcast = Random( - clamp( + std::clamp( std::abs( Global.Overcast ), 0.f, 2.f ) ); } diff --git a/simulation/simulationtime.cpp b/simulation/simulationtime.cpp index 0a0c5711..e80fb342 100644 --- a/simulation/simulationtime.cpp +++ b/simulation/simulationtime.cpp @@ -47,8 +47,8 @@ scenario_time::init(std::time_t timestamp) { daymonth( m_time.wDay, m_time.wMonth, m_time.wYear, static_cast( Global.fMoveLight ) ); } - if( requestedhour != -1 ) { m_time.wHour = static_cast( clamp( requestedhour, 0, 23 ) ); } - if( requestedminute != -1 ) { m_time.wMinute = static_cast( clamp( requestedminute, 0, 59 ) ); } + if( requestedhour != -1 ) { m_time.wHour = static_cast( std::clamp( requestedhour, 0, 23 ) ); } + if( requestedminute != -1 ) { m_time.wMinute = static_cast( std::clamp( requestedminute, 0, 59 ) ); } // if the time is taken from the local clock leave the seconds intact, otherwise set them to zero if( ( requestedhour != -1 ) || ( requestedminute != 1 ) ) { diff --git a/utilities/Globals.cpp b/utilities/Globals.cpp index 37c6c76a..bd1f69d1 100644 --- a/utilities/Globals.cpp +++ b/utilities/Globals.cpp @@ -55,7 +55,7 @@ static void ParseOneClamped(cParser& parser, T& out, T minValue, T maxValue, int { parser.getTokens(tokenCount, convert); parser >> out; - out = clamp(out, minValue, maxValue); + out = std::clamp(out, minValue, maxValue); } void global_settings::FinalizeConfig() @@ -301,7 +301,7 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to if (token == "dynamiclights") { ParseOne(Parser, DynamicLightCount, 1, false); - DynamicLightCount = clamp(DynamicLightCount, 0, 7); + DynamicLightCount = std::clamp(DynamicLightCount, 0, 7); return true; } @@ -358,7 +358,7 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to if (token == "multisampling") { ParseOne(Parser, iMultisampling, 1, false); - iMultisampling = clamp(iMultisampling, 0, 4); + iMultisampling = std::clamp(iMultisampling, 0, 4); return true; } @@ -546,7 +546,7 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& stream >> ScenarioTimeOverride; } - ScenarioTimeOverride = clamp(ScenarioTimeOverride, 0.f, 24 * 1439 / 1440.f); + ScenarioTimeOverride = std::clamp(ScenarioTimeOverride, 0.f, 24 * 1439 / 1440.f); return true; } @@ -578,7 +578,7 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string& { float splinefidelity = 0.f; ParseOne(Parser, splinefidelity); - SplineFidelity = clamp(splinefidelity, 1.f, 4.f); + SplineFidelity = std::clamp(splinefidelity, 1.f, 4.f); return true; } @@ -1317,7 +1317,7 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token float smokefidelity; Parser.getTokens(); Parser >> smokefidelity; - SmokeFidelity = clamp(smokefidelity, 1.f, 4.f); + SmokeFidelity = std::clamp(smokefidelity, 1.f, 4.f); } else if (Token == "gfx.resource.sweep") { @@ -1338,7 +1338,7 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token { Parser.getTokens(1, false); Parser >> reflectiontune.fidelity; - reflectiontune.fidelity = clamp(reflectiontune.fidelity, 0, 2); + reflectiontune.fidelity = std::clamp(reflectiontune.fidelity, 0, 2); } else if (Token == "gfx.reflections.range_instances") { @@ -1462,13 +1462,13 @@ global_settings::ConfigParse_gfx( cParser &Parser, std::string_view const Token if( gfx_shadow_angle_min > 0 ) { gfx_shadow_angle_min *= -1; } - gfx_shadow_angle_min = clamp(gfx_shadow_angle_min, -1.f, -0.2f); + gfx_shadow_angle_min = std::clamp(gfx_shadow_angle_min, -1.f, -0.2f); } else if (Token == "gfx.shadow.rank.cutoff") { Parser.getTokens(1); Parser >> gfx_shadow_rank_cutoff; - gfx_shadow_rank_cutoff = clamp(gfx_shadow_rank_cutoff, 1, 3); + gfx_shadow_rank_cutoff = std::clamp(gfx_shadow_rank_cutoff, 1, 3); } else { diff --git a/utilities/Globals.h b/utilities/Globals.h index 09e3435c..a42f059c 100644 --- a/utilities/Globals.h +++ b/utilities/Globals.h @@ -52,7 +52,7 @@ struct global_settings { basic_light DayLight; float SunAngle{ 0.f }; // angle of the sun relative to horizon int trainThreads{0}; - double fLuminance{ 1.0 }; // jasność światła do automatycznego zapalania + double fLuminance{ 1.0 }; // jasność światła do automatycznego zapalania // TODO: Why double? double fTimeAngleDeg{ 0.0 }; // godzina w postaci kąta float fClockAngleDeg[ 6 ]; // kąty obrotu cylindrów dla zegara cyfrowego std::string LastGLError; diff --git a/utilities/utilities.h b/utilities/utilities.h index b506678e..353d722b 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -251,21 +251,6 @@ template bool is_equal(T const &Left, T const &Right, T const Epsil return (Left == Right); } -template Type_ clamp(Type_ const Value, Type_ const Min, Type_ const Max) -{ - - Type_ value = Value; - if (value < Min) - { - value = Min; - } - if (value > Max) - { - value = Max; - } - return value; -} - // keeps the provided value in specified range 0-Range, as if the range was circular buffer template Type_ clamp_circular(Type_ Value, Type_ const Range = static_cast(360)) { diff --git a/vehicle/Camera.cpp b/vehicle/Camera.cpp index d5216930..cf46a03a 100644 --- a/vehicle/Camera.cpp +++ b/vehicle/Camera.cpp @@ -128,7 +128,7 @@ TCamera::OnCommand( command_data const &Command ) { static void UpdateVelocityAxis(double& velocity, double moverate, double deltatime) { - velocity = clamp(velocity + moverate * 10.0 * deltatime, -std::abs(moverate), std::abs(moverate)); + velocity = std::clamp(velocity + moverate * 10.0 * deltatime, -std::abs(moverate), std::abs(moverate)); } @@ -155,7 +155,7 @@ void TCamera::Update() Angle.y = std::remainder(Angle.y, 2.0 * M_PI); // Limit the camera pitch to +/- 90°. - Angle.x = clamp(Angle.x - (m_rotationoffsets.x * rotationfactor), -M_PI_2, M_PI_2); + Angle.x = std::clamp(Angle.x - (m_rotationoffsets.x * rotationfactor), -M_PI_2, M_PI_2); m_rotationoffsets.x *= ( 1.0 - rotationfactor ); // update position diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 0a3f6265..709e866d 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -935,7 +935,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN if( brakingdistance > 0.0 ) { // maintain desired acc while we have enough room to brake safely, when close enough start paying attention // try to make a smooth transition instead of sharp change - a = interpolate( a, AccPreferred, clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) ); + a = interpolate( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) ); } } if( ( d < fMinProximityDist ) @@ -1738,7 +1738,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const { if( ( is_dmu() ) && ( mvOccupied->Vel < 40.0 ) && ( Targetvelocity == 0.f ) ) { - auto const multiplier { clamp( 1.f + iVehicles * 0.5f, 2.f, 4.f ) }; + auto const multiplier { std::clamp( 1.f + iVehicles * 0.5f, 2.f, 4.f ) }; return ( interpolate( multiplier, 1.f, @@ -1752,7 +1752,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const { return ( interpolate( 1.f, 2.f, - clamp( + std::clamp( ( fBrake_a0[ 1 ] - 0.2 ) / 0.2, 0.0, 1.0 ) ) * frictionmultiplier ); @@ -3183,7 +3183,7 @@ bool TController::IncBrake() interpolate( mvOccupied->Handle->GetPos( bh_EPR ), mvOccupied->Handle->GetPos( bh_EPB ), - clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); + std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); OK = ( mvOccupied->fBrakeCtrlPos != initialbrakeposition ); } else if( mvOccupied->fBrakeCtrlPos != mvOccupied->Handle->GetPos( bh_EPB ) ) { @@ -3211,7 +3211,7 @@ bool TController::IncBrakeEIM() auto const maxpos{mvOccupied->EIMCtrlEmergency ? 0.9 : 1.0 }; auto const brakelimit{ -2.2 * AccDesired / fMedAmax - 1.0}; //additional limit when hinted is too low auto const brakehinted{ -1.0 * mvOccupied->AIHintLocalBrakeAccFactor * AccDesired / fMedAmax }; //preffered by AI - auto const brakeposition{ maxpos * clamp(std::max(brakelimit, brakehinted), 0.0, 1.0)}; + auto const brakeposition{ maxpos * std::clamp(std::max(brakelimit, brakehinted), 0.0, 1.0)}; OK = ( brakeposition != mvOccupied->LocalBrakePosA ); mvOccupied->LocalBrakePosA = brakeposition; } @@ -3315,7 +3315,7 @@ bool TController::DecBrake() { interpolate( mvOccupied->Handle->GetPos( bh_EPR ), mvOccupied->Handle->GetPos( bh_EPB ), - clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); + std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) ); OK = ( mvOccupied->fBrakeCtrlPos != initialbrakeposition ); } else { @@ -3372,7 +3372,7 @@ bool TController::DecBrakeEIM() case 0: { if( mvOccupied->MED_amax != 9.81 ) { auto const desiredacceleration { ( mvOccupied->Vel > EU07_AI_NOMOVEMENT ? AccDesired : std::max( 0.0, AccDesired ) ) }; - auto const brakeposition { clamp( -1.0 * mvOccupied->AIHintLocalBrakeAccFactor * desiredacceleration / mvOccupied->MED_amax, 0.0, 1.0 ) }; + auto const brakeposition { std::clamp( -1.0 * mvOccupied->AIHintLocalBrakeAccFactor * desiredacceleration / mvOccupied->MED_amax, 0.0, 1.0 ) }; OK = ( brakeposition != mvOccupied->LocalBrakePosA ); mvOccupied->LocalBrakePosA = brakeposition; } @@ -3774,7 +3774,7 @@ bool TController::IncSpeedEIM() { // TBD, TODO: set position based on desired acceleration? OK = mvControlling->MainCtrlPos < mvControlling->MainCtrlPosNo; if( OK ) { - mvControlling->MainCtrlPos = clamp( mvControlling->MainCtrlPos + 1, 6, mvControlling->MainCtrlPosNo ); + mvControlling->MainCtrlPos = std::clamp( mvControlling->MainCtrlPos + 1, 6, mvControlling->MainCtrlPosNo ); } */ break; @@ -3830,7 +3830,7 @@ void TController::BrakeLevelSet(double b) // jedyny dopuszczalny sposób przestawienia hamulca zasadniczego if (BrakeCtrlPosition == b) return; // nie przeliczać, jak nie ma zmiany - BrakeCtrlPosition = clamp(b, (double)gbh_MIN, (double)gbh_MAX); + BrakeCtrlPosition = std::clamp(b, (double)gbh_MIN, (double)gbh_MAX); } bool TController::BrakeLevelAdd(double b) @@ -4143,7 +4143,7 @@ void TController::SetTimeControllers() else if (VelDesired > MinVel) //more power for faster ride { auto const Factor{ 10 * (mvControlling->Vmax) / (mvControlling->Vmax + 3 * mvControlling->Vel) }; - auto DesiredPercentage{ clamp( + auto DesiredPercentage{ std::clamp( (VelDesired > mvControlling->Vel ? (VelDesired - mvControlling->Vel) / Factor : 0), @@ -6026,7 +6026,7 @@ TController::determine_consist_state() { fBrake_a1[0] = fBrake_a1[index]; if ((is_emu()) || (is_dmu())) { - auto Coeff = clamp( mvOccupied->Vel*0.015 , 0.5 , 1.0); + auto Coeff = std::clamp( mvOccupied->Vel*0.015 , 0.5 , 1.0); fAccThreshold = fNominalAccThreshold * Coeff - fBrake_a0[BrakeAccTableSize] * (1.0 - Coeff); } @@ -6742,8 +6742,8 @@ TController::determine_proximity_ranges() { // na jaka odleglosc i z jaka predkoscia ma podjechac do przeszkody // jeśli pociąg if( is_train() ) { - fMinProximityDist = clamp( 5 + iVehicles, 10, 15 ); - fMaxProximityDist = clamp( 10 + iVehicles, 15, 40 ); + fMinProximityDist = std::clamp( 5 + iVehicles, 10, 15 ); + fMaxProximityDist = std::clamp( 10 + iVehicles, 15, 40 ); if( IsCargoTrain ) { // increase distances for cargo trains to take into account slower reaction to brakes @@ -6778,10 +6778,10 @@ TController::determine_proximity_ranges() { else { // gdy nie musi się sprężać // margines prędkości powodujący załączenie napędu; min 1.0 żeby nie ruszał przy 0.1 - fVelMinus = clamp( std::round( 0.05 * VelDesired ), 1.0, 5.0 ); + fVelMinus = std::clamp( std::round( 0.05 * VelDesired ), 1.0, 5.0 ); // normalnie dopuszczalne przekroczenie to 5% prędkości ale nie więcej niż 5km/h // bottom margin raised to 2 km/h to give the AI more leeway at low speed limits - fVelPlus = clamp( std::ceil( 0.05 * VelDesired ), 2.0, 5.0 ); + fVelPlus = std::clamp( std::ceil( 0.05 * VelDesired ), 2.0, 5.0 ); } } // samochod (sokista też) @@ -7392,7 +7392,7 @@ TController::pick_optimal_speed( double const Range ) { // last step sanity check, until the whole calculation is straightened out AccDesired = std::min( AccDesired, AccPreferred ); - AccDesired = clamp( + AccDesired = std::clamp( AccDesired, ( is_car() ? -2.0 : -0.9 ), ( is_car() ? 2.0 : 0.9 ) ); @@ -7760,7 +7760,7 @@ TController::adjust_desired_speed_for_current_speed() { // HACK: for cargo trains with high braking threshold ensure we cross that threshold if( ( true == IsCargoTrain ) && ( fBrake_a0[ 0 ] > 0.2 ) ) { - AccDesired -= clamp( fBrake_a0[ 0 ] - 0.2, 0.0, 0.15 ); + AccDesired -= std::clamp( fBrake_a0[ 0 ] - 0.2, 0.0, 0.15 ); } } } @@ -7770,22 +7770,22 @@ TController::adjust_desired_speed_for_current_speed() { AccDesired, // but don't override decceleration for VelNext interpolate( // ease off as you close to the target velocity EU07_AI_NOACCELERATION, AccPreferred, - clamp( VelDesired - speedestimate, 0.0, fVelMinus ) / fVelMinus ) ); + std::clamp( VelDesired - speedestimate, 0.0, fVelMinus ) / fVelMinus ) ); } // final tweaks if( vel > EU07_AI_NOMOVEMENT ) { // going downhill also take into account impact of gravity AccDesired -= fAccGravity; // HACK: if the max allowed speed was exceeded something went wrong; brake harder - AccDesired -= 0.15 * clamp( vel - VelDesired, 0.0, 5.0 ); + AccDesired -= 0.15 * std::clamp( vel - VelDesired, 0.0, 5.0 ); } } // HACK: limit acceleration for cargo trains, to reduce probability of breaking couplers on sudden jolts auto MaxAcc{ 0.5 * mvOccupied->Couplers[(mvOccupied->DirAbsolute >= 0 ? end::rear : end::front)].FmaxC / fMass }; if( iVehicles - ControlledEnginesCount > 0 ) { - MaxAcc *= clamp( vel * 0.025, 0.2, 1.0 ); + MaxAcc *= std::clamp( vel * 0.025, 0.2, 1.0 ); } - AccDesired = std::min(AccDesired, clamp(MaxAcc, HeavyCargoTrainAcceleration, AccPreferred)); + AccDesired = std::min(AccDesired, std::clamp(MaxAcc, HeavyCargoTrainAcceleration, AccPreferred)); // TBD: expand this behaviour to all trains with car(s) exceeding certain weight? /* if( ( IsPassengerTrain ) && ( iVehicles - ControlledEnginesCount > 0 ) ) { @@ -7887,7 +7887,7 @@ TController::adjust_desired_speed_for_braking_test() { break; } case 3: { - AccDesired = clamp( -AbsAccS, fAccThreshold * 1.01, fAccThreshold * 1.21 ); + AccDesired = std::clamp( -AbsAccS, fAccThreshold * 1.01, fAccThreshold * 1.21 ); VelDesired = DBT_VelocityBrake; if( vel <= DBT_VelocityRelease ) { DynamicBrakeTest = 4; @@ -8285,7 +8285,7 @@ void TController::control_main_pipe() { BrakeLevelSet( gbh_FS ); // don't charge the brakes too often, or we risk overcharging - BrakeChargingCooldown = -1 * clamp( iVehicles * 3, 30, 90 ); + BrakeChargingCooldown = -1 * std::clamp( iVehicles * 3, 30, 90 ); } } } diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index f1974555..ae298980 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -1077,7 +1077,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) continue; } - auto const dist { clamp( MoverParameters->Couplers[ i ].Dist / 2.0, -MoverParameters->Couplers[ i ].DmaxB, 0.0 ) }; + auto const dist { std::clamp( MoverParameters->Couplers[ i ].Dist / 2.0, -MoverParameters->Couplers[ i ].DmaxB, 0.0 ) }; if( dist >= 0.0 ) { continue; } @@ -2496,7 +2496,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" initial_track = MyTrack; iNumAxles = 2; // McZapkie-090402: odleglosc miedzy czopami skretu lub osiami - fAxleDist = clamp( + fAxleDist = std::clamp( std::max( MoverParameters->BDist, MoverParameters->ADist ), 0.2, //żeby się dało wektory policzyć MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur" @@ -3076,7 +3076,7 @@ TDynamicObject::update_load_offset() { 0.0 : 100.0 * MoverParameters->LoadAmount / MoverParameters->MaxLoad ) }; - LoadOffset = interpolate( MoverParameters->LoadType.offset_min, 0.f, clamp( 0.0, 1.0, loadpercentage * 0.01 ) ); + LoadOffset = interpolate( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) ); } void @@ -3528,7 +3528,7 @@ bool TDynamicObject::Update(double dt, double dt1) else p->MoverParameters->MED_EPVC_CurrentTime += dt1; bool EPVC = ((p->MoverParameters->MED_EPVC) && ((p->MoverParameters->MED_EPVC_Time < 0) || (p->MoverParameters->MED_EPVC_CurrentTime < p->MoverParameters->MED_EPVC_Time))); - float VelC = (EPVC ? clamp(p->MoverParameters->Vel, p->MoverParameters->MED_Vmin, p->MoverParameters->MED_Vmax) : p->MoverParameters->MED_Vref);//korekcja EP po prędkości + float VelC = (EPVC ? std::clamp(p->MoverParameters->Vel, p->MoverParameters->MED_Vmin, p->MoverParameters->MED_Vmax) : p->MoverParameters->MED_Vref);//korekcja EP po prędkości float FmaxPoj = Nmax * p->MoverParameters->Hamulec->GetFC( Nmax / (p->MoverParameters->NAxles * p->MoverParameters->NBpA), VelC) * @@ -3685,7 +3685,7 @@ bool TDynamicObject::Update(double dt, double dt1) auto volume = interpolate( 0.8, 1.2, - clamp( + std::clamp( MyTrack->iQualityFlag / 10.0, 0.0, 1.5 ) ); switch( MyTrack->eEnvironment ) { @@ -3730,8 +3730,8 @@ bool TDynamicObject::Update(double dt, double dt1) if(MyTrack->eType == tt_Normal) { MoverParameters->AccVert += - clamp(0.0, 4.0, - (clamp(0.0, MoverParameters->Vmax, + std::clamp(0.0, 4.0, + (std::clamp(0.0, MoverParameters->Vmax, MoverParameters->Vmax - (MoverParameters->Vel + MoverParameters->Vmax * 0.32f))) * @@ -3739,24 +3739,24 @@ bool TDynamicObject::Update(double dt, double dt1) } if (MyTrack->eType == tt_Switch){ MoverParameters->AccS += - clamp(0.0, 1.0, - (clamp(0.0, MoverParameters->Vmax, + std::clamp(0.0, 1.0, + (std::clamp(0.0, MoverParameters->Vmax, MoverParameters->Vmax - (MoverParameters->Vel + MoverParameters->Vmax * 0.32f))) * .05f * (MyTrack->iDamageFlag * 0.25f)) * ((axleindex % 2) != 0 ? 1 : -1); MoverParameters->AccN += - clamp(0.0, 1.0, - (clamp(0.0, MoverParameters->Vmax, + std::clamp(0.0, 1.0, + (std::clamp(0.0, MoverParameters->Vmax, MoverParameters->Vmax - (MoverParameters->Vel + MoverParameters->Vmax * 0.32f))) * .05f * (MyTrack->iDamageFlag * 0.25f)) * ((axleindex % 2) != 0 ? 1 : -1); MoverParameters->AccVert += - clamp(0.0, 2.0, - (clamp(0.0, MoverParameters->Vmax, + std::clamp(0.0, 2.0, + (std::clamp(0.0, MoverParameters->Vmax, MoverParameters->Vmax - (MoverParameters->Vel + MoverParameters->Vmax * 0.32f))) * @@ -4455,12 +4455,12 @@ void TDynamicObject::RenderSounds() { // NOTE: we do sound modulation here to avoid sudden jump on voltage loss frequency = ( voltage / ( MoverParameters->NominalVoltage * MoverParameters->RList[ MoverParameters->RlistSize ].Mn ) ); frequency *= sConverter.m_frequencyfactor + sConverter.m_frequencyoffset; - sConverter.pitch( clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits ) + sConverter.pitch( std::clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits ) } } else { frequency = sConverter.m_frequencyoffset + sConverter.m_frequencyfactor * frequency; - sConverter.pitch( clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits ) + sConverter.pitch( std::clamp( frequency, 0.75, 1.25 ) ); // arbitrary limits ) } sConverter.play( sound_flags::exclusive | sound_flags::looping ); } @@ -4491,7 +4491,7 @@ void TDynamicObject::RenderSounds() { // presume the compressor sound is recorded for idle revolutions // increase the pitch according to increase of engine revolutions auto const enginefactor { - clamp( // try to keep the sound pitch in semi-reasonable range + std::clamp( // try to keep the sound pitch in semi-reasonable range MoverParameters->EngineMaxRPM() / MoverParameters->EngineIdleRPM() * MoverParameters->EngineRPMRatio(), 0.5, 2.5 ) }; sCompressor.pitch( enginefactor ); @@ -4636,10 +4636,10 @@ void TDynamicObject::RenderSounds() { MoverParameters->EmergencyValveFlow : interpolate( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) ); // scale volume based on the flow rate and on the pressure in the main pipe - auto const flowpressure { clamp( m_emergencybrakeflow, 0.0, 1.0 ) + clamp( 0.1 * MoverParameters->PipePress, 0.0, 0.5 ) }; + auto const flowpressure { std::clamp( m_emergencybrakeflow, 0.0, 1.0 ) + std::clamp( 0.1 * MoverParameters->PipePress, 0.0, 0.5 ) }; m_emergencybrake .pitch( m_emergencybrake.m_frequencyoffset + 1.0 * m_emergencybrake.m_frequencyfactor ) - .gain( m_emergencybrake.m_amplitudeoffset + clamp( flowpressure, 0.0, 1.0 ) * m_emergencybrake.m_amplitudefactor ) + .gain( m_emergencybrake.m_amplitudeoffset + std::clamp( flowpressure, 0.0, 1.0 ) * m_emergencybrake.m_amplitudefactor ) .play( sound_flags::exclusive | sound_flags::looping ); } else if( MoverParameters->EmergencyValveFlow < 0.015 ) { @@ -4674,9 +4674,9 @@ void TDynamicObject::RenderSounds() { if( MoverParameters->Hamulec->Releaser() ) { sReleaser .gain( - clamp( - MoverParameters->BrakePress * 1.25f, // arbitrary multiplier - 0.f, 1.f ) ) + std::clamp( + MoverParameters->BrakePress * 1.25, // arbitrary multiplier + 0., 1. ) ) .play( sound_flags::exclusive | sound_flags::looping ); } else { @@ -4714,7 +4714,7 @@ void TDynamicObject::RenderSounds() { && ( MoverParameters->Vel > 0.05 ) ) { brakeforceratio = - clamp( + std::clamp( MoverParameters->UnitBrakeForce / std::max( 1.0, MoverParameters->BrakeForceR( 1.0, MoverParameters->Vel ) / ( MoverParameters->NAxles * std::max( 1, MoverParameters->NBpA ) ) ), 0.0, 1.0 ); rsBrake @@ -4966,7 +4966,7 @@ void TDynamicObject::RenderSounds() { volume *= interpolate( 0.8, 1.2, - clamp( + std::clamp( MyTrack->iQualityFlag / 20.0, 0.0, 1.0 ) ); // for single sample sounds muffle the playback at low speeds @@ -4974,7 +4974,7 @@ void TDynamicObject::RenderSounds() { volume *= interpolate( 0.0, 1.0, - clamp( + std::clamp( MoverParameters->Vel / 40.0, 0.0, 1.0 ) ); } @@ -5036,7 +5036,7 @@ void TDynamicObject::RenderSounds() { && ( MoverParameters->WheelFlat > 5.0 ) ) { m_wheelflat .pitch( m_wheelflat.m_frequencyoffset + std::abs( MoverParameters->nrot ) * m_wheelflat.m_frequencyfactor ) - .gain( m_wheelflat.m_amplitudeoffset + m_wheelflat.m_amplitudefactor * ( ( 1.0 + ( MoverParameters->Vel / MoverParameters->Vmax ) + clamp( MoverParameters->WheelFlat / 60.0, 0.0, 1.0 ) ) / 3.0 ) ) + .gain( m_wheelflat.m_amplitudeoffset + m_wheelflat.m_amplitudefactor * ( ( 1.0 + ( MoverParameters->Vel / MoverParameters->Vmax ) + std::clamp( MoverParameters->WheelFlat / 60.0, 0.0, 1.0 ) ) / 3.0 ) ) .play( sound_flags::exclusive | sound_flags::looping ); } else { @@ -5053,7 +5053,7 @@ void TDynamicObject::RenderSounds() { std::abs( MoverParameters->AccN ) // * MoverParameters->AccN * interpolate( 0.5, 1.0, - clamp( + std::clamp( MoverParameters->Vel / 40.0, 0.0, 1.0 ) ) * ( ( ( MyTrack->eType == tt_Switch ) && ( std::abs( ts.R ) < 1500.0 ) ) ? 100.0 : 1.0 ); @@ -5310,7 +5310,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co if( i < asModel.length() ) { m_materialdata.multi_textures = asModel[ i + 1 ] - '0'; } - m_materialdata.multi_textures = clamp( m_materialdata.multi_textures, 0, 1 ); // na razie ustawiamy na 1 + m_materialdata.multi_textures = std::clamp( m_materialdata.multi_textures, 0, 1 ); // na razie ustawiamy na 1 } */ asModel = asBaseDir + asModel; // McZapkie 2002-07-20: dynamics maja swoje modele w dynamics/basedir @@ -6563,7 +6563,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co >> soundproofing[ 5 ]; for( auto & soundproofingelement : soundproofing ) { if( soundproofingelement != -1.f ) { - soundproofingelement = std::sqrt( clamp( soundproofingelement, 0.f, 1.f ) ); + soundproofingelement = std::sqrt( std::clamp( soundproofingelement, 0.f, 1.f ) ); } } m_pasystem.soundproofing = soundproofing; @@ -7017,7 +7017,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co for( auto &soundproofingelement : soundproofingtable ) { auto const value { parser.getToken( false ) }; if( value != -1.f ) { - soundproofingelement = std::sqrt( clamp( value, 0.f, 1.f ) ); + soundproofingelement = std::sqrt( std::clamp( value, 0.f, 1.f ) ); } } } @@ -8086,13 +8086,13 @@ TDynamicObject::update_shake( double const Timedelta ) { shakevector.x += ( std::sin( MoverParameters->eAngle * 4.0 ) * Timedelta * EngineShake.scale ) // fade in with rpm above threshold - * clamp( + * std::clamp( ( MoverParameters->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor, 0.0, 1.0 ) // fade out with rpm above threshold * interpolate( 1.0, 0.0, - clamp( + std::clamp( ( MoverParameters->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor, 0.0, 1.0 ) ); } @@ -8105,7 +8105,7 @@ TDynamicObject::update_shake( double const Timedelta ) { auto const huntingamount = interpolate( 0.0, 1.0, - clamp( + std::clamp( ( MoverParameters->Vel - HuntingShake.fadein_begin ) / ( HuntingShake.fadein_end - HuntingShake.fadein_begin ), 0.0, 1.0 ) ); shakevector.x += @@ -8325,7 +8325,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub engine_revs_change = std::max( 0.0, engine_revs_change - 2.5 * Deltatime ); if( ( revolutionsperminute > idlerevolutionsthreshold ) && ( revolutionsdifference > 1.0 * Deltatime ) ) { - engine_revs_change = clamp( engine_revs_change + 5.0 * Deltatime, 0.0, 1.25 ); + engine_revs_change = std::clamp( engine_revs_change + 5.0 * Deltatime, 0.0, 1.25 ); } enginerevvolume = 0.8 * engine_revs_change; } @@ -8513,7 +8513,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub } // scale motor volume based on whether they're active motor_momentum = - clamp( + std::clamp( motor_momentum - 1.0 * Deltatime // smooth out decay + std::abs( Vehicle.Mm ) / 60.0 * Deltatime, diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index 390f8e9b..cefd8a97 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -459,7 +459,7 @@ float TGauge::GetScaledValue() const { m_value * interpolate( m_scale, m_endscale, - clamp( + std::clamp( m_value / m_endvalue, 0.f, 1.f ) ) + m_offset ); diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index c97bff53..521573cd 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -1108,7 +1108,7 @@ void TTrain::OnCommand_jointcontrollerset( TTrain *Train, command_data const &Co } else { Train->mvOccupied->LocalBrakePosA = ( - clamp( + std::clamp( 1.0 - ( Command.param1 * 2 ), 0.0, 1.0 ) ); if( Train->mvControlled->MainCtrlPowerPos() > 0 ) { @@ -1223,7 +1223,7 @@ void TTrain::OnCommand_secondcontrollerincrease( TTrain *Train, command_data con && ( true == Train->mvControlled->ShuntModeAllow ) && ( true == Train->mvControlled->ShuntMode ) ) { if( Command.action != GLFW_RELEASE ) { - Train->mvControlled->AnPos = clamp( + Train->mvControlled->AnPos = std::clamp( Train->mvControlled->AnPos + 0.025, 0.0, 1.0 ); } @@ -1393,7 +1393,7 @@ void TTrain::OnCommand_secondcontrollerdecrease( TTrain *Train, command_data con if( ( Train->mvControlled->EngineType == TEngineType::DieselElectric ) && ( true == Train->mvControlled->ShuntMode ) ) { if( Command.action != GLFW_RELEASE ) { - Train->mvControlled->AnPos = clamp( + Train->mvControlled->AnPos = std::clamp( Train->mvControlled->AnPos - 0.025, 0.0, 1.0 ); } @@ -1577,7 +1577,7 @@ void TTrain::OnCommand_independentbrakeset( TTrain *Train, command_data const &C if( Command.action != GLFW_RELEASE ) { Train->mvOccupied->LocalBrakePosA = ( - clamp( + std::clamp( Command.param1, 0.0, 1.0 ) ); } @@ -1587,7 +1587,7 @@ void TTrain::OnCommand_independentbrakeset( TTrain *Train, command_data const &C interpolate( 0.0, LocalBrakePosNo, - clamp( + std::clamp( Command.param1, 0.0, 1.0 ) ) ) ); */ @@ -1716,7 +1716,7 @@ void TTrain::OnCommand_trainbrakeset( TTrain *Train, command_data const &Command interpolate( Train->mvOccupied->Handle->GetPos( bh_MIN ), Train->mvOccupied->Handle->GetPos( bh_MAX ), - clamp( + std::clamp( Command.param1, 0.0, 1.0 ) ) ); } else { @@ -1801,7 +1801,7 @@ void TTrain::OnCommand_trainbrakebasepressureincrease( TTrain *Train, command_da switch( Train->mvOccupied->BrakeHandle ) { case TBrakeHandle::FV4a: { - Train->mvOccupied->BrakeCtrlPos2 = clamp( Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0 ); + Train->mvOccupied->BrakeCtrlPos2 = std::clamp( Train->mvOccupied->BrakeCtrlPos2 - 0.01, -1.5, 2.0 ); break; } default: { @@ -1818,7 +1818,7 @@ void TTrain::OnCommand_trainbrakebasepressuredecrease( TTrain *Train, command_da switch( Train->mvOccupied->BrakeHandle ) { case TBrakeHandle::FV4a: { - Train->mvOccupied->BrakeCtrlPos2 = clamp( Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0 ); + Train->mvOccupied->BrakeCtrlPos2 = std::clamp( Train->mvOccupied->BrakeCtrlPos2 + 0.01, -1.5, 2.0 ); break; } default: { @@ -3032,7 +3032,7 @@ void TTrain::change_pantograph_selection( int const Change ) { auto const &presets { mvOccupied->PantsPreset.first }; auto &selection { mvOccupied->PantsPreset.second[ cab_to_end() ] }; auto const initialstate { selection }; - selection = clamp( selection + Change, 0, std::max( presets.size() - 1, 0 ) ); + selection = std::clamp( selection + Change, 0, std::max( presets.size() - 1, 0 ) ); if( selection == initialstate ) { return; } // no change, nothing to do @@ -5125,7 +5125,7 @@ void TTrain::OnCommand_redmarkerstoggle( TTrain *Train, command_data const &Comm auto locationHead = vehicle->HeadPosition() - glm::dvec3(Command.location); // TODO: Maybe command_data should be dvec3? auto locationRear = vehicle->RearPosition() - glm::dvec3(Command.location); int const CouplNr { - clamp(vehicle->DirectionGet() * (glm::dot(locationHead, locationHead) > glm::dot(locationRear, locationRear) ? + std::clamp(vehicle->DirectionGet() * (glm::dot(locationHead, locationHead) > glm::dot(locationRear, locationRear) ? 1 : -1 ), 0, 1 ) }; // z [-1,1] zrobić [0,1] @@ -5148,7 +5148,7 @@ void TTrain::OnCommand_endsignalstoggle( TTrain *Train, command_data const &Comm if( vehicle == nullptr ) { return; } int const CouplNr { - clamp( + std::clamp( vehicle->DirectionGet() * ( glm::length2( vehicle->HeadPosition() - glm::dvec3(Command.location) ) > glm::length2( vehicle->RearPosition() - glm::dvec3(Command.location) ) ? 1 : @@ -6859,7 +6859,7 @@ void TTrain::OnCommand_radiochanneldecrease( TTrain *Train, command_data const & void TTrain::OnCommand_radiochannelset(TTrain *Train, command_data const &Command) { if( Command.action != GLFW_RELEASE ) { // on press or hold - Train->RadioChannel() = clamp((int) Command.param1, 1, 10); + Train->RadioChannel() = std::clamp((int) Command.param1, 1, 10); Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 ); } } @@ -6981,7 +6981,7 @@ void TTrain::OnCommand_radiovolumedecrease(TTrain *Train, command_data const &Co void TTrain::OnCommand_radiovolumeset(TTrain *Train, command_data const &Command) { if( Command.action != GLFW_RELEASE ) { // on press or hold - Train->m_radiovolume = clamp(Command.param1, 0.0, 1.0); + Train->m_radiovolume = std::clamp(Command.param1, 0.0, 1.0); Train->ggRadioVolumeSelector.UpdateValue(Train->m_radiovolume); audio::event_volume_change = true; } @@ -8218,7 +8218,7 @@ bool TTrain::Update( double const Deltatime ) { double b = Console::AnalogCalibrateGet(0); b = b * 8.0 - 2.0; - b = clamp( b, -2.0, mvOccupied->BrakeCtrlPosNo ); // przycięcie zmiennej do granic + b = std::clamp( b, -2.0, (double)mvOccupied->BrakeCtrlPosNo ); // przycięcie zmiennej do granic ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia mvOccupied->BrakeLevelSet(b); } @@ -8226,14 +8226,14 @@ bool TTrain::Update( double const Deltatime ) { double b = Console::AnalogCalibrateGet(0); b = b * 7.0 - 1.0; - b = clamp( b, -1.0, mvOccupied->BrakeCtrlPosNo ); // przycięcie zmiennej do granic + b = std::clamp(b, -1.0, (double)mvOccupied->BrakeCtrlPosNo); // przycięcie zmiennej do granic ggBrakeCtrl.UpdateValue(b); // przesów bez zaokrąglenia mvOccupied->BrakeLevelSet(b); } else { double b = Console::AnalogCalibrateGet( 0 ); b = b * ( mvOccupied->Handle->GetPos( bh_MAX ) - mvOccupied->Handle->GetPos( bh_MIN ) ) + mvOccupied->Handle->GetPos( bh_MIN ); - b = clamp( b, mvOccupied->Handle->GetPos( bh_MIN ), mvOccupied->Handle->GetPos( bh_MAX ) ); // przycięcie zmiennej do granic + b = std::clamp(b, mvOccupied->Handle->GetPos(bh_MIN), mvOccupied->Handle->GetPos(bh_MAX)); // przycięcie zmiennej do granic ggBrakeCtrl.UpdateValue( b ); // przesów bez zaokrąglenia mvOccupied->BrakeLevelSet( b ); } @@ -8257,8 +8257,8 @@ bool TTrain::Update( double const Deltatime ) /* || ( Global.bMWDmasterEnable && Global.bMWDBreakEnable )*/ ) ) { // Ra: nie najlepsze miejsce, ale na początek gdzieś to dać trzeba // Firleju: dlatego kasujemy i zastepujemy funkcją w Console - auto const b = clamp( - Console::AnalogCalibrateGet( 1 ), + auto const b = std::clamp( + (double)Console::AnalogCalibrateGet( 1 ), 0.0, 1.0 ); mvOccupied->LocalBrakePosA = b; @@ -8559,7 +8559,7 @@ TTrain::update_sounds( double const Deltatime ) { if( rsSBHiss ) { if( ( m_localbrakepressurechange < -0.05f ) && ( mvOccupied->LocBrakePress > mvOccupied->BrakePress - 0.05 ) ) { - rsSBHiss->gain( clamp( rsSBHiss->m_amplitudeoffset + rsSBHiss->m_amplitudefactor * -m_localbrakepressurechange * 0.05, 0.0, 1.5 ) ); + rsSBHiss->gain( std::clamp( rsSBHiss->m_amplitudeoffset + rsSBHiss->m_amplitudefactor * -m_localbrakepressurechange * 0.05, 0.0, 1.5 ) ); rsSBHiss->play( sound_flags::exclusive | sound_flags::looping ); } else { @@ -8574,7 +8574,7 @@ TTrain::update_sounds( double const Deltatime ) { // local brake, engage if( rsSBHissU ) { if( m_localbrakepressurechange > 0.05f ) { - rsSBHissU->gain( clamp( rsSBHissU->m_amplitudeoffset + rsSBHissU->m_amplitudefactor * m_localbrakepressurechange * 0.05, 0.0, 1.5 ) ); + rsSBHissU->gain( std::clamp( rsSBHissU->m_amplitudeoffset + rsSBHissU->m_amplitudefactor * m_localbrakepressurechange * 0.05, 0.0, 1.5 ) ); rsSBHissU->play( sound_flags::exclusive | sound_flags::looping ); } else { @@ -8695,7 +8695,7 @@ TTrain::update_sounds( double const Deltatime ) { && ( mvOccupied->Vel > 0.05 ) ) { auto const brakeforceratio{ - clamp( + std::clamp( mvOccupied->UnitBrakeForce / std::max( 1.0, mvOccupied->BrakeForceR( 1.0, mvOccupied->Vel ) / ( mvOccupied->NAxles * std::max( 1, mvOccupied->NBpA ) ) ), 0.0, 1.0 ) }; // HACK: in external view mute the sound rather than stop it, in case there's an opening bookend it'd (re)play on sound restart after returning inside @@ -8778,7 +8778,7 @@ TTrain::update_sounds( double const Deltatime ) { auto const huntingamount = interpolate( 0.0, 1.0, - clamp( + std::clamp( ( mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin ) / ( DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin ), 0.0, 1.0 ) ); @@ -8936,7 +8936,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { if( std::abs( mvOccupied->nrot ) > 0.01 ) { // hamulce wzmagaja halas auto const brakeforceratio { ( - clamp( + std::clamp( mvOccupied->UnitBrakeForce / std::max( 1.0, mvOccupied->BrakeForceR( 1.0, mvOccupied->Vel ) / ( mvOccupied->NAxles * std::max( 1, mvOccupied->NBpA ) ) ), 0.0, 1.0 ) ) }; @@ -8947,7 +8947,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { volume *= interpolate( 0.8, 1.2, - clamp( + std::clamp( DynamicObject->MyTrack->iQualityFlag / 20.0, 0.0, 1.0 ) ); // for single sample sounds muffle the playback at low speeds @@ -8955,7 +8955,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) { volume *= interpolate( 0.0, 1.0, - clamp( + std::clamp( mvOccupied->Vel / 25.0, 0.0, 1.0 ) ); } @@ -9728,9 +9728,9 @@ glm::dvec3 TTrain::clamp_inside(glm::dvec3 const &Point) const if( DebugModeFlag ) { return Point; } return { - clamp( Point.x, (double)Cabine[ iCabn ].CabPos1.x, (double)Cabine[ iCabn ].CabPos2.x ), - clamp( Point.y, (double)Cabine[ iCabn ].CabPos1.y + 0.5, (double)Cabine[ iCabn ].CabPos2.y + 1.8 ), - clamp( Point.z, (double)Cabine[ iCabn ].CabPos1.z, (double)Cabine[ iCabn ].CabPos2.z ) }; + std::clamp( Point.x, (double)Cabine[ iCabn ].CabPos1.x, (double)Cabine[ iCabn ].CabPos2.x ), + std::clamp( Point.y, (double)Cabine[ iCabn ].CabPos1.y + 0.5, (double)Cabine[ iCabn ].CabPos2.y + 1.8 ), + std::clamp( Point.z, (double)Cabine[ iCabn ].CabPos1.z, (double)Cabine[ iCabn ].CabPos2.z ) }; } const TTrain::screenentry_sequence& TTrain::get_screens() { @@ -10966,7 +10966,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con Parser >> i >> j; auto &gauge = Cabine[Cabindex].Gauge(-1); // pierwsza wolna gałka gauge.Load(Parser, DynamicObject, 0.1); - gauge.AssignFloat(&fPress[clamp(i, 1, 20) - 1][clamp(j, 0, 3)]); + gauge.AssignFloat(&fPress[std::clamp(i, 1, 20) - 1][std::clamp(j, 0, 3)]); } else if ((Label == "brakepress:") || (Label == "brakepressb:")) { diff --git a/world/Event.cpp b/world/Event.cpp index a2bbd6d9..350a6a48 100644 --- a/world/Event.cpp +++ b/world/Event.cpp @@ -1508,7 +1508,7 @@ texture_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) { // intercept potential error, index specified using .t3d format convention m_skinindex *= -1; } - m_skinindex = clamp( m_skinindex, 1, 4 ); // TODO: define-based upper bound in case of future extension + m_skinindex = std::clamp( m_skinindex, 1, 4 ); // TODO: define-based upper bound in case of future extension Input.getTokens(); // preload next token } diff --git a/world/Segment.cpp b/world/Segment.cpp index 9ddccae4..05124233 100644 --- a/world/Segment.cpp +++ b/world/Segment.cpp @@ -273,7 +273,7 @@ TSegment::find_nearest_point( glm::dvec3 const &Point ) const { for( int segmentidx = 0; segmentidx < iSegCount; ++segmentidx ) { auto const segmentpoint = - clamp( + std::clamp( nearest_segment_point( glm::dvec3{ FastGetPoint( fTsBuffer[ segmentidx ] ) }, glm::dvec3{ FastGetPoint( fTsBuffer[ segmentidx + 1 ] ) }, @@ -331,7 +331,7 @@ Math3D::vector3 TSegment::GetPoint(double const fDistance) const return interpolate( Point1, Point2, - clamp( + std::clamp( fDistance / fLength, 0.0, 1.0 ) ); } diff --git a/world/Track.cpp b/world/Track.cpp index 2f40a723..4bf38f29 100644 --- a/world/Track.cpp +++ b/world/Track.cpp @@ -569,7 +569,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( fRadius != 0 ) { // gdy podany promień segsize = - clamp( + std::clamp( std::abs( fRadius ) * ( 0.02 / Global.SplineFidelity ), 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -583,7 +583,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) else { // HACK: divide roughly in 10 segments. segsize = - clamp( + std::clamp( glm::length( p1 - p2 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -667,7 +667,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( fRadiusTable[ 0 ] != 0 ) { // gdy podany promień segsize = - clamp( + std::clamp( std::abs( fRadiusTable[ 0 ] ) * ( 0.02 / Global.SplineFidelity ), 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -681,7 +681,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) else { // HACK: divide roughly in 10 segments. segsize = - clamp( + std::clamp( glm::length( p1 - p2 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -732,7 +732,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) if( fRadiusTable[ 1 ] != 0 ) { // gdy podany promień segsize = - clamp( + std::clamp( std::abs( fRadiusTable[ 1 ] ) * ( 0.02 / Global.SplineFidelity ), 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -746,7 +746,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin) else { // HACK: divide roughly in 10 segments. segsize = - clamp( + std::clamp( glm::length( p3 - p4 ) * 0.1, 2.0 / Global.SplineFidelity, 10.0 / Global.SplineFidelity ); @@ -2531,7 +2531,7 @@ float TTrack::Friction() const { return fFriction; } else { - return clamp( fFriction * m_friction.second->Value1() + m_friction.second->Value2(), 0.0, 1.0 ); + return std::clamp( fFriction * m_friction.second->Value1() + m_friction.second->Value2(), 0.0, 1.0 ); } }