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.h b/McZapkie/MOVER.h
index 058fcfb5..34650052 100644
--- a/McZapkie/MOVER.h
+++ b/McZapkie/MOVER.h
@@ -77,7 +77,6 @@ zwiekszenie nacisku przy duzych predkosciach w hamulcach Oerlikona
...
*/
-#include "utilities/utilities.h"
/// Global counter incremented when a string-to-numeric conversion fails during config parsing.
extern int ConversionError;
diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp
index f7813216..63215f0c 100644
--- a/McZapkie/Mover.cpp
+++ b/McZapkie/Mover.cpp
@@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "MOVER.h"
-#include "utilities/utilities.h"
#include "vehicle/DynObj.h"
#include "Oerlikon_ESt.h"
#include "utilities/Globals.h"
@@ -356,7 +355,7 @@ double TMoverParameters::Current(double n, double U)
if (DynamicBrakeFlag && (!FuseFlag) && (DynamicBrakeType == dbrake_automatic) && Power110vIsAvailable && Mains) // hamowanie EP09 //TUHEX
{
// TODO: zrobic bardziej uniwersalne nie tylko dla EP09
- MotorCurrent = -Max0R(MotorParam[0].fi * (Vadd / (Vadd + MotorParam[0].Isat) - MotorParam[0].fi0), 0) * n * 2.0 / DynamicBrakeRes;
+ MotorCurrent = -std::max(MotorParam[0].fi * (Vadd / (Vadd + MotorParam[0].Isat) - MotorParam[0].fi0), 0.) * n * 2.0 / DynamicBrakeRes;
}
else if ((RList[MainCtrlActualPos].Bn == 0) || (false == StLinFlag))
{
@@ -862,7 +861,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 +873,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
@@ -1079,7 +1078,7 @@ double TMoverParameters::LocalBrakeRatio(void)
LBR = 0;
}
// if (TestFlag(BrakeStatus, b_antislip))
- // LBR = Max0R(LBR, PipeRatio) + 0.4;
+ // LBR = std::max(LBR, PipeRatio) + 0.4;
return LBR;
}
@@ -1137,17 +1136,17 @@ double TMoverParameters::PipeRatio(void)
if (false) // SPKS!! no to jak nie wchodzimy to po co branch?
{
if ((3.0 * PipePress) > (HighPipePress + LowPipePress + LowPipePress))
- pr = (HighPipePress - Min0R(HighPipePress, PipePress)) / (DeltaPipePress * 4.0 / 3.0);
+ pr = (HighPipePress - std::min(HighPipePress, PipePress)) / (DeltaPipePress * 4.0 / 3.0);
else
- pr = (HighPipePress - 1.0 / 3.0 * DeltaPipePress - Max0R(LowPipePress, PipePress)) / (DeltaPipePress * 2.0 / 3.0);
+ pr = (HighPipePress - 1.0 / 3.0 * DeltaPipePress - std::max(LowPipePress, PipePress)) / (DeltaPipePress * 2.0 / 3.0);
// if (not TestFlag(BrakeStatus, b_Ractive))
// and(BrakeMethod and 1 = 0) and TestFlag(BrakeDelays, bdelay_R) and (Power < 1) and
- // (BrakeCtrlPos < 1) then pr : = Min0R(0.5, pr);
+ // (BrakeCtrlPos < 1) then pr : = std::min(0.5, pr);
// if (Compressor > 0.5)
// then pr : = pr * 1.333; // dziwny rapid wywalamy
}
else
- pr = (HighPipePress - Max0R(LowPipePress, Min0R(HighPipePress, PipePress))) / DeltaPipePress;
+ pr = (HighPipePress - std::max(LowPipePress, std::min(HighPipePress, PipePress))) / DeltaPipePress;
else
pr = 0;
return pr;
@@ -1156,7 +1155,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 +1258,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;
// }
}
@@ -1393,8 +1392,8 @@ 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)
+ AccS = std::lerp(AccSprev, FTotal / TotalMass, 0.5);
+ // 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 +1415,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 = std::lerp(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);
@@ -1490,8 +1489,8 @@ 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)
+ AccS = std::lerp(AccSprev, FTotal / TotalMass, 0.5);
+ // 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)
@@ -2098,8 +2097,8 @@ void TMoverParameters::HeatingCheck(double const Timestep)
absrevolutions < generator.revolutions_min ?
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::lerp(generator.voltage_min, generator.voltage_max,
+ std::clamp((absrevolutions - generator.revolutions_min) / (generator.revolutions_max - generator.revolutions_min), 0.0, 1.0))) *
sign(generator.revolutions);
}
break;
@@ -2208,7 +2207,7 @@ void TMoverParameters::OilPumpCheck(double const Timestep)
auto const minpressure{OilPump.pressure_minimum > 0.f ? OilPump.pressure_minimum : 0.15f}; // arbitrary fallback value
OilPump.pressure_target = (
- enrot > 0.1 ? interpolate( minpressure, OilPump.pressure_maximum, static_cast( EngineRPMRatio() ) ) * OilPump.resource_amount :
+ enrot > 0.1 ? std::lerp( minpressure, OilPump.pressure_maximum, static_cast( EngineRPMRatio() ) ) * OilPump.resource_amount :
true == OilPump.is_active ? std::min( minpressure + 0.1f, OilPump.pressure_maximum ) : // slight pressure margin to give time to switch off the pump and start the engine
0.f );
@@ -2221,7 +2220,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 +2275,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
{
@@ -2979,7 +2978,7 @@ bool TMoverParameters::AddPulseForce(int Multipler)
DirActive = CabActive;
DirAbsolute = DirActive * CabActive;
if (Vel > 0)
- PulseForce = Min0R(1000.0 * Power / (abs(V) + 0.1), Ftmax);
+ PulseForce = std::min(1000.0 * Power / (abs(V) + 0.1), Ftmax);
else
PulseForce = Ftmax;
if (PulseForceCount > 1000.0)
@@ -3751,7 +3750,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)
{
@@ -3925,7 +3924,7 @@ bool TMoverParameters::DynamicBrakeLevelSet(double Position)
{
if (false == SplitEDPneumaticBrake)
return false;
- DynamicBrakeCtrlPos = clamp(Position, 0.0, 1.0);
+ DynamicBrakeCtrlPos = std::clamp(Position, 0.0, 1.0);
return true;
}
@@ -3937,7 +3936,7 @@ double TMoverParameters::DynamicBrakeRatio(void) const
{
if (false == SplitEDPneumaticBrake)
return 0.0;
- return clamp(DynamicBrakeCtrlPos, 0.0, 1.0);
+ return std::clamp(DynamicBrakeCtrlPos, 0.0, 1.0);
}
// *************************************************************************************************
@@ -5278,7 +5277,7 @@ double TMoverParameters::Adhesive(double staticfriction) const
if (SlippingWheels == false)
{
if (SandDose)
- adhesion = (Max0R(staticfriction * (100.0 + Vel) / ((50.0 + Vel) * 11.0), 0.048)) *
+ adhesion = (std::max(staticfriction * (100.0 + Vel) / ((50.0 + Vel) * 11.0), 0.048)) *
(11.0 - 2.0 * Random(0.0, 1.0));
else
adhesion = (staticfriction * (100.0 + Vel) / ((50.0 + Vel) * 10.0)) *
@@ -5364,7 +5363,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;
@@ -5504,7 +5503,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
{
@@ -5514,7 +5513,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)
{
@@ -5616,9 +5615,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
{
@@ -5634,8 +5633,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
{
@@ -5827,7 +5826,7 @@ double TMoverParameters::TractionForce(double dt)
else if ((DynamicBrakeFlag) && ((Vadd + abs(Im)) < TUHEX_Sum - TUHEX_Diff))
{
Vadd += 70.0 * dt;
- Vadd = Min0R(Max0R(Vadd, TUHEX_MinIw), TUHEX_MaxIw);
+ Vadd = std::min(std::max(Vadd, TUHEX_MinIw), TUHEX_MaxIw);
}
if (Vadd > 0)
Mm = MomentumF(Im, Vadd, 0);
@@ -6014,7 +6013,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)));
}
}
@@ -6029,9 +6028,9 @@ double TMoverParameters::TractionForce(double dt)
// power curve drop
// NOTE: disabled for the time being due to side-effects
if( ( tmpV > 1 ) && ( EnginePower < tmp ) ) {
- Ft = interpolate(
+ Ft = std::lerp(
Ft, EnginePower / tmp,
- clamp( tmpV - 1.0, 0.0, 1.0 ) );
+ std::clamp( tmpV - 1.0, 0.0, 1.0 ) );
}
*/
}
@@ -6155,7 +6154,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 ) };
*/
@@ -6332,8 +6331,8 @@ double TMoverParameters::TractionForce(double dt)
// ustalanie współczynnika blendingu do luzowania hamulca PN
if (eimv[eimv_Fmax] * Sign(V) * DirAbsolute < -1)
{
- PosRatio = -Sign(V) * DirAbsolute * eimv[eimv_Fr] / (eimc[eimc_p_Fh] * Max0R(edBCP, Max0R(0.01, Hamulec->GetEDBCP())) / MaxBrakePress[0]);
- PosRatio = clamp(PosRatio, 0.0, 1.0);
+ PosRatio = -Sign(V) * DirAbsolute * eimv[eimv_Fr] / (eimc[eimc_p_Fh] * std::max(edBCP, std::max(0.01, Hamulec->GetEDBCP())) / MaxBrakePress[0]);
+ PosRatio = std::clamp(PosRatio, 0.0, 1.0);
}
else
{
@@ -6342,7 +6341,7 @@ double TMoverParameters::TractionForce(double dt)
PosRatio = Round(20.0 * PosRatio) / 20.0; // stopniowanie PN/ED
if (PosRatio < 19.5 / 20.0)
PosRatio *= 0.9;
- Hamulec->SetED(Max0R(0.0, std::min(PosRatio, 1.0))); // ustalenie stopnia zmniejszenia ciśnienia
+ Hamulec->SetED(std::max(0.0, std::min(PosRatio, 1.0))); // ustalenie stopnia zmniejszenia ciśnienia
// ustalanie siły hamowania ED
if ((Hamulec->GetEDBCP() > 0.25) && (eimc[eimc_p_abed] < 0.001) || (ActiveInverters < InvertersNo)) // jeśli PN wyłącza ED
{
@@ -6371,16 +6370,16 @@ double TMoverParameters::TractionForce(double dt)
}
else
{
- PosRatio = Max0R(eimic_real, 0);
+ PosRatio = std::max(eimic_real, 0.);
eimv[eimv_Fzad] = PosRatio;
if ((Flat) && (eimc[eimc_p_F0] * eimv[eimv_Fful] > 0))
- PosRatio = Min0R(PosRatio * eimc[eimc_p_F0] / eimv[eimv_Fful], 1);
+ PosRatio = std::min(PosRatio * eimc[eimc_p_F0] / eimv[eimv_Fful], 1.);
/* if (ScndCtrlActualPos > 0) //speed control
if (Vmax < 250)
- PosRatio = Min0R(PosRatio, Max0R(-1, 0.5 * (ScndCtrlActualPos - Vel)));
+ PosRatio = std::min(PosRatio, std::max(-1, 0.5 * (ScndCtrlActualPos - Vel)));
else
PosRatio =
- Min0R(PosRatio, Max0R(-1, 0.5 * (ScndCtrlActualPos * 2 - Vel))); */
+ std::min(PosRatio, std::max(-1, 0.5 * (ScndCtrlActualPos * 2 - Vel))); */
// PosRatio = 1.0 * (PosRatio * 0 + 1) * PosRatio; // 1 * 1 * PosRatio = PosRatio
Hamulec->SetED(0);
// (Hamulec as TLSt).SetLBP(LocBrakePress);
@@ -6409,7 +6408,7 @@ double TMoverParameters::TractionForce(double dt)
eimv_pr = 0;
}
- eimv_pr += Max0R(Min0R(PosRatio - eimv_pr, 0.02), -0.02) * 12 * (tmp /*2{+4*byte(PosRatio vh0 + 0.001)
{
- double const vhRamp = clamp((Vel - vh0) / (vh1 - vh0), 0.0, 1.0);
+ double const vhRamp = std::clamp((Vel - vh0) / (vh1 - vh0), 0.0, 1.0);
brakeDemand *= vhRamp;
}
}
@@ -7362,25 +7361,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)
@@ -7396,18 +7395,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;
@@ -7444,11 +7443,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;
@@ -7483,7 +7482,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;
}
@@ -7509,7 +7508,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)
@@ -7553,7 +7552,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)
{
@@ -7566,14 +7565,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);
@@ -7595,9 +7594,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))
{
@@ -8021,7 +8020,7 @@ double TMoverParameters::dizel_fillcheck(int mcp, double dt)
}
}
- return clamp(realfill, 0.0, 1.0);
+ return std::clamp(realfill, 0.0, 1.0);
}
// *************************************************************************************************
@@ -8080,7 +8079,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))
@@ -8095,7 +8094,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
{
@@ -8145,7 +8144,7 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt)
}
// sprawdzanie dociskow poszczegolnych sprzegiel
- if (abs(Moment) > Min0R(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) || (abs(dizel_n_old - enrot) > 0.1)) // slizga sie z powodu roznic predkosci albo przekroczenia momentu
+ if (abs(Moment) > std::min(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) || (abs(dizel_n_old - enrot) > 0.1)) // slizga sie z powodu roznic predkosci albo przekroczenia momentu
{
dizel_engagedeltaomega = enrot - dizel_n_old;
@@ -8183,9 +8182,9 @@ double TMoverParameters::dizel_Momentum(double dizel_fill, double n, double dt)
dizel_engagedeltaomega = 0;
gearMoment = Moment;
enMoment = 0;
- double enrot_min = enrot - (Min0R(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) - Moment) / dizel_AIM * dt;
- double enrot_max = enrot + (Min0R(TorqueC, TorqueL + abs(hydro_TC_TorqueIn)) + Moment) / dizel_AIM * dt;
- enrot = clamp(n, enrot_min, enrot_max);
+ 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 = std::clamp(n, enrot_min, enrot_max);
}
if ((hydro_R) && (hydro_R_Placement == 1))
gearMoment -= dizel_MomentumRetarder(hydro_TC_nOut, dt);
@@ -8281,9 +8280,9 @@ void TMoverParameters::dizel_Heat(double const dt)
auto const revolutionsfactor{EngineRPMRatio()};
auto const waterpump{WaterPump.is_active ? 1 : 0};
- auto const gw = engineon * interpolate(gwmin, gwmax, revolutionsfactor) + waterpump * 1000 + engineoff * 200;
- auto const gw2 = engineon * interpolate(gwmin2, gwmax2, revolutionsfactor) + waterpump * 1000 + engineoff * 200;
- auto const gwO = interpolate(gwmin, gwmax, revolutionsfactor);
+ auto const gw = engineon * std::lerp(gwmin, gwmax, revolutionsfactor) + waterpump * 1000 + engineoff * 200;
+ auto const gw2 = engineon * std::lerp(gwmin2, gwmax2, revolutionsfactor) + waterpump * 1000 + engineoff * 200;
+ auto const gwO = std::lerp(gwmin, gwmax, revolutionsfactor);
dizel_heat.water.is_cold = ((dizel_heat.water.config.temp_min > 0) && (dizel_heat.temperatura1 < dizel_heat.water.config.temp_min - (Mains ? 5 : 0)));
dizel_heat.water.is_hot = ((dizel_heat.water.config.temp_max > 0) && (dizel_heat.temperatura1 > dizel_heat.water.config.temp_max - (dizel_heat.water.is_hot ? 8 : 0)));
@@ -8478,7 +8477,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;
}
@@ -8527,7 +8526,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)
{
@@ -8565,7 +8564,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)};
@@ -9661,8 +9660,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
inputline = fizparser.getToken(false, "\n\r");
- bool comment = ((contains(inputline, '#')) || (starts_with(inputline, "//")));
- if (true == comment)
+ if (inputline.starts_with("//") || contains(inputline, '#'))
{
// skip commented lines
continue;
@@ -10239,7 +10237,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
modernDimmerPosition = modernDimmerDefaultPosition;
}
- WriteLog("CERROR: " + to_string(ConversionError) + ", SUCCES: " + to_string(result));
+ WriteLog("CERROR: " + std::to_string(ConversionError) + ", SUCCES: " + std::to_string(result));
return result;
}
@@ -10858,7 +10856,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, "");
@@ -10989,9 +10987,9 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
void TMoverParameters::LoadFIZ_Blending(std::string const &line)
{
- extract_value(MED_Vmax, "MED_Vmax", line, to_string(Vmax));
+ extract_value(MED_Vmax, "MED_Vmax", line, std::to_string(Vmax));
extract_value(MED_Vmin, "MED_Vmin", line, "0");
- extract_value(MED_Vref, "MED_Vref", line, to_string(Vmax));
+ extract_value(MED_Vref, "MED_Vref", line, std::to_string(Vmax));
extract_value(MED_amax, "MED_amax", line, "9.81");
extract_value(MED_EPVC, "MED_EPVC", line, "");
extract_value(MED_Ncor, "MED_Ncor", line, "");
@@ -11289,7 +11287,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input)
extract_value(eimc[eimc_f_DU], "DU", Input, "");
extract_value(eimc[eimc_f_I0], "I0", Input, "");
extract_value(eimc[eimc_f_cfu], "fcfu", Input, "");
- extract_value(eimc[eimc_f_cfuH], "fcfuH", Input, to_string(eimc[eimc_f_cfu]));
+ extract_value(eimc[eimc_f_cfuH], "fcfuH", Input, std::to_string(eimc[eimc_f_cfu]));
extract_value(eimc[eimc_p_F0], "F0", Input, "");
extract_value(eimc[eimc_p_a1], "a1", Input, "");
extract_value(eimc[eimc_p_Pmax], "Pmax", Input, "");
@@ -12087,7 +12085,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;
}
@@ -12491,7 +12489,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/friction.cpp b/McZapkie/friction.cpp
index 8899a5a5..f3eca234 100644
--- a/McZapkie/friction.cpp
+++ b/McZapkie/friction.cpp
@@ -29,7 +29,7 @@ double TP10Bg::GetFC(double N, double Vel)
// if Vel<20 then Vel:=20;
// Vel:= Vel-20;
// GetFC:=0.52*((1*Vel+100)/(5.0*Vel+100))*(13.08-0.083*N)/(12.94+0.285*N);
- // GetFC:=Min0R(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(13.08-0.083*N)/(12.94+0.285*N),0.4);
+ // GetFC:=std::min(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(13.08-0.083*N)/(12.94+0.285*N),0.4);
return exp(-0.022 * N) * (0.19 - 0.095 * exp(-Vel * 1.0 / 25.7)) +
0.384 * exp(-Vel * 1.0 / 25.7) - 0.028;
}
@@ -44,7 +44,7 @@ double TP10Bgu::GetFC(double N, double Vel)
// Vel:= Vel-20;
// GetFC:=0.52*((0.0*Vel+120)/(5*Vel+100))*(11.33-0.013*N)/(11.33+0.280*N);
// GetFC:=0.49*100/(3*Vel+100)*(11.33-0.013*N)/(11.33+0.280*N);
- // GetFC:=Min0R(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(11.33-0.013*N)/(11.33+0.280*N),0.4);
+ // GetFC:=std::min(0.67*(1*(277-2.66*Vel)/(100+2.1*Vel)+0.23*(-686+8.27*Vel)/(100+1.16*Vel))*(11.33-0.013*N)/(11.33+0.280*N),0.4);
return exp(-0.017 * N) * (0.18 - 0.09 * exp(-Vel * 1.0 / 25.7)) +
0.381 * exp(-Vel * 1.0 / 25.7) - 0.022; // 0.05*exp(-0.2*N);
}
diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp
index 6eb33eb7..a957dc79 100644
--- a/McZapkie/hamulce.cpp
+++ b/McZapkie/hamulce.cpp
@@ -45,7 +45,7 @@ double const TFVE408::pos_table[11] = {0, 10, 0, 0, 10, 7, 8, 9, 0, 1, 5};
/// Dimensionless flow driver (positive when P2 > P1).
double PR(double P1, double P2)
{
- double PH = Max0R(P1, P2) + 0.1;
+ double PH = std::max(P1, P2) + 0.1;
double PL = P1 + P2 - PH + 0.2;
return (P2 - P1) / (1.13 * PH - PL);
}
@@ -59,7 +59,7 @@ double PR(double P1, double P2)
/// Volumetric flow rate (signed).
double PF_old(double P1, double P2, double S)
{
- double PH = Max0R(P1, P2) + 1;
+ double PH = std::max(P1, P2) + 1;
double PL = P1 + P2 - PH + 2;
if (PH - PL < 0.0001)
return 0;
@@ -1229,19 +1229,19 @@ double TEStEP2::GetPF(double const PP, double const dt, double const Vel)
result = dv - dV1;
- temp = Max0R(BCP, LBP);
+ temp = std::max(BCP, LBP);
if ((ImplsRes->P() > LBP + 0.01))
LBP = 0;
// luzowanie CH
- if ((BrakeCyl->P() > temp + 0.005) || (Max0R(ImplsRes->P(), 8 * LBP) < 0.05))
+ if ((BrakeCyl->P() > temp + 0.005) || (std::max(ImplsRes->P(), 8 * LBP) < 0.05))
dv = PF(0, BrakeCyl->P(), 0.25 * SizeBC * (0.01 + (BrakeCyl->P() - temp))) * dt;
else
dv = 0;
BrakeCyl->Flow(-dv);
// przeplyw ZP <-> CH
- if ((BrakeCyl->P() < temp - 0.005) && (Max0R(ImplsRes->P(), 8 * LBP) > 0.10) && (Max0R(BCP, LBP) < MaxBP * LoadC))
+ if ((BrakeCyl->P() < temp - 0.005) && (std::max(ImplsRes->P(), 8 * LBP) > 0.10) && (std::max(BCP, LBP) < MaxBP * LoadC))
dv = PF(BVP, BrakeCyl->P(), 0.35 * SizeBC * (0.01 - (BrakeCyl->P() - temp))) * dt;
else
dv = 0;
@@ -1313,8 +1313,8 @@ void TEStEP2::EPCalc(double dt)
void TEStEP1::EPCalc(double dt)
{
double temp = EPS - std::floor(EPS); // część ułamkowa jest hamulcem EP
- double LBPLim = Min0R(MaxBP * LoadC * temp, BrakeRes->P()); // do czego dążymy
- double S = 10 * clamp(LBPLim - LBP, -0.1, 0.1); // przymykanie zaworku
+ double LBPLim = std::min(MaxBP * LoadC * temp, BrakeRes->P()); // do czego dążymy
+ 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;
}
@@ -1782,7 +1782,7 @@ double TLSt::GetPF(double const PP, double const dt, double const Vel)
if (((UniversalFlag & TUniversalBrake::ub_AntiSlipBrake) > 0) || ((BrakeStatus & b_asb_unbrake) == b_asb_unbrake))
tempasb = ASBP;
// powtarzacz — podwojny zawor zwrotny
- temp = Max0R(((CVP - BCP) * BVM + tempasb) / temp, LBP);
+ temp = std::max(((CVP - BCP) * BVM + tempasb) / temp, LBP);
// luzowanie CH
if ((BrakeCyl->P() > temp + 0.005) || (temp < 0.28))
// dV:=PF(0,BrakeCyl->P(),0.0015*3*sizeBC)*dt
@@ -1881,7 +1881,7 @@ double TLSt::GetHPFlow(double const HP, double const dt)
{
double dv;
- dv = Min0R(PF(HP, BrakeRes->P(), 0.01 * dt), 0);
+ dv = std::min(PF(HP, BrakeRes->P(), 0.01 * dt), 0.0);
BrakeRes->Flow(-dv);
return dv;
}
@@ -1994,12 +1994,12 @@ double TEStED::GetPF(double const PP, double const dt, double const Vel)
Miedzypoj->Flow(dv * dt * 0.15);
RapidTemp = RapidTemp + (RM * int((Vel > RV) && (BrakeDelayFlag == bdelay_R)) - RapidTemp) * dt / 2;
- temp = Max0R(1 - RapidTemp, 0.001);
+ temp = std::max(1 - RapidTemp, 0.001);
// if EDFlag then temp:=1000;
// temp:=temp/(1-);
// powtarzacz — podwojny zawor zwrotny
- temp = Max0R(LoadC * BCP / temp * Min0R(Max0R(1 - EDFlag, 0), 1), LBP);
+ temp = std::max(LoadC * BCP / temp * std::clamp(1 - EDFlag, 0., 1.), LBP);
if ((UniversalFlag & TUniversalBrake::ub_AntiSlipBrake) > 0)
temp = std::max(temp, ASBP);
@@ -2156,7 +2156,7 @@ void TCV1::CheckState(double const BCP, double &dV1)
double CVP;
BVP = BrakeRes->P();
- VVP = Min0R(ValveRes->P(), BVP + 0.05);
+ VVP = std::min(ValveRes->P(), BVP + 0.05);
CVP = CntrlRes->P();
// odluzniacz
@@ -2243,7 +2243,7 @@ double TCV1::GetPF(double const PP, double const dt, double const Vel)
double CVP;
BVP = BrakeRes->P();
- VVP = Min0R(ValveRes->P(), BVP + 0.05);
+ VVP = std::min(ValveRes->P(), BVP + 0.05);
BCP = BrakeCyl->P();
CVP = CntrlRes->P();
@@ -2360,7 +2360,7 @@ double TCV1L_TR::GetHPFlow(double const HP, double const dt)
double dv;
dv = PF(HP, BrakeRes->P(), 0.01) * dt;
- dv = Min0R(0, dv);
+ dv = std::min(0., dv);
BrakeRes->Flow(-dv);
return dv;
}
@@ -2402,7 +2402,7 @@ double TCV1L_TR::GetPF(double const PP, double const dt, double const Vel)
double CVP;
BVP = BrakeRes->P();
- VVP = Min0R(ValveRes->P(), BVP + 0.05);
+ VVP = std::min(ValveRes->P(), BVP + 0.05);
BCP = ImplsRes->P();
CVP = CntrlRes->P();
@@ -2447,17 +2447,17 @@ double TCV1L_TR::GetPF(double const PP, double const dt, double const Vel)
dv = PF(PP, VVP, 0.01) * dt;
result = dv - dV1;
- temp = Max0R(BCP, LBP);
+ temp = std::max(BCP, LBP);
// luzowanie CH
- if ((BrakeCyl->P() > temp + 0.005) || (Max0R(ImplsRes->P(), 8 * LBP) < 0.25))
+ if ((BrakeCyl->P() > temp + 0.005) || (std::max(ImplsRes->P(), 8 * LBP) < 0.25))
dv = PF(0, BrakeCyl->P(), 0.015 * SizeBC) * dt;
else
dv = 0;
BrakeCyl->Flow(-dv);
// przeplyw ZP <-> CH
- if ((BrakeCyl->P() < temp - 0.005) && (Max0R(ImplsRes->P(), 8 * LBP) > 0.3) && (Max0R(BCP, LBP) < MaxBP))
+ if ((BrakeCyl->P() < temp - 0.005) && (std::max(ImplsRes->P(), 8 * LBP) > 0.3) && (std::max(BCP, LBP) < MaxBP))
dv = PF(BVP, BrakeCyl->P(), 0.020 * SizeBC) * dt;
else
dv = 0;
@@ -2710,17 +2710,17 @@ double TKE::GetPF(double const PP, double const dt, double const Vel)
temp = 1;
temp = temp / LoadC;
// luzowanie CH
- // temp:=Max0R(BCP,LBP);
- IMP = Max0R(IMP / temp, Max0R(LBP, ASBP * int((BrakeStatus & b_asb) == b_asb)));
+ // temp:=std::max(BCP,LBP);
+ IMP = std::max(IMP / temp, std::max(LBP, ASBP * int((BrakeStatus & b_asb) == b_asb)));
if ((ASBP < 0.1) && ((BrakeStatus & b_asb) == b_asb))
IMP = 0;
// luzowanie CH
- if ((BCP > IMP + 0.005) || (Max0R(ImplsRes->P(), 8 * LBP) < 0.25))
+ if ((BCP > IMP + 0.005) || (std::max(ImplsRes->P(), 8 * LBP) < 0.25))
dv = PFVd(BCP, 0, 0.05, IMP) * dt;
else
dv = 0;
BrakeCyl->Flow(-dv);
- if ((BCP < IMP - 0.005) && (Max0R(ImplsRes->P(), 8 * LBP) > 0.3))
+ if ((BCP < IMP - 0.005) && (std::max(ImplsRes->P(), 8 * LBP) > 0.3))
dv = PFVa(BVP, BCP, 0.05, IMP) * dt;
else
dv = 0;
@@ -2797,7 +2797,7 @@ double TKE::GetHPFlow(double const HP, double const dt)
double dv;
dv = PF(HP, BrakeRes->P(), 0.01) * dt;
- dv = Min0R(0, dv);
+ dv = std::min(0., dv);
BrakeRes->Flow(-dv);
return dv;
}
@@ -2975,7 +2975,7 @@ double TFV4a::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
// if(cp+0.03<5.4)then
if ((RP + 0.03 < 5.4) || (CP + 0.03 < 5.4)) // fala
dpMainValve = PF(std::min(HP, 17.1), PP, ActFlowSpeed / LBDelay) * dt;
- // dpMainValve:=20*Min0R(abs(ep-7.1),0.05)*PF(HP,pp,ActFlowSpeed/LBDelay)*dt;
+ // dpMainValve:=20*std::min(abs(ep-7.1),0.05)*PF(HP,pp,ActFlowSpeed/LBDelay)*dt;
else
{
RP = 5.45;
@@ -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)
@@ -3286,7 +3286,7 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep
DP = 0;
- i_bcp = Max0R(Min0R(i_bcp, 9.999), -0.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
+ i_bcp = std::clamp(i_bcp, -0.999, 9.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
if ((TP > 0) && (CP > 4.9))
{
@@ -3300,7 +3300,7 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep
TP = 0;
}
- LimPP = Min0R(LPP_RP(i_bcp) + TP * 0.08 + RedAdj, HP); // pozycja + czasowy lub zasilanie
+ LimPP = std::min(LPP_RP(i_bcp) + TP * 0.08 + RedAdj, HP); // pozycja + czasowy lub zasilanie
ActFlowSpeed = 4;
double uop = UnbrakeOverPressure; // unbrake over pressure in actual state
@@ -3309,20 +3309,20 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep
uop = 0;
if ((EQ(i_bcp, -1)) && (uop > 0))
- pom = Min0R(HP, 5.4 + RedAdj + uop);
+ pom = std::min(HP, 5.4 + RedAdj + uop);
else
- pom = Min0R(CP, HP);
+ pom = std::min(CP, HP);
if ((LimPP > CP)) // podwyzszanie szybkie
- CP = CP + 60 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy;
+ CP = CP + 60 * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy;
else
- CP = CP + 13 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
+ CP = CP + 13 * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
LimPP = pom; // cp
// if (EQ(i_bcp, -1))
// dpPipe = HP;
// else
- dpPipe = Min0R(HP, LimPP);
+ dpPipe = std::min(HP, LimPP);
if (dpPipe > PP)
dpMainValve = -PFVa(HP, PP, ActFlowSpeed / LBDelay, dpPipe, 0.4);
@@ -3355,9 +3355,9 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep
}
if ((i_bcp < 1.5))
- RP = Max0R(0, 0.125 * i_bcp);
+ RP = std::max(0., 0.125 * i_bcp);
else
- RP = Min0R(1, 0.125 * i_bcp - 0.125);
+ RP = std::min(1., 0.125 * i_bcp - 0.125);
return dpMainValve * dt;
}
@@ -3413,7 +3413,7 @@ double TMHZ_EN57::GetRP()
double TMHZ_EN57::GetEP(double pos)
{
if (pos < 9.5)
- return Min0R(Max0R(0, 0.125 * pos), 1);
+ return std::clamp(0.125 * pos, 0., 1.);
else
return 0;
}
@@ -3493,7 +3493,7 @@ double TMHZ_K5P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
DP = 0;
- i_bcp = Max0R(Min0R(i_bcp, 2.999), -0.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
+ i_bcp = std::clamp(i_bcp, -0.999, 2.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
if ((TP > 0) && (CP > 4.9))
{
@@ -3513,20 +3513,20 @@ double TMHZ_K5P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
else // luzowanie
LimCP = 5.0;
pom = CP;
- LimCP = Min0R(LimCP, HP); // pozycja + czasowy lub zasilanie
+ LimCP = std::min(LimCP, HP); // pozycja + czasowy lub zasilanie
ActFlowSpeed = 4;
if ((LimCP > CP)) // podwyzszanie szybkie
- CP = CP + 9 * Min0R(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy;
+ CP = CP + 9 * std::min(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy;
else
- CP = CP + 9 * Min0R(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy
+ CP = CP + 9 * std::min(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy
double uop = UnbrakeOverPressure; // unbrake over pressure in actual state
ManualOvrldActive = (UniversalFlag & TUniversalBrake::ub_HighPressure); // button is pressed
if (ManualOvrld && !ManualOvrldActive) // no overpressure for not pressed button if it does not exists
uop = 0;
- dpPipe = Min0R(HP, CP + TP + RedAdj);
+ dpPipe = std::min(HP, CP + TP + RedAdj);
if (EQ(i_bcp, -1))
{
@@ -3676,7 +3676,7 @@ double TMHZ_6P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
DP = 0;
- i_bcp = Max0R(Min0R(i_bcp, 3.999), -0.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
+ i_bcp = std::clamp(i_bcp, -0.999, 3.999); // na wszelki wypadek, zeby nie wyszlo poza zakres
if ((TP > 0) && (CP > 4.9))
{
@@ -3696,15 +3696,15 @@ double TMHZ_6P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
else // luzowanie
LimCP = 5.0;
pom = CP;
- LimCP = Min0R(LimCP, HP); // pozycja + czasowy lub zasilanie
+ LimCP = std::min(LimCP, HP); // pozycja + czasowy lub zasilanie
ActFlowSpeed = 4;
if ((LimCP > CP)) // podwyzszanie szybkie
- CP = CP + 9 * Min0R(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy;
+ CP = CP + 9 * std::min(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy;
else
- CP = CP + 9 * Min0R(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy
+ CP = CP + 9 * std::min(abs(LimCP - CP), 0.05) * PR(CP, LimCP) * dt; // zbiornik sterujacy
- dpPipe = Min0R(HP, CP + TP + RedAdj);
+ dpPipe = std::min(HP, CP + TP + RedAdj);
double uop = UnbrakeOverPressure; // unbrake over pressure in actual state
ManualOvrldActive = (UniversalFlag & TUniversalBrake::ub_HighPressure); // button is pressed
@@ -3856,7 +3856,7 @@ double TM394::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
if (BCP < -1)
BCP = 1;
- LimPP = Min0R(BPT_394[BCP + 1][1], HP);
+ LimPP = std::min(BPT_394[BCP + 1][1], HP);
ActFlowSpeed = BPT_394[BCP + 1][0];
if ((BCP == 1) || (BCP == i_bcpno))
LimPP = PP;
@@ -3864,16 +3864,16 @@ double TM394::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
LimPP = LimPP + RedAdj;
if ((BCP != 2))
if (CP < LimPP)
- CP = CP + 4 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
- // cp:=cp+6*(2+int(bcp<0))*Min0R(abs(Limpp-cp),0.05)*PR(cp,Limpp)*dt //zbiornik
+ CP = CP + 4 * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
+ // cp:=cp+6*(2+int(bcp<0))*std::min(abs(Limpp-cp),0.05)*PR(cp,Limpp)*dt //zbiornik
// sterujacy;
else if (BCP == 0)
CP = CP - 0.2 * dt / 100;
else
- CP = CP + 4 * (1 + int(BCP != 3) + int(BCP > 4)) * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
+ CP = CP + 4 * (1 + int(BCP != 3) + int(BCP > 4)) * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
LimPP = CP;
- dpPipe = Min0R(HP, LimPP);
+ dpPipe = std::min(HP, LimPP);
// if(dpPipe>pp)then //napelnianie
// dpMainValve:=PF(dpPipe,pp,ActFlowSpeed/LBDelay)*dt
@@ -4060,7 +4060,7 @@ double TSt113::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
LimPP = CP;
ActFlowSpeed = BPT_K[BCP + 1][0];
- CP = CP + 6 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
+ CP = CP + 6 * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt; // zbiornik sterujacy
dpMainValve = 0;
@@ -4140,10 +4140,10 @@ double Ttest::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
if ((i_bcp == -1))
LimPP = 7;
- CP = CP + 20 * Min0R(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt / 1;
+ CP = CP + 20 * std::min(abs(LimPP - CP), 0.05) * PR(CP, LimPP) * dt / 1;
LimPP = CP;
- dpPipe = Min0R(HP, LimPP);
+ dpPipe = std::min(HP, LimPP);
dpMainValve = PF(dpPipe, PP, ActFlowSpeed / LBDelay) * dt;
@@ -4181,7 +4181,7 @@ double TFD1::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double temp;
// MaxBP:=4;
- // temp:=Min0R(i_bcp*MaxBP,Min0R(5.0,HP));
+ // temp:=std::min(i_bcp*MaxBP,std::min(5.0,HP));
temp = std::min(i_bcp * MaxBP, HP); // 0011
DP = 10.0 * std::min(std::abs(temp - BP), 0.1) * PF(temp, BP, 0.0006 * (temp > BP ? 3.0 : 2.0)) * dt * Speed;
BP = BP - DP;
@@ -4229,18 +4229,18 @@ double TH1405::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double temp;
double A;
- PP = Min0R(PP, MaxBP);
+ PP = std::min(PP, MaxBP);
if (i_bcp > 0.5)
{
- temp = Min0R(MaxBP, HP);
+ temp = std::min(MaxBP, HP);
A = 2 * (i_bcp - 0.5) * 0.0011;
- BP = Max0R(BP, PP);
+ BP = std::max(BP, PP);
}
else
{
temp = 0;
A = 0.2 * (0.5 - i_bcp) * 0.0033;
- BP = Min0R(BP, PP);
+ BP = std::min(BP, PP);
}
DP = PF(temp, BP, A) * dt;
BP = BP - DP;
@@ -4285,7 +4285,7 @@ double TFVel6::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
CP = PP;
- LimPP = Min0R(5 * int(i_bcp < 3.5), HP);
+ LimPP = std::min(5. * int(i_bcp < 3.5), HP);
if ((i_bcp >= 3.5) && ((i_bcp < 4.3) || (i_bcp > 5.5)))
ActFlowSpeed = 0;
else if ((i_bcp > 4.3) && (i_bcp < 4.8))
@@ -4382,7 +4382,7 @@ double TFVE408::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
CP = PP;
- LimPP = Min0R(5 * int(i_bcp < 6.5), HP);
+ LimPP = std::min(5. * int(i_bcp < 6.5), HP);
if ((i_bcp >= 6.5) && ((i_bcp < 7.5) || (i_bcp > 9.5)))
ActFlowSpeed = 0;
else if ((i_bcp > 7.5) && (i_bcp < 8.5))
diff --git a/application/driverhints.cpp b/application/driverhints.cpp
index 792b2bd2..fd1e6e05 100644
--- a/application/driverhints.cpp
+++ b/application/driverhints.cpp
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "vehicle/Driver.h"
#include "utilities/Globals.h"
+#include "utilities/utilities.h"
void
TController::hint( driver_hint const Value, hintpredicate const Predicate, float const Predicateparameter ) {
diff --git a/application/drivermode.cpp b/application/drivermode.cpp
index 1aec7a7a..9efb88ea 100644
--- a/application/drivermode.cpp
+++ b/application/drivermode.cpp
@@ -28,7 +28,6 @@ http://mozilla.org/MPL/2.0/.
#include "input/messaging.h"
#include "utilities/Timer.h"
#include "rendering/renderer.h"
-#include "utilities/utilities.h"
#include "utilities/Logs.h"
/*
namespace input {
@@ -929,8 +928,8 @@ void driver_mode::OnKeyDown(int cKey)
Global.FreeCameraInitAngle[i] = Camera.Angle;
// logowanie, żeby można było do scenerii przepisać
WriteLog("camera " + std::to_string(Global.FreeCameraInit[i].x) + " " + std::to_string(Global.FreeCameraInit[i].y) + " " + std::to_string(Global.FreeCameraInit[i].z) + " " +
- std::to_string(RadToDeg(Global.FreeCameraInitAngle[i].x)) + " " + std::to_string(RadToDeg(Global.FreeCameraInitAngle[i].y)) + " " +
- std::to_string(RadToDeg(Global.FreeCameraInitAngle[i].z)) + " " + std::to_string(i) + " endcamera");
+ std::to_string(glm::degrees(Global.FreeCameraInitAngle[i].x)) + " " + std::to_string(glm::degrees(Global.FreeCameraInitAngle[i].y)) + " " +
+ std::to_string(glm::degrees(Global.FreeCameraInitAngle[i].z)) + " " + std::to_string(i) + " endcamera");
}
else // również przeskakiwanie
{ // Ra: to z tą kamerą (Camera.Pos i Global.pCameraPosition) jest trochę bez sensu
diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp
index 05e20b84..10c25861 100644
--- a/application/driveruipanels.cpp
+++ b/application/driveruipanels.cpp
@@ -27,7 +27,6 @@ http://mozilla.org/MPL/2.0/.
#include "vehicle/DynObj.h"
#include "model/Model3d.h"
#include "rendering/renderer.h"
-#include "utilities/utilities.h"
#include "utilities/Logs.h"
#include "widgets/vehicleparams.h"
@@ -422,11 +421,11 @@ timetable_panel::update() {
.substr( 0, 34 - tableline->StationWare.size() ) };
auto const arrival { (
tableline->Ah >= 0 ?
- to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Am, true, 3 ) :
+ std::to_string( int( 100 + tableline->Ah ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Am, true, 3 ) :
" │ " ) };
auto const departure { (
tableline->Dh >= 0 ?
- to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Dm, true, 3 ) :
+ std::to_string( int( 100 + tableline->Dh ) ).substr( 1, 2 ) + ":" + to_minutes_str( tableline->Dm, true, 3 ) :
" │ " ) };
auto const candepart { (
( table.StationStart < table.StationIndex )
@@ -663,7 +662,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 +676,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 +689,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 +700,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 );
}
@@ -722,15 +721,15 @@ debug_panel::render_section_scenario() {
ImGui::PopStyleColor();
auto time = simulation::Time.data().wHour * 60 + simulation::Time.data().wMinute;
auto const timestring {
- std::string( to_string( int( 100 + simulation::Time.data().wHour ) ).substr( 1, 2 )
+ std::string( std::to_string( int( 100 + simulation::Time.data().wHour ) ).substr( 1, 2 )
+ ":"
- + std::string( to_string( int( 100 + simulation::Time.data().wMinute ) ).substr( 1, 2 ) ) ) };
+ + std::string( std::to_string( int( 100 + simulation::Time.data().wMinute ) ).substr( 1, 2 ) ) ) };
if( ImGui::SliderInt( ( timestring + " (" + Global.Period + ")###simulationtime" ).c_str(), &time, 0, 1439, "Time of day" ) ) {
command_relay relay;
relay.post(
user_command::setdatetime,
Global.fMoveLight,
- clamp( time, 0, 1439 ),
+ std::clamp( time, 0, 1439 ),
GLFW_PRESS, 0 );
}
}
@@ -747,7 +746,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);
}
}
}
@@ -1211,8 +1210,8 @@ debug_panel::update_section_ai( std::vector &Output ) {
+ ", corrected: " + to_string( mechanik.AccDesired * mechanik.BrakeAccFactor(), 2 )
+ "\n current: " + to_string( mechanik.AbsAccS + 0.001f, 2 )
+ ", slope: " + to_string( mechanik.fAccGravity + 0.001f, 2 ) + " (" + ( mechanik.fAccGravity > 0.01 ? "\\" : ( mechanik.fAccGravity < -0.01 ? "/" : "-" ) ) + ")"
- + "\n desired diesel percentage: " + to_string(mechanik.DizelPercentage)
- + "/" + to_string(mechanik.DizelPercentage_Speed)
+ + "\n desired diesel percentage: " + std::to_string(mechanik.DizelPercentage)
+ + "/" + std::to_string(mechanik.DizelPercentage_Speed)
+ "/" + to_string(100.4*mechanik.mvControlling->eimic_real, 0);
Output.emplace_back( textline, Global.UITextColor );
@@ -1223,7 +1222,7 @@ debug_panel::update_section_ai( std::vector &Output ) {
+ "\n activation threshold: " + to_string( mechanik.fAccThreshold, 2 )
+ ", delays: " + to_string( mechanik.fBrake_a0[ 0 ], 2 ) + " + " + to_string( mechanik.fBrake_a1[ 0 ], 2 )
+ "\n virtual brake position: " + to_string( mechanik.BrakeCtrlPosition, 2 )
- + "\n test stage: " + to_string( mechanik.DynamicBrakeTest )
+ + "\n test stage: " + std::to_string( mechanik.DynamicBrakeTest )
+ ", applied at: " + to_string( mechanik.DBT_VelocityBrake, 0 )
+ ", release at: " + to_string( mechanik.DBT_VelocityRelease, 0 )
+ ", done at: " + to_string( mechanik.DBT_VelocityFinish, 0 );
@@ -1256,7 +1255,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; }
@@ -1394,7 +1393,7 @@ debug_panel::update_section_powergrid( std::vector &Output ) {
+ " " + to_string( powerstation->FuseTimer, 1, 8 )
+ ( powerstation->FuseCounter == 0 ?
"" :
- " (x" + to_string( powerstation->FuseCounter ) + ")" );
+ " (x" + std::to_string( powerstation->FuseCounter ) + ")" );
Output.emplace_back(
textline,
@@ -1446,7 +1445,7 @@ debug_panel::update_section_renderer( std::vector &Output ) {
+ ", FPS: " + std::to_string( static_cast(std::round(GfxRenderer->Framerate())) )
+ ( Global.VSync ? " (vsync on)" : "" );
if( Global.iSlowMotion ) {
- textline += " (slowmotion " + to_string( Global.iSlowMotion ) + ")";
+ textline += " (slowmotion " + std::to_string( Global.iSlowMotion ) + ")";
}
Output.emplace_back( textline, Global.UITextColor );
@@ -1549,8 +1548,8 @@ debug_panel::render_section_settings() {
ImGui::TextUnformatted( "Graphics" );
ImGui::PopStyleColor();
// reflection fidelity
- ImGui::SliderInt( ( to_string( Global.reflectiontune.fidelity ) + "###reflectionfidelity" ).c_str(), &Global.reflectiontune.fidelity, 0, 2, "Reflection fidelity" );
- ImGui::SliderInt( ( to_string( Global.gfx_shadow_rank_cutoff ) + "###shadowrankcutoff" ).c_str(), &Global.gfx_shadow_rank_cutoff, 1, 3, "Shadow ranks" );
+ ImGui::SliderInt( ( std::to_string( Global.reflectiontune.fidelity ) + "###reflectionfidelity" ).c_str(), &Global.reflectiontune.fidelity, 0, 2, "Reflection fidelity" );
+ ImGui::SliderInt( ( std::to_string( Global.gfx_shadow_rank_cutoff ) + "###shadowrankcutoff" ).c_str(), &Global.gfx_shadow_rank_cutoff, 1, 3, "Shadow ranks" );
if( ImGui::SliderFloat( ( to_string( std::abs( Global.gfx_shadow_angle_min ), 2 ) + "###shadowanglecutoff" ).c_str(), &Global.gfx_shadow_angle_min, -1.0, -0.2, "Shadow angle cutoff" ) ) {
Global.gfx_shadow_angle_min = quantize( Global.gfx_shadow_angle_min, 0.05f );
};
@@ -1570,19 +1569,19 @@ debug_panel::render_section_settings() {
ImGui::TextUnformatted( "Sound" );
ImGui::PopStyleColor();
// audio volume sliders
- ImGui::SliderFloat( ( to_string( static_cast( Global.AudioVolume * 100 ) ) + "%###volumemain" ).c_str(), &Global.AudioVolume, 0.0f, 2.0f, "Main audio volume" );
- if( ImGui::SliderFloat( ( to_string( static_cast( Global.VehicleVolume * 100 ) ) + "%###volumevehicle" ).c_str(), &Global.VehicleVolume, 0.0f, 1.0f, "Vehicle sounds" ) ) {
+ ImGui::SliderFloat( ( std::to_string( static_cast( Global.AudioVolume * 100 ) ) + "%###volumemain" ).c_str(), &Global.AudioVolume, 0.0f, 2.0f, "Main audio volume" );
+ if( ImGui::SliderFloat( ( std::to_string( static_cast( Global.VehicleVolume * 100 ) ) + "%###volumevehicle" ).c_str(), &Global.VehicleVolume, 0.0f, 1.0f, "Vehicle sounds" ) ) {
audio::event_volume_change = true;
}
- if( ImGui::SliderFloat( ( to_string( static_cast( Global.EnvironmentPositionalVolume * 100 ) ) + "%###volumepositional" ).c_str(), &Global.EnvironmentPositionalVolume, 0.0f, 1.0f, "Positional sounds" ) ) {
+ if( ImGui::SliderFloat( ( std::to_string( static_cast( Global.EnvironmentPositionalVolume * 100 ) ) + "%###volumepositional" ).c_str(), &Global.EnvironmentPositionalVolume, 0.0f, 1.0f, "Positional sounds" ) ) {
audio::event_volume_change = true;
}
- if( ImGui::SliderFloat( ( to_string( static_cast( Global.EnvironmentAmbientVolume * 100 ) ) + "%###volumeambient" ).c_str(), &Global.EnvironmentAmbientVolume, 0.0f, 1.0f, "Ambient sounds" ) ) {
+ if( ImGui::SliderFloat( ( std::to_string( static_cast( Global.EnvironmentAmbientVolume * 100 ) ) + "%###volumeambient" ).c_str(), &Global.EnvironmentAmbientVolume, 0.0f, 1.0f, "Ambient sounds" ) ) {
audio::event_volume_change = true;
}
if (simulation::Train) {
float val = simulation::Train->get_radiovolume();
- if( ImGui::SliderFloat( ( to_string( static_cast( val * 100 ) ) + "%###volumeradio" ).c_str(), &val, 0.0f, 1.0f, "Vehicle radio volume" ) ) {
+ if( ImGui::SliderFloat( ( std::to_string( static_cast( val * 100 ) ) + "%###volumeradio" ).c_str(), &val, 0.0f, 1.0f, "Vehicle radio volume" ) ) {
command_relay relay;
relay.post(user_command::radiovolumeset, val, 0.0, GLFW_PRESS, 0);
}
@@ -1600,7 +1599,9 @@ transcripts_panel::update() {
for( auto const &transcript : ui::Transcripts.aLines ) {
if( Global.fTimeAngleDeg + ( transcript.fShow - Global.fTimeAngleDeg > 180 ? 360 : 0 ) < transcript.fShow ) { continue; }
- text_lines.emplace_back( ExchangeCharInString( transcript.asText, '|', ' ' ), colors::white );
+ std::string text = transcript.asText;
+ std::ranges::replace(text, '|', ' ');
+ text_lines.emplace_back( text, colors::white );
}
}
diff --git a/application/editoruilayer.cpp b/application/editoruilayer.cpp
index 0a225fe3..d87dd8fa 100644
--- a/application/editoruilayer.cpp
+++ b/application/editoruilayer.cpp
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include "application/editoruilayer.h"
#include "utilities/Globals.h"
+#include "utilities/utilities.h"
#include "scene/scenenode.h"
#include "rendering/renderer.h"
diff --git a/application/editoruipanels.cpp b/application/editoruipanels.cpp
index 966f14fb..25028a8d 100644
--- a/application/editoruipanels.cpp
+++ b/application/editoruipanels.cpp
@@ -19,7 +19,6 @@ http://mozilla.org/MPL/2.0/.
#include "world/MemCell.h"
#include "application/editoruilayer.h"
#include "rendering/renderer.h"
-#include "utilities/utilities.h"
void itemproperties_panel::update(scene::basic_node const *Node)
{
@@ -81,7 +80,7 @@ void itemproperties_panel::update(scene::basic_node const *Node)
textline += '[';
for (int lightidx = 0; lightidx < subnode->iNumLights; ++lightidx)
{
- textline += to_string(subnode->lsLights[lightidx]);
+ textline += std::to_string(subnode->lsLights[lightidx]);
if (lightidx < subnode->iNumLights - 1)
{
textline += ", ";
@@ -126,8 +125,8 @@ void itemproperties_panel::update(scene::basic_node const *Node)
}
// basic attributes
- textline = "isolated: " + (!isolatedlist.empty() ? isolatedlist : "(none)") + "\nvelocity: " + to_string(subnode->SwitchExtension ? subnode->SwitchExtension->fVelocity : subnode->fVelocity) +
- "\nwidth: " + to_string(subnode->fTrackWidth) + " m" + "\nfriction: " + to_string(subnode->fFriction, 2) + "\nquality: " + to_string(subnode->iQualityFlag);
+ textline = "isolated: " + (!isolatedlist.empty() ? isolatedlist : "(none)") + "\nvelocity: " + std::to_string(subnode->SwitchExtension ? subnode->SwitchExtension->fVelocity : subnode->fVelocity) +
+ "\nwidth: " + std::to_string(subnode->fTrackWidth) + " m" + "\nfriction: " + to_string(subnode->fFriction, 2) + "\nquality: " + std::to_string(subnode->iQualityFlag);
text_lines.emplace_back(textline, Global.UITextColor);
// textures
auto texturefile{((subnode->m_material1 != null_handle) ? GfxRenderer->Material(subnode->m_material1)->GetName() : "(none)")};
@@ -237,7 +236,7 @@ void itemproperties_panel::update_group()
for (auto const &name : names)
{
// NOTE: first calculation runs over two instances of the same name, but, eh
- auto const prefixlength{len_common_prefix(m_groupprefix, name)};
+ auto const prefixlength{len_common_prefix(m_groupprefix, name.get())};
if (prefixlength > 0)
{
m_groupprefix = m_groupprefix.substr(0, prefixlength);
@@ -257,7 +256,7 @@ void itemproperties_panel::update_group()
m_grouphandle = grouphandle;
}
- m_grouplines.emplace_back("nodes: " + to_string(static_cast(nodegroup.nodes.size())) + "\nevents: " + to_string(static_cast(nodegroup.events.size())), Global.UITextColor);
+ m_grouplines.emplace_back("nodes: " + std::to_string(nodegroup.nodes.size()) + "\nevents: " + std::to_string(nodegroup.events.size()), Global.UITextColor);
m_grouplines.emplace_back("names prefix: " + (m_groupprefix.empty() ? "(none)" : m_groupprefix), Global.UITextColor);
}
diff --git a/application/scenarioloaderuilayer.cpp b/application/scenarioloaderuilayer.cpp
index 7ec9b0aa..7b53e543 100644
--- a/application/scenarioloaderuilayer.cpp
+++ b/application/scenarioloaderuilayer.cpp
@@ -88,7 +88,7 @@ std::vector scenarioloader_ui::get_random_trivia()
json triviaData = json::parse(fileContent);
// select random
- int i = RandomInt(0, static_cast(triviaData.size()) - 1);
+ int i = Random(0, static_cast(triviaData.size()) - 1);
std::string triviaStr = triviaData[i]["text"];
std::string background = triviaData[i]["background"];
if (triviaData[i].contains("scenery"))
@@ -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/application/uitranscripts.cpp b/application/uitranscripts.cpp
index 6de03d34..96c9f735 100644
--- a/application/uitranscripts.cpp
+++ b/application/uitranscripts.cpp
@@ -20,7 +20,8 @@ TTranscripts::AddLine( std::string const &txt, float show, float hide, bool it )
hide = Global.fTimeAngleDeg + hide / 240.0;
TTranscript transcript;
- transcript.asText = ExchangeCharInString( txt, '|', ' ' ); // NOTE: legacy transcript lines use | as new line mark
+ transcript.asText = txt;
+ std::ranges::replace(transcript.asText, '|', ' '); // NOTE: legacy transcript lines use | as new line mark
transcript.fShow = show;
transcript.fHide = hide;
transcript.bItalic = it;
diff --git a/audio/audiorenderer.cpp b/audio/audiorenderer.cpp
index 88fd74e8..20f7a64c 100644
--- a/audio/audiorenderer.cpp
+++ b/audio/audiorenderer.cpp
@@ -14,7 +14,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "vehicle/Camera.h"
#include "utilities/Logs.h"
-#include "utilities/utilities.h"
#include "simulation/simulation.h"
#include "vehicle/Train.h"
@@ -191,9 +190,8 @@ openal_source::sync_with( sound_properties const &State ) {
// adjust the volume to a suitable fraction of nominal value
auto const fadedistance { sound_range * 0.75f };
auto const rangefactor {
- interpolate(
- 1.f, 0.f,
- clamp(
+ std::lerp(
+ 1.f, 0.f, std::clamp(
( distancesquared - rangesquared ) / ( fadedistance * fadedistance ),
0.f, 1.f ) ) };
::alSourcef( id, AL_GAIN, gain * rangefactor );
@@ -203,7 +201,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 fafcd53b..59130232 100644
--- a/audio/sound.cpp
+++ b/audio/sound.cpp
@@ -185,12 +185,12 @@ 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;
}
- else if( starts_with( key, "sound" ) ) {
+ else if( key.starts_with("sound") ) {
// sound chunks, defined with key soundX where X = activation threshold
auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };
@@ -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,11 +217,11 @@ 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 );
}
- else if( starts_with( key, "pitch" ) ) {
+ else if ( key.starts_with("pitch") ) {
// sound chunk pitch, defined with key pitchX where X = activation threshold
auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };
@@ -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;
}
@@ -781,10 +781,10 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
// based on how far the current soundpoint is in the range of previous chunk
auto const &previouschunkdata{ m_soundchunks[ chunkindex - 1 ].second };
m_properties.pitch =
- interpolate(
+ std::lerp(
previouschunkdata.pitch / chunkdata.pitch,
1.f,
- clamp(
+ std::clamp(
( soundpoint - previouschunkdata.threshold ) / ( chunkdata.threshold - previouschunkdata.threshold ),
0.f, 1.f ) );
}
@@ -796,10 +796,10 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
// based on how far the current soundpoint is in the range of this chunk
auto const &nextchunkdata { m_soundchunks[ chunkindex + 1 ].second };
m_properties.pitch =
- interpolate(
+ std::lerp(
1.f,
nextchunkdata.pitch / chunkdata.pitch,
- clamp(
+ std::clamp(
( soundpoint - chunkdata.threshold ) / ( nextchunkdata.threshold - chunkdata.threshold ),
0.f, 1.f ) );
}
@@ -816,9 +816,9 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
auto const fadeinwidth { chunkdata.threshold - chunkdata.fadein };
if( soundpoint < chunkdata.threshold ) {
float lineargain =
- interpolate(
+ std::lerp(
0.f, 1.f,
- clamp(
+ std::clamp(
( soundpoint - chunkdata.fadein ) / fadeinwidth,
0.f, 1.f ) );
m_properties.gain *=
@@ -836,9 +836,9 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
auto const fadeoutstart { chunkdata.fadeout - fadeoutwidth };
if( soundpoint > fadeoutstart ) {
float lineargain =
- interpolate(
+ std::lerp(
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/betterRenderer/renderer/source/nvtexture.cpp b/betterRenderer/renderer/source/nvtexture.cpp
index adc3ff1d..16cc1923 100644
--- a/betterRenderer/renderer/source/nvtexture.cpp
+++ b/betterRenderer/renderer/source/nvtexture.cpp
@@ -305,7 +305,7 @@ size_t NvTextureManager::FetchTexture(std::string path, int format_hint,
path = ToLower(path);
// temporary code for legacy assets -- textures with names beginning with #
// are to be sharpened
- if ((starts_with(path, "#")) || (contains(path, "/#"))) {
+ if (path.starts_with("#") || contains(path, "/#")) {
traits += '#';
}
}
@@ -415,7 +415,7 @@ bool NvTexture::CreateRhiTexture() {
backend->GetDevice()->executeCommandList(command_list,
nvrhi::CommandQueue::Graphics);
if (m_sz_texture->get_type() == "make:") {
- auto const components{Split(std::string(m_sz_texture->get_name()), '?')};
+ auto const components{Split(m_sz_texture->get_name(), '?')};
auto dictionary = std::make_shared(components.back());
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..3729214e 100644
--- a/environment/skydome.cpp
+++ b/environment/skydome.cpp
@@ -2,7 +2,6 @@
#include "stdafx.h"
#include "environment/skydome.h"
#include "utilities/color.h"
-#include "utilities/utilities.h"
#include "simulation/simulationenvironment.h"
#include "utilities/Globals.h"
@@ -134,18 +133,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,8 +184,8 @@ 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;
- auto gammacorrection = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
+ float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
+ auto gammacorrection = glm::mix( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
// get zenith luminance
float const chi = ( (4.0f / 9.0f) - (m_turbidity / 120.0f) ) * ( M_PI - (2.0f * m_thetasun) );
@@ -243,7 +242,7 @@ void CSkyDome::RebuildColors() {
float const yclear = std::max( 0.01f, PerezFunctionO2( perezluminance, icostheta, gamma, cosgamma2, zenithluminance ) );
float const yover = std::max( 0.01f, zenithluminance * ( 1.0f + 2.0f * vertex.y ) / 3.0f );
- float const Y = interpolate( yclear, yover, m_overcast );
+ float const Y = std::lerp( yclear, yover, m_overcast );
float const X = (x / y) * Y;
float const Z = ((1.0f - x - y) / y) * Y;
@@ -263,7 +262,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,18 +271,18 @@ 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( std::lerp(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 );
color = colors::HSVtoRGB(colorconverter);
- color = interpolate( color, shiftedcolor, shiftfactor * Global.m_skyhuecorrection );
+ color = glm::mix( color, shiftedcolor, shiftfactor * Global.m_skyhuecorrection );
// crude correction for the times where the model breaks (late night)
// TODO: use proper night sky calculation for these times instead
@@ -296,7 +295,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/command.cpp b/input/command.cpp
index bad03f60..dc4ff462 100644
--- a/input/command.cpp
+++ b/input/command.cpp
@@ -13,7 +13,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include "utilities/Timer.h"
-#include "utilities/utilities.h"
#include "simulation/simulation.h"
#include "vehicle/Train.h"
diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp
index 73f69141..8f96dc24 100644
--- a/input/drivermouseinput.cpp
+++ b/input/drivermouseinput.cpp
@@ -12,7 +12,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "application/application.h"
-#include "utilities/utilities.h"
#include "utilities/Globals.h"
#include "utilities/Timer.h"
#include "simulation/simulation.h"
@@ -147,7 +146,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 :
@@ -164,10 +163,10 @@ drivermouse_input::init() {
#ifdef _WIN32
DWORD systemkeyboardspeed;
::SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &systemkeyboardspeed, 0 );
- m_updaterate = interpolate( 0.5, 0.04, systemkeyboardspeed / 31.0 );
+ m_updaterate = std::lerp( 0.5, 0.04, systemkeyboardspeed / 31.0 );
DWORD systemkeyboarddelay;
::SystemParametersInfo( SPI_GETKEYBOARDDELAY, 0, &systemkeyboarddelay, 0 );
- m_updatedelay = interpolate( 0.25, 1.0, systemkeyboarddelay / 3.0 );
+ m_updatedelay = std::lerp( 0.25, 1.0, systemkeyboarddelay / 3.0 );
#endif
default_bindings();
@@ -303,7 +302,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/input/gamepadinput.cpp b/input/gamepadinput.cpp
index 1eea53f3..93453d89 100644
--- a/input/gamepadinput.cpp
+++ b/input/gamepadinput.cpp
@@ -41,7 +41,7 @@ glm::vec2 circle_to_square( glm::vec2 const &Point, int const Roundness = 0 ) {
// Find the inner-roundness scaling factor and LERP
auto const length = glm::length( Point );
auto const factor = std::pow( length, Roundness );
- return interpolate( Point, squared, (float)factor );
+ return glm::mix( Point, squared, (float)factor );
}
bool
diff --git a/input/messaging.cpp b/input/messaging.cpp
index 23f4dbb1..b3c48f40 100644
--- a/input/messaging.cpp
+++ b/input/messaging.cpp
@@ -80,7 +80,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
{
int i = int(pRozkaz->cString[8]); // długość pierwszego łańcucha (z przodu dwa floaty)
CommLog(
- Now() + " " + to_string(pRozkaz->iComm) + " " +
+ Now() + " " + std::to_string(pRozkaz->iComm) + " " +
std::string(pRozkaz->cString + 11 + i, (unsigned)(pRozkaz->cString[10 + i])) +
" rcvd");
// nazwa pojazdu jest druga
@@ -98,7 +98,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
break;
case 4: // badanie zajętości toru
{
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " " +
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " " +
std::string(pRozkaz->cString + 1, (unsigned)(pRozkaz->cString[0])) + " rcvd");
auto *track = simulation::Paths.find( std::string( pRozkaz->cString + 1, (unsigned)( pRozkaz->cString[ 0 ] ) ) );
@@ -110,7 +110,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
break;
case 5: // ustawienie parametrów
{
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " params " + to_string(*pRozkaz->iPar) + " rcvd");
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " params " + std::to_string(*pRozkaz->iPar) + " rcvd");
if (*pRozkaz->iPar == 0) // sprawdzenie czasu
if (*pRozkaz->iPar & 1) // ustawienie czasu
{
@@ -133,7 +133,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
// Ra 2014-12: to ma działać również dla pojazdów bez obsady
CommLog(
Now() + " "
- + to_string( pRozkaz->iComm ) + " "
+ + std::to_string( pRozkaz->iComm ) + " "
+ std::string{ pRozkaz->cString + 1, (unsigned)( pRozkaz->cString[ 0 ] ) }
+ " rcvd" );
if (pRozkaz->cString[0]) {
@@ -153,15 +153,15 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
}
break;
case 8: // ponowne wysłanie informacji o zajętych odcinkach toru
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " all busy track" + " rcvd");
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " all busy track" + " rcvd");
simulation::Paths.TrackBusyList();
break;
case 9: // ponowne wysłanie informacji o zajętych odcinkach izolowanych
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " all busy isolated" + " rcvd");
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " all busy isolated" + " rcvd");
simulation::Paths.IsolatedBusyList();
break;
case 10: // badanie zajętości jednego odcinka izolowanego
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " " +
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " " +
std::string(pRozkaz->cString + 1, (unsigned)(pRozkaz->cString[0])) + " rcvd");
simulation::Paths.IsolatedBusy( std::string( pRozkaz->cString + 1, (unsigned)( pRozkaz->cString[ 0 ] ) ) );
break;
@@ -169,12 +169,12 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
// Ground.IsolatedBusy(AnsiString(pRozkaz->cString+1,(unsigned)(pRozkaz->cString[0])));
break;
case 12: // skrocona ramka parametrow pojazdow AI (wszystkich!!)
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " obsadzone" + " rcvd");
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " obsadzone" + " rcvd");
WyslijObsadzone();
// Ground.IsolatedBusy(AnsiString(pRozkaz->cString+1,(unsigned)(pRozkaz->cString[0])));
break;
case 13: // ramka uszkodzenia i innych stanow pojazdu, np. wylaczenie CA, wlaczenie recznego itd.
- CommLog(Now() + " " + to_string(pRozkaz->iComm) + " " +
+ CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " " +
std::string(pRozkaz->cString + 1, (unsigned)(pRozkaz->cString[0])) +
" rcvd");
if( pRozkaz->cString[ 1 ] ) // jeśli długość nazwy jest niezerowa
diff --git a/launcher/scenery_scanner.cpp b/launcher/scenery_scanner.cpp
index 53e816ad..c28f7e7e 100644
--- a/launcher/scenery_scanner.cpp
+++ b/launcher/scenery_scanner.cpp
@@ -16,7 +16,7 @@ void scenery_scanner::scan()
if (*(path.filename().string().begin()) == '$')
continue;
- if (string_ends_with(path.string(), ".scn"))
+ if (path.string().ends_with(".scn"))
scan_scn(path);
}
@@ -50,7 +50,7 @@ void scenery_scanner::scan_scn(std::filesystem::path path)
{
line_counter++;
- if (line.size() < 6 || !string_starts_with(line, "//$"))
+ if (line.size() < 6 || !line.starts_with("//$"))
continue;
if (line[3] == 'i')
diff --git a/launcher/scenery_scanner.h b/launcher/scenery_scanner.h
index 573c2994..44854438 100644
--- a/launcher/scenery_scanner.h
+++ b/launcher/scenery_scanner.h
@@ -2,7 +2,6 @@
#include
#include "model/Texture.h"
-#include "utilities/utilities.h"
#include "utilities/parser.h"
#include "textures_scanner.h"
diff --git a/model/AnimModel.cpp b/model/AnimModel.cpp
index 96543401..f6c95345 100644
--- a/model/AnimModel.cpp
+++ b/model/AnimModel.cpp
@@ -288,7 +288,7 @@ bool TAnimModel::Load(cParser *parser, bool ter)
{ // gdy brak modelu
if (ter) // jeśli teren
{
- if( ends_with( name, ".t3d" ) ) {
+ if( name.ends_with(".t3d") ) {
name[ name.length() - 3 ] = 'e';
}
#ifdef EU07_USE_OLD_TERRAINCODE
@@ -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 0e5a12d8..b483d16e 100644
--- a/model/Model3d.cpp
+++ b/model/Model3d.cpp
@@ -17,7 +17,6 @@ Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
#include "utilities/Globals.h"
#include "utilities/Logs.h"
-#include "utilities/utilities.h"
#include "rendering/renderer.h"
#include "utilities/Timer.h"
#include "simulation/simulation.h"
@@ -382,11 +381,11 @@ std::pair TSubModel::Load(cParser &parser, bool dynamic)
// convert conve parameters if specified in degrees
if (fCosFalloffAngle > 1.0)
{
- fCosFalloffAngle = std::cos(DegToRad(0.5f * fCosFalloffAngle));
+ fCosFalloffAngle = std::cos(glm::radians(0.5f * fCosFalloffAngle));
}
if (fCosHotspotAngle > 1.0)
{
- fCosHotspotAngle = std::cos(DegToRad(0.5f * fCosHotspotAngle));
+ fCosHotspotAngle = std::cos(glm::radians(0.5f * fCosHotspotAngle));
}
m_geometry.vertex_count = 1;
iFlags |= 0x4030; // drawn both in solid (light point) and transparent (light glare) phases
@@ -2215,13 +2214,13 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t,
if (!pName.empty())
{ // jeśli dany submodel jest zgaszonym światłem, to
// domyślnie go ukrywamy
- if (starts_with(pName, "Light_On"))
+ if (pName.starts_with("Light_On"))
{ // jeśli jest światłem numerowanym
iVisible = 0; // to domyślnie wyłączyć, żeby się nie nakładało z obiektem "Light_Off"
}
else if (dynamic)
{ // inaczej wyłączało smugę w latarniach
- if (ends_with(pName, "_on"))
+ if (pName.ends_with("_on"))
{
// jeśli jest kontrolką w stanie zapalonym to domyślnie wyłączyć,
// żeby się nie nakładało z obiektem "_off"
@@ -2314,14 +2313,14 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, std::vector *t,
// intercept and fix hotspot values if specified in degrees and not directly
if (fCosFalloffAngle > 1.0f)
{
- fCosFalloffAngle = std::cos(DegToRad(0.5f * fCosFalloffAngle));
+ fCosFalloffAngle = std::cos(glm::radians(0.5f * fCosFalloffAngle));
}
if (fCosHotspotAngle > 1.0f)
{
- fCosHotspotAngle = std::cos(DegToRad(0.5f * fCosHotspotAngle));
+ fCosHotspotAngle = std::cos(glm::radians(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/model/Texture.cpp b/model/Texture.cpp
index c4dabd34..91e62f8b 100644
--- a/model/Texture.cpp
+++ b/model/Texture.cpp
@@ -22,7 +22,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "scene/sn_utils.h"
-#include "utilities/utilities.h"
#include "rendering/flip-s3tc.h"
#include "stb/stb_image.h"
//#include
@@ -270,7 +269,7 @@ opengl_texture::load() {
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't powers of 2", logtype::texture );
}
}
- if( ( quantize( data_width, 4 ) != data_width ) || ( quantize( data_height, 4 ) != data_height ) ) {
+ if( ( quantize( data_width, 4u ) != data_width ) || ( quantize( data_height, 4u ) != data_height ) ) {
WriteLog( "Warning: dimensions of texture \"" + name + "\" aren't multiples of 4", logtype::texture );
}
@@ -982,11 +981,11 @@ opengl_texture::create( bool const Static ) {
if (Global.gfx_usegles)
{
if( target == GL_TEXTURE_2D )
- glTexStorage2D(target, count_trailing_zeros(std::max(data_width, data_height)) + 1, data_format, data_width, data_height);
+ glTexStorage2D(target, std::countr_zero(static_cast(std::max(data_width, data_height))) + 1, data_format, data_width, data_height);
else if( target == GL_TEXTURE_2D_MULTISAMPLE )
glTexStorage2DMultisample( target, samples, data_format, data_width, data_height, GL_FALSE );
else if( target == GL_TEXTURE_2D_ARRAY )
- glTexStorage3D( target, count_trailing_zeros( std::max( data_width, data_height ) ) + 1, data_format, data_width, data_height, layers );
+ glTexStorage3D(target, std::countr_zero(static_cast(std::max(data_width, data_height))) + 1, data_format, data_width, data_height, layers);
else if( target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY )
glTexStorage3DMultisample( target, samples, data_format, data_width, data_height, layers, GL_FALSE );
}
@@ -1324,8 +1323,7 @@ texture_manager::create( std::string Filename, bool const Loadnow, GLint Formath
erase_leading_slashes( Filename );
Filename = ToLower( Filename );
// temporary code for legacy assets -- textures with names beginning with # are to be sharpened
- if( ( starts_with( Filename, "#" ) )
- || ( contains( Filename, "/#" ) ) ) {
+ if( Filename.starts_with("#") || contains( Filename, "/#" ) ) {
traits += '#';
}
}
diff --git a/model/Texture.h b/model/Texture.h
index b402d64c..cbcce4f6 100644
--- a/model/Texture.h
+++ b/model/Texture.h
@@ -119,7 +119,7 @@ public:
bool is_texstub = false; // for make_from_memory internal_src: functionality
std::vector data; // texture data (stored GL-style, bottom-left origin)
resource_state data_state{ resource_state::none }; // current state of texture data
- int data_width{ 0 },
+ unsigned int data_width{ 0 },
data_height{ 0 },
data_mapcount{ 0 };
GLint data_format{ 0 },
diff --git a/model/material.cpp b/model/material.cpp
index e0b04475..24b63752 100644
--- a/model/material.cpp
+++ b/model/material.cpp
@@ -16,7 +16,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Logs.h"
#include "scene/sn_utils.h"
#include "utilities/Globals.h"
-#include "utilities/Logs.h"
opengl_material::path_data opengl_material::paths;
diff --git a/model/vertex.h b/model/vertex.h
index 28b63b69..d3ec3eb9 100644
--- a/model/vertex.h
+++ b/model/vertex.h
@@ -9,8 +9,6 @@ http://mozilla.org/MPL/2.0/.
#pragma once
-#include "utilities/utilities.h"
-
// geometry vertex with double precision position
struct world_vertex {
@@ -19,6 +17,11 @@ struct world_vertex {
glm::vec3 normal;
glm::vec2 texture;
+ static world_vertex lerp(world_vertex const &a, world_vertex const &b, double factor)
+ {
+ return static_cast((a * (1.0f - factor)) + (b * factor));
+ }
+
// overloads
// operator+
template
@@ -55,7 +58,7 @@ struct world_vertex {
void
set_half( world_vertex const &Vertex1, world_vertex const &Vertex2 ) {
*this =
- interpolate(
+ world_vertex::lerp(
Vertex1,
Vertex2,
0.5 ); }
@@ -63,7 +66,7 @@ struct world_vertex {
void
set_from_x( world_vertex const &Vertex1, world_vertex const &Vertex2, double const X ) {
*this =
- interpolate(
+ world_vertex::lerp(
Vertex1,
Vertex2,
( X - Vertex1.position.x ) / ( Vertex2.position.x - Vertex1.position.x ) ); }
@@ -71,7 +74,7 @@ struct world_vertex {
void
set_from_z( world_vertex const &Vertex1, world_vertex const &Vertex2, double const Z ) {
*this =
- interpolate(
+ world_vertex::lerp(
Vertex1,
Vertex2,
( Z - Vertex1.position.z ) / ( Vertex2.position.z - Vertex1.position.z ) ); }
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..43fef6b4 100644
--- a/rendering/opengl33renderer.cpp
+++ b/rendering/opengl33renderer.cpp
@@ -16,7 +16,6 @@ http://mozilla.org/MPL/2.0/.
#include "vehicle/Camera.h"
#include "simulation/simulation.h"
#include "utilities/Logs.h"
-#include "utilities/utilities.h"
#include "simulation/simulationtime.h"
#include "application/application.h"
#include "model/AnimModel.h"
@@ -1293,7 +1292,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 +1912,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;
- 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);
+ 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 = glm::mix(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
+ /*float const size = std::lerp( // 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);
@@ -2000,10 +1999,10 @@ bool opengl33_renderer::Render(world_environment *Environment)
}
/*
- float const size = interpolate( // TODO: expose distance/scale factor from the moon object
+ float const size = std::lerp( // 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 +2043,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 = glm::mix(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 +3101,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 +3714,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] = glm::mix(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 +3890,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 +3928,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));
@@ -4161,7 +4160,7 @@ void opengl33_renderer::Render_Alpha(TSubModel *Submodel)
// NOTE: we're forced here to redo view angle calculations etc, because this data isn't instanced but stored along with the single mesh
// TODO: separate instance data from reusable geometry
auto const &modelview = OpenGLMatrices.data(GL_MODELVIEW);
- auto const lightcenter = modelview * interpolate(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f),
+ auto const lightcenter = modelview * glm::mix(glm::vec4(0.f, 0.f, -0.05f, 1.f), glm::vec4(0.f, 0.f, -0.25f, 1.f),
static_cast(TSubModel::fSquareDist / Submodel->fSquareMaxDist)); // pozycja punktu świecącego względem kamery
Submodel->fCosViewAngle = glm::dot(glm::normalize(modelview * glm::vec4(0.f, 0.f, -1.f, 1.f) - lightcenter), glm::normalize(-lightcenter));
@@ -4171,11 +4170,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 +4225,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 +4235,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{std::lerp(std::lerp(1.f, 0.25f, std::clamp(Global.Overcast * 0.75f - 0.5f, 0.f, 1.f)), 1.f, distancefactor)};
lightlevel *= precipitationfactor;
}
@@ -4263,7 +4262,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{std::lerp(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..79ce967c 100644
--- a/rendering/opengllight.cpp
+++ b/rendering/opengllight.cpp
@@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "rendering/opengllight.h"
-#include "utilities/utilities.h"
void
opengl_light::apply_intensity( float const Factor ) {
@@ -22,7 +21,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..868e5122 100644
--- a/rendering/openglrenderer.cpp
+++ b/rendering/openglrenderer.cpp
@@ -22,7 +22,6 @@ http://mozilla.org/MPL/2.0/.
#include "world/Traction.h"
#include "application/application.h"
#include "utilities/Logs.h"
-#include "utilities/utilities.h"
#include "rendering/openglgeometrybank.h"
#include "rendering/openglcolor.h"
#include "rendering/screenshot.h"
@@ -821,7 +820,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 +922,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; }
@@ -1507,10 +1506,10 @@ bool
opengl_renderer::Render( world_environment *Environment ) {
// calculate shadow tone, based on positions of celestial bodies
- m_shadowcolor = interpolate(
+ m_shadowcolor = glm::mix(
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,9 +1567,9 @@ 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;
- glm::vec3 suncolor = interpolate(
+ 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 = glm::mix(
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 );
@@ -1578,7 +1577,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 );
@@ -1586,10 +1585,10 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef( sunposition.x, sunposition.y, sunposition.z ); // początek układu zostaje bez zmian
- float const size = interpolate( // TODO: expose distance/scale factor from the moon object
+ float const size = std::lerp( // 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 );
@@ -1619,10 +1618,10 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLoadIdentity(); // macierz jedynkowa
::glTranslatef( moonposition.x, moonposition.y, moonposition.z );
- float const size = interpolate( // TODO: expose distance/scale factor from the moon object
+ float const size = std::lerp( // 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)
@@ -1662,8 +1661,8 @@ opengl_renderer::Render( world_environment *Environment ) {
::glLightModelfv(
GL_LIGHT_MODEL_AMBIENT,
glm::value_ptr(
- interpolate( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
- * interpolate( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds
+ glm::mix( Environment->m_skydome.GetAverageColor(), suncolor, duskfactor * 0.25f )
+ * std::lerp( 1.f, 0.35f, Global.Overcast / 2.f ) // overcast darkens the clouds
* 0.5f // arbitrary adjustment factor
) );
// render
@@ -2609,7 +2608,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 +2764,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 );
@@ -2911,7 +2910,7 @@ opengl_renderer::Render( TSubModel *Submodel ) {
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
auto const lightcenter =
modelview
- * interpolate(
+ * glm::mix(
glm::vec4( 0.f, 0.f, -0.05f, 1.f ),
glm::vec4( 0.f, 0.f, -0.25f, 1.f ),
static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery
@@ -2921,7 +2920,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;
@@ -2933,8 +2932,8 @@ opengl_renderer::Render( 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 ) ),
+ std::lerp(
+ std::lerp( 1.f, 0.25f, std::clamp( Global.Overcast * 0.75f - 0.5f, 0.f, 1.f ) ),
1.f,
distancefactor ) };
lightlevel *= precipitationfactor;
@@ -2968,9 +2967,9 @@ opengl_renderer::Render( TSubModel *Submodel ) {
if( Global.Overcast > 1.f ) {
// fake fog halo
float const fogfactor {
- interpolate(
+ std::lerp(
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 );
@@ -3343,10 +3342,10 @@ opengl_renderer::Render_precipitation() {
// ::glColor4fv( glm::value_ptr( glm::vec4( glm::min( glm::vec3( Global.fLuminance ), glm::vec3( 1 ) ), 1 ) ) );
::glColor4fv(
glm::value_ptr(
- interpolate(
+ glm::mix(
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 +3586,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 +3636,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 +3838,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,
@@ -3935,7 +3934,7 @@ opengl_renderer::Render_Alpha( TSubModel *Submodel ) {
auto const &modelview = OpenGLMatrices.data( GL_MODELVIEW );
auto const lightcenter =
modelview
- * interpolate(
+ * glm::mix(
glm::vec4( 0.f, 0.f, -0.05f, 1.f ),
glm::vec4( 0.f, 0.f, -0.10f, 1.f ),
static_cast( TSubModel::fSquareDist / Submodel->fSquareMaxDist ) ); // pozycja punktu świecącego względem kamery
@@ -3944,13 +3943,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 +4145,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..58951f17 100644
--- a/rendering/openglskydome.cpp
+++ b/rendering/openglskydome.cpp
@@ -59,8 +59,8 @@ 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;
- auto gamma = interpolate( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
+ float twilightfactor = std::clamp( -simulation::Environment.sun().getAngle(), 0.0f, 18.0f ) / 18.0f;
+ auto gamma = std::lerp( glm::vec3( 0.45f ), glm::vec3( 1.0f ), twilightfactor );
for( auto & color : colors ) {
color = glm::pow( color, gamma );
}
diff --git a/rendering/particles.cpp b/rendering/particles.cpp
index 7155eab0..12eaa737 100644
--- a/rendering/particles.cpp
+++ b/rendering/particles.cpp
@@ -282,7 +282,7 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
}
// determine bounding area from calculated bounding box
if( false == m_particles.empty() ) {
- m_area.center = interpolate( boundingbox[ value_limit::min ], boundingbox[ value_limit::max ], 0.5 );
+ m_area.center = glm::mix(boundingbox[value_limit::min], boundingbox[value_limit::max], 0.5);
m_area.radius = 0.5 * ( glm::length( boundingbox[ value_limit::max ] - boundingbox[ value_limit::min ] ) );
}
else {
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/scene.h b/scene/scene.h
index 31ae66e2..f63a7f9e 100644
--- a/scene/scene.h
+++ b/scene/scene.h
@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
#include "world/Traction.h"
#include "audio/sound.h"
#include "input/command.h"
+#include "utilities/utilities.h"
class opengl_renderer;
class opengl33_renderer;
diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp
index 38fe7f02..784fb14f 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: {
@@ -434,7 +434,7 @@ shape_node::merge( shape_node &Shape ) {
}
// add geometry from provided node
m_data.area.center =
- interpolate(
+ glm::mix(
m_data.area.center, Shape.m_data.area.center,
static_cast( Shape.m_data.vertices.size() ) / ( Shape.m_data.vertices.size() + m_data.vertices.size() ) );
m_data.vertices.insert(
@@ -659,7 +659,7 @@ lines_node::merge( lines_node &Lines ) {
}
// add geometry from provided node
m_data.area.center =
- interpolate(
+ glm::mix(
m_data.area.center, Lines.m_data.area.center,
static_cast( Lines.m_data.vertices.size() ) / ( Lines.m_data.vertices.size() + m_data.vertices.size() ) );
m_data.vertices.insert(
diff --git a/scene/scenenodegroups.cpp b/scene/scenenodegroups.cpp
index 4ee1f0e4..a28b1d86 100644
--- a/scene/scenenodegroups.cpp
+++ b/scene/scenenodegroups.cpp
@@ -111,7 +111,7 @@ node_groups::update_map()
for (basic_node *node : group.nodes) {
std::string postfix { "_sem_mem" };
- if (typeid(*node) == typeid(TMemCell) && string_ends_with(node->name(), postfix)) {
+ if (typeid(*node) == typeid(TMemCell) && node->name().ends_with(postfix)) {
std::string sem_name = node->name().substr(0, node->name().length() - postfix.length());
auto sem_info = std::make_shared();
@@ -122,7 +122,7 @@ node_groups::update_map()
sem_info->name = sem_name;
for (basic_event *event : group.events) {
- if (string_starts_with(event->name(), sem_name)
+ if (event->name().starts_with(sem_name)
&& event->name().substr(sem_name.length()).find("sem") == std::string::npos) {
sem_info->events.push_back(event);
}
@@ -130,7 +130,7 @@ node_groups::update_map()
for (basic_node *node : group.nodes)
if (auto *model = dynamic_cast(node))
- if (string_starts_with(model->name(), sem_name))
+ if (model->name().starts_with(sem_name))
sem_info->models.push_back(model);
}
diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp
index 38bdf373..9c9bb033 100644
--- a/scripting/PyInt.cpp
+++ b/scripting/PyInt.cpp
@@ -434,7 +434,7 @@ auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject *
return lookup->second;
}
// try to load specified renderer class
- auto const path{substr_path(Renderer)};
+ std::string const path{substr_path(Renderer)};
auto const file{Renderer.substr(path.size())};
PyObject *renderer{nullptr};
PyObject *rendererarguments{nullptr};
diff --git a/scripting/ladderlogic.cpp b/scripting/ladderlogic.cpp
index 56699818..37a209d0 100644
--- a/scripting/ladderlogic.cpp
+++ b/scripting/ladderlogic.cpp
@@ -378,7 +378,7 @@ basic_controller::log_error( std::string const &Error, int const Line ) const {
"Bad plc program: \"" + m_programfilename + "\" "
+ Error
+ ( Line > 0 ?
- " (line " + to_string( Line ) + ")" :
+ " (line " + std::to_string( Line ) + ")" :
"" ) );
}
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..0f5548be 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 )
+ + std::lerp( 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,8 +155,8 @@ 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;
- keylightcolor = interpolate(
+ float const duskfactor = 1.25f - std::clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f;
+ keylightcolor = glm::mix(
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 ),
duskfactor );
@@ -172,7 +172,7 @@ world_environment::update() {
// but whether it'd _look_ better is something to be tested
auto const intensity = std::min( 1.15f * ( 0.05f + keylightintensity + skydomehsv.z ), 1.25f );
// the impact of sun component is reduced proportionally to overcast level, as overcast increases role of ambient light
- auto const diffuselevel = interpolate( keylightintensity, intensity * ( 1.0f - twilightfactor ), 1.0f - std::min( 1.f, Global.Overcast ) * 0.75f );
+ auto const diffuselevel = std::lerp( keylightintensity, intensity * ( 1.0f - twilightfactor ), 1.0f - std::min( 1.f, Global.Overcast ) * 0.75f );
// ...update light colours and intensity.
keylightcolor = keylightcolor * diffuselevel;
Global.DayLight.diffuse = glm::vec4( keylightcolor, Global.DayLight.diffuse.a );
@@ -180,18 +180,18 @@ 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;
- 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;
+ 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 ] = std::lerp( skydomehsv.z, skydomecolour.r, ambienttone ) * ambientintensitynightfactor;
+ Global.DayLight.ambient[ 1 ] = std::lerp( skydomehsv.z, skydomecolour.g, ambienttone ) * ambientintensitynightfactor;
+ Global.DayLight.ambient[ 2 ] = std::lerp( skydomehsv.z, skydomecolour.b, ambienttone ) * ambientintensitynightfactor;
Global.fLuminance = intensity;
// 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/simulationsounds.cpp b/simulation/simulationsounds.cpp
index 43005589..fc11fc84 100644
--- a/simulation/simulationsounds.cpp
+++ b/simulation/simulationsounds.cpp
@@ -10,8 +10,6 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "simulation/simulationsounds.h"
-#include "utilities/utilities.h"
-
namespace simulation {
sound_overridemap Sound_overrides;
diff --git a/simulation/simulationstateserializer.cpp b/simulation/simulationstateserializer.cpp
index 3c0a6dcd..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 ) );
}
@@ -566,8 +566,8 @@ state_serializer::deserialize_node( cParser &Input, scene::scratch_data &Scratch
// crude way to detect fixed switch trackbed geometry
|| ( ( true == Global.CreateSwitchTrackbeds )
&& ( Input.Name().size() >= 15 )
- && ( starts_with( Input.Name(), "scenery/zwr" ) )
- && ( ends_with( Input.Name(), ".inc" ) ) ) };
+ && Input.Name().starts_with("scenery/zwr")
+ && Input.Name().ends_with(".inc") ) };
if( false == skip ) {
@@ -749,7 +749,7 @@ state_serializer::deserialize_terrain(cParser &Input, scene::scratch_data &Scrat
std::string line;
Input.getTokens(1);
Input >> line;
- if ((true == Global.file_binary_terrain) && (true == ends_with(line, ".sbt")))
+ if (Global.file_binary_terrain && line.ends_with(".sbt"))
{
Scratchpad.binary.terrain = Region->is_scene(line);
Global.file_binary_terrain_state = true;
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 8b40162b..23cf9ab9 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()
@@ -284,24 +284,24 @@ bool global_settings::ConfigParseGraphics(cParser& Parser, const std::string& to
if (token == "maxtexturesize")
{
- int size = 0;
+ unsigned int size = 0;
ParseOne(Parser, size, 1, false);
- iMaxTextureSize = clamp_power_of_two(size, 64, 8192);
+ iMaxTextureSize = static_cast(clamp_power_of_two(size, 64u, 8192u));
return true;
}
if (token == "maxcabtexturesize")
{
- int size = 0;
+ unsigned int size = 0;
ParseOne(Parser, size, 1, false);
- iMaxCabTextureSize = clamp_power_of_two(size, 512, 8192);
+ iMaxCabTextureSize = static_cast(clamp_power_of_two(size, 512u, 8192u));
return true;
}
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;
}
@@ -1323,7 +1323,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")
{
@@ -1344,7 +1344,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")
{
@@ -1468,13 +1468,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 55bbfdda..be79e42e 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/dictionary.cpp b/utilities/dictionary.cpp
index 244b5a51..70739847 100644
--- a/utilities/dictionary.cpp
+++ b/utilities/dictionary.cpp
@@ -11,7 +11,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/dictionary.h"
#include "simulation/simulation.h"
-#include "utilities/utilities.h"
#include "vehicle/DynObj.h"
#include "vehicle/Driver.h"
#include "world/mtable.h"
diff --git a/utilities/parser.cpp b/utilities/parser.cpp
index 93887479..68656c5d 100644
--- a/utilities/parser.cpp
+++ b/utilities/parser.cpp
@@ -9,7 +9,6 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "utilities/parser.h"
-#include "utilities/utilities.h"
#include "utilities/Logs.h"
#include "scene/scenenodegroups.h"
diff --git a/utilities/translation.cpp b/utilities/translation.cpp
index ddf8c031..129d1be9 100644
--- a/utilities/translation.cpp
+++ b/utilities/translation.cpp
@@ -86,11 +86,11 @@ bool locale::parse_translation(std::istream &stream)
if (line.size() > 0 && line[0] == '#')
continue;
- if (string_starts_with(line, "msgid"))
+ if (line.starts_with("msgid"))
last = 'i';
- else if (string_starts_with(line, "msgstr"))
+ else if (line.starts_with("msgstr"))
last = 's';
- else if (string_starts_with(line, "msgctxt"))
+ else if (line.starts_with("msgctxt"))
last = 'c';
if (line.size() > 1 && last != 'x') {
diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp
index 7d4cfd6d..46d74e07 100644
--- a/utilities/utilities.cpp
+++ b/utilities/utilities.cpp
@@ -11,56 +11,37 @@ MaSzyna EU07 - SPKS
Brakes.
Copyright (C) 2007-2014 Maciej Cierniak
*/
-#include "stdafx.h"
-
-#include
-#include
-#ifndef WIN32
-#include
-#endif
-
-#ifdef WIN32
-#define stat _stat
-#endif
+//#include "stdafx.h"
+//
+//#include
+//#include
+#include
+//#ifndef WIN32
+//#include
+//#endif
+//
+//#ifdef WIN32
+//#define stat _stat
+//#endif
#include "utilities/utilities.h"
#include "utilities/Globals.h"
#include "utilities/parser.h"
-#include "utilities/Logs.h"
+//#include "utilities/Logs.h"
+// TODO: This shouldn't be in Globals?
bool DebugModeFlag = false;
bool FreeFlyModeFlag = false;
bool EditorModeFlag = false;
bool DebugCameraFlag = false;
bool DebugTractionFlag = false;
-double Max0R(double x1, double x2)
-{
- if (x1 > x2)
- return x1;
- else
- return x2;
-}
-
-double Min0R(double x1, double x2)
-{
- if (x1 < x2)
- return x1;
- else
- return x2;
-}
-
-// shitty replacement for Borland timestamp function
-// TODO: replace with something sensible
std::string Now()
{
-
- std::time_t timenow = std::time(nullptr);
- std::tm tm = *std::localtime(&timenow);
- std::stringstream converter;
- converter << std::put_time(&tm, "%c");
- return converter.str();
+ auto now = std::chrono::system_clock::now();
+ auto local = std::chrono::current_zone()->to_local(now);
+ return std::format("{:%c}", local);
}
// zwraca różnicę czasu
@@ -117,15 +98,14 @@ bool ClearFlag(int &Flag, int const Value)
double Random(double a, double b)
{
- uint32_t val = Global.random_engine();
- return interpolate(a, b, (double)val / Global.random_engine.max());
+ std::uniform_real_distribution dist(a, b);
+ return dist(Global.random_engine);
}
-int RandomInt(int min, int max)
+int Random(int min, int max)
{
- static std::mt19937 engine(std::random_device{}());
std::uniform_int_distribution dist(min, max);
- return dist(engine);
+ return dist(Global.random_engine);
}
std::string generate_uuid_v4()
@@ -156,8 +136,8 @@ std::string generate_uuid_v4()
double LocalRandom(double a, double b)
{
- uint32_t val = Global.local_random_engine();
- return interpolate(a, b, (double)val / Global.random_engine.max());
+ std::uniform_real_distribution dist(a, b);
+ return dist(Global.local_random_engine);
}
bool FuzzyLogic(double Test, double Threshold, double Probability)
@@ -176,71 +156,12 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability)
return false;
}
-std::string DUE(std::string s) /*Delete Before Equal sign*/
-{
- // DUE = Copy(s, Pos("=", s) + 1, length(s));
- return s.substr(s.find("=") + 1, s.length());
-}
-
-std::string DWE(std::string s) /*Delete After Equal sign*/
-{
- size_t ep = s.find("=");
- if (ep != std::string::npos)
- // DWE = Copy(s, 1, ep - 1);
- return s.substr(0, ep);
- else
- return s;
-}
-
-std::string ExchangeCharInString(std::string const &Source, char const From, char const To)
-{
- std::string replacement;
- replacement.reserve(Source.size());
- std::for_each(std::begin(Source), std::end(Source),
- [&](char const idx)
- {
- if (idx != From)
- {
- replacement += idx;
- }
- else
- {
- replacement += To;
- }
- });
-
- return replacement;
-}
-
-std::vector &Split(const std::string &s, char delim, std::vector &elems)
+std::vector Split(std::string_view s, char delim)
{ // dzieli tekst na wektor tekstow
-
- std::stringstream ss(s);
- std::string item;
- while (std::getline(ss, item, delim))
- {
- elems.push_back(item);
- }
- return elems;
-}
-
-std::vector Split(const std::string &s, char delim)
-{ // dzieli tekst na wektor tekstow
- std::vector elems;
- Split(s, delim, elems);
- return elems;
-}
-
-std::vector Split(const std::string &s)
-{ // dzieli tekst na wektor tekstow po białych znakach
- std::vector elems;
- std::stringstream ss(s);
- std::string item;
- while (ss >> item)
- {
- elems.push_back(item);
- }
- return elems;
+ std::vector out;
+ for (const auto& part : s | std::ranges::views::split(delim))
+ out.emplace_back(part.begin(), part.end());
+ return out;
}
std::pair split_string_and_number(std::string const &Key)
@@ -255,73 +176,34 @@ std::pair split_string_and_number(std::string const &Key)
return {Key, 0};
}
-std::string to_string(int Value)
-{
- std::ostringstream o;
- o << Value;
- return o.str();
-};
-
-std::string to_string(unsigned int Value)
-{
- std::ostringstream o;
- o << Value;
- return o.str();
-};
-
-std::string to_string(double Value)
-{
- std::ostringstream o;
- o << Value;
- return o.str();
-};
-
std::string to_string(int Value, int width)
{
std::ostringstream o;
- o.width(width);
- o << Value;
- return o.str();
+ o << std::setw(width) << Value;
+ return std::move(o).str();
};
std::string to_string(double Value, int precision)
{
std::ostringstream o;
- o << std::fixed << std::setprecision(precision);
- o << Value;
- return o.str();
+ o << std::fixed << std::setprecision(precision) << Value;
+ return std::move(o).str();
};
std::string to_string(double const Value, int const Precision, int const Width)
{
- std::ostringstream converter;
- converter << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
- return converter.str();
+ std::ostringstream o;
+ o << std::setw(Width) << std::fixed << std::setprecision(Precision) << Value;
+ return std::move(o).str();
};
std::string to_hex_str(int const Value, int const Width)
{
- std::ostringstream converter;
- converter << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
- return converter.str();
+ std::ostringstream o;
+ o << "0x" << std::uppercase << std::setfill('0') << std::setw(Width) << std::hex << Value;
+ return o.str();
};
-bool string_ends_with(const std::string &string, const std::string &ending)
-{
- if (string.length() < ending.length())
- return false;
-
- return string.compare(string.length() - ending.length(), ending.length(), ending) == 0;
-}
-
-bool string_starts_with(const std::string &string, const std::string &begin)
-{
- if (string.length() < begin.length())
- return false;
-
- return string.compare(0, begin.length(), begin) == 0;
-}
-
std::string const fractionlabels[] = {" ", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"};
std::string to_minutes_str(float const Minutes, bool const Leadingzero, int const Width)
@@ -330,7 +212,7 @@ std::string to_minutes_str(float const Minutes, bool const Leadingzero, int cons
float minutesintegral;
auto const minutesfractional{std::modf(Minutes, &minutesintegral)};
auto const width{Width - 1};
- auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
+ auto minutes = (std::string(width - 1, ' ') + (Leadingzero ? std::to_string(100 + minutesintegral).substr(1, 2) : to_string(minutesintegral, 0)));
return (minutes.substr(minutes.size() - width, width) + fractionlabels[static_cast(std::floor(minutesfractional * 10 + 0.1))]);
}
@@ -499,61 +381,41 @@ bool erase_extension(std::string &Filename)
void erase_leading_slashes(std::string &Filename)
{
-
- while (Filename[0] == '/')
- {
- Filename.erase(0, 1);
- }
+ auto pos = Filename.find_first_not_of('/');
+ Filename.erase(0, pos);
}
// potentially replaces backward slashes in provided file path with unix-compatible forward slashes
void replace_slashes(std::string &Filename)
{
-
- std::replace(std::begin(Filename), std::end(Filename), '\\', '/');
+ std::ranges::replace(Filename, '\\', '/');
}
// returns potential path part from provided file name
-std::string substr_path(std::string const &Filename)
+std::string_view substr_path(std::string const &Filename)
{
-
- return (Filename.rfind('/') != std::string::npos ? Filename.substr(0, Filename.rfind('/') + 1) : "");
+ if (auto pos = Filename.rfind('/'); pos != std::string::npos)
+ return Filename.substr(0, pos + 1);
+ return {};
}
// returns length of common prefix between two provided strings
-std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right)
+std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b)
{
-
- auto const *left{Left.data()};
- auto const *right{Right.data()};
- // compare up to the length of the shorter string
- return (Right.size() <= Left.size() ? std::distance(right, std::mismatch(right, right + Right.size(), left).first) : std::distance(left, std::mismatch(left, left + Left.size(), right).first));
-}
-
-// returns true if provided string ends with another provided string
-bool ends_with(std::string_view String, std::string_view Suffix)
-{
-
- return (String.size() >= Suffix.size()) && (0 == String.compare(String.size() - Suffix.size(), Suffix.size(), Suffix));
-}
-
-// returns true if provided string begins with another provided string
-bool starts_with(std::string_view const String, std::string_view Prefix)
-{
-
- return (String.size() >= Prefix.size()) && (0 == String.compare(0, Prefix.size(), Prefix));
+ auto [it1, it2] = std::ranges::mismatch(a, b);
+ return std::distance(a.begin(), it1);
}
// returns true if provided string contains another provided string
bool contains(std::string_view const String, std::string_view Substring)
{
-
+ // To be replaced with string::contains in C++ 23
return (String.find(Substring) != std::string::npos);
}
bool contains(std::string_view const String, char Character)
{
-
+ // To be replaced with string::contains in C++ 23
return (String.find(Character) != std::string::npos);
}
@@ -597,14 +459,4 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
// shouldn't ever get here but, eh
return "";
}
-}
-
-int count_trailing_zeros(uint32_t val)
-{
- int r = 0;
-
- for (uint32_t shift = 1; !(val & shift); shift <<= 1)
- r++;
-
- return r;
-}
+}
\ No newline at end of file
diff --git a/utilities/utilities.h b/utilities/utilities.h
index 4738b62f..fafb708e 100644
--- a/utilities/utilities.h
+++ b/utilities/utilities.h
@@ -10,12 +10,6 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include "stdafx.h"
-
-#include
-#include
-#include
-#include
-#include
#include "utilities/parser.h"
/*rozne takie duperele do operacji na stringach w paszczalu, pewnie w delfi sa lepsze*/
@@ -26,14 +20,12 @@ template T sign(T x)
return x < static_cast(0) ? static_cast(-1) : (x > static_cast(0) ? static_cast(1) : static_cast(0));
}
-#define DegToRad(a) ((M_PI / 180.0) * (a)) //(a) w nawiasie, bo może być dodawaniem
-#define RadToDeg(r) ((180.0 / M_PI) * (r))
-
template constexpr T sq(T v)
{
return v * v;
}
+// TODO: Shouldn't this be in globals?
namespace paths
{
inline constexpr const char *scenery = "scenery/";
@@ -53,9 +45,6 @@ extern bool DebugCameraFlag;
extern bool DebugTractionFlag;
/*funkcje matematyczne*/
-double Max0R(double x1, double x2);
-double Min0R(double x1, double x2);
-
inline double Sign(double x)
{
return x >= 0 ? 1.0 : -1.0;
@@ -68,7 +57,7 @@ inline long Round(double const f)
}
double Random(double a, double b);
-int RandomInt(int min, int max);
+int Random(int min, int max);
std::string generate_uuid_v4();
double LocalRandom(double a, double b);
@@ -125,24 +114,17 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability);
/*to samo ale zawsze niezaleznie od DebugFlag*/
/*operacje na stringach*/
-std::string DUE(std::string s); /*Delete Until Equal sign*/
-std::string DWE(std::string s); /*Delete While Equal sign*/
-std::string ExchangeCharInString(std::string const &Source, char const From, char const To); // zamienia jeden znak na drugi
-std::vector &Split(const std::string &s, char delim, std::vector &elems);
-std::vector Split(const std::string &s, char delim);
-// std::vector Split(const std::string &s);
+std::vector Split(std::string_view s, char delim);
std::pair split_string_and_number(std::string const &Key);
-std::string to_string(int Value);
-std::string to_string(unsigned int Value);
std::string to_string(int Value, int width);
-std::string to_string(double Value);
std::string to_string(double Value, int precision);
std::string to_string(double Value, int precision, int width);
std::string to_hex_str(int const Value, int const width = 4);
std::string to_minutes_str(float const Minutes, bool const Leadingzero, int const Width);
-inline std::string to_string(bool Value)
+template T> // Without this line this function can be used with other types implicit casted to boolean which may create hard to debug bugs.
+inline std::string to_string(T Value)
{
return (Value == true ? "true" : "false");
}
@@ -157,9 +139,6 @@ template std::string
return to_string(Value.x, Width) + ", " + to_string(Value.y, Width) + ", " + to_string(Value.z, Width) + ", " + to_string(Value.w, Width);
}
-bool string_ends_with(std::string const &string, std::string const &ending);
-bool string_starts_with(std::string const &string, std::string const &begin);
-
int stol_def(const std::string &str, const int &DefaultValue);
std::string ToLower(std::string const &text);
@@ -235,82 +214,65 @@ void erase_leading_slashes(std::string &Filename);
void replace_slashes(std::string &Filename);
// returns potential path part from provided file name
-std::string substr_path(std::string const &Filename);
+std::string_view substr_path(std::string const &Filename);
// returns common prefix of two provided strings
-std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right);
+std::ptrdiff_t len_common_prefix(std::string_view a, std::string_view b);
-// returns true if provided string ends with another provided string
-bool ends_with(std::string_view String, std::string_view Suffix);
-// returns true if provided string begins with another provided string
-bool starts_with(std::string_view String, std::string_view Prefix);
// returns true if provided string contains another provided string
bool contains(std::string_view const String, std::string_view Substring);
bool contains(std::string_view const String, char Character);
-template void SafeDelete(Type_ &Pointer)
+// TODO: Ideally unique_ptr should be used instead of this (not safe) inline functions
+template inline void SafeDelete(T* &Pointer)
{
delete Pointer;
Pointer = nullptr;
}
-template void SafeDeleteArray(Type_ &Pointer)
+template inline void SafeDeleteArray(T *&Pointer)
{
delete[] Pointer;
Pointer = nullptr;
}
-template Type_ is_equal(Type_ const &Left, Type_ const &Right, Type_ const Epsilon = 1e-5)
+template bool is_equal(T const &Left, T const &Right, T const Epsilon = T(1e-5))
{
-
- if (Epsilon != 0)
- {
+ if (Epsilon != T(0))
return glm::epsilonEqual(Left, Right, Epsilon);
- }
- else
- {
- 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;
+ return (Left == Right);
}
// 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))
+template T clamp_circular(T Value, T const Range = T(360))
{
+ if constexpr (std::is_floating_point_v)
+ {
+ Value = std::fmod(Value, Range);
+ }
+ else
+ {
+ Value %= Range;
+ }
- Value -= Range * (int)(Value / Range); // clamp the range to 0-360
- if (Value < Type_(0))
+ if (Value < T(0))
Value += Range;
-
return Value;
}
// rounds down provided value to nearest power of two
-template Type_ clamp_power_of_two(Type_ Value, Type_ const Min = static_cast(1), Type_ const Max = static_cast(16384))
+template T clamp_power_of_two(T Value, T const Min = T(1), T const Max = T(16384))
{
+ if (Value < Min)
+ return Min;
- Type_ p2size{Min};
- Type_ size;
- while ((p2size <= Max) && (p2size <= Value))
- {
- size = p2size;
- p2size = p2size << 1;
- }
- return size;
+ T p2 = std::bit_floor(Value);
+
+ if (p2 > Max)
+ return Max;
+
+ return p2;
}
template Type_ quantize(Type_ const Value, Type_ const Step)
@@ -319,35 +281,23 @@ template Type_ quantize(Type_ const Value, Type_ const Step)
return (Step * std::round(Value / Step));
}
-template Type_ min_speed(Type_ const Left, Type_ const Right)
+template T min_speed(T const Left, T const Right)
{
-
- if (Left == Right)
- {
+ constexpr T none = T(-1);
+ if (Left == none)
+ return Right;
+ if (Right == none)
return Left;
- }
- return std::min((Left != -1 ? Left : std::numeric_limits::max()), (Right != -1 ? Right : std::numeric_limits::max()));
+ return std::min(Left, Right);
}
-template Type_ interpolate(Type_ const &First, Type_ const &Second, float const Factor)
-{
-
- return static_cast((First * (1.0f - Factor)) + (Second * Factor));
-}
-
-template Type_ interpolate(Type_ const &First, Type_ const &Second, double const Factor)
-{
-
- return static_cast((First * (1.0 - Factor)) + (Second * Factor));
-}
-
-template Type_ smoothInterpolate(Type_ const &First, Type_ const &Second, double Factor)
+template T smoothInterpolate(T const &First, T const &Second, double Factor)
{
// Apply smoothing (ease-in-out quadratic)
Factor = Factor * Factor * (3 - 2 * Factor);
- return static_cast((First * (1.0 - Factor)) + (Second * Factor));
+ return First + (Second - First) * Factor;
}
// tests whether provided points form a degenerate triangle
@@ -398,8 +348,6 @@ glm::dvec3 LoadPoint(class cParser &Input);
// extracts a group of tokens from provided data stream
std::string deserialize_random_set(cParser &Input, char const *Break = "\n\r\t ;");
-int count_trailing_zeros(uint32_t val);
-
// extracts a group of pairs from provided data stream
// NOTE: expects no more than single pair per line
template void deserialize_map(MapType_ &Map, cParser &Input)
diff --git a/vehicle/Camera.cpp b/vehicle/Camera.cpp
index 0b6f127d..3b6f8c07 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..fe3dd0e9 100644
--- a/vehicle/Driver.cpp
+++ b/vehicle/Driver.cpp
@@ -353,8 +353,8 @@ std::string TSpeedPos::GetName() const
else if( iFlags & spEvent ) // jeśli event
return
evEvent->m_name
- + " [" + to_string( static_cast( evEvent->input_value( 1 ) ) )
- + ", " + to_string( static_cast( evEvent->input_value( 2 ) ) )
+ + " [" + std::to_string( static_cast( evEvent->input_value( 1 ) ) )
+ + ", " + std::to_string( static_cast( evEvent->input_value( 2 ) ) )
+ "]";
else
return "";
@@ -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 = std::lerp( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) );
}
}
if( ( d < fMinProximityDist )
@@ -1738,9 +1738,9 @@ 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(
+ std::lerp(
multiplier, 1.f,
static_cast( mvOccupied->Vel / 40.0 ) )
* frictionmultiplier );
@@ -1750,9 +1750,9 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
&& ( ( true == IsCargoTrain )
|| ( fAccGravity > 0.025 ) ) ) {
return (
- interpolate(
+ std::lerp(
1.f, 2.f,
- clamp(
+ std::clamp(
( fBrake_a0[ 1 ] - 0.2 ) / 0.2,
0.0, 1.0 ) )
* frictionmultiplier );
@@ -1762,7 +1762,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
}
// stretch the braking distance up to 3 times; the lower the speed, the greater the stretch
return (
- interpolate(
+ std::lerp(
3.f, 1.f,
( Targetvelocity - 5.f ) / 60.f )
* frictionmultiplier );
@@ -3180,10 +3180,10 @@ bool TController::IncBrake()
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) };
mvOccupied->BrakeLevelSet(
- interpolate(
+ std::lerp(
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;
}
@@ -3312,10 +3312,10 @@ bool TController::DecBrake() {
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) };
mvOccupied->BrakeLevelSet(
- interpolate(
+ std::lerp(
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;
}
@@ -3454,7 +3454,7 @@ bool TController::IncSpeed()
auto const minvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MinV : 0.0 ) };
auto const maxvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MaxV : 0.0 ) };
auto const seriesmodevoltage {
- interpolate(
+ std::lerp(
minvoltage,
maxvoltage,
( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) };
@@ -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);
}
@@ -6447,7 +6447,7 @@ TController::control_handles() {
}
// if the power station is heavily burdened drop down to series mode to reduce the load
auto const useseriesmodevoltage {
- interpolate(
+ std::lerp(
mvControlling->EnginePowerSource.CollectorParameters.MinV,
mvControlling->EnginePowerSource.CollectorParameters.MaxV,
( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) };
@@ -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 );
}
}
}
@@ -7768,24 +7768,24 @@ TController::adjust_desired_speed_for_current_speed() {
// stop accelerating when close enough to target speed
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
- interpolate( // ease off as you close to the target velocity
+ std::lerp( // 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,8 @@ TController::adjust_desired_speed_for_braking_test() {
break;
}
case 3: {
- AccDesired = clamp( -AbsAccS, fAccThreshold * 1.01, fAccThreshold * 1.21 );
+ auto [minV, maxV] = std::minmax(fAccThreshold * 1.01f, fAccThreshold * 1.21f);
+ AccDesired = std::clamp(-AbsAccS, minV, maxV);
VelDesired = DBT_VelocityBrake;
if( vel <= DBT_VelocityRelease ) {
DynamicBrakeTest = 4;
@@ -8285,7 +8286,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/Driver.h b/vehicle/Driver.h
index 40f05ba8..84dbbe55 100644
--- a/vehicle/Driver.h
+++ b/vehicle/Driver.h
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include
#include "utilities/Classes.h"
+#include "utilities/utilities.h"
#include "MOVER.h"
#include "audio/sound.h"
#include "vehicle/DynObj.h"
diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp
index f5452f5a..504078c6 100644
--- a/vehicle/DynObj.cpp
+++ b/vehicle/DynObj.cpp
@@ -81,7 +81,7 @@ void TAnimPant::AKP_4E()
// ramienia
fHeight = 0.07; // wysokość ślizgu ponad oś obrotu
fWidth = 0.635; // połowa szerokości ślizgu, 0.635 dla AKP-1 i AKP-4E
- fAngleL0 = DegToRad(2.8547285515689267247882521833308);
+ fAngleL0 = glm::radians(2.8547285515689267247882521833308);
fAngleL = fAngleL0; // początkowy kąt dolnego ramienia
// fAngleU0=acos((1.22*cos(fAngleL)+0.535)/1.755); //górne ramię
fAngleU0 = acos((fLenL1 * cos(fAngleL) + fHoriz) / fLenU1); // górne ramię
@@ -115,7 +115,7 @@ void TAnimPant::WBL85()
// osi obrotu dolnego ramienia
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
fWidth = 0.4969; // połowa szerokości ślizgu
- fAngleL0 = DegToRad(2.8547285515689267247882521833308);
+ fAngleL0 = glm::radians(2.8547285515689267247882521833308);
fAngleL = fAngleL0; // początkowy kąt dolnego ramienia
// fAngleU0=acos((1.22*cos(fAngleL)+0.535)/1.755); //górne ramię
fAngleU0 = acos((fLenL1 * cos(fAngleL) + fHoriz) / fLenU1); // górne ramię
@@ -149,7 +149,7 @@ void TAnimPant::EC160_200()
// osi obrotu dolnego ramienia
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
fWidth = 0.4969; // połowa szerokości ślizgu
- fAngleL0 = DegToRad(2.8547285515689267247882521833308);
+ fAngleL0 = glm::radians(2.8547285515689267247882521833308);
fAngleL = fAngleL0; // początkowy kąt dolnego ramienia
// fAngleU0=acos((1.22*cos(fAngleL)+0.535)/1.755); //górne ramię
fAngleU0 = acos((fLenL1 * cos(fAngleL) + fHoriz) / fLenU1); // górne ramię
@@ -183,7 +183,7 @@ void TAnimPant::DSAx()
// osi obrotu dolnego ramienia
fHeight = 0.09353; // wysokość ślizgu ponad oś obrotu
fWidth = 0.4969; // połowa szerokości ślizgu
- fAngleL0 = DegToRad(2.8547285515689267247882521833308);
+ fAngleL0 = glm::radians(2.8547285515689267247882521833308);
fAngleL = fAngleL0; // początkowy kąt dolnego ramienia
// fAngleU0=acos((1.22*cos(fAngleL)+0.535)/1.755); //górne ramię
fAngleU0 = acos((fLenL1 * cos(fAngleL) + fHoriz) / fLenU1); // górne ramię
@@ -697,8 +697,8 @@ void TDynamicObject::UpdateDoorPlug(TAnim *pAnim) {
void TDynamicObject::UpdatePant(TAnim *pAnim)
{ // animacja pantografu - 4 obracane ramiona, ślizg piąty
float a, b, c;
- a = RadToDeg(pAnim->fParamPants->fAngleL - pAnim->fParamPants->fAngleL0);
- b = RadToDeg(pAnim->fParamPants->fAngleU - pAnim->fParamPants->fAngleU0);
+ a = glm::degrees(pAnim->fParamPants->fAngleL - pAnim->fParamPants->fAngleL0);
+ b = glm::degrees(pAnim->fParamPants->fAngleU - pAnim->fParamPants->fAngleU0);
c = a + b;
if (pAnim->smElement[0])
pAnim->smElement[0]->SetRotate(float3(-1, 0, 0), a); // dolne ramie 1
@@ -724,7 +724,7 @@ void TDynamicObject::UpdatePlatformTranslate( TAnim *pAnim ) {
pAnim->smAnimated->SetTranslate(
glm::vec3{
- interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ),
+ std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ),
0.0,
0.0 } );
}
@@ -741,7 +741,7 @@ void TDynamicObject::UpdatePlatformRotate( TAnim *pAnim ) {
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
- interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ) );
+ std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ) );
}
// mirror animation, rotate
@@ -758,11 +758,11 @@ void TDynamicObject::UpdateMirror( TAnim *pAnim ) {
if( pAnim->iNumber & 1 )
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
- interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) );
+ std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) );
else
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
- interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) );
+ std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) );
}
// wipers
@@ -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; }
@@ -1354,7 +1354,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist)
if( cabsection ) {
// check whether we're still processing cab sections
auto const §ionname { section.compartment->pName };
- cabsection &= ( ( sectionname.size() >= 4 ) && ( starts_with( sectionname, "cab" ) ) );
+ cabsection &= ( ( sectionname.size() >= 4 ) && sectionname.starts_with("cab") );
}
// TODO: add cablight devices
auto const sectionlightlevel { section.light_level * ( cabsection ? 1.0f : MoverParameters->CompartmentLights.intensity ) };
@@ -2023,7 +2023,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
if (ConversionError == 666)
ErrorLog( "Bad vehicle: failed to locate definition file \"" + BaseDir + "/" + Type_Name + ".fiz" + "\"" );
else {
- ErrorLog( "Bad vehicle: failed to load definition from file \"" + BaseDir + "/" + Type_Name + ".fiz\" (error " + to_string( ConversionError ) + ")" );
+ ErrorLog( "Bad vehicle: failed to load definition from file \"" + BaseDir + "/" + Type_Name + ".fiz\" (error " + std::to_string( ConversionError ) + ")" );
}
return 0.0; // zerowa długość to brak pojazdu
}
@@ -2466,11 +2466,11 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
if( mdModel ) {
// jeśli ma w czym szukać
for( int i = 0; i < 2; i++ ) {
- asAnimName = std::string( "buffer_left0" ) + to_string( i + 1 );
+ asAnimName = std::string( "buffer_left0" ) + std::to_string( i + 1 );
smBuforLewy[ i ] = mdModel->GetFromName( asAnimName );
if( smBuforLewy[ i ] )
smBuforLewy[ i ]->WillBeAnimated(); // ustawienie flagi animacji
- asAnimName = std::string( "buffer_right0" ) + to_string( i + 1 );
+ asAnimName = std::string( "buffer_right0" ) + std::to_string( i + 1 );
smBuforPrawy[ i ] = mdModel->GetFromName( asAnimName );
if( smBuforPrawy[ i ] )
smBuforPrawy[ i ]->WillBeAnimated();
@@ -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"
@@ -2753,7 +2753,7 @@ void TDynamicObject::Move(double fDistance)
case e_tunnel: { shadefrom = 0.2f; break; }
default: {break; }
}
- fShade = interpolate( shadefrom, shadeto, static_cast( d ) );
+ fShade = std::lerp( shadefrom, shadeto, static_cast( d ) );
/*
switch (t0->eEnvironment)
{ // typ zmiany oświetlenia - zakładam, że
@@ -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 = std::lerp( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) );
}
void
@@ -3165,7 +3165,7 @@ bool TDynamicObject::Update(double dt, double dt1)
// ts.R=ComputeRadius(Axle1.pPosition,Axle2.pPosition,Axle3.pPosition,Axle0.pPosition);
// Ra: składową pochylenia wzdłużnego mamy policzoną w jednostkowym wektorze
// vFront
- ts.Len = 1.0; // Max0R(MoverParameters->BDist,MoverParameters->ADist);
+ ts.Len = 1.0; // std::max(MoverParameters->BDist,MoverParameters->ADist);
ts.dHtrack = -vFront.y; // Axle1.pPosition.y-Axle0.pPosition.y; //wektor
// między skrajnymi osiami
// (!!!odwrotny)
@@ -3278,12 +3278,12 @@ bool TDynamicObject::Update(double dt, double dt1)
MoverParameters->CheckEIMIC(dt1);
MoverParameters->CheckSpeedCtrl(dt1);
- auto eimic = Min0R(MoverParameters->eimic, MoverParameters->eimicSpeedCtrl);
+ auto eimic = std::min(MoverParameters->eimic, MoverParameters->eimicSpeedCtrl);
MoverParameters->eimic_real = eimic;
if (MoverParameters->EIMCtrlType == 2 && MoverParameters->MainCtrlPos == 0)
eimic = -1.0;
- MoverParameters->SendCtrlToNext("EIMIC", Max0R(0, eimic), MoverParameters->CabActive);
- auto LBR = Max0R(-eimic, 0);
+ MoverParameters->SendCtrlToNext("EIMIC", std::max(0., eimic), MoverParameters->CabActive);
+ auto LBR = std::max(-eimic, 0.);
auto eim_lb = (Mechanik->AIControllFlag || !MoverParameters->LocHandleTimeTraxx ? 0 : MoverParameters->eim_localbrake);
// 1. ustal wymagana sile hamowania calego pociagu
@@ -3379,7 +3379,7 @@ bool TDynamicObject::Update(double dt, double dt1)
if ((Fzad > 1) && (!MEDLogFile.is_open()) && (MoverParameters->Vel > 1))
{
MEDLogFile.open(
- "MEDLOGS/" + MoverParameters->Name + "_" + to_string( ++MEDLogCount ) + ".csv",
+ "MEDLOGS/" + MoverParameters->Name + "_" + std::to_string( ++MEDLogCount ) + ".csv",
std::ios::in | std::ios::out | std::ios::trunc );
MEDLogFile << "t\tVel\tMasa\tOsie\tFmaxPN\tFmaxED\tFfulED\tFrED\tFzad\tFzadED\tFzadPN";
for(int k=1;k<=np;k++)
@@ -3484,17 +3484,17 @@ bool TDynamicObject::Update(double dt, double dt1)
if ((FzEP[i] > 0.01) &&
(FzEP[i] >
p->MoverParameters->TotalMass * p->MoverParameters->eimc[eimc_p_eped] +
- Min0R(p->MoverParameters->eimv[eimv_Fmax], 0) * 1000) &&
+ std::min(p->MoverParameters->eimv[eimv_Fmax], 0.) * 1000) &&
(!PrzekrF[i]))
{
- float przek1 = -Min0R(p->MoverParameters->eimv[eimv_Fmax], 0) * 1000 +
+ float przek1 = -std::min(p->MoverParameters->eimv[eimv_Fmax], 0.) * 1000 +
FzEP[i] -
p->MoverParameters->TotalMass *
p->MoverParameters->eimc[eimc_p_eped] * 0.999;
PrzekrF[i] = true;
test = true;
nPrzekrF++;
- przek1 = Min0R(przek1, FzEP[i]);
+ przek1 = std::min(przek1, FzEP[i]);
FzEP[i] -= przek1;
if (FzEP[i] < 0)
FzEP[i] = 0;
@@ -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) *
@@ -3683,9 +3683,9 @@ bool TDynamicObject::Update(double dt, double dt1)
if( MoverParameters->Vel > 0 ) {
// TODO: track quality and/or environment factors as separate subroutine
auto volume =
- interpolate(
+ std::lerp(
0.8, 1.2,
- clamp(
+ std::clamp(
MyTrack->iQualityFlag / 10.0,
0.0, 1.5 ) );
switch( MyTrack->eEnvironment ) {
@@ -3727,41 +3727,23 @@ bool TDynamicObject::Update(double dt, double dt1)
// crude bump simulation, drop down on even axles, move back up on
// the odd ones
// MoverParameters->AccVert += (MoverParameters->Vel*0.1f) *
- if(MyTrack->eType == tt_Normal)
+ static double minV, maxV;
+ std::tie(minV, maxV) = std::minmax(MoverParameters->Vmax, MoverParameters->Vmax - (MoverParameters->Vel + MoverParameters->Vmax * 0.32f));
+ double precalculatedValue = (std::clamp(0.0, minV, maxV)) * .05f * (MyTrack->iDamageFlag * 0.25f);
+ if (MyTrack->eType == tt_Normal)
{
- MoverParameters->AccVert +=
- clamp(0.0, 4.0,
- (clamp(0.0, MoverParameters->Vmax,
- MoverParameters->Vmax -
- (MoverParameters->Vel +
- MoverParameters->Vmax * 0.32f))) *
- .05f * (MyTrack->iDamageFlag * 0.25f));
+ std::tie(minV, maxV) = std::minmax(4.0, precalculatedValue);
+ MoverParameters->AccVert += std::clamp(0.0, minV, maxV);
+ }
+ else if (MyTrack->eType == tt_Switch)
+ {
+ std::tie(minV, maxV) = std::minmax(1.0, precalculatedValue);
+ double accHorizontal = std::clamp(0.0, minV, maxV) * ((axleindex % 2) != 0 ? 1 : -1);
+ MoverParameters->AccS += accHorizontal;
+ MoverParameters->AccN += accHorizontal;
+ std::tie(minV, maxV) = std::minmax(2.0, precalculatedValue);
+ MoverParameters->AccVert += std::clamp(0.0, minV, maxV);
}
- if (MyTrack->eType == tt_Switch){
- MoverParameters->AccS +=
- clamp(0.0, 1.0,
- (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,
- 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,
- MoverParameters->Vmax -
- (MoverParameters->Vel +
- MoverParameters->Vmax * 0.32f))) *
- .05f * (MyTrack->iDamageFlag * 0.25f));
- }
}
}
++axleindex;
@@ -4354,7 +4336,7 @@ bool TDynamicObject::FastUpdate(double dt)
modelRot.z };
// McZapkie: parametry powinny byc pobierane z toru
// ts.R=MyTrack->fRadius;
- // ts.Len= Max0R(MoverParameters->BDist,MoverParameters->ADist);
+ // ts.Len= std::max(MoverParameters->BDist,MoverParameters->ADist);
// ts.dHtrack=Axle1.pPosition.y-Axle0.pPosition.y;
// ts.dHrail=((Axle1.GetRoll())+(Axle0.GetRoll()))*0.5f;
// tp.Width=MyTrack->fTrackWidth;
@@ -4455,12 +4437,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 +4473,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 );
@@ -4634,12 +4616,12 @@ void TDynamicObject::RenderSounds() {
m_emergencybrakeflow = (
m_emergencybrakeflow == 0.0 ?
MoverParameters->EmergencyValveFlow :
- interpolate( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) );
+ std::lerp( 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 ) {
@@ -4651,7 +4633,7 @@ void TDynamicObject::RenderSounds() {
if( m_lastbrakepressure != -1.f ) {
// calculate rate of pressure drop in brake cylinder, once it's been initialized
auto const brakepressuredifference{ m_lastbrakepressure - MoverParameters->BrakePress };
- m_brakepressurechange = interpolate( m_brakepressurechange, brakepressuredifference / dt, 0.05f );
+ m_brakepressurechange = std::lerp( m_brakepressurechange, brakepressuredifference / dt, 0.05f );
}
m_lastbrakepressure = MoverParameters->BrakePress;
// ensure some basic level of volume and scale it up depending on pressure in the cylinder; scale this by the air release rate
@@ -4674,9 +4656,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,12 +4696,12 @@ 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
.pitch( rsBrake.m_frequencyoffset + MoverParameters->Vel * rsBrake.m_frequencyfactor )
- .gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * interpolate( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor )
+ .gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor )
.play( sound_flags::exclusive | sound_flags::looping );
}
else {
@@ -4736,7 +4718,7 @@ void TDynamicObject::RenderSounds() {
// McZapkie-280302 - pisk mocno zacisnietych hamulcow
if( MoverParameters->Vel > 2.5 ) {
- volume = rsPisk.m_amplitudeoffset + interpolate( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor;
+ volume = rsPisk.m_amplitudeoffset + std::lerp( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor;
if( volume > 0.075 ) {
rsPisk
.pitch(
@@ -4964,17 +4946,17 @@ void TDynamicObject::RenderSounds() {
// scale volume by track quality
// TODO: track quality and/or environment factors as separate subroutine
volume *=
- interpolate(
+ std::lerp(
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
if( false == bogiesound.is_combined() ) {
volume *=
- interpolate(
+ std::lerp(
0.0, 1.0,
- clamp(
+ std::clamp(
MoverParameters->Vel / 40.0,
0.0, 1.0 ) );
}
@@ -5036,7 +5018,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 {
@@ -5051,9 +5033,9 @@ void TDynamicObject::RenderSounds() {
// scale volume with curve radius and vehicle speed
volume =
std::abs( MoverParameters->AccN ) // * MoverParameters->AccN
- * interpolate(
+ * std::lerp(
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 +5292,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 +6545,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 +6999,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 ) );
}
}
}
@@ -7954,7 +7936,7 @@ material_handle TDynamicObject::DestinationFind( std::string Destination ) {
auto destinationhandle { null_handle };
- if( starts_with( Destination, "make:" ) ) {
+ if( Destination.starts_with("make:") ) {
// autogenerated texture
destinationhandle = GfxRenderer->Fetch_Material( Destination );
}
@@ -8086,13 +8068,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(
+ * std::lerp(
1.0, 0.0,
- clamp(
+ std::clamp(
( MoverParameters->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor,
0.0, 1.0 ) );
}
@@ -8103,9 +8085,9 @@ TDynamicObject::update_shake( double const Timedelta ) {
// hunting oscillation
HuntingAngle = clamp_circular( HuntingAngle + 4.0 * HuntingShake.frequency * Timedelta * MoverParameters->Vel, 360.0 );
auto const huntingamount =
- interpolate(
+ std::lerp(
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 +8307,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;
}
@@ -8376,7 +8358,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
fake_engine.stop();
}
- engine_volume = interpolate( engine_volume, volume, 0.25 );
+ engine_volume = std::lerp( engine_volume, volume, 0.25 );
if( engine_volume < 0.05 ) {
engine.stop();
}
@@ -8513,13 +8495,13 @@ 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,
0.0, 1.25 );
volume *= std::max( 0.25f, motor_momentum );
- motor_volume = interpolate( motor_volume, volume, 0.25 );
+ motor_volume = std::lerp( motor_volume, volume, 0.25 );
if( motor_volume >= 0.05 ) {
// apply calculated parameters to all motor instances
for( auto &motor : motors ) {
diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp
index cf5c2c98..1b68561b 100644
--- a/vehicle/Gauge.cpp
+++ b/vehicle/Gauge.cpp
@@ -273,7 +273,7 @@ TGauge::Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad ) {
>> soundproofing[ 5 ];
Scratchpad.soundproofing = soundproofing;
}
- else if( starts_with( key, "sound" ) ) {
+ else if( key.starts_with("sound") ) {
// sounds assigned to specific gauge values, defined by key soundX: where X = value
auto const indexstart { key.find_first_of( "-1234567890" ) };
auto const indexend { key.find_first_not_of( "-1234567890", indexstart ) };
@@ -457,9 +457,9 @@ float TGauge::GetScaledValue() const {
( false == m_interpolatescale ) ?
m_value * m_scale + m_offset :
m_value
- * interpolate(
+ * std::lerp(
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 b79657f8..324a9bde 100644
--- a/vehicle/Train.cpp
+++ b/vehicle/Train.cpp
@@ -31,6 +31,8 @@ http://mozilla.org/MPL/2.0/.
#include "application/application.h"
#include "rendering/renderer.h"
#include
+#include
+#include
/*
namespace input {
@@ -1143,7 +1145,7 @@ void TTrain::OnCommand_jointcontrollerset(TTrain *Train, command_data const &Com
}
else
{
- auto const negativeRange{clamp(1.0 - (Command.param1 * 2), 0.0, 1.0)};
+ auto const negativeRange{std::clamp(1.0 - (Command.param1 * 2), 0.0, 1.0)};
if (Train->mvControlled->SplitEDPneumaticBrake)
{
// negative range of jointctrl drives only ED braking, local pneumatic brake stays untouched.
@@ -1393,7 +1395,7 @@ void TTrain::OnCommand_DynamicBrakeControllerSet(TTrain *Train, command_data con
}
// when input source uses raw 0..1 value, snap to nearest DBPN step
- auto const target{clamp(Command.param1, 0.0, 1.0)};
+ auto const target{std::clamp(Command.param1, 0.0, 1.0)};
auto const stepCount{std::max(1, Train->mvControlled->DynamicBrakeCtrlPosNo)};
auto const snapped{std::round(target * stepCount) / stepCount};
Train->mvControlled->DynamicBrakeLevelSet(snapped);
@@ -1406,7 +1408,7 @@ void TTrain::OnCommand_secondcontrollerincrease(TTrain *Train, command_data cons
{
if (Command.action != GLFW_RELEASE)
{
- Train->mvControlled->AnPos = clamp(Train->mvControlled->AnPos + 0.025, 0.0, 1.0);
+ Train->mvControlled->AnPos = std::clamp(Train->mvControlled->AnPos + 0.025, 0.0, 1.0);
}
}
else
@@ -1611,7 +1613,7 @@ void TTrain::OnCommand_secondcontrollerdecrease(TTrain *Train, command_data cons
{
if (Command.action != GLFW_RELEASE)
{
- Train->mvControlled->AnPos = clamp(Train->mvControlled->AnPos - 0.025, 0.0, 1.0);
+ Train->mvControlled->AnPos = std::clamp(Train->mvControlled->AnPos - 0.025, 0.0, 1.0);
}
}
else
@@ -1827,7 +1829,7 @@ void TTrain::OnCommand_independentbrakeset(TTrain *Train, command_data const &Co
if (Command.action != GLFW_RELEASE)
{
- Train->mvOccupied->LocalBrakePosA = (clamp(Command.param1, 0.0, 1.0));
+ Train->mvOccupied->LocalBrakePosA = (std::clamp(Command.param1, 0.0, 1.0));
}
/*
Train->mvControlled->LocalBrakePos = (
@@ -1982,7 +1984,7 @@ void TTrain::OnCommand_trainbrakeset(TTrain *Train, command_data const &Command)
if (Command.action != GLFW_RELEASE)
{
// press or hold
- Train->mvOccupied->BrakeLevelSet(interpolate(Train->mvOccupied->Handle->GetPos(bh_MIN), Train->mvOccupied->Handle->GetPos(bh_MAX), clamp(Command.param1, 0.0, 1.0)));
+ Train->mvOccupied->BrakeLevelSet(std::lerp(Train->mvOccupied->Handle->GetPos(bh_MIN), Train->mvOccupied->Handle->GetPos(bh_MAX), std::clamp(Command.param1, 0.0, 1.0)));
}
else
{
@@ -2082,7 +2084,7 @@ void TTrain::OnCommand_trainbrakebasepressureincrease(TTrain *Train, command_dat
{
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:
@@ -2104,7 +2106,7 @@ void TTrain::OnCommand_trainbrakebasepressuredecrease(TTrain *Train, command_dat
{
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:
@@ -3530,7 +3532,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)
{
@@ -6086,7 +6088,7 @@ void TTrain::OnCommand_redmarkerstoggle(TTrain *Train, command_data const &Comma
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) ? 1 : -1), 0, 1)}; // z [-1,1] zrobić [0,1]
+ int const CouplNr{std::clamp(vehicle->DirectionGet() * (glm::dot(locationHead, locationHead) > glm::dot(locationRear, locationRear) ? 1 : -1), 0, 1)}; // z [-1,1] zrobić [0,1]
auto const lightset{light::redmarker_left | light::redmarker_right};
@@ -6109,7 +6111,7 @@ void TTrain::OnCommand_endsignalstoggle(TTrain *Train, command_data const &Comma
return;
}
int const CouplNr{
- clamp(vehicle->DirectionGet() * (glm::length2(vehicle->HeadPosition() - glm::dvec3(Command.location)) > glm::length2(vehicle->RearPosition() - glm::dvec3(Command.location)) ? 1 : -1), 0,
+ std::clamp(vehicle->DirectionGet() * (glm::length2(vehicle->HeadPosition() - glm::dvec3(Command.location)) > glm::length2(vehicle->RearPosition() - glm::dvec3(Command.location)) ? 1 : -1), 0,
1)}; // z [-1,1] zrobić [0,1]
auto const lightset{light::rearendsignals};
@@ -8139,7 +8141,7 @@ void TTrain::OnCommand_radiochannelset(TTrain *Train, command_data const &Comman
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);
}
}
@@ -8280,7 +8282,7 @@ 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;
}
@@ -8707,11 +8709,11 @@ bool TTrain::Update(double const Deltatime)
if ((in < 8) && (p->MoverParameters->eimc[eimc_p_Pmax] > 1))
{
fEIMParams[1 + in][0] = p->MoverParameters->eimv[eimv_Fmax];
- fEIMParams[1 + in][1] = Max0R(fEIMParams[1 + in][0], 0);
- fEIMParams[1 + in][2] = -Min0R(fEIMParams[1 + in][0], 0);
- fEIMParams[1 + in][3] = p->MoverParameters->eimv[eimv_Fmax] / Max0R(p->MoverParameters->eimv[eimv_Fful], 1);
- fEIMParams[1 + in][4] = Max0R(fEIMParams[1 + in][3], 0);
- fEIMParams[1 + in][5] = -Min0R(fEIMParams[1 + in][3], 0);
+ fEIMParams[1 + in][1] = std::max(fEIMParams[1 + in][0], 0.f);
+ fEIMParams[1 + in][2] = -std::min(fEIMParams[1 + in][0], 0.f);
+ fEIMParams[1 + in][3] = p->MoverParameters->eimv[eimv_Fmax] / std::max(p->MoverParameters->eimv[eimv_Fful], 1.);
+ fEIMParams[1 + in][4] = std::max(fEIMParams[1 + in][3], 0.f);
+ fEIMParams[1 + in][5] = -std::min(fEIMParams[1 + in][3], 0.f);
fEIMParams[1 + in][6] = p->MoverParameters->eimv[eimv_If];
fEIMParams[1 + in][7] = p->MoverParameters->eimv[eimv_U];
fEIMParams[1 + in][8] = p->MoverParameters->Itot; // p->MoverParameters->eimv[eimv_Ipoj];
@@ -8772,8 +8774,8 @@ bool TTrain::Update(double const Deltatime)
// fEIMParams[0][3] =
// mvControlled->eimv[eimv_Fzad] - mvOccupied->LocalBrakeRatio(); // procent zadany
fEIMParams[0][3] = mvOccupied->eimic_real;
- fEIMParams[0][4] = Max0R(fEIMParams[0][3], 0);
- fEIMParams[0][5] = -Min0R(fEIMParams[0][3], 0);
+ fEIMParams[0][4] = std::max(fEIMParams[0][3], 0.f);
+ fEIMParams[0][5] = -std::min(fEIMParams[0][3], 0.f);
fEIMParams[0][1] = fEIMParams[0][4] * mvControlled->eimv[eimv_Fful];
fEIMParams[0][2] = fEIMParams[0][5] * mvControlled->eimv[eimv_Fful];
fEIMParams[0][0] = fEIMParams[0][1] - fEIMParams[0][2];
@@ -9489,7 +9491,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);
}
@@ -9497,7 +9499,7 @@ 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);
}
@@ -9505,7 +9507,7 @@ bool TTrain::Update(double const Deltatime)
{
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);
}
@@ -9530,7 +9532,7 @@ bool TTrain::Update(double const Deltatime)
{
// 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), 0.0, 1.0);
+ auto const b = std::clamp(Console::AnalogCalibrateGet(1), 0.f, 1.f);
mvOccupied->LocalBrakePosA = b;
ggLocalBrake.UpdateValue(b * LocalBrakePosNo);
}
@@ -9820,7 +9822,7 @@ void TTrain::update_sounds(double const Deltatime)
{
// calculate rate of pressure drop in local brake cylinder, once it's been initialized
auto const brakepressuredifference{mvOccupied->LocBrakePress - m_lastlocalbrakepressure};
- m_localbrakepressurechange = interpolate(m_localbrakepressurechange, 10 * (brakepressuredifference / Deltatime), 0.1f);
+ m_localbrakepressurechange = std::lerp(m_localbrakepressurechange, 10 * (brakepressuredifference / Deltatime), 0.1f);
}
m_lastlocalbrakepressure = mvOccupied->LocBrakePress;
// local brake, release
@@ -9828,7 +9830,7 @@ void TTrain::update_sounds(double const Deltatime)
{
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
@@ -9847,7 +9849,7 @@ void TTrain::update_sounds(double const Deltatime)
{
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
@@ -9869,7 +9871,7 @@ void TTrain::update_sounds(double const Deltatime)
// upuszczanie z PG
if (rsHiss)
{
- fPPress = interpolate(fPPress, static_cast(mvOccupied->Handle->GetSound(s_fv4a_b)), 0.05f);
+ fPPress = std::lerp(fPPress, static_cast(mvOccupied->Handle->GetSound(s_fv4a_b)), 0.05f);
volume = (fPPress > 0 ? rsHiss->m_amplitudefactor * fPPress * 0.25 + rsHiss->m_amplitudeoffset : 0);
if (volume * brakevolumescale > 0.05)
{
@@ -9884,7 +9886,7 @@ void TTrain::update_sounds(double const Deltatime)
// napelnianie PG
if (rsHissU)
{
- fNPress = interpolate(fNPress, static_cast(mvOccupied->Handle->GetSound(s_fv4a_u)), 0.25f);
+ fNPress = std::lerp(fNPress, static_cast(mvOccupied->Handle->GetSound(s_fv4a_u)), 0.25f);
volume = (fNPress > 0 ? rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset : 0);
if (volume * brakevolumescale > 0.05)
{
@@ -9960,7 +9962,7 @@ void TTrain::update_sounds(double const Deltatime)
// napelnianie PG
if (rsHissU)
{
- fNPress = (4.0f * fNPress + Min0R(0.0, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
+ fNPress = (4.0f * fNPress + std::min(0.0, mvOccupied->dpMainValve)) / (4.0f + 1.0f);
volume = (fNPress < 0.0f ? -1.0 * rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset : 0.0);
if (volume > 0.01)
{
@@ -9981,9 +9983,9 @@ void TTrain::update_sounds(double const Deltatime)
{
auto const brakeforceratio{
- clamp(mvOccupied->UnitBrakeForce / std::max(1.0, mvOccupied->BrakeForceR(1.0, mvOccupied->Vel) / (mvOccupied->NAxles * std::max(1, mvOccupied->NBpA))), 0.0, 1.0)};
+ 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
- volume = (FreeFlyModeFlag ? 0.0 : rsBrake->m_amplitudeoffset + std::sqrt(brakeforceratio * interpolate(0.4, 1.0, (mvOccupied->Vel / (1 + mvOccupied->Vmax)))) * rsBrake->m_amplitudefactor);
+ volume = (FreeFlyModeFlag ? 0.0 : rsBrake->m_amplitudeoffset + std::sqrt(brakeforceratio * std::lerp(0.4, 1.0, (mvOccupied->Vel / (1 + mvOccupied->Vmax)))) * rsBrake->m_amplitudefactor);
rsBrake->pitch(rsBrake->m_frequencyoffset + mvOccupied->Vel * rsBrake->m_frequencyfactor);
rsBrake->gain(volume);
rsBrake->play(sound_flags::exclusive | sound_flags::looping);
@@ -10057,8 +10059,8 @@ void TTrain::update_sounds(double const Deltatime)
update_sounds_runningnoise(*rsHuntingNoise);
// modify calculated sound volume by hunting amount
- auto const huntingamount = interpolate(
- 0.0, 1.0, clamp((mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin) / (DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin), 0.0, 1.0));
+ auto const huntingamount = std::lerp(
+ 0.0, 1.0, std::clamp((mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin) / (DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin), 0.0, 1.0));
rsHuntingNoise->gain(rsHuntingNoise->gain() * huntingamount);
}
@@ -10199,7 +10201,7 @@ void TTrain::update_sounds_resonancenoise(sound_source &Sound)
auto const frequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer};
// volume calculation
- auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * interpolate(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0
+ auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0
if (volume > 0.05)
{
@@ -10218,22 +10220,22 @@ void TTrain::update_sounds_runningnoise(sound_source &Sound)
auto const frequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer};
// volume calculation
- auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * interpolate(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0,
+ auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0,
0.5); // scale base volume between 0.5-1.0
if (std::abs(mvOccupied->nrot) > 0.01)
{
// hamulce wzmagaja halas
- auto const brakeforceratio{(clamp(mvOccupied->UnitBrakeForce / std::max(1.0, mvOccupied->BrakeForceR(1.0, mvOccupied->Vel) / (mvOccupied->NAxles * std::max(1, mvOccupied->NBpA))), 0.0, 1.0))};
+ auto const brakeforceratio{(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))};
volume *= 1 + 0.125 * brakeforceratio;
}
// scale volume by track quality
// TODO: track quality and/or environment factors as separate subroutine
- volume *= interpolate(0.8, 1.2, clamp(DynamicObject->MyTrack->iQualityFlag / 20.0, 0.0, 1.0));
+ volume *= std::lerp(0.8, 1.2, std::clamp(DynamicObject->MyTrack->iQualityFlag / 20.0, 0.0, 1.0));
// for single sample sounds muffle the playback at low speeds
if (false == Sound.is_combined())
{
- volume *= interpolate(0.0, 1.0, clamp(mvOccupied->Vel / 25.0, 0.0, 1.0));
+ volume *= std::lerp(0.0, 1.0, std::clamp(mvOccupied->Vel / 25.0, 0.0, 1.0));
}
if (volume > 0.05)
@@ -10825,7 +10827,7 @@ glm::dvec3 TTrain::MirrorPosition(bool lewe)
auto const shiftdirection{(lewe ? -1 : 1) * (iCabn == 2 ? 1 : -1)};
return DynamicObject->mMatrix *
- glm::dvec4(mvOccupied->Dim.W * (0.5 * shiftdirection) + (0.2 * shiftdirection), 1.5 + Cabine[iCabn].CabPos1.y, interpolate(Cabine[iCabn].CabPos1.z, Cabine[iCabn].CabPos2.z, 0.5), 1.0);
+ glm::dvec4(mvOccupied->Dim.W * (0.5 * shiftdirection) + (0.2 * shiftdirection), 1.5 + Cabine[iCabn].CabPos1.y, std::lerp(Cabine[iCabn].CabPos1.z, Cabine[iCabn].CabPos2.z, 0.5), 1.0);
};
void TTrain::DynamicSet(TDynamicObject *d)
@@ -11019,8 +11021,8 @@ glm::dvec3 TTrain::clamp_inside(glm::dvec3 const &Point) const
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)};
+ return {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()
@@ -12178,7 +12180,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/EvLaunch.cpp b/world/EvLaunch.cpp
index a59af9d1..eebc4255 100644
--- a/world/EvLaunch.cpp
+++ b/world/EvLaunch.cpp
@@ -24,7 +24,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/parser.h"
#include "Console.h"
#include "simulation/simulationtime.h"
-#include "utilities/utilities.h"
//---------------------------------------------------------------------------
@@ -151,7 +150,7 @@ bool TEventLauncher::Load(cParser *parser)
WriteLog(
"EventLauncher at "
+ std::to_string( iHour ) + ":"
- + ( iMinute < 10 ? "0" : "" ) + to_string( iMinute )
+ + ( iMinute < 10 ? "0" : "" ) + std::to_string( iMinute )
+ " (" + asEvent1Name
+ ( asEvent2Name != "none" ? " / " + asEvent2Name : "" )
+ ")" ); // wyświetlenie czasu
@@ -317,8 +316,8 @@ TEventLauncher::export_as_text_( std::ostream &Output ) const {
<< "condition "
<< asMemCellName << ' '
<< szText << ' '
- << ( ( iCheckMask & basic_event::flags::value1 ) != 0 ? to_string( fVal1 ) : "*" ) << ' '
- << ( ( iCheckMask & basic_event::flags::value2 ) != 0 ? to_string( fVal2 ) : "*" ) << ' ';
+ << ( ( iCheckMask & basic_event::flags::value1 ) != 0 ? std::to_string( fVal1 ) : "*" ) << ' '
+ << ( ( iCheckMask & basic_event::flags::value2 ) != 0 ? std::to_string( fVal2 ) : "*" ) << ' ';
}
// footer
Output
diff --git a/world/Event.cpp b/world/Event.cpp
index 10a71bac..fad60bc4 100644
--- a/world/Event.cpp
+++ b/world/Event.cpp
@@ -275,8 +275,8 @@ basic_event::event_conditions::export_as_text( std::ostream &Output ) const {
Output
<< "memcompareex "
<< ( ( flags & flags::text ) == 0 ? "*" : memcompare_text + ' ' + to_string( memcompare_text_operator ) ) << ' '
- << ( ( flags & flags::value1 ) == 0 ? "*" : to_string( memcompare_value1 ) + ' ' + to_string( memcompare_value1_operator ) ) << ' '
- << ( ( flags & flags::value2 ) == 0 ? "*" : to_string( memcompare_value2 ) + ' ' + to_string( memcompare_value2_operator ) ) << ' ';
+ << ( ( flags & flags::value1 ) == 0 ? "*" : std::to_string( memcompare_value1 ) + ' ' + to_string( memcompare_value1_operator ) ) << ' '
+ << ( ( flags & flags::value2 ) == 0 ? "*" : std::to_string( memcompare_value2 ) + ' ' + to_string( memcompare_value2_operator ) ) << ' ';
}
}
}
@@ -298,7 +298,7 @@ basic_event::deserialize( cParser &Input, scene::scratch_data &Scratchpad ) {
Input >> token;
deserialize_targets( token );
- if( starts_with( m_name, "none_" ) ) {
+ if( m_name.starts_with("none_") ) {
m_ignored = true; // Ra: takie są ignorowane
}
@@ -557,8 +557,8 @@ updatevalues_event::export_as_text_( std::ostream &Output ) const {
Output
<< ( ( m_input.flags & flags::text ) == 0 ? "*" : m_input.data_text ) << ' '
- << ( ( m_input.flags & flags::value1 ) == 0 ? "*" : to_string( m_input.data_value_1 ) ) << ' '
- << ( ( m_input.flags & flags::value2 ) == 0 ? "*" : to_string( m_input.data_value_2 ) ) << ' ';
+ << ( ( m_input.flags & flags::value1 ) == 0 ? "*" : std::to_string( m_input.data_value_1 ) ) << ' '
+ << ( ( m_input.flags & flags::value2 ) == 0 ? "*" : std::to_string( m_input.data_value_2 ) ) << ' ';
m_conditions.export_as_text( Output );
}
@@ -716,7 +716,7 @@ putvalues_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
Input.getTokens( 1, false ); // komendy 'case sensitive'
Input >> token;
// command type, previously held in param 6
- if( starts_with( token, "PassengerStopPoint:" ) ) {
+ if( token.starts_with("PassengerStopPoint:") ) {
if( contains( token, '#' ) ) {
token.erase( token.find( '#' ) ); // obcięcie unikatowości
}
@@ -835,8 +835,9 @@ putvalues_event::export_as_text_( std::ostream &Output ) const {
bool
putvalues_event::is_command_for_owner( input_data const &Input ) const {
- if( starts_with( Input.data_text, "Load=" ) ) { return false; }
- if( starts_with( Input.data_text, "UnLoad=" ) ) { return false; }
+ if (Input.data_text.starts_with("Load=") || Input.data_text.starts_with("UnLoad=")) {
+ return false;
+ }
// TBD, TODO: add other exceptions
return true;
@@ -1051,7 +1052,7 @@ whois_event::run_() {
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[next station: " + nextstop + "], "
+ "[X], "
+ "[stop at next station: " + ( isstop != 0 ? "yes" : "no" ) + "]" );
@@ -1065,7 +1066,7 @@ whois_event::run_() {
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[name: " + m_activator->asName + "], "
+ "[X], "
+ "[X]" );
@@ -1097,7 +1098,7 @@ whois_event::run_() {
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[type: " + m_activator->MoverParameters->TypeName + "], "
+ "[consist brake level: " + to_string( consistbrakelevel, 2 ) + "], "
+ "[obstacle distance: " + to_string( collisiondistance, 2 ) + " m]" );
@@ -1111,7 +1112,7 @@ whois_event::run_() {
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[load type: " + m_activator->MoverParameters->LoadType.name + "], "
+ "[current load: " + to_string( m_activator->MoverParameters->LoadAmount, 2 ) + "], "
+ "[max load: " + to_string( m_activator->MoverParameters->MaxLoad, 2 ) + "]" );
@@ -1126,9 +1127,9 @@ whois_event::run_() {
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[destination: " + m_activator->asDestination + "], "
- + "[direction: " + to_string( m_activator->DirectionGet() ) + "], "
+ + "[direction: " + std::to_string( m_activator->DirectionGet() ) + "], "
+ "[engine power: " + to_string( m_activator->MoverParameters->Power, 2 ) + "]" );
}
// +0
@@ -1142,9 +1143,9 @@ whois_event::run_() {
0, // 1, gdy ma tu zatrzymanie
m_input.flags & ( flags::text | flags::value1 | flags::value2 ) );
WriteLog(
- "Type: WhoIs (" + to_string( m_input.flags ) + ") - "
+ "Type: WhoIs (" + std::to_string( m_input.flags ) + ") - "
+ "[train: " + m_activator->Mechanik->TrainName() + "], "
- + "[stations left: " + to_string( m_activator->Mechanik->StationCount() - m_activator->Mechanik->StationIndex() ) + "], "
+ + "[stations left: " + std::to_string( m_activator->Mechanik->StationCount() - m_activator->Mechanik->StationIndex() ) + "], "
+ "[stop at next station: " + ( m_activator->Mechanik->IsStop() ? "yes" : "no") + "]" );
}
}
@@ -1268,7 +1269,7 @@ multi_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
}
else {
// potentially valid event name
- if( starts_with( token, "none_" ) ) {
+ if( token.starts_with("none_") ) {
// eventy rozpoczynające się od "none_" są ignorowane
WriteLog( "Multi-event \"" + m_name + "\" ignored link to event \"" + token + "\"" );
}
@@ -1394,7 +1395,7 @@ sound_event::run_() {
WriteLog(
"Type: Sound - [" + std::string( m_soundmode == 1 ? "play" : m_soundmode == -1 ? "loop" : "stop" ) + "]"
- + ( m_soundradiochannel > 0 ? " [channel " + to_string( m_soundradiochannel ) + "]" : "" ) );
+ + ( m_soundradiochannel > 0 ? " [channel " + std::to_string( m_soundradiochannel ) + "]" : "" ) );
for( auto &target : m_sounds ) {
auto *targetsound = std::get( target );
if( targetsound == nullptr ) { continue; }
@@ -1507,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
}
@@ -1650,7 +1651,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
>> m_animationparams[ 2 ]
>> m_animationparams[ 3 ];
}
- else if( ends_with( token, ".vmd" ) ) // na razie tu, może będzie inaczej
+ else if( token.ends_with(".vmd") ) // na razie tu, może będzie inaczej
{ // animacja z pliku VMD
{
m_animationfilename = token;
@@ -1770,7 +1771,7 @@ lights_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) {
Input >> m_lights[ lightidx++ ];
}
else {
- ErrorLog( "Bad event: \"" + m_name + "\" (type: " + type() + ") with more than " + to_string( lightcountlimit ) + " parameters" );
+ ErrorLog( "Bad event: \"" + m_name + "\" (type: " + type() + ") with more than " + std::to_string( lightcountlimit ) + " parameters" );
}
}
while( lightidx < lightcountlimit ) {
@@ -2305,15 +2306,15 @@ event_manager::insert( basic_event *Event ) {
return false;
}
// tymczasowo wyjątki:
- else if( ends_with( Event->m_name, "lineinfo:" ) ) {
+ else if( Event->m_name.ends_with("lineinfo:") ) {
// tymczasowa utylizacja duplikatów W5
return false;
}
- else if( ends_with( Event->m_name, "_warning" ) ) {
+ else if( Event->m_name.ends_with("_warning") ) {
// tymczasowa utylizacja duplikatu z trąbieniem
return false;
}
- else if( ends_with( Event->m_name, "_shp" ) ) {
+ else if( Event->m_name.ends_with("_shp") ) {
// nie podlegają logowaniu
// tymczasowa utylizacja duplikatu SHP
return false;
diff --git a/world/MemCell.cpp b/world/MemCell.cpp
index a5e79ce0..71c48c97 100644
--- a/world/MemCell.cpp
+++ b/world/MemCell.cpp
@@ -71,7 +71,7 @@ TCommandType TMemCell::CommandCheck()
eCommand = TCommandType::cm_OutsideStation;
bCommand = false; // tego nie powinno być w komórce
}
- else if( starts_with( szText, "PassengerStopPoint:" ) ) // porównanie początków
+ else if( szText.starts_with("PassengerStopPoint:") ) // porównanie początków
{
eCommand = TCommandType::cm_PassengerStopPoint;
bCommand = false; // tego nie powinno być w komórce
diff --git a/world/Segment.cpp b/world/Segment.cpp
index 9ddccae4..41bfacf0 100644
--- a/world/Segment.cpp
+++ b/world/Segment.cpp
@@ -198,7 +198,7 @@ double TSegment::GetTFromS(double const s) const
// initial guess for Newton's method
double fTolerance = 0.001;
double fRatio = s / RombergIntegral(0, 1);
- double fTime = interpolate( 0.0, 1.0, fRatio );
+ double fTime = std::lerp( 0.0, 1.0, fRatio );
int iteration = 0;
double fDifference {}; // exposed for debug down the road
@@ -243,7 +243,7 @@ double TSegment::ComputeLength() const // McZapkie-150503: dlugosc miedzy punkta
for (int i = 1; i <= m; i++)
{
t = double(i) / double(m); // wyznaczenie parametru na krzywej z przedziału (0,1>
- // tmp=Interpolate(t,p1,cp1,cp2,p2);
+ // tmp=std::lerp(t,p1,cp1,cp2,p2);
tmp = RaInterpolate0(t); // obliczenie punktu dla tego parametru
t = glm::length(tmp - last); // obliczenie długości wektora
l += t; // zwiększenie wyliczanej długości
@@ -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 ] ) },
@@ -323,15 +323,15 @@ Math3D::vector3 TSegment::GetPoint(double const fDistance) const
if (bCurve)
{ // można by wprowadzić uproszczony wzór dla okręgów płaskich
double t = GetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera
- // return Interpolate(t,Point1,CPointOut,CPointIn,Point2);
+ // return std::lerp(t,Point1,CPointOut,CPointIn,Point2);
return RaInterpolate(t);
}
else {
// wyliczenie dla odcinka prostego jest prostsze
return
- interpolate(
+ std::lerp(
Point1, Point2,
- clamp(
+ std::clamp(
fDistance / fLength,
0.0, 1.0 ) );
}
@@ -344,7 +344,7 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a
auto const t = GetTFromS(fDistance); // aproksymacja dystansu na krzywej Beziera na parametr (t)
p = FastGetPoint( t );
// przechyłka w danym miejscu (zmienia się liniowo)
- a.x = interpolate( fRoll1, fRoll2, t );
+ a.x = std::lerp( fRoll1, fRoll2, t );
// pochodna jest 3*A*t^2+2*B*t+C
auto const tangent = t * ( t * 3.0 * vA + vB + vB ) + vC;
// pochylenie krzywej (w pionie)
@@ -357,7 +357,7 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a
auto const t = fDistance / fLength; // zerowych torów nie ma
p = FastGetPoint( t );
// przechyłka w danym miejscu (zmienia się liniowo)
- a.x = interpolate( fRoll1, fRoll2, t );
+ a.x = std::lerp( fRoll1, fRoll2, t );
a.y = fStoop; // pochylenie toru prostego
a.z = fDirection; // kierunek toru w planie
}
@@ -365,11 +365,10 @@ void TSegment::RaPositionGet(double const fDistance, glm::dvec3 &p, glm::vec3 &a
glm::dvec3 TSegment::FastGetPoint(double const t) const
{
- // return (bCurve?Interpolate(t,Point1,CPointOut,CPointIn,Point2):((1.0-t)*Point1+(t)*Point2));
+ // return (bCurve?std::lerp(t,Point1,CPointOut,CPointIn,Point2):((1.0-t)*Point1+(t)*Point2));
return (
( ( true == bCurve ) || ( iSegCount != 1 ) ) ?
- RaInterpolate( t ) :
- interpolate( Point1, Point2, t ) );
+ RaInterpolate( t ) : glm::mix(Point1, Point2, t));
}
bool TSegment::RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin, const gfx::vertex_array &ShapePoints, bool const Transition, double fTextureLength, double Texturescale, int iSkip, int iEnd, std::pair fOffsetX, glm::vec3 **p, bool bRender)
diff --git a/world/Segment.h b/world/Segment.h
index 24725d78..fe69c864 100644
--- a/world/Segment.h
+++ b/world/Segment.h
@@ -11,7 +11,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Classes.h"
#include "rendering/geometrybank.h"
-#include "utilities/utilities.h"
#include
struct map_colored_paths {
@@ -105,7 +104,7 @@ public:
inline
float
GetRoll(double const Distance) const {
- return interpolate( fRoll1, fRoll2, static_cast(Distance / fLength) ); }
+ return std::lerp( fRoll1, fRoll2, static_cast(Distance / fLength) ); }
inline
void
GetRolls(float &r1, float &r2) const {
diff --git a/world/Track.cpp b/world/Track.cpp
index 2f40a723..22e56ea8 100644
--- a/world/Track.cpp
+++ b/world/Track.cpp
@@ -26,7 +26,6 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Timer.h"
#include "utilities/Logs.h"
#include "rendering/renderer.h"
-#include "utilities/utilities.h"
// 101206 Ra: trapezoidalne drogi i tory
// 110720 Ra: rozprucie zwrotnicy i odcinki izolowane
@@ -248,20 +247,20 @@ TTrack * TTrack::NullCreate(int dir)
p1 = Segment->FastGetPoint_0();
p2 = p1 - 450.0 * glm::normalize(Segment->GetDirection1());
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk->Segment->Init(p1, p2, 5, -RadToDeg(r1), 70.0);
+ trk->Segment->Init(p1, p2, 5, -glm::degrees(r1), 70.0);
ConnectPrevPrev(trk, 0);
break;
case 1:
p1 = Segment->FastGetPoint_1();
p2 = p1 - 450.0 * glm::normalize(Segment->GetDirection2());
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk->Segment->Init(p1, p2, 5, RadToDeg(r2), 70.0);
+ trk->Segment->Init(p1, p2, 5, glm::degrees(r2), 70.0);
ConnectNextPrev(trk, 0);
break;
case 3: // na razie nie możliwe
p1 = SwitchExtension->Segments[1]->FastGetPoint_1(); // koniec toru drugiego zwrotnicy
p2 = p1 - 450.0 * glm::normalize(SwitchExtension->Segments[1]->GetDirection2()); // przedłużenie na wprost
- trk->Segment->Init(p1, p2, 5, RadToDeg(r2), 70.0); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce
+ trk->Segment->Init(p1, p2, 5, glm::degrees(r2), 70.0); // bo prosty, kontrolne wyliczane przy zmiennej przechyłce
ConnectNextPrev(trk, 0);
// trk->ConnectPrevNext(trk,dir);
SetConnections(1); // skopiowanie połączeń
@@ -290,10 +289,10 @@ TTrack * TTrack::NullCreate(int dir)
cv1 = -20.0 * glm::normalize(Segment->GetDirection1()); // pierwszy wektor kontrolny
p2 = p1 + cv1 + cv1; // 40m
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, -RadToDeg(r1), 0.0);
+ trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, -glm::degrees(r1), 0.0);
ConnectPrevPrev(trk, 0);
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, -RadToDeg(r1), 0.0);
+ trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, -glm::degrees(r1), 0.0);
trk2->iPrevDirection = 0; // zwrotnie do tego samego odcinka
break;
case 1:
@@ -301,10 +300,10 @@ TTrack * TTrack::NullCreate(int dir)
cv1 = -20.0 * glm::normalize(Segment->GetDirection2()); // pierwszy wektor kontrolny
p2 = p1 + cv1 + cv1;
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, RadToDeg(r2), 0.0);
+ trk->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(-cv1.z, cv1.y, cv1.x), p2, 2, glm::degrees(r2), 0.0);
ConnectNextPrev(trk, 0);
// bo prosty, kontrolne wyliczane przy zmiennej przechyłce
- trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, RadToDeg(r2), 0.0);
+ trk2->Segment->Init(p1, p1 + cv1, p2 + glm::dvec3(cv1.z, cv1.y, -cv1.x), p2, 2, glm::degrees(r2), 0.0);
trk2->iPrevDirection = 1; // zwrotnie do tego samego odcinka
break;
}
@@ -569,7 +568,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 +582,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 +666,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 +680,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 +731,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 +745,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 +2530,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 );
}
}
diff --git a/world/Traction.cpp b/world/Traction.cpp
index db7d033b..d660ac02 100644
--- a/world/Traction.cpp
+++ b/world/Traction.cpp
@@ -156,7 +156,7 @@ TTraction::Load( cParser *parser, glm::dvec3 const &pOrigin ) {
Init(); // przeliczenie parametrów
// calculate traction location
- location( interpolate( pPoint2, pPoint1, 0.5 ) );
+ location( glm::mix( pPoint2, pPoint1, 0.5 ) );
}
// retrieves list of the track's end points
diff --git a/world/mtable.cpp b/world/mtable.cpp
index ba560ff1..24a19336 100644
--- a/world/mtable.cpp
+++ b/world/mtable.cpp
@@ -611,7 +611,7 @@ TTrainParameters::load_sounds() {
}
// specified arrival time means it's a scheduled stop
auto const stationname { (
- ends_with( station.StationName, "_po" ) ?
+ station.StationName.ends_with("_po") ?
station.StationName.substr( 0, station.StationName.size() - 3 ) :
station.StationName ) };
diff --git a/world/station.cpp b/world/station.cpp
index 7bd18587..fd8d7067 100644
--- a/world/station.cpp
+++ b/world/station.cpp
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "world/station.h"
+#include "utilities/utilities.h"
#include "vehicle/DynObj.h"
#include "world/mtable.h"
@@ -29,9 +30,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
// HACK: determine whether current station is a (small) stop from the presence of "po" at the name end
auto const stationname { Schedule.TimeTable[ Schedule.StationIndex ].StationName };
auto const stationequipment { Schedule.TimeTable[ Schedule.StationIndex ].StationWare };
- auto const trainstop { (
- ( ends_with( stationname, "po" ) )
- || ( contains( stationequipment, "po" ) ) ) };
+ auto const trainstop {stationname.ends_with("po") || contains( stationequipment, "po" ) };
auto const maintenancestop { ( contains( stationequipment, "pt" ) ) };
// train stops exchange smaller groups than regular stations
// NOTE: this is crude and unaccurate, but for now will do