18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-24 06:09:12 +01:00

refactor(sonar): use range-based loops and ranges algorithms (cpp:S5566)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 16:13:12 +02:00
parent b6349b76e3
commit 03652a5934
8 changed files with 132 additions and 143 deletions

View File

@@ -471,23 +471,23 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string TypeNameInit,
iLights[1] = 0; // światła zgaszone iLights[1] = 0; // światła zgaszone
// inicjalizacja stalych // inicjalizacja stalych
for (int b = 0; b < ResArraySize + 1; ++b) for (auto &scheme : RList)
{ {
RList[b] = TScheme(); scheme = TScheme();
} }
RlistSize = 0; RlistSize = 0;
for (int b = 0; b < MotorParametersArraySize + 1; ++b) for (auto &motorparam : MotorParam)
{ {
MotorParam[b] = TMotorParameters(); motorparam = TMotorParameters();
} }
for (int b = 0; b < 2; ++b) for (auto &cablights : Lights)
for (int k = 0; k < 17; ++k) for (int k = 0; k < 17; ++k)
Lights[b][k] = 0; cablights[k] = 0;
for (int b = 0; b < 4; ++b) for (auto &compressorrow : CompressorList)
for (int k = 1; k < 9; ++k) for (int k = 1; k < 9; ++k)
CompressorList[b][k] = 0; compressorrow[k] = 0;
CompressorList[0][0] = 0.0; CompressorList[0][0] = 0.0;
CompressorList[1][0] = CompressorList[2][0] = CompressorList[3][0] = 1.0; CompressorList[1][0] = CompressorList[2][0] = CompressorList[3][0] = 1.0;
@@ -503,9 +503,9 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string TypeNameInit,
BrakePressureTable[-2].BrakePressureVal = -1.0; BrakePressureTable[-2].BrakePressureVal = -1.0;
BrakePressureTable[-2].FlowSpeedVal = 0.0; BrakePressureTable[-2].FlowSpeedVal = 0.0;
} }
for (int b = 0; b < 4; ++b) for (auto &delay : BrakeDelay)
{ {
BrakeDelay[b] = 0.0; delay = 0.0;
} }
for (int b = 0; b < 2; ++b) // Ra: kto tu zrobił "for b:=1 to 2 do" ??? for (int b = 0; b < 2; ++b) // Ra: kto tu zrobił "for b:=1 to 2 do" ???
@@ -518,40 +518,40 @@ TMoverParameters::TMoverParameters(double VelInitial, std::string TypeNameInit,
Couplers[b].DmaxC = 0.1; Couplers[b].DmaxC = 0.1;
Couplers[b].FmaxC = 1000.0; Couplers[b].FmaxC = 1000.0;
} }
for (int b = 0; b < 3; ++b) for (auto &cylindermult : BrakeCylMult)
{ {
BrakeCylMult[b] = 0.0; cylindermult = 0.0;
} }
for (int b = 0; b < 26; ++b) for (auto &eimcvalue : eimc)
{ {
eimc[b] = 0.0; eimcvalue = 0.0;
} }
eimc[eimc_p_eped] = 1.5; eimc[eimc_p_eped] = 1.5;
for (int b = 0; b < 2; ++b) for (auto &couplerentry : Couplers)
{ {
Couplers[b].AllowedFlag = 3; // domyślnie hak i hamulec, inne trzeba włączyć jawnie w FIZ couplerentry.AllowedFlag = 3; // domyślnie hak i hamulec, inne trzeba włączyć jawnie w FIZ
Couplers[b].CouplingFlag = 0; couplerentry.CouplingFlag = 0;
Couplers[b].Connected = nullptr; couplerentry.Connected = nullptr;
Couplers[b].ConnectedNr = 0; // Ra: to nie ma znaczenia jak nie podłączony couplerentry.ConnectedNr = 0; // Ra: to nie ma znaczenia jak nie podłączony
Couplers[b].Render = false; couplerentry.Render = false;
Couplers[b].CForce = 0.0; couplerentry.CForce = 0.0;
Couplers[b].Dist = 0.0; couplerentry.Dist = 0.0;
Couplers[b].CheckCollision = false; couplerentry.CheckCollision = false;
} }
for (int b = 0; b < 5; ++b) for (auto &brakepress : MaxBrakePress)
{ {
MaxBrakePress[b] = 0.0; brakepress = 0.0;
} }
Vel = abs(VelInitial); Vel = abs(VelInitial);
V = VelInitial / 3.6; V = VelInitial / 3.6;
for (int b = 0; b < 21; b++) for (auto &eimvvalue : eimv)
{ {
eimv[b] = 0.0; eimvvalue = 0.0;
} }
RunningShape.Len = 1.0; RunningShape.Len = 1.0;
@@ -1933,10 +1933,8 @@ void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling c
Coupling == coupling::power24v ? &PowerCircuits[0].second : Coupling == coupling::power24v ? &PowerCircuits[0].second :
nullptr; nullptr;
for (auto side = 0; side < 2; ++side) for (auto &coupler : Couplers)
{ {
auto &coupler{Couplers[side]};
auto *coupling = Coupling == coupling::highvoltage ? &coupler.power_high : auto *coupling = Coupling == coupling::highvoltage ? &coupler.power_high :
Coupling == coupling::power110v ? &coupler.power_110v : Coupling == coupling::power110v ? &coupler.power_110v :
Coupling == coupling::power24v ? &coupler.power_24v : Coupling == coupling::power24v ? &coupler.power_24v :
@@ -3978,10 +3976,10 @@ bool TMoverParameters::DynamicBrakeSwitch(bool Switch)
{ {
DynamicBrakeFlag = Switch; DynamicBrakeFlag = Switch;
DBS = true; DBS = true;
for (int b = 0; b < 2; b++) for (auto &coupler : Couplers)
// with Couplers[b] do // with Couplers[b] do
if (TestFlag(Couplers[b].CouplingFlag, coupling::control)) if (TestFlag(coupler.CouplingFlag, coupling::control))
Couplers[b].Connected->DynamicBrakeFlag = Switch; coupler.Connected->DynamicBrakeFlag = Switch;
// end; // end;
// if (DynamicBrakeType=dbrake_passive) and (TrainType=dt_ET42) then // if (DynamicBrakeType=dbrake_passive) and (TrainType=dt_ET42) then
// begin // begin
@@ -4602,11 +4600,11 @@ void TMoverParameters::UpdatePipePressure(double dt)
{ {
LocBrakePress = LocHandle->GetCP(); LocBrakePress = LocHandle->GetCP();
for (int b = 0; b < 2; b++) for (auto &couplerentry : Couplers)
// nie podoba mi się to rozwiązanie, chyba trzeba // nie podoba mi się to rozwiązanie, chyba trzeba
// dodać jakiś wpis do fizyki na to // dodać jakiś wpis do fizyki na to
if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && Couplers[b].Connected != nullptr && (Couplers[b].Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (Couplers[b].CouplingFlag & 36) == 36) if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && couplerentry.Connected != nullptr && (couplerentry.Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (couplerentry.CouplingFlag & 36) == 36)
LocBrakePress = std::max(Couplers[b].Connected->LocHandle->GetCP(), LocBrakePress); LocBrakePress = std::max(couplerentry.Connected->LocHandle->GetCP(), LocBrakePress);
// if ((DynamicBrakeFlag) && (EngineType == ElectricInductionMotor)) // if ((DynamicBrakeFlag) && (EngineType == ElectricInductionMotor))
//{ //{
@@ -6493,8 +6491,8 @@ double TMoverParameters::TractionForce(double dt)
eimv_pr = 0.0; eimv_pr = 0.0;
EnginePower = 0.0; EnginePower = 0.0;
{ {
for (int i = 0; i < 21; ++i) for (auto &eimvvalue : eimv)
eimv[i] = 0.0; eimvvalue = 0.0;
} }
Hamulec->SetED(0.0); Hamulec->SetED(0.0);
InverterFrequency = 0.0; //(Hamulec as TLSt).SetLBP(LocBrakePress); InverterFrequency = 0.0; //(Hamulec as TLSt).SetLBP(LocBrakePress);
@@ -6558,9 +6556,9 @@ bool TMoverParameters::FuseFlagCheck(void) const
if (Power > 0.01) if (Power > 0.01)
FFC = FuseFlag; FFC = FuseFlag;
else // pobor pradu jezeli niema mocy else // pobor pradu jezeli niema mocy
for (int b = 0; b < 2; b++) for (auto &coupler : Couplers)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01) if (TestFlag(coupler.CouplingFlag, coupling::control) && coupler.Connected->Power > 0.01)
FFC = Couplers[b].Connected->FuseFlagCheck(); FFC = coupler.Connected->FuseFlagCheck();
return FFC; return FFC;
} }
@@ -6788,9 +6786,9 @@ bool TMoverParameters::ResistorsFlagCheck(void) const
RFC = ResistorsFlag; RFC = ResistorsFlag;
else // pobor pradu jezeli niema mocy else // pobor pradu jezeli niema mocy
{ {
for (int b = 0; b < 2; b++) for (auto &coupler : Couplers)
if (TestFlag(Couplers[b].CouplingFlag, coupling::control) && Couplers[b].Connected->Power > 0.01) if (TestFlag(coupler.CouplingFlag, coupling::control) && coupler.Connected->Power > 0.01)
RFC = Couplers[b].Connected->ResistorsFlagCheck(); RFC = coupler.Connected->ResistorsFlagCheck();
} }
return RFC; return RFC;
} }
@@ -8409,20 +8407,18 @@ bool TMoverParameters::AssignLoad(std::string const &Name, float const Amount)
return false; return false;
} }
for (auto const &loadattributes : LoadAttributes) auto const loadattributes = std::ranges::find_if(LoadAttributes, [&](auto const &attributes) { return attributes.name == Name; });
{ if (loadattributes == std::end(LoadAttributes))
if (Name == loadattributes.name)
{ {
// didn't find matching load configuration, this type is unsupported
return false;
}
LoadTypeChange = LoadType.name != Name; LoadTypeChange = LoadType.name != Name;
LoadType = loadattributes; LoadType = *loadattributes;
LoadAmount = std::clamp(Amount, 0.f, MaxLoad); LoadAmount = std::clamp(Amount, 0.f, MaxLoad);
ComputeMass(); ComputeMass();
return true; return true;
} }
}
// didn't find matching load configuration, this type is unsupported
return false;
}
// ************************************************************************************************* // *************************************************************************************************
// Q: 20160713 // Q: 20160713
@@ -8989,10 +8985,10 @@ int s2NPW(std::string s)
{ // wylicza ilosc osi napednych z opisu ukladu osi { // wylicza ilosc osi napednych z opisu ukladu osi
const char A = 64; const char A = 64;
int NPW = 0; int NPW = 0;
for (std::size_t k = 0; k < s.size(); ++k) for (char const chentry : s)
{ {
if (s[k] >= (char)65 && s[k] <= (char)90) if (chentry >= (char)65 && chentry <= (char)90)
NPW += s[k] - A; NPW += chentry - A;
} }
return NPW; return NPW;
} }
@@ -9001,10 +8997,10 @@ int s2NNW(std::string s)
{ // wylicza ilosc osi nienapedzanych z opisu ukladu osi { // wylicza ilosc osi nienapedzanych z opisu ukladu osi
const char Zero = 48; const char Zero = 48;
int NNW = 0; int NNW = 0;
for (std::size_t k = 0; k < s.size(); ++k) for (char const ch : s)
{ {
if (s[k] >= (char)49 && s[k] <= (char)57) if (ch >= (char)49 && ch <= (char)57)
NNW += s[k] - Zero; NNW += ch - Zero;
} }
return NNW; return NNW;
} }

