17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-05 16:52:31 +01:00

refactor(sonar): scope single-use variables in if init-statements (cpp:S6004)

This commit is contained in:
jerrrrycho
2026-10-10 15:44:18 +02:00
parent 0d886e65ec
commit 6fce71af36
27 changed files with 78 additions and 175 deletions

View File

@@ -595,9 +595,8 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters *
auto &othercoupler = ConnectTo->Couplers[(ConnectToNr != 2 ? ConnectToNr : coupler.ConnectedNr)]; auto &othercoupler = ConnectTo->Couplers[(ConnectToNr != 2 ? ConnectToNr : coupler.ConnectedNr)];
auto const distance{CouplerDist(this, ConnectTo) - (coupler.adapter_length + othercoupler.adapter_length)}; 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; return false;
} }
@@ -1570,10 +1569,9 @@ void TMoverParameters::compute_movement_(double const Deltatime)
// Uproszczona symulacja wentylatorow rezystora hamowania // Uproszczona symulacja wentylatorow rezystora hamowania
// Prad oddawany na rezystor // 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 // 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; BRVtimer = 0;
BRVentilators = true; 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 TMoverParameters::SandboxAuto(bool const State, range_t const Notify)
{ {
bool result{false}; bool result{false};
bool NewState = State && SandDoseAutoAllow; if (bool NewState = State && SandDoseAutoAllow; SandDoseAuto != NewState)
if (SandDoseAuto != NewState)
{ {
if (SandDoseAuto == false) if (SandDoseAuto == false)
{ {
@@ -3921,8 +3918,7 @@ double TMoverParameters::DynamicBrakeRatio(void) const
bool TMoverParameters::DynamicBrakeAvailable(void) const bool TMoverParameters::DynamicBrakeAvailable(void) const
{ {
double const vh0{eimc[eimc_p_Vh0]}; double const vh0{eimc[eimc_p_Vh0]};
double const vh1{eimc[eimc_p_Vh1]}; if (double const vh1{eimc[eimc_p_Vh1]}; vh1 <= 0.001)
if (vh1 <= 0.001)
{ {
// brak zdefiniowanej strefy - ED dziala zawsze // brak zdefiniowanej strefy - ED dziala zawsze
return true; return true;
@@ -4331,9 +4327,8 @@ void TMoverParameters::CompressorCheck(double dt)
auto const MaxCompressorF{CompressorList[TCompressorList::cl_MaxFactor][CompressorListPos] * MaxCompressor}; auto const MaxCompressorF{CompressorList[TCompressorList::cl_MaxFactor][CompressorListPos] * MaxCompressor};
auto const MinCompressorF{CompressorList[TCompressorList::cl_MinFactor][CompressorListPos] * MinCompressor}; auto const MinCompressorF{CompressorList[TCompressorList::cl_MinFactor][CompressorListPos] * MinCompressor};
auto const CompressorSpeedF{CompressorList[TCompressorList::cl_SpeedFactor][CompressorListPos] * CompressorSpeed}; auto const CompressorSpeedF{CompressorList[TCompressorList::cl_SpeedFactor][CompressorListPos] * CompressorSpeed};
auto const AllowFactor{CompressorList[TCompressorList::cl_Allow][CompressorListPos]};
// checking the impact on the compressor allowance // 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; CompressorAllow = AllowFactor > 1.5;
} }
@@ -6470,9 +6465,8 @@ double TMoverParameters::TractionForce(double dt)
auto const tmpV{std::abs(eimv[eimv_fp])}; auto const tmpV{std::abs(eimv[eimv_fp])};
auto const useFFEDList = FFEDListSize > 0 && DynamicBrakeFlag; auto const useFFEDList = FFEDListSize > 0 && DynamicBrakeFlag;
auto const list = useFFEDList ? FFEDlist : FFlist; 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; int i = 0;
@@ -6610,8 +6604,7 @@ void TMoverParameters::FuseOff(void)
bool TMoverParameters::UniversalResetButton(int const Button, range_t const Notify) bool TMoverParameters::UniversalResetButton(int const Button, range_t const Notify)
{ {
auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; if (auto const lowvoltagepower{Power24vIsAvailable || Power110vIsAvailable}; false == lowvoltagepower)
if (false == lowvoltagepower)
{ {
return false; return false;
} }
@@ -8195,8 +8188,7 @@ double TMoverParameters::dizel_MomentumRetarder(double n, double dt)
} }
double Moment = hydro_R_MaxTorque; double Moment = hydro_R_MaxTorque;
double pwr = Moment * std::abs(n) * M_PI * 2 * 0.001; if (double pwr = Moment * std::abs(n) * M_PI * 2 * 0.001; pwr > hydro_R_MaxPower)
if (pwr > hydro_R_MaxPower)
Moment = Moment * hydro_R_MaxPower / pwr; Moment = Moment * hydro_R_MaxPower / pwr;
double moment_in = n * n * hydro_R_TorqueInIn; double moment_in = n * n * hydro_R_TorqueInIn;
Moment = std::min(moment_in, Moment * hydro_R_Fill); Moment = std::min(moment_in, Moment * hydro_R_Fill);
@@ -8937,8 +8929,7 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const
continue; continue;
} }
auto const &coupler{Couplers[end]}; auto const &coupler{Couplers[end]};
auto const fullcoupling{coupler.CouplingFlag | (TestFlag(coupler.CouplingFlag, coupler.PowerCoupling) ? coupler.PowerFlag : 0)}; if (auto const fullcoupling{coupler.CouplingFlag | (TestFlag(coupler.CouplingFlag, coupler.PowerCoupling) ? coupler.PowerFlag : 0)}; (fullcoupling & Coupling) == 0)
if ((fullcoupling & Coupling) == 0)
{ {
continue; continue;
} }
@@ -10835,8 +10826,7 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
extract_value(ScndInMain, "SCIM", line, ""); extract_value(ScndInMain, "SCIM", line, "");
extract_value(MainCtrlMaxDirChangePos, "DirChangeMaxPos", line, ""); extract_value(MainCtrlMaxDirChangePos, "DirChangeMaxPos", line, "");
auto const autorelay{ToLower(extract_value("AutoRelay", line))}; if (auto const autorelay{ToLower(extract_value("AutoRelay", line))}; autorelay == "optional")
if (autorelay == "optional")
{ {
AutoRelayType = 2; AutoRelayType = 2;
} }
@@ -11117,8 +11107,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input)
EngineType = LoadFIZ_EngineDecode(extract_value("EngineType", Input)); EngineType = LoadFIZ_EngineDecode(extract_value("EngineType", Input));
std::string transmission = extract_value("Trans", Input); if (std::string transmission = extract_value("Trans", Input); false == transmission.empty())
if (false == transmission.empty())
{ {
// transmission type. moved here because more than one engine type has this entry // transmission type. moved here because more than one engine type has this entry
auto ratios = Split(transmission, ':'); // e.g. 18:79 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, ""); extract_value(RlistSize, "Size", Input, "");
auto const venttype{ToLower(extract_value("RVent", Input))}; if (auto const venttype{ToLower(extract_value("RVent", Input))}; venttype == "automatic")
if (venttype == "automatic")
{ {
RVentType = 2; RVentType = 2;
@@ -11564,8 +11552,7 @@ void TMoverParameters::LoadFIZ_PowerParamsDecode(TPowerParameters &Powerparamete
// prime mover for the generator // prime mover for the generator
auto &generatorparameters{Powerparameters.EngineGenerator}; auto &generatorparameters{Powerparameters.EngineGenerator};
auto const enginetype{LoadFIZ_EngineDecode(extract_value(Prefix + "GeneratorEngine", Line))}; if (auto const enginetype{LoadFIZ_EngineDecode(extract_value(Prefix + "GeneratorEngine", Line))}; enginetype == TEngineType::Main)
if (enginetype == TEngineType::Main)
{ {
generatorparameters.engine_revolutions = &enrot; 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 left{CValue2 > 0 ? 1 : 2};
auto const right{3 - left};
if (std::abs(static_cast<int>(CValue1)) & right) if (auto const right{3 - left}; std::abs(static_cast<int>(CValue1)) & right)
{ {
PermitDoors_(side::right, CValue1 > 0); PermitDoors_(side::right, CValue1 > 0);
} }
@@ -12580,8 +12566,7 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV
auto const inputoperation{static_cast<int>(CValue1) & ~(0x80 | 0x40)}; auto const inputoperation{static_cast<int>(CValue1) & ~(0x80 | 0x40)};
auto const noswap{TrainType == dt_EZT || TrainType == dt_ET41}; 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 swap{false == noswap && TestFlag(Couplers[(CValue2 == -1 ? end::rear : end::front)].CouplingFlag, coupling::control)};
auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed)
if (reversed)
{ {
swap = !swap; swap = !swap;
} // TODO: check whether this part has RL equivalent } // 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") else if (Command == "BrakeDelay")
{ {
auto const brakesetting = static_cast<int>(std::floor(CValue1)); if (auto const brakesetting = static_cast<int>(std::floor(CValue1)); true == Hamulec->SetBDF(brakesetting))
if (true == Hamulec->SetBDF(brakesetting))
{ {
BrakeDelayFlag = brakesetting; BrakeDelayFlag = brakesetting;
OK = true; OK = true;
@@ -12784,8 +12768,7 @@ bool TMoverParameters::reload_FIZ()
WriteLog("[DEV] Reloading FIZ for " + Name); WriteLog("[DEV] Reloading FIZ for " + Name);
// pause simulation // pause simulation
Global.iPause |= 0b1000; Global.iPause |= 0b1000;
bool result = LoadFIZ(chkPath); if (bool result = LoadFIZ(chkPath); result == true)
if (result == true)
{ {
// jesli sie udalo przeladowac FIZ // jesli sie udalo przeladowac FIZ
Global.iPause &= 0b0111; Global.iPause &= 0b0111;

View File

@@ -1712,8 +1712,7 @@ double TLSt::GetPF(double const PP, double const dt, double const Vel)
SoundFlag |= sf_CylU; SoundFlag |= sf_CylU;
} }
// equivalent of checkreleaser() in the base class? // equivalent of checkreleaser() in the base class?
bool is_releasing = BrakeStatus & b_rls || UniversalFlag & TUniversalBrake::ub_Release; if (bool is_releasing = BrakeStatus & b_rls || UniversalFlag & TUniversalBrake::ub_Release; is_releasing)
if (is_releasing)
{ {
if (CVP < 0.0) if (CVP < 0.0)
{ {

View File

@@ -61,8 +61,7 @@ drivingaid_panel::update() {
// grade // grade
std::string gradetext; std::string gradetext;
auto const reverser { ( mover->DirActive > 0 ? 1 : -1 ) }; auto const reverser { ( mover->DirActive > 0 ? 1 : -1 ) };
auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser }; if( auto const grade { controlled->VectorFront().y * 100 * ( controlled->DirectionGet() == reverser ? 1 : -1 ) * reverser }; std::abs( grade ) >= 0.25 ) {
if( std::abs( grade ) >= 0.25 ) {
std::snprintf( std::snprintf(
m_buffer.data(), m_buffer.size(), m_buffer.data(), m_buffer.size(),
STR_C(" Grade: %.1f%%%%"), 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 // 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 // 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 noactivespeedlimit { owner->VelLimitLastDist.second < 0 };
auto const speedatproximitydistance { min_speed( schedulespeedlimit, static_cast<int>( owner->VelNext ) ) }; if( auto const speedatproximitydistance { min_speed( schedulespeedlimit, static_cast<int>( owner->VelNext ) ) }; speedatproximitydistance == nextspeedlimit ) {
if( speedatproximitydistance == nextspeedlimit ) {
if( noactivespeedlimit ) { if( noactivespeedlimit ) {
nextspeedlimit = speedatproximitydistance; nextspeedlimit = speedatproximitydistance;
nextspeedlimitdistance = owner->ActualProximityDist; nextspeedlimitdistance = owner->ActualProximityDist;
@@ -253,12 +251,7 @@ scenario_panel::render() {
if( size_min.x > 0 ) { if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
} }
auto const panelname { ( if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
title.empty() ?
m_name :
title )
+ "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// potential assignment section // potential assignment section
auto const *owner { ( auto const *owner { (
m_nearest->Mechanik != nullptr && m_nearest->Mechanik->primary() ? m_nearest->Mechanik != nullptr && m_nearest->Mechanik->primary() ?
@@ -362,8 +355,7 @@ timetable_panel::update() {
//odejmij lokomotywy czynne, a przynajmniej aktualną //odejmij lokomotywy czynne, a przynajmniej aktualną
consistmass -= owner->pVehicle->MoverParameters->TotalMass; consistmass -= owner->pVehicle->MoverParameters->TotalMass;
// subtract potential other half of a two-part vehicle // subtract potential other half of a two-part vehicle
auto const *previous { owner->pVehicle->Prev( coupling::permanent ) }; if( auto const *previous { owner->pVehicle->Prev( coupling::permanent ) }; previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; }
if( previous != nullptr ) { consistmass -= previous->MoverParameters->TotalMass; }
auto const *next { owner->pVehicle->Next( coupling::permanent ) }; auto const *next { owner->pVehicle->Next( coupling::permanent ) };
if( next != nullptr ) { consistmass -= next->MoverParameters->TotalMass; } if( next != nullptr ) { consistmass -= next->MoverParameters->TotalMass; }
} }
@@ -484,12 +476,7 @@ timetable_panel::render() {
if( size_min.x > 0 ) { if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x * horizontalScale, size_min.y ), ImVec2S( size_max.x * horizontalScale, size_max.y ) ); ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x * horizontalScale, size_min.y ), ImVec2S( size_max.x * horizontalScale, size_max.y ) );
} }
auto const panelname { ( if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
title.empty() ?
m_name :
title )
+ "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
for( auto const &line : text_lines ) { 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() ); 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 ) { if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
} }
auto const panelname { ( if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
title.empty() ?
m_name :
title )
+ "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section // header section
for( auto const &line : text_lines ) { 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() ); 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 ) { if( size_min.x > 0 ) {
ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) ); ImGui::SetNextWindowSizeConstraints( ImVec2S( size_min.x, size_min.y ), ImVec2S( size_max.x, size_max.y ) );
} }
auto const panelname { ( if( auto const panelname { ( title.empty() ? m_name : title ) + "###" + m_name }; true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
title.empty() ?
m_name :
title )
+ "###" + m_name };
if( true == ImGui::Begin( panelname.c_str(), &is_open, flags ) ) {
// header section // header section
for( auto const &line : text_lines ) { for( auto const &line : text_lines ) {
ImGui::TextWrapped( "%s", line.data.c_str() ); ImGui::TextWrapped( "%s", line.data.c_str() );

View File

@@ -154,8 +154,7 @@ std::pair<GLuint, std::string> gl::shader::process_source(const std::string &fil
// the driver advertises support (see desktop comment above). // the driver advertises support (see desktop comment above).
// (Glad config doesn't generate GLAD_GL_EXT_gpu_shader5 -- query // (Glad config doesn't generate GLAD_GL_EXT_gpu_shader5 -- query
// the live extension string the same way.) // the live extension string the same way.)
static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5"); if (static bool const have_gpu_shader5 = has_gl_extension("GL_EXT_gpu_shader5"); have_gpu_shader5)
if (have_gpu_shader5)
str += "#extension GL_EXT_gpu_shader5 : enable\n"; str += "#extension GL_EXT_gpu_shader5 : enable\n";
if (type == GL_GEOMETRY_SHADER) if (type == GL_GEOMETRY_SHADER)
str += "#extension GL_EXT_geometry_shader : require\n"; str += "#extension GL_EXT_geometry_shader : require\n";

View File

@@ -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) { void command_queue::push_direct(const command_data &Command, const uint32_t Recipient) {
auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( Command.command ) ]; if (auto const &desc = simulation::Commands_descriptions[ static_cast<std::size_t>( Command.command ) ]; desc.mode == command_mode::continuous)
if (desc.mode == command_mode::continuous)
{ {
if (Command.action == GLFW_PRESS) if (Command.action == GLFW_PRESS)
m_active_continuous.emplace(std::make_pair(Command.command, Recipient)); 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 { 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 false;
return true; return true;

View File

@@ -171,8 +171,7 @@ drivermouse_input::recall_bindings() {
std::string filePath = "eu07_input-mouse.ini"; std::string filePath = "eu07_input-mouse.ini";
fs::path appPath = user_config_path("eu07_input-mouse.ini"); if (fs::path appPath = user_config_path("eu07_input-mouse.ini"); !appPath.empty() && fs::exists(appPath))
if (!appPath.empty() && fs::exists(appPath))
filePath = appPath.string(); filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);

View File

@@ -51,8 +51,7 @@ gamepad_input::init() {
m_inputbuttons.clear(); m_inputbuttons.clear();
// NOTE: we're only checking for joystick_1 and rely for it to stay connected throughout. // 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 // not exactly flexible, but for quick hack it'll do
auto const name = glfwGetJoystickName( GLFW_JOYSTICK_1 ); if( auto const name = glfwGetJoystickName( GLFW_JOYSTICK_1 ); name != nullptr ) {
if( name != nullptr ) {
WriteLog( "Connected gamepad: " + std::string( name ) ); WriteLog( "Connected gamepad: " + std::string( name ) );
m_deviceid = GLFW_JOYSTICK_1; m_deviceid = GLFW_JOYSTICK_1;
} }
@@ -154,8 +153,7 @@ bool
gamepad_input::recall_bindings() { gamepad_input::recall_bindings() {
std::string filePath = "eu07_input-gamepad.ini"; std::string filePath = "eu07_input-gamepad.ini";
fs::path appPath = user_config_path("eu07_input-gamepad.ini"); if (fs::path appPath = user_config_path("eu07_input-gamepad.ini"); !appPath.empty() && fs::exists(appPath))
if (!appPath.empty() && fs::exists(appPath))
filePath = appPath.string(); filePath = appPath.string();
// bindingparser tworzony zawsze, z wybran<61> <20>cie<69>k<EFBFBD> // bindingparser tworzony zawsze, z wybran<61> <20>cie<69>k<EFBFBD>
@@ -211,8 +209,7 @@ gamepad_input::recall_bindings() {
std::string key {}; std::string key {};
entryparser >> key; entryparser >> key;
// check for potential mode indicator // check for potential mode indicator
auto const splitkey { split_string_and_number( key ) }; if( auto const splitkey { split_string_and_number( key ) }; splitkey.first == "mode" ) {
if( splitkey.first == "mode" ) {
// indicate we'll be processing specified mode // indicate we'll be processing specified mode
controlmode = splitkey.second; controlmode = splitkey.second;
continue; continue;

View File

@@ -239,8 +239,7 @@ void keyboard_input::dump_bindings() const
stream << simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name << ' '; stream << simulation::Commands_descriptions[static_cast<std::size_t>(binding.first)].name << ' ';
int keycode = std::get<int>(binding.second); int keycode = std::get<int>(binding.second);
auto it = keytonamemap.find(keycode & 0xFFFF); if (auto it = keytonamemap.find(keycode & 0xFFFF); it != keytonamemap.end()) {
if (it != keytonamemap.end()) {
if (keycode & keymodifier::control) if (keycode & keymodifier::control)
stream << "ctrl "; stream << "ctrl ";
if (keycode & keymodifier::shift) 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 ); | ( modifier ? 0 : input::key_ctrl ? keymodifier::control : 0 );
if( Action == GLFW_RELEASE ) { if( Action == GLFW_RELEASE ) {
auto const stored = m_modsforkeys.find( Key ); if( auto const stored = m_modsforkeys.find( Key ); stored != m_modsforkeys.end() ) {
if( stored != m_modsforkeys.end() ) {
key = stored->second; key = stored->second;
} }
m_modsforkeys.erase( Key ); m_modsforkeys.erase( Key );

View File

@@ -86,8 +86,7 @@ void ui::vehicles_bank::parse_category_entry(const std::string &param)
if (tok.size() < 1) if (tok.size() < 1)
return; return;
auto it = type_map.find(tok[0]); if (auto it = type_map.find(tok[0]); it != type_map.end())
if (it != type_map.end())
ctx_type = it->second; ctx_type = it->second;
else if (tok[0] >= 'A' && tok[0] <= 'Z') else if (tok[0] >= 'A' && tok[0] <= 'Z')
ctx_type = vehicle_type::carriage; ctx_type = vehicle_type::carriage;

View File

@@ -103,9 +103,8 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const
} }
// first load attempt, check if it's on disk // 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ć model = LoadModel( disklookup, disklookup + postfix, Dynamic ); // model nie znaleziony, to wczytać
} }
else { else {

View File

@@ -54,8 +54,7 @@ void network::tcp::connection::handle_header(const asio::error_code &err, size_t
return; return;
} }
uint32_t sig = sn_utils::ld_uint32(header); if (uint32_t sig = sn_utils::ld_uint32(header); sig != NETWORK_MAGIC) {
if (sig != NETWORK_MAGIC) {
disconnect(); disconnect();
return; return;
} }

View File

@@ -467,16 +467,14 @@ particle_manager::find( std::string const &Template ) {
auto const templatename { ToLower( Template ) }; auto const templatename { ToLower( Template ) };
// try to locate specified rail profile... // try to locate specified rail profile...
auto const lookup { m_sourcetemplates.find( templatename ) }; if( auto const lookup { m_sourcetemplates.find( templatename ) }; lookup != m_sourcetemplates.end() ) {
if( lookup != m_sourcetemplates.end() ) {
// ...if it works, we're done... // ...if it works, we're done...
return &(lookup->second); return &(lookup->second);
} }
// ... and if it fails try to add the template to the database from a data file // ... and if it fails try to add the template to the database from a data file
smoke_source source; 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... // if deserialization didn't fail finish source setup...
source.m_opacitymodifier.bind( &Global.SmokeFidelity ); source.m_opacitymodifier.bind( &Global.SmokeFidelity );

View File

@@ -181,8 +181,7 @@ void render_task::run()
int p1 = 0; int p1 = 0;
int p2 = 0; int p2 = 0;
size_t pos1 = cmd.find(';'); if (size_t pos1 = cmd.find(';'); pos1 == std::string::npos)
if (pos1 == std::string::npos)
{ {
baseCmd = cmd; baseCmd = cmd;
} }
@@ -474,8 +473,7 @@ void python_taskqueue::release_lock() const
auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject * auto python_taskqueue::fetch_renderer(std::string const Renderer) -> PyObject *
{ {
auto const lookup{m_renderers.find(Renderer)}; if (auto const lookup{m_renderers.find(Renderer)}; lookup != std::end(m_renderers))
if (lookup != std::end(m_renderers))
{ {
return lookup->second; return lookup->second;
} }
@@ -623,11 +621,9 @@ void python_taskqueue::error()
{ {
// std err pythona jest buforowane // std err pythona jest buforowane
PyErr_Print(); PyErr_Print();
auto *errortext{PyObject_CallMethod(m_stderr, const_cast<char *>("getvalue"), nullptr)}; if (auto *errortext{PyObject_CallMethod(m_stderr, const_cast<char *>("getvalue"), nullptr)}; errortext != nullptr)
if (errortext != nullptr)
{ {
const char *errstr = PyUnicode_AsUTF8(errortext); if (const char *errstr = PyUnicode_AsUTF8(errortext); errstr != nullptr)
if (errstr != nullptr)
ErrorLog(errstr); ErrorLog(errstr);
Py_DECREF(errortext); Py_DECREF(errortext);
} }
@@ -650,11 +646,9 @@ void python_taskqueue::error()
{ {
ErrorLog("Python Interpreter: don't know how to handle null exception"); ErrorLog("Python Interpreter: don't know how to handle null exception");
} }
auto *typetext{PyObject_Str(type)}; if (auto *typetext{PyObject_Str(type)}; typetext != nullptr)
if (typetext != nullptr)
{ {
const char *s = PyUnicode_AsUTF8(typetext); if (const char *s = PyUnicode_AsUTF8(typetext); s)
if (s)
ErrorLog(s); ErrorLog(s);
Py_DECREF(typetext); Py_DECREF(typetext);
} }
@@ -663,8 +657,7 @@ void python_taskqueue::error()
auto *valuetext{PyObject_Str(value)}; auto *valuetext{PyObject_Str(value)};
if (valuetext != nullptr) if (valuetext != nullptr)
{ {
const char *s = PyUnicode_AsUTF8(valuetext); if (const char *s = PyUnicode_AsUTF8(valuetext); s)
if (s)
ErrorLog(s); ErrorLog(s);
Py_DECREF(valuetext); Py_DECREF(valuetext);
} }
@@ -672,8 +665,7 @@ void python_taskqueue::error()
auto *tracebacktext{PyObject_Str(traceback)}; auto *tracebacktext{PyObject_Str(traceback)};
if (tracebacktext != nullptr) if (tracebacktext != nullptr)
{ {
const char *s = PyUnicode_AsUTF8(tracebacktext); if (const char *s = PyUnicode_AsUTF8(tracebacktext); s)
if (s)
ErrorLog(s); ErrorLog(s);
Py_DECREF(tracebacktext); Py_DECREF(tracebacktext);
} }

View File

@@ -176,8 +176,7 @@ scenario_time::julian_day() const {
// for dates in Julian calendar // for dates in Julian calendar
int JD = K1 + K2 + m_time.wDay + 59; int JD = K1 + K2 + m_time.wDay + 59;
// for dates in Gregorian calendar; 2299160 is October 15th, 1582 // for dates in Gregorian calendar; 2299160 is October 15th, 1582
const int gregorianswitchday = 2299160; if( const int gregorianswitchday = 2299160; JD > gregorianswitchday ) {
if( JD > gregorianswitchday ) {
int K3 = static_cast<int>(std::floor( std::floor( yy * 0.01 + 49 ) * 0.75 ) - 38); int K3 = static_cast<int>(std::floor( std::floor( yy * 0.01 + 49 ) * 0.75 ) - 38);
JD -= K3; JD -= K3;

View File

@@ -193,8 +193,7 @@ uart_input::recall_bindings() {
m_inputbindings.clear(); m_inputbindings.clear();
std::string filePath = "eu07_input-uart.ini"; std::string filePath = "eu07_input-uart.ini";
fs::path appPath = user_config_path("eu07_input-uart.ini"); if (fs::path appPath = user_config_path("eu07_input-uart.ini"); !appPath.empty() && fs::exists(appPath))
if (!appPath.empty() && fs::exists(appPath))
filePath = appPath.string(); filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); cParser bindingparser(filePath.c_str(), cParser::buffer_FILE);
if (false == bindingparser.ok()) if (false == bindingparser.ok())

View File

@@ -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 // NOTE, HACK: the leading space allows to uniformly look for " variable=" substring
std::string const input{" " + Input}; std::string const input{" " + Input};
std::string value; std::string value;
auto lookup = input.find(" " + Key + "="); if (auto lookup = input.find(" " + Key + "="); lookup != std::string::npos)
if (lookup != std::string::npos)
{ {
value = input.substr(input.find_first_not_of(' ', lookup + Key.size() + 2)); value = input.substr(input.find_first_not_of(' ', lookup + Key.size() + 2));
lookup = value.find(' '); lookup = value.find(' ');

View File

@@ -123,9 +123,8 @@ TButton::Turn( bool const State ) {
void TButton::Update( bool const Power ) { void TButton::Update( bool const Power ) {
// TODO: remove passing manually power state when LD is in place // 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; m_state = state;
play(); play();

View File

@@ -172,11 +172,7 @@ void TCamera::Update()
// attached movement position update // attached movement position update
auto movement { Velocity * -2.0 }; auto movement { Velocity * -2.0 };
movement.y = -movement.y; movement.y = -movement.y;
auto const *owner { ( if( auto const *owner { ( m_owner->Mechanik ? m_owner->Mechanik : m_owner->ctOwner ) }; owner && owner->Occupied()
m_owner->Mechanik ?
m_owner->Mechanik :
m_owner->ctOwner ) };
if( owner && owner->Occupied()
&& owner->Occupied()->CabOccupied < 0 ) { && owner->Occupied()->CabOccupied < 0 ) {
movement *= -1.f; movement *= -1.f;
movement.y = -movement.y; movement.y = -movement.y;

View File

@@ -307,8 +307,7 @@ TGauge::UpdateValue( float fNewDesired ) {
m_targetvalue = fNewDesired; m_targetvalue = fNewDesired;
// if there's any sound associated with new requested value, play it // if there's any sound associated with new requested value, play it
// check value-specific table first... // check value-specific table first...
auto const fullinteger { desiredtimes100 % 100 == 0 }; if( auto const fullinteger { desiredtimes100 % 100 == 0 }; fullinteger ) {
if( fullinteger ) {
// filter out values other than full integers // filter out values other than full integers
auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 ); auto const lookup = m_soundfxvalues.find( desiredtimes100 / 100 );
if( lookup != m_soundfxvalues.end() ) { if( lookup != m_soundfxvalues.end() ) {
@@ -321,9 +320,8 @@ TGauge::UpdateValue( float fNewDesired ) {
m_soundtype = sound_flags::exclusive; m_soundtype = sound_flags::exclusive;
} }
// ...and if there isn't any, fall back on the basic set... // ...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 // HACK: crude way to discern controls with continuous and quantized value range
if( currentvalue < fNewDesired ) { if( auto const currentvalue = GetValue(); currentvalue < fNewDesired ) {
// shift up // shift up
if( false == m_soundfxincrease.empty() ) { if( false == m_soundfxincrease.empty() ) {
m_soundfxincrease.play( m_soundtype ); m_soundfxincrease.play( m_soundtype );
@@ -471,8 +469,7 @@ TGauge::UpdateAnimation( TSubModel *Submodel ) const {
case TGaugeAnimation::gt_Wiper: { case TGaugeAnimation::gt_Wiper: {
auto const scaledvalue { GetScaledValue() }; auto const scaledvalue { GetScaledValue() };
Submodel->SetRotate( float3( 0, 1, 0 ), static_cast<float>(scaledvalue * 360.0) ); Submodel->SetRotate( float3( 0, 1, 0 ), static_cast<float>(scaledvalue * 360.0) );
auto *sm = Submodel->ChildGet(); if( auto *sm = Submodel->ChildGet(); sm ) {
if( sm ) {
sm->SetRotate( float3( 0, 1, 0 ), static_cast<float>(scaledvalue * 360.0) ); sm->SetRotate( float3( 0, 1, 0 ), static_cast<float>(scaledvalue * 360.0) );
sm = sm->ChildGet(); sm = sm->ChildGet();
if( sm ) if( sm )

View File

@@ -3593,9 +3593,8 @@ void TTrain::OnCommand_pantographcompressorvalvetoggle(TTrain *Train, command_da
void TTrain::OnCommand_pantographcompressorvalveenable(TTrain *Train, command_data const &Command) 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 // tylko w maszynowym, unless actual device is present
return; return;
@@ -3614,9 +3613,8 @@ void TTrain::OnCommand_pantographcompressorvalveenable(TTrain *Train, command_da
void TTrain::OnCommand_pantographcompressorvalvedisable(TTrain *Train, command_data const &Command) 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 // tylko w maszynowym, unless actual device is present
return; return;
@@ -3636,8 +3634,7 @@ void TTrain::OnCommand_pantographcompressoractivate(TTrain *Train, command_data
{ {
// tylko w maszynowym, unless actual device is present // 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 (auto const switchispresent{Train->m_controlmapper.contains("pantcompressor_sw:") || (Train->mvOccupied == Train->mvPantographUnit && Train->iCabn == 0)}; false == switchispresent)
if (false == switchispresent)
{ {
return; return;
} }
@@ -5839,8 +5836,7 @@ void TTrain::OnCommand_modernlightdimmerincrease(TTrain *Train, command_data con
// update modern dimmer state // update modern dimmer state
auto &dimPos = Train->mvOccupied->modernDimmerPosition; auto &dimPos = Train->mvOccupied->modernDimmerPosition;
auto dimCount = Train->mvOccupied->dimPositions.size(); if (auto dimCount = Train->mvOccupied->dimPositions.size(); dimPos + 1 < dimCount)
if (dimPos + 1 < dimCount)
dimPos++; dimPos++;
else if (Train->mvOccupied->modernDimmerCanCycle) else if (Train->mvOccupied->modernDimmerCanCycle)
dimPos = 0; // return to 0 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 // 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 (auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; vehicle == nullptr)
if (vehicle == nullptr)
{ {
return; return;
} }
@@ -7247,9 +7242,8 @@ void TTrain::OnCommand_doorpermitpresetactivateprevious(TTrain *Train, command_d
void TTrain::OnCommand_dooropenleft(TTrain *Train, command_data const &Command) 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; 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) 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; 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) 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; 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) 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; 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) 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; 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) 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; return;
} }
@@ -8219,8 +8208,7 @@ void TTrain::OnCommand_cabchangeforward(TTrain *Train, command_data const &Comma
if (Command.action == GLFW_PRESS) if (Command.action == GLFW_PRESS)
{ {
auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)}; auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)};
auto const movedirection{1}; if (auto const movedirection{1}; false == Train->CabChange(movedirection))
if (false == Train->CabChange(movedirection))
{ {
auto const exitdirection{(movedirection > 0 ? end::front : end::rear)}; auto const exitdirection{(movedirection > 0 ? end::front : end::rear)};
if (TestFlag(Train->mvOccupied->Couplers[exitdirection].CouplingFlag, coupling::gangway)) 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) if (Command.action == GLFW_PRESS)
{ {
auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)}; auto const *owner{(Train->DynamicObject->ctOwner != nullptr ? Train->DynamicObject->ctOwner : Train->DynamicObject->Mechanik)};
auto const movedirection{-1}; if (auto const movedirection{-1}; false == Train->CabChange(movedirection))
if (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 // 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)}; 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) void TTrain::radio_message(sound_source *Message, int const Channel)
{ {
auto const soundrange{Message->range()}; if (auto const soundrange{Message->range()}; soundrange > 0 && glm::length2(Message->location() - glm::dvec3{DynamicObject->GetPosition()}) > sq(soundrange))
if (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 // skip message playback if the receiver is outside of the emitter's range
return; return;

View File

@@ -12,8 +12,7 @@ bool vr_interface_factory::register_backend(const std::string &backend, vr_inter
std::unique_ptr<vr_interface> vr_interface_factory::create(const std::string &backend) std::unique_ptr<vr_interface> vr_interface_factory::create(const std::string &backend)
{ {
auto it = backends.find(backend); if (auto it = backends.find(backend); it != backends.end())
if (it != backends.end())
return it->second(); return it->second();
ErrorLog("vr backend \"" + backend + "\" not found!"); ErrorLog("vr backend \"" + backend + "\" not found!");

View File

@@ -62,8 +62,7 @@ void ui::cameraview_panel::render()
ImGui::SetNextWindowSizeConstraints(ImVec2(200, 200), ImVec2(2500, 2500), cameraview_window_callback); ImGui::SetNextWindowSizeConstraints(ImVec2(200, 200), ImVec2(2500, 2500), cameraview_window_callback);
auto const panelname{(title.empty() ? m_name : title) + "###" + m_name}; if (auto const panelname{(title.empty() ? m_name : title) + "###" + m_name}; ImGui::Begin(panelname.c_str(), &is_open)) {
if (ImGui::Begin(panelname.c_str(), &is_open)) {
render_contents(); render_contents();
} }

View File

@@ -138,8 +138,7 @@ bool TEventLauncher::Load(cParser *parser)
iHour = int( DeltaTime - iMinute ) / 100; // godzina to setki iHour = int( DeltaTime - iMinute ) / 100; // godzina to setki
DeltaTime = 0; // bez powtórzeń DeltaTime = 0; // bez powtórzeń
// potentially shift the provided time by requested offset // potentially shift the provided time by requested offset
auto const timeoffset{ static_cast<int>( Global.ScenarioTimeOffset * 60 ) }; if( auto const timeoffset{ static_cast<int>( Global.ScenarioTimeOffset * 60 ) }; timeoffset != 0 ) {
if( timeoffset != 0 ) {
auto const adjustedtime{ clamp_circular( iHour * 60 + iMinute + timeoffset, 24 * 60 ) }; auto const adjustedtime{ clamp_circular( iHour * 60 + iMinute + timeoffset, 24 * 60 ) };
iHour = adjustedtime / 60 % 24; iHour = adjustedtime / 60 % 24;
iMinute = adjustedtime % 60; iMinute = adjustedtime % 60;
@@ -269,9 +268,8 @@ TEventLauncher::export_as_text_( std::ostream &Output ) const {
// activation key // activation key
if( iKey != 0 ) { if( iKey != 0 ) {
auto key { iKey & 0xff }; 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; key += 32;
Output << (char)key; Output << (char)key;

View File

@@ -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) { for (x = step; x <= 1.0f; x += step) {
glm::vec3 p1 = FastGetPoint(x); 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 l2 = glm::distance2(p1, p2);
float t = glm::max(0.0f, glm::min(1.0f, glm::dot((glm::vec3)point - p1, p2 - p1) / l2)); 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); glm::vec3 proj = p1 + t * (p2 - p1);

View File

@@ -24,8 +24,7 @@ glm::dvec3 TSpring::ComputateForces(glm::dvec3 const &pPosition1, glm::dvec3 con
// VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance // VectorDifference(&p1->pos,&p2->pos,&deltaP); // Vector distance
auto deltaP = pPosition1 - pPosition2; auto deltaP = pPosition1 - pPosition2;
// dist = VectorLength(&deltaP); // Magnitude of deltaP // dist = VectorLength(&deltaP); // Magnitude of deltaP
auto dist = glm::length(deltaP); if( auto dist = glm::length(deltaP); dist > restLen ) {
if( dist > restLen ) {
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest) // Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
auto Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest) auto Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)

View File

@@ -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 // 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 // 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 // C120-2C, 2C120-2C, 2C120-2C-1, 2C120-2C-2, 2C120-2C-3, 2C120-2C-4
auto const material = parser->getToken<std::string>();
// 1=miedziana, rysuje się na zielono albo czerwono // 1=miedziana, rysuje się na zielono albo czerwono
// 2=aluminiowa, rysuje się na czarno // 2=aluminiowa, rysuje się na czarno
if( material == "none" ) { Material = 0; } if( auto const material = parser->getToken<std::string>(); material == "none" ) { Material = 0; }
else if( material == "al" ) { Material = 2; } else if( material == "al" ) { Material = 2; }
else { Material = 1; } else { Material = 1; }
parser->getTokens( 2 ); parser->getTokens( 2 );
@@ -824,8 +823,7 @@ traction_table::InitTraction() {
} }
else if( traction->hvParallel == nullptr ) { else if( traction->hvParallel == nullptr ) {
// jeśli jeszcze nie został włączony w kółko // jeśli jeszcze nie został włączony w kółko
auto *nTemp = find( traction->asParallel ); if( auto *nTemp = find( traction->asParallel ); nTemp != nullptr ) {
if( nTemp != nullptr ) {
// o ile zostanie znalezione przęsło o takiej nazwie // o ile zostanie znalezione przęsło o takiej nazwie
if( nTemp->hvParallel == nullptr ) { if( nTemp->hvParallel == nullptr ) {
// jeśli tamten jeszcze nie ma wskaźnika bieżni wspólnej // jeśli tamten jeszcze nie ma wskaźnika bieżni wspólnej

View File

@@ -574,8 +574,7 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax)
// //
load_sounds(); load_sounds();
// potentially offset table times // potentially offset table times
auto const timeoffset { static_cast<int>( Global.ScenarioTimeOffset * 60 ) + iPlus }; if( auto const timeoffset { static_cast<int>( Global.ScenarioTimeOffset * 60 ) + iPlus }; timeoffset != 0 ) // jeżeli jest przesunięcie rozkładu
if( timeoffset != 0 ) // jeżeli jest przesunięcie rozkładu
{ {
long i_end = StationCount + 1; long i_end = StationCount + 1;
float adjustedtime; // do zwiększania czasu float adjustedtime; // do zwiększania czasu