From 2b74c6dba7a47355e35c27e3a6327071bb4ce51f Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 11 Oct 2026 01:41:01 +0200 Subject: [PATCH] refactor(sonar): clean up issues reported on PR 209 - remove locals left unused after the dead-store cleanup (cpp:S1481, cpp:S1854) - unnamed unused parameter (cpp:S1172) - single-use declarations moved into if init-statements (cpp:S6004) - auto for casted initialisers (cpp:S5827) - const references and pointers where nothing is modified (cpp:S5350) - rename structured bindings shadowed by inner declarations (cpp:S1117) --- McZapkie/Mover.cpp | 13 +++++-------- McZapkie/hamulce.cpp | 14 ++++---------- application/driveruipanels.cpp | 2 +- environment/moon.cpp | 5 +---- environment/skydome.cpp | 12 ++++++------ gl/vao.cpp | 2 +- input/gamepadinput.cpp | 10 +++++----- network/manager.cpp | 2 +- network/network.cpp | 2 +- scene/sn_utils.cpp | 2 +- scripting/PyInt.cpp | 2 +- simulation/simulationtime.cpp | 8 ++++---- vehicle/Gauge.cpp | 2 +- vehicle/Train.cpp | 5 ++--- world/EvLaunch.cpp | 2 +- world/Traction.cpp | 2 +- world/mtable.cpp | 2 +- 17 files changed, 37 insertions(+), 50 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 2d9f4428..16fe3066 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -4295,7 +4295,7 @@ void TMoverParameters::CompressorCheck(double dt) EmergencyValveOpen = Compressor > (EmergencyValveOpen ? EmergencyValveOff : EmergencyValveOn); if (EmergencyValveOpen) { - float dV = static_cast(PF(0, Compressor, EmergencyValveArea) * dt); + auto dV = static_cast(PF(0, Compressor, EmergencyValveArea) * dt); CompressedVolume -= dV; } @@ -4578,7 +4578,7 @@ void TMoverParameters::UpdatePipePressure(double dt) { LocBrakePress = LocHandle->GetCP(); - for (auto &couplerentry : Couplers) + for (auto const &couplerentry : Couplers) // nie podoba mi się to rozwiązanie, chyba trzeba // dodać jakiś wpis do fizyki na to if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && couplerentry.Connected != nullptr && (couplerentry.Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (couplerentry.CouplingFlag & 36) == 36) @@ -6246,7 +6246,7 @@ double TMoverParameters::TractionForce(double dt) SpeedCtrlTimer += dt; if (SpeedCtrlTimer > SpeedCtrlDelay) { - int NewSCAP = static_cast((float)ScndCtrlPos / (float)ScndCtrlPosNo * Vmax); + auto NewSCAP = static_cast((float)ScndCtrlPos / (float)ScndCtrlPosNo * Vmax); if (NewSCAP != SpeedCtrlValue) { SpeedCtrlValue = NewSCAP; @@ -7945,7 +7945,6 @@ double TMoverParameters::dizel_Momentum(double Fill, double n, double dt) double eps = 0; double newn = 0; double friction = 0; - double neps = 0; double TorqueH = 0; double TorqueL = 0; double TorqueC = 0; @@ -12472,9 +12471,8 @@ bool TMoverParameters::RunCommand(std::string const &Command, double CValue1, do { auto const leftside{CValue2 > 0 ? 1 : 2}; - auto const rightside{3 - leftside}; - if (static_cast(CValue1) & rightside) + if (auto const rightside{3 - leftside}; static_cast(CValue1) & rightside) { Doors.instances[side::right].remote_open = true; Doors.instances[side::right].remote_close = false; @@ -12494,9 +12492,8 @@ bool TMoverParameters::RunCommand(std::string const &Command, double CValue1, do { auto const leftside{CValue2 > 0 ? 1 : 2}; - auto const rightside{3 - leftside}; - if (static_cast(CValue1) & rightside) + if (auto const rightside{3 - leftside}; static_cast(CValue1) & rightside) { Doors.instances[side::right].remote_close = true; Doors.instances[side::right].remote_open = false; diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index 2572432a..c0a7d2a0 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -364,7 +364,7 @@ TBrake::TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn BrakeDelayFlag = bdelay_P; // 210.88 // SizeBR:=i_bcn*i_bcr*i_bcr*i_bcd*40.17*MaxBP/(5-MaxBP); //objetosc ZP w stosunku do cylindra - // 14" i cisnienia 4.2 atm + // 14" i cisnienia 4.2 atm SizeBC = i_bcn * i_bcr * i_bcr * i_bcd * 210.88 * MaxBP / 4.2; // objetosc CH w stosunku do cylindra 14" i cisnienia 4.2 atm BrakeCyl = std::make_shared(); @@ -773,7 +773,6 @@ void TWest::SetLBP(double const P) /// New EP intensity. void TWest::SetEPS(double const nEPS) { - double BCP; if (nEPS > 0) DCV = true; @@ -2481,7 +2480,6 @@ void TKE::CheckReleaser(double const dt) void TKE::CheckState(double const BCP, double & /*dV1*/) { double VVP; - double BVP; double CVP; VVP = ValveRes->P(); @@ -2556,7 +2554,6 @@ void TKE::CheckState(double const BCP, double & /*dV1*/) double TKE::CVs(double const BP) const { double VVP; - double BVP; double CVP; CVP = CntrlRes->P(); @@ -2668,8 +2665,7 @@ double TKE::GetPF(double const PP, double const dt, double const Vel) // rapid auto const &frictionmaterial{*FM}; - auto const &frictionmaterialtype{typeid(frictionmaterial)}; - if (!(frictionmaterialtype == typeid(TDisk1) || frictionmaterialtype == typeid(TDisk2))) // jesli zeliwo to schodz + if (auto const &frictionmaterialtype{typeid(frictionmaterial)}; !(frictionmaterialtype == typeid(TDisk1) || frictionmaterialtype == typeid(TDisk2))) // jesli zeliwo to schodz RapidStatus = (BrakeDelayFlag & bdelay_R) == bdelay_R && (RV < 0 || (Vel > RV && RapidStatus) || Vel > RV + 20); else // jesli tarczowki, to zostan RapidStatus = (BrakeDelayFlag & bdelay_R) == bdelay_R; @@ -3210,7 +3206,7 @@ double TFV4aM::GetRP() /// Interpolated target pressure [bar]. double TFV4aM::LPP_RP(double pos) const // cisnienie z zaokraglonej pozycji; { - int const i_pos = static_cast(2 + std::floor(pos)); // zaokraglone w dol + auto const i_pos = static_cast(2 + std::floor(pos)); // zaokraglone w dol return BPT[i_pos][1] + (BPT[i_pos + 1][1] - BPT[i_pos][1]) * (pos + 2 - i_pos); // interpolacja liniowa } @@ -3452,7 +3448,6 @@ double TMHZ_K5P::GetPF(double i_bcp, double PP, double HP, double dt, double ep) double dpMainValve; double ActFlowSpeed; double DP; - double pom; for (auto &soundvalue : Sounds) { @@ -3629,7 +3624,6 @@ double TMHZ_6P::GetPF(double i_bcp, double PP, double HP, double dt, double ep) double dpMainValve; double ActFlowSpeed; double DP; - double pom; for (auto &soundvalue : Sounds) { @@ -3903,7 +3897,7 @@ double TH14K1::GetPF(double i_bcp, double PP, double HP, double dt, double ep) //{ (10, 0), (4, 1), (0, 1), (4, 0), (4, -1), (15, -1) }; double const NomPress = 5.0; - int BCP = static_cast(std::lround(i_bcp)); + auto BCP = static_cast(std::lround(i_bcp)); if (i_bcp < -1) { BCP = 1; diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 699bedbc..e318d356 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -587,7 +587,7 @@ debug_panel::render() { render_section_developer(); // Developer tools #ifdef WITH_UART if(true == render_section( "UART", m_uartlines)) { - int ports_num = static_cast(UartStatus.available_ports.size()); + auto ports_num = static_cast(UartStatus.available_ports.size()); auto avlports = new char*[ports_num]; for (int i=0; i < ports_num; i++) { avlports[i] = (char *) UartStatus.available_ports[i].c_str(); diff --git a/environment/moon.cpp b/environment/moon.cpp index 4c38b6c9..302e5d8e 100644 --- a/environment/moon.cpp +++ b/environment/moon.cpp @@ -156,7 +156,6 @@ void cMoon::move() { double const yeclip = m_body.distance * ( std::sin( degtorad * longascnode ) * std::cos( vpluswinrad ) + std::cos( degtorad * longascnode ) * std::sin( vpluswinrad ) * std::cos( degtorad * inclination ) ); double const zeclip = m_body.distance * std::sin( vpluswinrad ) * std::sin( degtorad * inclination ); // ecliptic coordinates - double ecliplat = radtodeg * std::atan2( zeclip, std::sqrt( xeclip*xeclip + yeclip*yeclip ) ); m_body.eclong = clamp_circular( radtodeg * std::atan2( yeclip, xeclip ) ); // distance m_body.distance = std::sqrt( xeclip*xeclip + yeclip*yeclip + zeclip*zeclip ); @@ -172,8 +171,6 @@ void cMoon::move() { m_body.mnlong = clamp_circular( longascnode + perigeearg + m_body.mnanom ); // Moon's mean elongation: D = Lm - Ls double const mnelong = clamp_circular( m_body.mnlong - sunmnlong ); - // Moon's argument of latitude: F = Lm - N - double const arglat = clamp_circular( m_body.mnlong - longascnode ); // longitude perturbations double const pertevection = -1.274 * std::sin( degtorad * ( m_body.mnanom - 2.0 * mnelong ) ); // Evection double const pertvariation = +0.658 * std::sin( degtorad * ( 2.0 * mnelong ) ); // Variation @@ -303,7 +300,7 @@ cMoon::phase() { float cMoon::normalize( const float Value ) const { - float value = static_cast(Value - floor( Value )); + auto value = static_cast(Value - floor( Value )); if( value < 0.f ) { ++value; } return value; diff --git a/environment/skydome.cpp b/environment/skydome.cpp index 08240bf7..654b3a34 100644 --- a/environment/skydome.cpp +++ b/environment/skydome.cpp @@ -70,13 +70,13 @@ void CSkyDome::Generate() { for( int i = 0; i <= latitudes; ++i ) { - float const latitude = static_cast(M_PI * ( -0.5f + (float)i / static_cast(latitudes) / 2 )); // half-sphere only + auto const latitude = static_cast(M_PI * ( -0.5f + (float)i / static_cast(latitudes) / 2 )); // half-sphere only float const z = std::sin( latitude ); float const zr = std::cos( latitude ); for( int j = 0; j <= longitudes; ++j ) { - float const longitude = static_cast(2.0 * M_PI * (float)j / longitudes); + auto const longitude = static_cast(2.0 * M_PI * (float)j / longitudes); float const x = std::cos( longitude ); float const y = std::sin( longitude ); /* @@ -168,7 +168,7 @@ float CSkyDome::GetZenith( float Zenithmatrix[ 3 ][ 4 ], const float Theta, cons float CSkyDome::PerezFunctionO1( float const Perezcoeffs[ 5 ], const float Thetasun, const float Zenithval ) const { - const float val = static_cast(( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) * + const auto val = static_cast(( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) * ( 1.0f + Perezcoeffs[ 2 ] * std::exp( Perezcoeffs[ 3 ] * Thetasun ) + Perezcoeffs[ 4 ] * std::pow( std::cos( Thetasun ), 2 ) )); return Zenithval / val; @@ -187,7 +187,7 @@ void CSkyDome::RebuildColors() { auto gammacorrection = glm::mix( glm::vec3( 1.0f ), glm::vec3( 0.45f ), twilightfactor ); // get zenith luminance - float const chi = static_cast(( 4.0f / 9.0f - m_turbidity / 120.0f ) * ( M_PI - 2.0f * m_thetasun )); + auto const chi = static_cast(( 4.0f / 9.0f - m_turbidity / 120.0f ) * ( M_PI - 2.0f * m_thetasun )); float zenithluminance = ( 4.0453f * m_turbidity - 4.9710f ) * std::tan( chi ) - 0.2155f * m_turbidity + 2.4192f; // get x / y zenith @@ -238,7 +238,7 @@ void CSkyDome::RebuildColors() { // = 1.0f / cosf( arccos( vertex.y ) ); // = 1.0f / vertex.y; float const icostheta = 1.0f / vertex.y; - float const cosgamma2 = static_cast(std::pow( std::cos( gamma ), 2 )); + auto const cosgamma2 = static_cast(std::pow( std::cos( gamma ), 2 )); // Compute x,y values float const x = PerezFunctionO2( perezx.data(), icostheta, gamma, cosgamma2, zenithx ); @@ -274,7 +274,7 @@ 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 = static_cast(90.0f - m_thetasun * ( 180.0f / M_PI )); + auto const degreesabovehorizon = static_cast(90.0f - m_thetasun * ( 180.0f / M_PI )); 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 = std::clamp( vertex.y * 2.0f, 0.0f, 1.0f ); diff --git a/gl/vao.cpp b/gl/vao.cpp index 093b8beb..e984ea3b 100644 --- a/gl/vao.cpp +++ b/gl/vao.cpp @@ -60,7 +60,7 @@ void gl::vao::bind() glBindVertexArray(*this); } else { - for (attrib_params ¶m : params) { + for (attrib_params const ¶m : params) { param.buffer.bind(gl::buffer::ARRAY_BUFFER); glVertexAttribPointer(param.attrib, param.size, param.type, GL_FALSE, param.stride, reinterpret_cast(param.offset)); glEnableVertexAttribArray(param.attrib); diff --git a/input/gamepadinput.cpp b/input/gamepadinput.cpp index 6dd4d7a7..c4e537b2 100644 --- a/input/gamepadinput.cpp +++ b/input/gamepadinput.cpp @@ -189,16 +189,16 @@ gamepad_input::recall_bindings() { std::string bindingpoint {}; entryparser >> bindingpoint; - auto const [bindingtype, bindingindex]{ split_string_and_number( bindingpoint ) }; + auto const [pointtype, pointindex]{ split_string_and_number( bindingpoint ) }; - if( bindingtype == "axis" ) { + if( pointtype == "axis" ) { // one or more sets of: [modeIDX] input type, parameters // [optional] modeIDX associates the set with control mode IDX // input types: // -- range commandname IDX; axis value is passed as paramIDX of commandname // -- 3state commandname commandname; positive axis value issues first commandname, negative value issues second commandname - auto const axisindex { bindingindex }; + auto const axisindex { pointindex }; // sanity check, connected gamepad isn't guaranteed to have that many axes if( axisindex >= m_inputaxes.size() ) { continue; } @@ -265,9 +265,9 @@ gamepad_input::recall_bindings() { } } } - else if( bindingtype == "button" ) { + else if( pointtype == "button" ) { - auto const buttonindex { bindingindex }; + auto const buttonindex { pointindex }; // sanity check, connected gamepad isn't guaranteed to have that many buttons if( buttonindex >= m_inputbuttons.size() ) { continue; } diff --git a/network/manager.cpp b/network/manager.cpp index 60adfd9e..932f9b08 100644 --- a/network/manager.cpp +++ b/network/manager.cpp @@ -59,7 +59,7 @@ network::manager::manager() = default; void network::manager::update() { - for (auto &[backendname, backendinstance] : backend_list()) + for (auto const &[backendname, backendinstance] : backend_list()) backendinstance->update(); if (client) diff --git a/network/network.cpp b/network/network.cpp index 026ee2d5..b5eeced4 100644 --- a/network/network.cpp +++ b/network/network.cpp @@ -188,7 +188,7 @@ std::tuple network::client::get_nex float size = static_cast(delta_queue.size()) - consume_counter; const auto& entry = delta_queue.front(); - float mult = static_cast(entry.render_dt / std::chrono::duration_cast>(frame_time).count()); + auto mult = static_cast(entry.render_dt / std::chrono::duration_cast>(frame_time).count()); if (counter == 1 && size < MAX_BUFFER_SIZE * 2.0f) { last_target = last_target * TARGET_MIX + diff --git a/scene/sn_utils.cpp b/scene/sn_utils.cpp index d74d97cb..b6a3f7c3 100644 --- a/scene/sn_utils.cpp +++ b/scene/sn_utils.cpp @@ -18,7 +18,7 @@ uint16_t sn_utils::ld_uint16(std::istream &s) { std::array buf{}; s.read(reinterpret_cast(buf.data()), buf.size()); - uint16_t v = static_cast(buf[1] << 8 | buf[0]); + auto v = static_cast(buf[1] << 8 | buf[0]); return v; } diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index f84d64bf..666609b0 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -376,7 +376,7 @@ void python_taskqueue::exit() // reclaim cached python objects while the interpreter is still alive, // so no Py_DECREF lands on a finalized interpreter during later teardown acquire_lock(); - for (auto &[renderername, rendererobject] : m_renderers) + for (auto const &[renderername, rendererobject] : m_renderers) { Py_XDECREF(rendererobject); } diff --git a/simulation/simulationtime.cpp b/simulation/simulationtime.cpp index d2f8b26c..6f9f87a5 100644 --- a/simulation/simulationtime.cpp +++ b/simulation/simulationtime.cpp @@ -167,19 +167,19 @@ scenario_time::daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yea int scenario_time::julian_day() const { - int yy = static_cast( m_time.wYear - std::floor( ( 12 - m_time.wMonth ) / 10.f )); + auto yy = static_cast( m_time.wYear - std::floor( ( 12 - m_time.wMonth ) / 10.f )); int mm = m_time.wMonth + 9; if( mm >= 12 ) { mm -= 12; } - int K1 = static_cast(std::floor( 365.25 * ( yy + 4712 ) )); - int K2 = static_cast(std::floor( 30.6 * mm + 0.5 )); + auto K1 = static_cast(std::floor( 365.25 * ( yy + 4712 ) )); + auto K2 = static_cast(std::floor( 30.6 * mm + 0.5 )); // for dates in Julian calendar int JD = K1 + K2 + m_time.wDay + 59; // for dates in Gregorian calendar; 2299160 is October 15th, 1582 if( const int gregorianswitchday = 2299160; JD > gregorianswitchday ) { - int K3 = static_cast(std::floor( std::floor( yy * 0.01 + 49 ) * 0.75 ) - 38); + auto K3 = static_cast(std::floor( std::floor( yy * 0.01 + 49 ) * 0.75 ) - 38); JD -= K3; } diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index 48d351f9..d7a41062 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -359,7 +359,7 @@ void TGauge::Update( bool const Power ) { // update value // TODO: remove passing manually power state when LD is in place if( m_value != m_targetvalue ) { - float dt = static_cast(Timer::GetDeltaTime()); + auto dt = static_cast(Timer::GetDeltaTime()); if( m_friction > 0 && dt < 0.5 * m_friction ) { // McZapkie-281102: zabezpieczenie przed oscylacjami dla dlugich czasow m_value += dt * ( m_targetvalue - m_value ) / m_friction; diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 3ea7affd..f0b2367f 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -758,8 +758,7 @@ std::shared_ptr TTrain::GetTrainState(dictionary_source const dict->insert("dir_brake", bEP); bool bPN{false}; auto const &brakevalve{*mvOccupied->Hamulec}; - auto const &brakevalvetype{typeid(brakevalve)}; - if (brakevalvetype == typeid(TLSt) || brakevalvetype == typeid(TEStED)) + if (auto const &brakevalvetype{typeid(brakevalve)}; brakevalvetype == typeid(TLSt) || brakevalvetype == typeid(TEStED)) { TBrake *temp_ham = mvOccupied->Hamulec.get(); @@ -6792,7 +6791,7 @@ void TTrain::OnCommand_springbrakerelease(TTrain *Train, command_data const &Com { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if (auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; vehicle == nullptr) + if (auto const *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; vehicle == nullptr) { return; } diff --git a/world/EvLaunch.cpp b/world/EvLaunch.cpp index 5856d9d8..22cfa413 100644 --- a/world/EvLaunch.cpp +++ b/world/EvLaunch.cpp @@ -163,7 +163,7 @@ bool TEventLauncher::check_activation_key() const { bool result = Console::Pressed(key); - char modifier = static_cast(iKey >> 8); + auto modifier = static_cast(iKey >> 8); if (modifier & GLFW_MOD_SHIFT) result &= Global.shiftState; if (modifier & GLFW_MOD_CONTROL) diff --git a/world/Traction.cpp b/world/Traction.cpp index d8be38d5..b9e47d5b 100644 --- a/world/Traction.cpp +++ b/world/Traction.cpp @@ -416,7 +416,7 @@ void TTraction::ResistanceCalc(int d, double r, TTractionPowerSource *ps) if (d >= 0) { // podążanie we wskazanym kierunku TTraction *t = hvNext[d]; - TTraction *p; + TTraction const *p; if (ps) psPower[d ^ 1] = ps; // podłączenie podanego else diff --git a/world/mtable.cpp b/world/mtable.cpp index 4b667dac..b69cacfb 100644 --- a/world/mtable.cpp +++ b/world/mtable.cpp @@ -227,7 +227,7 @@ void TTrainParameters::NewName(std::string_view NewTrainName) LocLoad = 0; } -void TTrainParameters::UpdateVelocity(int Stationcount, double vActual) +void TTrainParameters::UpdateVelocity(int /*Stationcount*/, double vActual) // zapisywanie prędkości maksymalnej do wcześniejszych odcinków // wywoływane z numerem ostatniego przetworzonego przystanku {