View File

@@ -637,9 +637,9 @@ void TNESt3::SetSize( int const size, std::string const &params ) // ustawianie
Nozzles[dSm] = 0.9; Nozzles[dSm] = 0.9;
// przeliczanie z mm^2 na l/m // przeliczanie z mm^2 na l/m
for (int i = 0; i < dMAX; ++i) for (auto &nozzle : Nozzles)
{ {
Nozzles[i] = d2A(Nozzles[i]); //(/1000^2*pi/4*1000) nozzle = d2A(nozzle); //(/1000^2*pi/4*1000)
} }
for (int i = 1; i < 4; ++i) for (int i = 1; i < 4; ++i)
{ {

View File

@@ -3014,9 +3014,9 @@ double TFV4aM::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double const xpM{0.3}; // mnoznik membrany komory pod double const xpM{0.3}; // mnoznik membrany komory pod
for (int idx = 0; idx < 5; ++idx) for (auto &soundvalue : Sounds)
{ {
Sounds[idx] = 0; soundvalue = 0;
} }
// na wszelki wypadek, zeby nie wyszlo poza zakres // na wszelki wypadek, zeby nie wyszlo poza zakres
@@ -3250,9 +3250,9 @@ double TMHZ_EN57::GetPF(double i_bcp, double PP, double HP, double dt, double ep
double DP; double DP;
double pom; double pom;
for (int idx = 0; idx < 5; ++idx) for (auto &soundvalue : Sounds)
{ {
Sounds[idx] = 0; soundvalue = 0;
} }
@@ -3456,9 +3456,9 @@ double TMHZ_K5P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double DP; double DP;
double pom; double pom;
for (int idx = 0; idx < 5; ++idx) for (auto &soundvalue : Sounds)
{ {
Sounds[idx] = 0; soundvalue = 0;
} }
@@ -3633,9 +3633,9 @@ double TMHZ_6P::GetPF(double i_bcp, double PP, double HP, double dt, double ep)
double DP; double DP;
double pom; double pom;
for (int idx = 0; idx < 5; ++idx) for (auto &soundvalue : Sounds)
{ {
Sounds[idx] = 0; soundvalue = 0;
} }

View File

@@ -73,16 +73,11 @@ bool
cFrustum::point_inside( float const X, float const Y, float const Z ) const { cFrustum::point_inside( float const X, float const Y, float const Z ) const {
// cycle through the sides of the frustum, checking if the point is behind them // cycle through the sides of the frustum, checking if the point is behind them
for( int idx = 0; idx < 6; ++idx ) { return std::ranges::all_of( m_frustum, [&]( auto const &frustumplane ) {
if( m_frustum[ idx ][ plane_A ] * X return frustumplane[ plane_A ] * X
+ m_frustum[ idx ][ plane_B ] * Y + frustumplane[ plane_B ] * Y
+ m_frustum[ idx ][ plane_C ] * Z + frustumplane[ plane_C ] * Z
+ m_frustum[ idx ][ plane_D ] <= 0 ) + frustumplane[ plane_D ] > 0; } );
return false;
}
// the point is in front of each frustum plane, i.e. inside of the frustum
return true;
} }
float float
@@ -90,12 +85,12 @@ cFrustum::sphere_inside( float const X, float const Y, float const Z, float cons
float distance; float distance;
// go through all the sides of the frustum. bail out as soon as possible // go through all the sides of the frustum. bail out as soon as possible
for( int idx = 0; idx < 6; ++idx ) { for (auto &frustumplane : m_frustum) {
distance = distance =
m_frustum[ idx ][ plane_A ] * X frustumplane[ plane_A ] * X
+ m_frustum[ idx ][ plane_B ] * Y + frustumplane[ plane_B ] * Y
+ m_frustum[ idx ][ plane_C ] * Z + frustumplane[ plane_C ] * Z
+ m_frustum[ idx ][ plane_D ]; + frustumplane[ plane_D ];
if( distance <= -Radius ) if( distance <= -Radius )
return 0.0f; return 0.0f;
} }
@@ -105,52 +100,50 @@ cFrustum::sphere_inside( float const X, float const Y, float const Z, float cons
bool bool
cFrustum::cube_inside( float const X, float const Y, float const Z, float const Size ) const { cFrustum::cube_inside( float const X, float const Y, float const Z, float const Size ) const {
for( int idx = 0; idx < 6; ++idx ) { // the cube is inside unless all of its corners lie behind one of the frustum planes
if( m_frustum[ idx ][ plane_A ] * ( X - Size ) return std::ranges::all_of( m_frustum, [&]( auto const &frustumplane ) {
+ m_frustum[ idx ][ plane_B ] * ( Y - Size ) if( frustumplane[ plane_A ] * ( X - Size )
+ m_frustum[ idx ][ plane_C ] * ( Z - Size ) + frustumplane[ plane_B ] * ( Y - Size )
+ m_frustum[ idx ][ plane_D ] > 0 ) + frustumplane[ plane_C ] * ( Z - Size )
continue; + frustumplane[ plane_D ] > 0 )
if( m_frustum[ idx ][ plane_A ] * ( X + Size )
+ m_frustum[ idx ][ plane_B ] * ( Y - Size )
+ m_frustum[ idx ][ plane_C ] * ( Z - Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X - Size )
+ m_frustum[ idx ][ plane_B ] * ( Y + Size )
+ m_frustum[ idx ][ plane_C ] * ( Z - Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X + Size )
+ m_frustum[ idx ][ plane_B ] * ( Y + Size )
+ m_frustum[ idx ][ plane_C ] * ( Z - Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X - Size )
+ m_frustum[ idx ][ plane_B ] * ( Y - Size )
+ m_frustum[ idx ][ plane_C ] * ( Z + Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X + Size )
+ m_frustum[ idx ][ plane_B ] * ( Y - Size )
+ m_frustum[ idx ][ plane_C ] * ( Z + Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X - Size )
+ m_frustum[ idx ][ plane_B ] * ( Y + Size )
+ m_frustum[ idx ][ plane_C ] * ( Z + Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
if( m_frustum[ idx ][ plane_A ] * ( X + Size )
+ m_frustum[ idx ][ plane_B ] * ( Y + Size )
+ m_frustum[ idx ][ plane_C ] * ( Z + Size )
+ m_frustum[ idx ][ plane_D ] > 0 )
continue;
return false;
}
return true; return true;
if( frustumplane[ plane_A ] * ( X + Size )
+ frustumplane[ plane_B ] * ( Y - Size )
+ frustumplane[ plane_C ] * ( Z - Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X - Size )
+ frustumplane[ plane_B ] * ( Y + Size )
+ frustumplane[ plane_C ] * ( Z - Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X + Size )
+ frustumplane[ plane_B ] * ( Y + Size )
+ frustumplane[ plane_C ] * ( Z - Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X - Size )
+ frustumplane[ plane_B ] * ( Y - Size )
+ frustumplane[ plane_C ] * ( Z + Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X + Size )
+ frustumplane[ plane_B ] * ( Y - Size )
+ frustumplane[ plane_C ] * ( Z + Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X - Size )
+ frustumplane[ plane_B ] * ( Y + Size )
+ frustumplane[ plane_C ] * ( Z + Size )
+ frustumplane[ plane_D ] > 0 )
return true;
if( frustumplane[ plane_A ] * ( X + Size )
+ frustumplane[ plane_B ] * ( Y + Size )
+ frustumplane[ plane_C ] * ( Z + Size )
+ frustumplane[ plane_D ] > 0 )
return true;
return false; } );
} }
void cFrustum::normalize_plane( cFrustum::side const Side ) { void cFrustum::normalize_plane( cFrustum::side const Side ) {

View File

@@ -15,20 +15,20 @@ http://mozilla.org/MPL/2.0/.
void float4x4::deserialize_float32(std::istream &s) void float4x4::deserialize_float32(std::istream &s)
{ {
for (size_t i = 0; i < 16; i++) for (auto &elemententry : e)
e[i] = sn_utils::ld_float32(s); elemententry = sn_utils::ld_float32(s);
} }
void float4x4::deserialize_float64(std::istream &s) void float4x4::deserialize_float64(std::istream &s)
{ {
for (size_t i = 0; i < 16; i++) for (auto &elemententry : e)
e[i] = (float)sn_utils::ld_float64(s); elemententry = (float)sn_utils::ld_float64(s);
} }
void float4x4::serialize_float32(std::ostream &s) const void float4x4::serialize_float32(std::ostream &s) const
{ {
for (size_t i = 0; i < 16; i++) for (auto &element : e)
sn_utils::ls_float32(s, e[i]); sn_utils::ls_float32(s, element);
} }
void float4x4::Quaternion(float4 *q) void float4x4::Quaternion(float4 *q)

View File

@@ -234,8 +234,8 @@ public:
} }
void Identity() void Identity()
{ {
for (int i = 0; i < 16; ++i) for (auto &element : e)
e[i] = 0; element = 0;
e[0] = e[5] = e[10] = e[15] = 1.0f; e[0] = e[5] = e[10] = e[15] = 1.0f;
} }
const float *operator[](int i) const const float *operator[](int i) const

View File

@@ -626,8 +626,8 @@ TTrain::TTrain()
for (int i = 0; i < 20; ++i) for (int i = 0; i < 20; ++i)
{ {
for (int j = 0; j < 7; ++j) for (auto &press : fPress[i])
fPress[i][j] = 0.0; press = 0.0;
bBrakes[i][0] = bBrakes[i][1] = false; bBrakes[i][0] = bBrakes[i][1] = false;
} }
} }

View File

@@ -217,9 +217,9 @@ void TTrainParameters::NewName(std::string const &NewTrainName)
Direction = 1; Direction = 1;
Relation1 = ""; Relation1 = "";
Relation2 = ""; Relation2 = "";
for (int i = 0; i < MaxTTableSize + 1; ++i) for (auto &tableline : TimeTable)
{ {
TimeTable[ i ] = TMTableLine(); tableline = TMTableLine();
} }
TTVmax = 100; /*wykasowac*/ TTVmax = 100; /*wykasowac*/
BrakeRatio = 0; BrakeRatio = 0;