From 6fce71af361b46ff202a5684b0fe83216c6d6537 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 15:44:18 +0200 Subject: [PATCH] refactor(sonar): scope single-use variables in if init-statements (cpp:S6004) --- McZapkie/Mover.cpp | 51 ++++++++++++---------------------- McZapkie/hamulce.cpp | 3 +- application/driveruipanels.cpp | 37 +++++------------------- gl/shader.cpp | 3 +- input/command.cpp | 6 ++-- input/drivermouseinput.cpp | 3 +- input/gamepadinput.cpp | 9 ++---- input/keyboardinput.cpp | 6 ++-- launcher/textures_scanner.cpp | 3 +- model/MdlMngr.cpp | 3 +- network/backend/asio.cpp | 3 +- rendering/particles.cpp | 6 ++-- scripting/PyInt.cpp | 24 ++++++---------- simulation/simulationtime.cpp | 3 +- utilities/uart.cpp | 3 +- utilities/utilities.h | 3 +- vehicle/Button.cpp | 3 +- vehicle/Camera.cpp | 6 +--- vehicle/Gauge.cpp | 9 ++---- vehicle/Train.cpp | 42 ++++++++++------------------ vr/vr_interface.cpp | 3 +- widgets/cameraview_extcam.cpp | 3 +- world/EvLaunch.cpp | 6 ++-- world/Segment.cpp | 3 +- world/Spring.cpp | 3 +- world/Traction.cpp | 6 ++-- world/mtable.cpp | 3 +- 27 files changed, 78 insertions(+), 175 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 7ffa66c4..a1eb5794 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -595,9 +595,8 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters * auto &othercoupler = ConnectTo->Couplers[(ConnectToNr != 2 ? ConnectToNr : coupler.ConnectedNr)]; auto const distance{CouplerDist(this, ConnectTo) - (coupler.adapter_length + othercoupler.adapter_length)}; - auto const couplercheck{Enforce || (distance <= dEpsilon && coupler.type() != TCouplerType::NoCoupler && coupler.type() == othercoupler.type())}; - if (false == couplercheck) + if (auto const couplercheck{Enforce || (distance <= dEpsilon && coupler.type() != TCouplerType::NoCoupler && coupler.type() == othercoupler.type())}; false == couplercheck) { return false; } @@ -1570,10 +1569,9 @@ void TMoverParameters::compute_movement_(double const Deltatime) // Uproszczona symulacja wentylatorow rezystora hamowania // Prad oddawany na rezystor - double Irh = abs(eimv[eimv_Pe]) - abs(eimv[eimv_Ipoj]); // Wlacz wentylator jesli prad rekuperacji przekroczy maksymalny dla pasywnego chlodzenia rezystora - if (Irh > Imaxrpc && eimv[eimv_Ipoj] < 0) + if (double Irh = abs(eimv[eimv_Pe]) - abs(eimv[eimv_Ipoj]); Irh > Imaxrpc && eimv[eimv_Ipoj] < 0) { BRVtimer = 0; BRVentilators = true; @@ -3007,8 +3005,7 @@ bool TMoverParameters::SandboxManual(bool const State, range_t const Notify) bool TMoverParameters::SandboxAuto(bool const State, range_t const Notify) { bool result{false}; - bool NewState = State && SandDoseAutoAllow; - if (SandDoseAuto != NewState) + if (bool NewState = State && SandDoseAutoAllow; SandDoseAuto != NewState) { if (SandDoseAuto == false) { @@ -3921,8 +3918,7 @@ double TMoverParameters::DynamicBrakeRatio(void) const bool TMoverParameters::DynamicBrakeAvailable(void) const { double const vh0{eimc[eimc_p_Vh0]}; - double const vh1{eimc[eimc_p_Vh1]}; - if (vh1 <= 0.001) + if (double const vh1{eimc[eimc_p_Vh1]}; vh1 <= 0.001) { // brak zdefiniowanej strefy - ED dziala zawsze return true; @@ -4331,9 +4327,8 @@ void TMoverParameters::CompressorCheck(double dt) auto const MaxCompressorF{CompressorList[TCompressorList::cl_MaxFactor][CompressorListPos] * MaxCompressor}; auto const MinCompressorF{CompressorList[TCompressorList::cl_MinFactor][CompressorListPos] * MinCompressor}; auto const CompressorSpeedF{CompressorList[TCompressorList::cl_SpeedFactor][CompressorListPos] * CompressorSpeed}; - auto const AllowFactor{CompressorList[TCompressorList::cl_Allow][CompressorListPos]}; // checking the impact on the compressor allowance - if (AllowFactor > 0.5) + if (auto const AllowFactor{CompressorList[TCompressorList::cl_Allow][CompressorListPos]}; AllowFactor > 0.5) { CompressorAllow = AllowFactor > 1.5; } @@ -6470,9 +6465,8 @@ double TMoverParameters::TractionForce(double dt) auto const tmpV{std::abs(eimv[eimv_fp])}; auto const useFFEDList = FFEDListSize > 0 && DynamicBrakeFlag; auto const list = useFFEDList ? FFEDlist : FFlist; - auto const listSize = useFFEDList ? FFEDListSize : FFListSize; - if (listSize > 0 && std::abs(eimv[eimv_If]) > 1.0 && tmpV > 0.0001) + if (auto const listSize = useFFEDList ? FFEDListSize : FFListSize; listSize > 0 && std::abs(eimv[eimv_If]) > 1.0 && tmpV > 0.0001) { int i = 0; @@ -6610,8 +6604,7 @@ void TMoverParameters::FuseOff(void) bool TMoverParameters::UniversalResetButton(int const Button, range_t const Notify) { - auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; - if (false == lowvoltagepower) + if (auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; false == lowvoltagepower) { return false; } @@ -8195,8 +8188,7 @@ double TMoverParameters::dizel_MomentumRetarder(double n, double dt) } double Moment = hydro_R_MaxTorque; - double pwr = Moment * std::abs(n) * M_PI * 2 * 0.001; - if (pwr > hydro_R_MaxPower) + if (double pwr = Moment * std::abs(n) * M_PI * 2 * 0.001; pwr > hydro_R_MaxPower) Moment = Moment * hydro_R_MaxPower / pwr; double moment_in = n * n * hydro_R_TorqueInIn; Moment = std::min(moment_in, Moment * hydro_R_Fill); @@ -8937,8 +8929,7 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const continue; } auto const &coupler{Couplers[end]}; - auto const fullcoupling{coupler.CouplingFlag | (TestFlag(coupler.CouplingFlag, coupler.PowerCoupling) ? coupler.PowerFlag : 0)}; - if ((fullcoupling & Coupling) == 0) + if (auto const fullcoupling{coupler.CouplingFlag | (TestFlag(coupler.CouplingFlag, coupler.PowerCoupling) ? coupler.PowerFlag : 0)}; (fullcoupling & Coupling) == 0) { continue; } @@ -10835,8 +10826,7 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line) extract_value(ScndInMain, "SCIM", line, ""); extract_value(MainCtrlMaxDirChangePos, "DirChangeMaxPos", line, ""); - auto const autorelay{ToLower(extract_value("AutoRelay", line))}; - if (autorelay == "optional") + if (auto const autorelay{ToLower(extract_value("AutoRelay", line))}; autorelay == "optional") { AutoRelayType = 2; } @@ -11117,8 +11107,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input) EngineType = LoadFIZ_EngineDecode(extract_value("EngineType", Input)); - std::string transmission = extract_value("Trans", Input); - if (false == transmission.empty()) + if (std::string transmission = extract_value("Trans", Input); false == transmission.empty()) { // transmission type. moved here because more than one engine type has this entry auto ratios = Split(transmission, ':'); // e.g. 18:79 @@ -11442,8 +11431,7 @@ void TMoverParameters::LoadFIZ_RList(std::string const &Input) extract_value(RlistSize, "Size", Input, ""); - auto const venttype{ToLower(extract_value("RVent", Input))}; - if (venttype == "automatic") + if (auto const venttype{ToLower(extract_value("RVent", Input))}; venttype == "automatic") { RVentType = 2; @@ -11564,8 +11552,7 @@ void TMoverParameters::LoadFIZ_PowerParamsDecode(TPowerParameters &Powerparamete // prime mover for the generator auto &generatorparameters{Powerparameters.EngineGenerator}; - auto const enginetype{LoadFIZ_EngineDecode(extract_value(Prefix + "GeneratorEngine", Line))}; - if (enginetype == TEngineType::Main) + if (auto const enginetype{LoadFIZ_EngineDecode(extract_value(Prefix + "GeneratorEngine", Line))}; enginetype == TEngineType::Main) { generatorparameters.engine_revolutions = &enrot; } @@ -12496,9 +12483,8 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV { auto const left{CValue2 > 0 ? 1 : 2}; - auto const right{3 - left}; - if (std::abs(static_cast(CValue1)) & right) + if (auto const right{3 - left}; std::abs(static_cast(CValue1)) & right) { PermitDoors_(side::right, CValue1 > 0); } @@ -12580,8 +12566,7 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV auto const inputoperation{static_cast(CValue1) & ~(0x80 | 0x40)}; auto const noswap{TrainType == dt_EZT || TrainType == dt_ET41}; auto swap{false == noswap && TestFlag(Couplers[(CValue2 == -1 ? end::rear : end::front)].CouplingFlag, coupling::control)}; - auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; - if (reversed) + if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed) { swap = !swap; } // TODO: check whether this part has RL equivalent @@ -12624,8 +12609,7 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV } else if (Command == "BrakeDelay") { - auto const brakesetting = static_cast(std::floor(CValue1)); - if (true == Hamulec->SetBDF(brakesetting)) + if (auto const brakesetting = static_cast(std::floor(CValue1)); true == Hamulec->SetBDF(brakesetting)) { BrakeDelayFlag = brakesetting; OK = true; @@ -12784,8 +12768,7 @@ bool TMoverParameters::reload_FIZ() WriteLog("[DEV] Reloading FIZ for " + Name); // pause simulation Global.iPause |= 0b1000; - bool result = LoadFIZ(chkPath); - if (result == true) + if (bool result = LoadFIZ(chkPath); result == true) { // jesli sie udalo przeladowac FIZ Global.iPause &= 0b0111; diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index eb290e8b..856cd740 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -1712,8 +1712,7 @@ double TLSt::GetPF(double const PP, double const dt, double const Vel) SoundFlag |= sf_CylU; } // equivalent of checkreleaser() in the base class? - bool is_releasing = BrakeStatus & b_rls || UniversalFlag & TUniversalBrake::ub_Release; - if (is_releasing) + if (bool is_releasing = BrakeStatus & b_rls || UniversalFlag & TUniversalBrake::ub_Release; is_releasing) { if (CVP < 0.0) { diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 86e22ed1..60bc0252 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -61,8 +61,7 @@ drivingaid_panel::update() { // grade std::string gradetext; auto const reverser { ( mover->DirActive > 0 ? 1 : -1 ) }; - auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser }; - if( std::abs( grade ) >= 0.25 ) { + if( auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser }; std::abs( grade ) >= 0.25 ) { std::snprintf( m_buffer.data(), m_buffer.size(), STR_C(" Grade: %.1f%%%%"), @@ -87,8 +86,7 @@ drivingaid_panel::update() { // then take into account speed change ahead, compare it with speed after potentially clearing last limit // lower of these two takes priority; otherwise limit lasts at least until potential last limit is cleared auto const noactivespeedlimit { owner->VelLimitLastDist.second < 0 }; - auto const speedatproximitydistance { min_speed( schedulespeedlimit, static_cast( owner->VelNext ) ) }; - if( speedatproximitydistance == nextspeedlimit ) { + if( auto const speedatproximitydistance { min_speed( schedulespeedlimit, static_cast( owner->VelNext ) ) }; speedatproximitydistance == nextspeedlimit ) { if( noactivespeedlimit ) { nextspeedlimit = speedatproximitydistance; nextspeedlimitdistance = owner->ActualProximityDist; @@ -253,12 +251,7 @@ scenario_panel::render() { if( size_min.x > 0 ) { ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); } - auto const panelname { ( - title.empty() ? - m_name : - title ) - + "###" + m_name }; - if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { + if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { // potential assignment section auto const *owner { ( m_nearest->Mechanik != nullptr && m_nearest->Mechanik->primary() ? @@ -362,8 +355,7 @@ timetable_panel::update() { //odejmij lokomotywy czynne, a przynajmniej aktualną consistmass -= owner->pVehicle->MoverParameters->TotalMass; // subtract potential other half of a two-part vehicle - auto const *previous { owner->pVehicle->Prev( coupling::permanent ) }; - if( previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; } + if( auto const *previous { owner->pVehicle->Prev( coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; } auto const *next { owner->pVehicle->Next( coupling::permanent ) }; if( next != nullptr ) { consistmass -= next->MoverParameters->TotalMass; } } @@ -484,12 +476,7 @@ timetable_panel::render() { if( size_min.x > 0 ) { ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x * horizontalScale, size_min.y ), ImVec2S( size_max.x * horizontalScale, size_max.y ) ); } - auto const panelname { ( - title.empty() ? - m_name : - title ) - + "###" + m_name }; - if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { + if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { for( auto const &line : text_lines ) { ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() ); } @@ -574,12 +561,7 @@ debug_panel::render() { if( size_min.x > 0 ) { ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); } - auto const panelname { ( - title.empty() ? - m_name : - title ) - + "###" + m_name }; - if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { + if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { // header section for( auto const &line : text_lines ) { ImGui::TextColored( ImVec4( line.color.r, line.color.g, line.color.b, line.color.a ), line.data.c_str() ); @@ -1627,12 +1609,7 @@ transcripts_panel::render() { if( size_min.x > 0 ) { ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); } - auto const panelname { ( - title.empty() ? - m_name : - title ) - + "###" + m_name }; - if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { + if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) { // header section for( auto const &line : text_lines ) { ImGui::TextWrapped( "%s", line.data.c_str() ); diff --git a/gl/shader.cpp b/gl/shader.cpp index cb18c6f4..4adb99ad 100644 --- a/gl/shader.cpp +++ b/gl/shader.cpp @@ -154,8 +154,7 @@ std::pair gl::shader::process_source(const std::string &fil // the driver advertises support (see desktop comment above). // (Glad config doesn't generate GLAD_GL_EXT_gpu_shader5 -- query // the live extension string the same way.) - static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5"); - if (have_gpu_shader5) + if (static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5"); have_gpu_shader5) str += "#extension GL_EXT_gpu_shader5 : enable\n"; if (type == GL_GEOMETRY_SHADER) str += "#extension GL_EXT_geometry_shader : require\n"; diff --git a/input/command.cpp b/input/command.cpp index 89a35846..0836a177 100644 --- a/input/command.cpp +++ b/input/command.cpp @@ -817,8 +817,7 @@ command_queue::push( command_data const &Command, uint32_t const Recipient ) { } void command_queue::push_direct(const command_data &Command, const uint32_t Recipient) { - auto const &desc = simulation::Commands_descriptions[ static_cast( Command.command ) ]; - if (desc.mode == command_mode::continuous) + if (auto const &desc = simulation::Commands_descriptions[ static_cast( Command.command ) ]; desc.mode == command_mode::continuous) { if (Command.action == GLFW_PRESS) m_active_continuous.emplace(std::make_pair(Command.command, Recipient)); @@ -855,9 +854,8 @@ command_queue::pop( command_data &Command, uint32_t const Recipient ) { } bool command_queue::is_network_target(uint32_t const Recipient) const { - const command_target target = (command_target)(Recipient & ~0xffff); - if (target == command_target::entity) + if (const command_target target = (command_target)(Recipient & ~0xffff); target == command_target::entity) return false; return true; diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 803a1422..f1fbc4f8 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -171,8 +171,7 @@ drivermouse_input::recall_bindings() { std::string filePath = "eu07_input-mouse.ini"; - fs::path appPath = user_config_path("eu07_input-mouse.ini"); - if (!appPath.empty() && fs::exists(appPath)) + if (fs::path appPath = user_config_path("eu07_input-mouse.ini"); !appPath.empty() && fs::exists(appPath)) filePath = appPath.string(); cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); diff --git a/input/gamepadinput.cpp b/input/gamepadinput.cpp index 5d652be5..22aabeb4 100644 --- a/input/gamepadinput.cpp +++ b/input/gamepadinput.cpp @@ -51,8 +51,7 @@ gamepad_input::init() { m_inputbuttons.clear(); // NOTE: we're only checking for joystick_1 and rely for it to stay connected throughout. // not exactly flexible, but for quick hack it'll do - auto const name = glfwGetJoystickName( GLFW_JOYSTICK_1 ); - if( name != nullptr ) { + if( auto const name = glfwGetJoystickName( GLFW_JOYSTICK_1 ); name != nullptr ) { WriteLog( "Connected gamepad: " + std::string( name ) ); m_deviceid = GLFW_JOYSTICK_1; } @@ -154,8 +153,7 @@ bool gamepad_input::recall_bindings() { std::string filePath = "eu07_input-gamepad.ini"; - fs::path appPath = user_config_path("eu07_input-gamepad.ini"); - if (!appPath.empty() && fs::exists(appPath)) + if (fs::path appPath = user_config_path("eu07_input-gamepad.ini"); !appPath.empty() && fs::exists(appPath)) filePath = appPath.string(); // bindingparser tworzony zawsze, z wybran� �cie�k� @@ -211,8 +209,7 @@ gamepad_input::recall_bindings() { std::string key {}; entryparser >> key; // check for potential mode indicator - auto const splitkey { split_string_and_number( key ) }; - if( splitkey.first == "mode" ) { + if( auto const splitkey { split_string_and_number( key ) }; splitkey.first == "mode" ) { // indicate we'll be processing specified mode controlmode = splitkey.second; continue; diff --git a/input/keyboardinput.cpp b/input/keyboardinput.cpp index 922f4405..06e1ffbe 100644 --- a/input/keyboardinput.cpp +++ b/input/keyboardinput.cpp @@ -239,8 +239,7 @@ void keyboard_input::dump_bindings() const stream << simulation::Commands_descriptions[static_cast(binding.first)].name << ' '; int keycode = std::get(binding.second); - auto it = keytonamemap.find(keycode & 0xFFFF); - if (it != keytonamemap.end()) { + if (auto it = keytonamemap.find(keycode & 0xFFFF); it != keytonamemap.end()) { if (keycode & keymodifier::control) stream << "ctrl "; if (keycode & keymodifier::shift) @@ -298,8 +297,7 @@ keyboard_input::key( int const Key, int const Action ) { | ( modifier ? 0 : input::key_ctrl ? keymodifier::control : 0 ); if( Action == GLFW_RELEASE ) { - auto const stored = m_modsforkeys.find( Key ); - if( stored != m_modsforkeys.end() ) { + if( auto const stored = m_modsforkeys.find( Key ); stored != m_modsforkeys.end() ) { key = stored->second; } m_modsforkeys.erase( Key ); diff --git a/launcher/textures_scanner.cpp b/launcher/textures_scanner.cpp index 86c19e24..ab2df672 100644 --- a/launcher/textures_scanner.cpp +++ b/launcher/textures_scanner.cpp @@ -86,8 +86,7 @@ void ui::vehicles_bank::parse_category_entry(const std::string ¶m) if (tok.size() < 1) return; - auto it = type_map.find(tok[0]); - if (it != type_map.end()) + if (auto it = type_map.find(tok[0]); it != type_map.end()) ctx_type = it->second; else if (tok[0] >= 'A' && tok[0] <= 'Z') ctx_type = vehicle_type::carriage; diff --git a/model/MdlMngr.cpp b/model/MdlMngr.cpp index 9ead9716..01408a0b 100644 --- a/model/MdlMngr.cpp +++ b/model/MdlMngr.cpp @@ -103,9 +103,8 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const } // first load attempt, check if it's on disk - std::string disklookup { find_on_disk( filename ) }; - if( false == disklookup.empty() ) { + if( std::string disklookup { find_on_disk( filename ) }; false == disklookup.empty() ) { model = LoadModel( disklookup, disklookup + postfix, Dynamic ); // model nie znaleziony, to wczytać } else { diff --git a/network/backend/asio.cpp b/network/backend/asio.cpp index f0d03641..4f7c9259 100644 --- a/network/backend/asio.cpp +++ b/network/backend/asio.cpp @@ -54,8 +54,7 @@ void network::tcp::connection::handle_header(const asio::error_code &err, size_t return; } - uint32_t sig = sn_utils::ld_uint32(header); - if (sig != NETWORK_MAGIC) { + if (uint32_t sig = sn_utils::ld_uint32(header); sig != NETWORK_MAGIC) { disconnect(); return; } diff --git a/rendering/particles.cpp b/rendering/particles.cpp index 01e2f21f..60a6edce 100644 --- a/rendering/particles.cpp +++ b/rendering/particles.cpp @@ -467,16 +467,14 @@ particle_manager::find( std::string const &Template ) { auto const templatename { ToLower( Template ) }; // try to locate specified rail profile... - auto const lookup { m_sourcetemplates.find( templatename ) }; - if( lookup != m_sourcetemplates.end() ) { + if( auto const lookup { m_sourcetemplates.find( templatename ) }; lookup != m_sourcetemplates.end() ) { // ...if it works, we're done... return &(lookup->second); } // ... and if it fails try to add the template to the database from a data file smoke_source source; - cParser parser(templatepath + templatename + ".txt", cParser::buffer_FILE); - if (source.deserialize(parser)) + if (cParser parser(templatepath + templatename + ".txt", cParser::buffer_FILE); source.deserialize(parser)) { // if deserialization didn't fail finish source setup... source.m_opacitymodifier.bind( &Global.SmokeFidelity ); diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index 656e655b..e1cad41f 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -181,8 +181,7 @@ void render_task::run() int p1 = 0; int p2 = 0; - size_t pos1 = cmd.find(';'); - if (pos1 == std::string::npos) + if (size_t pos1 = cmd.find(';'); pos1 == std::string::npos) { baseCmd = cmd; } @@ -474,8 +473,7 @@ void python_taskqueue::release_lock() const auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject * { - auto const lookup{m_renderers.find(Renderer)}; - if (lookup != std::end(m_renderers)) + if (auto const lookup{m_renderers.find(Renderer)}; lookup != std::end(m_renderers)) { return lookup->second; } @@ -623,11 +621,9 @@ void python_taskqueue::error() { // std err pythona jest buforowane PyErr_Print(); - auto *errortext{PyObject_CallMethod(m_stderr, const_cast("getvalue"), nullptr)}; - if (errortext != nullptr) + if (auto *errortext{PyObject_CallMethod(m_stderr, const_cast("getvalue"), nullptr)}; errortext != nullptr) { - const char *errstr = PyUnicode_AsUTF8(errortext); - if (errstr != nullptr) + if (const char *errstr = PyUnicode_AsUTF8(errortext); errstr != nullptr) ErrorLog(errstr); Py_DECREF(errortext); } @@ -650,11 +646,9 @@ void python_taskqueue::error() { ErrorLog("Python Interpreter: don't know how to handle null exception"); } - auto *typetext{PyObject_Str(type)}; - if (typetext != nullptr) + if (auto *typetext{PyObject_Str(type)}; typetext != nullptr) { - const char *s = PyUnicode_AsUTF8(typetext); - if (s) + if (const char *s = PyUnicode_AsUTF8(typetext); s) ErrorLog(s); Py_DECREF(typetext); } @@ -663,8 +657,7 @@ void python_taskqueue::error() auto *valuetext{PyObject_Str(value)}; if (valuetext != nullptr) { - const char *s = PyUnicode_AsUTF8(valuetext); - if (s) + if (const char *s = PyUnicode_AsUTF8(valuetext); s) ErrorLog(s); Py_DECREF(valuetext); } @@ -672,8 +665,7 @@ void python_taskqueue::error() auto *tracebacktext{PyObject_Str(traceback)}; if (tracebacktext != nullptr) { - const char *s = PyUnicode_AsUTF8(tracebacktext); - if (s) + if (const char *s = PyUnicode_AsUTF8(tracebacktext); s) ErrorLog(s); Py_DECREF(tracebacktext); } diff --git a/simulation/simulationtime.cpp b/simulation/simulationtime.cpp index 4ed3ef3d..0ab60d46 100644 --- a/simulation/simulationtime.cpp +++ b/simulation/simulationtime.cpp @@ -176,8 +176,7 @@ scenario_time::julian_day() const { // for dates in Julian calendar int JD = K1 + K2 + m_time.wDay + 59; // for dates in Gregorian calendar; 2299160 is October 15th, 1582 - const int gregorianswitchday = 2299160; - if( JD > gregorianswitchday ) { + if( const int gregorianswitchday = 2299160; JD > gregorianswitchday ) { int K3 = static_cast(std::floor( std::floor( yy * 0.01 + 49 ) * 0.75 ) - 38); JD -= K3; diff --git a/utilities/uart.cpp b/utilities/uart.cpp index 1ef1f372..59ebb597 100644 --- a/utilities/uart.cpp +++ b/utilities/uart.cpp @@ -193,8 +193,7 @@ uart_input::recall_bindings() { m_inputbindings.clear(); std::string filePath = "eu07_input-uart.ini"; - fs::path appPath = user_config_path("eu07_input-uart.ini"); - if (!appPath.empty() && fs::exists(appPath)) + if (fs::path appPath = user_config_path("eu07_input-uart.ini"); !appPath.empty() && fs::exists(appPath)) filePath = appPath.string(); cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); if (false == bindingparser.ok()) diff --git a/utilities/utilities.h b/utilities/utilities.h index 0e365c94..f78aa965 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -176,8 +176,7 @@ inline std::string extract_value(std::string const &Key, std::string const &Inpu // NOTE, HACK: the leading space allows to uniformly look for " variable=" substring std::string const input{" " + Input}; std::string value; - auto lookup = input.find(" " + Key + "="); - if (lookup != std::string::npos) + if (auto lookup = input.find(" " + Key + "="); lookup != std::string::npos) { value = input.substr(input.find_first_not_of(' ', lookup + Key.size() + 2)); lookup = value.find(' '); diff --git a/vehicle/Button.cpp b/vehicle/Button.cpp index b6359ded..bdd579a3 100644 --- a/vehicle/Button.cpp +++ b/vehicle/Button.cpp @@ -123,9 +123,8 @@ TButton::Turn( bool const State ) { void TButton::Update( bool const Power ) { // TODO: remove passing manually power state when LD is in place - auto const state { Power && ( bData ? *bData : m_state ) }; - if( state != m_state ) { + if( auto const state { Power && ( bData ? *bData : m_state ) }; state != m_state ) { m_state = state; play(); diff --git a/vehicle/Camera.cpp b/vehicle/Camera.cpp index 19405c8c..e2fe5846 100644 --- a/vehicle/Camera.cpp +++ b/vehicle/Camera.cpp @@ -172,11 +172,7 @@ void TCamera::Update() // attached movement position update auto movement { Velocity * -2.0 }; movement.y = -movement.y; - auto const *owner { ( - m_owner->Mechanik ? - m_owner->Mechanik : - m_owner->ctOwner ) }; - if( owner && owner->Occupied() + if( auto const *owner { ( m_owner->Mechanik ? m_owner->Mechanik : m_owner->ctOwner ) }; owner && owner->Occupied() && owner->Occupied()->CabOccupied < 0 ) { movement *= -1.f; movement.y = -movement.y; diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index aef4772a..25ba07a2 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -307,8 +307,7 @@ TGauge::UpdateValue( float fNewDesired ) { m_targetvalue = fNewDesired; // if there's any sound associated with new requested value, play it // check value-specific table first... - auto const fullinteger { desiredtimes100 % 100 == 0 }; - if( fullinteger ) { + if( auto const fullinteger { desiredtimes100 % 100 == 0 }; fullinteger ) { // filter out values other than full integers auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 ); if( lookup != m_soundfxvalues.end() ) { @@ -321,9 +320,8 @@ TGauge::UpdateValue( float fNewDesired ) { m_soundtype = sound_flags::exclusive; } // ...and if there isn't any, fall back on the basic set... - auto const currentvalue = GetValue(); // HACK: crude way to discern controls with continuous and quantized value range - if( currentvalue < fNewDesired ) { + if( auto const currentvalue = GetValue(); currentvalue < fNewDesired ) { // shift up if( false == m_soundfxincrease.empty() ) { m_soundfxincrease.play( m_soundtype ); @@ -471,8 +469,7 @@ TGauge::UpdateAnimation( TSubModel *Submodel ) const { case TGaugeAnimation::gt_Wiper: { auto const scaledvalue { GetScaledValue() }; Submodel->SetRotate( float3( 0, 1, 0 ), static_cast(scaledvalue * 360.0) ); - auto *sm = Submodel->ChildGet(); - if( sm ) { + if( auto *sm = Submodel->ChildGet(); sm ) { sm->SetRotate( float3( 0, 1, 0 ), static_cast(scaledvalue * 360.0) ); sm = sm->ChildGet(); if( sm ) diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index ea1edc76..79a2a64e 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -3593,9 +3593,8 @@ void TTrain::OnCommand_pantographcompressorvalvetoggle(TTrain *Train, command_da void TTrain::OnCommand_pantographcompressorvalveenable(TTrain *Train, command_data const &Command) { - auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; - if (false == valveispresent) + if (auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == valveispresent) { // tylko w maszynowym, unless actual device is present return; @@ -3614,9 +3613,8 @@ void TTrain::OnCommand_pantographcompressorvalveenable(TTrain *Train, command_da void TTrain::OnCommand_pantographcompressorvalvedisable(TTrain *Train, command_data const &Command) { - auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; - if (false == valveispresent) + if (auto const valveispresent{Train->ggPantCompressorValve.SubModel != nullptr || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == valveispresent) { // tylko w maszynowym, unless actual device is present return; @@ -3636,8 +3634,7 @@ void TTrain::OnCommand_pantographcompressoractivate(TTrain *Train, command_data { // tylko w maszynowym, unless actual device is present - auto const switchispresent{Train->m_controlmapper.contains("pantcompressor_sw:") || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; - if (false == switchispresent) + if (auto const switchispresent{Train->m_controlmapper.contains("pantcompressor_sw:") || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == switchispresent) { return; } @@ -5839,8 +5836,7 @@ void TTrain::OnCommand_modernlightdimmerincrease(TTrain *Train, command_data con // update modern dimmer state auto &dimPos = Train->mvOccupied->modernDimmerPosition; - auto dimCount = Train->mvOccupied->dimPositions.size(); - if (dimPos + 1 < dimCount) + if (auto dimCount = Train->mvOccupied->dimPositions.size(); dimPos + 1 < dimCount) dimPos++; else if (Train->mvOccupied->modernDimmerCanCycle) dimPos = 0; // return to 0 @@ -6810,8 +6806,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 - auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; - if (vehicle == nullptr) + if (auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; vehicle == nullptr) { return; } @@ -7247,9 +7242,8 @@ void TTrain::OnCommand_doorpermitpresetactivateprevious(TTrain *Train, command_d void TTrain::OnCommand_dooropenleft(TTrain *Train, command_data const &Command) { - auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; - if (false == remoteopencontrol) + if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol) { return; } @@ -7289,9 +7283,8 @@ void TTrain::OnCommand_dooropenleft(TTrain *Train, command_data const &Command) void TTrain::OnCommand_doorcloseleft(TTrain *Train, command_data const &Command) { - auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; - if (false == remoteclosecontrol) + if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol) { return; } @@ -7422,9 +7415,8 @@ void TTrain::OnCommand_doortoggleright(TTrain *Train, command_data const &Comman void TTrain::OnCommand_dooropenright(TTrain *Train, command_data const &Command) { - auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; - if (false == remoteopencontrol) + if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol) { return; } @@ -7465,9 +7457,8 @@ void TTrain::OnCommand_dooropenright(TTrain *Train, command_data const &Command) void TTrain::OnCommand_doorcloseright(TTrain *Train, command_data const &Command) { - auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; - if (false == remoteclosecontrol) + if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol) { return; } @@ -7522,9 +7513,8 @@ void TTrain::OnCommand_doorcloseright(TTrain *Train, command_data const &Command void TTrain::OnCommand_dooropenall(TTrain *Train, command_data const &Command) { - auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; - if (false == remoteopencontrol) + if (auto const remoteopencontrol{Train->mvOccupied->Doors.open_control == control_t::driver || Train->mvOccupied->Doors.open_control == control_t::mixed}; false == remoteopencontrol) { return; } @@ -7557,9 +7547,8 @@ void TTrain::OnCommand_dooropenall(TTrain *Train, command_data const &Command) void TTrain::OnCommand_doorcloseall(TTrain *Train, command_data const &Command) { - auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; - if (false == remoteclosecontrol) + if (auto const remoteclosecontrol{Train->mvOccupied->Doors.close_control == control_t::driver || Train->mvOccupied->Doors.close_control == control_t::mixed}; false == remoteclosecontrol) { return; } @@ -8219,8 +8208,7 @@ void TTrain::OnCommand_cabchangeforward(TTrain *Train, command_data const &Comma if (Command.action == GLFW_PRESS) { auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)}; - auto const movedirection{1}; - if (false == Train->CabChange(movedirection)) + if (auto const movedirection{1}; false == Train->CabChange(movedirection)) { auto const exitdirection{(movedirection > 0 ? end::front : end::rear)}; if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway)) @@ -8250,8 +8238,7 @@ void TTrain::OnCommand_cabchangebackward(TTrain *Train, command_data const &Comm if (Command.action == GLFW_PRESS) { auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)}; - auto const movedirection{-1}; - if (false == Train->CabChange(movedirection)) + if (auto const movedirection{-1}; false == Train->CabChange(movedirection)) { // current vehicle doesn't extend any farther in this direction, check if we there's one connected we can move to auto const exitdirection{(movedirection > 0 ? end::front : end::rear)}; @@ -10897,8 +10884,7 @@ const TTrain::screenentry_sequence &TTrain::get_screens() void TTrain::radio_message(sound_source *Message, int const Channel) { - auto const soundrange{Message->range()}; - if (soundrange > 0 && glm::length2(Message->location() - glm::dvec3{DynamicObject->GetPosition()}) > sq(soundrange)) + if (auto const soundrange{Message->range()}; soundrange > 0 && glm::length2(Message->location() - glm::dvec3{DynamicObject->GetPosition()}) > sq(soundrange)) { // skip message playback if the receiver is outside of the emitter's range return; diff --git a/vr/vr_interface.cpp b/vr/vr_interface.cpp index 9f9ff4e4..c46bce56 100644 --- a/vr/vr_interface.cpp +++ b/vr/vr_interface.cpp @@ -12,8 +12,7 @@ bool vr_interface_factory::register_backend(const std::string &backend, vr_inter std::unique_ptr vr_interface_factory::create(const std::string &backend) { - auto it = backends.find(backend); - if (it != backends.end()) + if (auto it = backends.find(backend); it != backends.end()) return it->second(); ErrorLog("vr backend \"" + backend + "\" not found!"); diff --git a/widgets/cameraview_extcam.cpp b/widgets/cameraview_extcam.cpp index 6e777249..1da51535 100644 --- a/widgets/cameraview_extcam.cpp +++ b/widgets/cameraview_extcam.cpp @@ -62,8 +62,7 @@ void ui::cameraview_panel::render() ImGui::SetNextWindowSizeConstraints(ImVec2(200, 200), ImVec2(2500, 2500), cameraview_window_callback); - auto const panelname{(title.empty() ? m_name : title) + "###" + m_name}; - if (ImGui::Begin(panelname.c_str(), &is_open)) { + if (auto const panelname{(title.empty() ? m_name : title) + "###" + m_name}; ImGui::Begin(panelname.c_str(), &is_open)) { render_contents(); } diff --git a/world/EvLaunch.cpp b/world/EvLaunch.cpp index 4c804045..018a70e9 100644 --- a/world/EvLaunch.cpp +++ b/world/EvLaunch.cpp @@ -138,8 +138,7 @@ bool TEventLauncher::Load(cParser *parser) iHour = int( DeltaTime - iMinute ) / 100; // godzina to setki DeltaTime = 0; // bez powtórzeń // potentially shift the provided time by requested offset - auto const timeoffset{ static_cast( Global.ScenarioTimeOffset * 60 ) }; - if( timeoffset != 0 ) { + if( auto const timeoffset{ static_cast( Global.ScenarioTimeOffset * 60 ) }; timeoffset != 0 ) { auto const adjustedtime{ clamp_circular( iHour * 60 + iMinute + timeoffset, 24 * 60 ) }; iHour = adjustedtime / 60 % 24; iMinute = adjustedtime % 60; @@ -269,9 +268,8 @@ TEventLauncher::export_as_text_( std::ostream &Output ) const { // activation key if( iKey != 0 ) { auto key { iKey & 0xff }; - auto const modifier { iKey >> 8 }; - if (key >= 'A' && key <= 'Z' && !(modifier & GLFW_MOD_SHIFT)) + if (auto const modifier { iKey >> 8 }; key >= 'A' && key <= 'Z' && !(modifier & GLFW_MOD_SHIFT)) key += 32; Output << (char)key; diff --git a/world/Segment.cpp b/world/Segment.cpp index 6d26ee54..a9b79527 100644 --- a/world/Segment.cpp +++ b/world/Segment.cpp @@ -593,9 +593,8 @@ glm::vec3 TSegment::get_nearest_point(const glm::dvec3 &point, float quality) co for (x = step; x <= 1.0f; x += step) { glm::vec3 p1 = FastGetPoint(x); - glm::vec3 p2 = FastGetPoint(glm::min(1.0f, x + step)); - if (p1 != p2) { + if (glm::vec3 p2 = FastGetPoint(glm::min(1.0f, x + step)); p1 != p2) { float l2 = glm::distance2(p1, p2); float t = glm::max(0.0f, glm::min(1.0f, glm::dot((glm::vec3)point - p1, p2 - p1) / l2)); glm::vec3 proj = p1 + t * (p2 - p1); diff --git a/world/Spring.cpp b/world/Spring.cpp index 0ef99f62..56bcb845 100644 --- a/world/Spring.cpp +++ b/world/Spring.cpp @@ -24,8 +24,7 @@ glm::dvec3 TSpring::ComputateForces(glm::dvec3 const &pPosition1, glm::dvec3 con // VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance auto deltaP = pPosition1 - pPosition2; // dist = VectorLength(&deltaP); // Magnitude of deltaP - auto dist = glm::length(deltaP); - if( dist > restLen ) { + if( auto dist = glm::length(deltaP); dist > restLen ) { // Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest) auto Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest) diff --git a/world/Traction.cpp b/world/Traction.cpp index 8442a3d7..f258a328 100644 --- a/world/Traction.cpp +++ b/world/Traction.cpp @@ -114,10 +114,9 @@ TTraction::Load( cParser *parser, glm::dvec3 const &pOrigin ) { // SKB70-C, CuCd70-2C, KB95-2C, C95-C, C95-2C, YC95-2C, YpC95-2C, YC120-2C // YpC120-2C, YzC120-2C, YwsC120-2C, YC150-C150, YC150-2C150, C150-C150 // C120-2C, 2C120-2C, 2C120-2C-1, 2C120-2C-2, 2C120-2C-3, 2C120-2C-4 - auto const material = parser->getToken(); // 1=miedziana, rysuje się na zielono albo czerwono // 2=aluminiowa, rysuje się na czarno - if( material == "none" ) { Material = 0; } + if( auto const material = parser->getToken(); material == "none" ) { Material = 0; } else if( material == "al" ) { Material = 2; } else { Material = 1; } parser->getTokens( 2 ); @@ -824,8 +823,7 @@ traction_table::InitTraction() { } else if( traction->hvParallel == nullptr ) { // jeśli jeszcze nie został włączony w kółko - auto *nTemp = find( traction->asParallel ); - if( nTemp != nullptr ) { + if( auto *nTemp = find( traction->asParallel ); nTemp != nullptr ) { // o ile zostanie znalezione przęsło o takiej nazwie if( nTemp->hvParallel == nullptr ) { // jeśli tamten jeszcze nie ma wskaźnika bieżni wspólnej diff --git a/world/mtable.cpp b/world/mtable.cpp index aef5812c..d2b7975b 100644 --- a/world/mtable.cpp +++ b/world/mtable.cpp @@ -574,8 +574,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) // load_sounds(); // potentially offset table times - auto const timeoffset { static_cast( Global.ScenarioTimeOffset * 60 ) + iPlus }; - if( timeoffset != 0 ) // jeżeli jest przesunięcie rozkładu + if( auto const timeoffset { static_cast( Global.ScenarioTimeOffset * 60 ) + iPlus }; timeoffset != 0 ) // jeżeli jest przesunięcie rozkładu { long i_end = StationCount + 1; float adjustedtime; // do zwiększania czasu