17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-05 20:39:09 +01:00

refactor(sonar): make read-only local references and pointers const (cpp:S5350)

This commit is contained in:
jerrrrycho
2026-10-10 17:05:09 +02:00
parent 29e8a1befc
commit 693a817d5e
16 changed files with 38 additions and 38 deletions

View File

@@ -1187,10 +1187,10 @@ void TMoverParameters::CollisionDetect(int const End, double const dt)
return; return;
} // shouldn't normally happen but, eh } // shouldn't normally happen but, eh
auto &thiscoupler{Couplers[End]}; auto const &thiscoupler{Couplers[End]};
auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters};
auto const otherend{Neighbours[End].vehicle_end}; auto const otherend{Neighbours[End].vehicle_end};
auto &othercoupler{othervehicle->Couplers[otherend]}; auto const &othercoupler{othervehicle->Couplers[otherend]};
auto velocity{V}; auto velocity{V};
auto othervehiclevelocity{othervehicle->V}; auto othervehiclevelocity{othervehicle->V};
@@ -1830,7 +1830,7 @@ void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling c
for (auto side = 0; side < 2; ++side) for (auto side = 0; side < 2; ++side)
{ {
auto &thiscoupler{Couplers[side]}; auto const &thiscoupler{Couplers[side]};
// NOTE: in the loop we actually update the state of the coupler on the opposite end of the vehicle // NOTE: in the loop we actually update the state of the coupler on the opposite end of the vehicle
auto &oppositecoupler{Couplers[side == end::front ? end::rear : end::front]}; auto &oppositecoupler{Couplers[side == end::front ? end::rear : end::front]};
@@ -2275,7 +2275,7 @@ void TMoverParameters::PantographsCheck(double const /*Timestep*/)
using enum start_t; using enum start_t;
{ {
auto &valve{PantsValve}; auto const &valve{PantsValve};
auto const lowvoltagepower{valve.solenoid ? Power24vIsAvailable || Power110vIsAvailable : true}; auto const lowvoltagepower{valve.solenoid ? Power24vIsAvailable || Power110vIsAvailable : true};
auto const autostart{valve.start_type == automatic || valve.start_type == manualwithautofallback}; auto const autostart{valve.start_type == automatic || valve.start_type == manualwithautofallback};
auto const manualcontrol{valve.start_type == manual || valve.start_type == manualwithautofallback}; auto const manualcontrol{valve.start_type == manual || valve.start_type == manualwithautofallback};
@@ -6211,7 +6211,7 @@ double TMoverParameters::TractionForce(double dt)
if (true == Mains && !SecuritySystem.is_engine_blocked()) if (true == Mains && !SecuritySystem.is_engine_blocked())
{ {
double ActiveInverters = 0.0; double ActiveInverters = 0.0;
for (auto &inv : Inverters) for (auto const &inv : Inverters)
{ {
if (inv.IsActive) if (inv.IsActive)
ActiveInverters += 1.0; ActiveInverters += 1.0;
@@ -8946,7 +8946,7 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const
{ {
continue; continue;
} }
auto *connectedpowercoupling = (Coupling & (coupling::highvoltage | coupling::heating)) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high : auto const *connectedpowercoupling = (Coupling & (coupling::highvoltage | coupling::heating)) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high :
(Coupling & coupling::power110v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_110v : (Coupling & coupling::power110v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_110v :
(Coupling & coupling::power24v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_24v : (Coupling & coupling::power24v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_24v :
nullptr; nullptr;

View File

@@ -1259,7 +1259,7 @@ debug_panel::update_section_scantable( std::vector<text_line> &Output ) const {
#ifdef WITH_UART #ifdef WITH_UART
void void
debug_panel::update_section_uart( std::vector<text_line> &Output ) const { debug_panel::update_section_uart( std::vector<text_line> &Output ) const {
uart_status *status = &UartStatus; uart_status const *status = &UartStatus;
Output.emplace_back( Output.emplace_back(
("Port: " + status->port_name).c_str(), ("Port: " + status->port_name).c_str(),

View File

@@ -87,7 +87,7 @@ void gl::buffer::download(targets target, void *data, int offset, GLsizeiptr siz
} }
else else
{ {
void *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT); void const *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT);
memcpy(data, glbuf, size); memcpy(data, glbuf, size);
glUnmapBuffer(glenum_target(target)); glUnmapBuffer(glenum_target(target));
} }

View File

@@ -339,7 +339,7 @@ void gl::program::init()
for (auto [texturename, textureentry] : texture_conf) for (auto [texturename, textureentry] : texture_conf)
{ {
shader::texture_entry &e = textureentry; shader::texture_entry const &e = textureentry;
GLuint loc = glGetUniformLocation(*this, texturename.c_str()); GLuint loc = glGetUniformLocation(*this, texturename.c_str());
glUniform1i(loc, static_cast<GLint>(e.id)); glUniform1i(loc, static_cast<GLint>(e.id));
} }

View File

@@ -210,7 +210,7 @@ drivermouse_input::recall_bindings() {
} }
// TODO: binding targets for mouse buttons // TODO: binding targets for mouse buttons
for( auto &bindingtarget : bindingtargets ) { for( auto const &bindingtarget : bindingtargets ) {
// grab command(s) associated with the input pin // grab command(s) associated with the input pin
auto const bindingcommandname{ entryparser.getToken<std::string>() }; auto const bindingcommandname{ entryparser.getToken<std::string>() };
if( true == bindingcommandname.empty() ) { if( true == bindingcommandname.empty() ) {

View File

@@ -126,7 +126,7 @@ gamepad_input::poll() {
void void
gamepad_input::bind( std::vector< std::reference_wrapper<user_command> > &Targets, cParser &Input, std::unordered_map<std::string, user_command> const &Translator, std::string const Point ) const { gamepad_input::bind( std::vector< std::reference_wrapper<user_command> > &Targets, cParser &Input, std::unordered_map<std::string, user_command> const &Translator, std::string const Point ) const {
for( auto &bindingtarget : Targets ) { for( auto const &bindingtarget : Targets ) {
// grab command(s) associated with the input pin // grab command(s) associated with the input pin
auto const bindingcommandname{ Input.getToken<std::string>() }; auto const bindingcommandname{ Input.getToken<std::string>() };
if( true == bindingcommandname.empty() ) { if( true == bindingcommandname.empty() ) {

View File

@@ -62,7 +62,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) + " rcvd" ); std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) + " rcvd" );
if( Global.iMultiplayer ) { if( Global.iMultiplayer ) {
auto *foundevent = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) ); auto const *foundevent = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) );
if (foundevent != nullptr && (typeid(*foundevent) == typeid(multi_event) if (foundevent != nullptr && (typeid(*foundevent) == typeid(multi_event)
|| typeid(*foundevent) == typeid(lights_event) || typeid(*foundevent) == typeid(lights_event)
|| foundevent->m_sibling != nullptr)) { || foundevent->m_sibling != nullptr)) {
@@ -136,7 +136,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz)
+ " rcvd" ); + " rcvd" );
if (pRozkaz->cString[0]) { if (pRozkaz->cString[0]) {
// jeśli długość nazwy jest niezerowa szukamy pierwszego pojazdu o takiej nazwie i odsyłamy parametry ramką #7 // jeśli długość nazwy jest niezerowa szukamy pierwszego pojazdu o takiej nazwie i odsyłamy parametry ramką #7
auto *vehicle = pRozkaz->cString[1] == '*' ? simulation::Train->Dynamic() : simulation::Vehicles.find(std::string{pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0]}); auto const *vehicle = pRozkaz->cString[1] == '*' ? simulation::Train->Dynamic() : simulation::Vehicles.find(std::string{pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0]});
if( vehicle != nullptr ) { if( vehicle != nullptr ) {
WyslijNamiary( vehicle ); // wysłanie informacji o pojeździe WyslijNamiary( vehicle ); // wysłanie informacji o pojeździe
} }

View File

@@ -42,7 +42,7 @@ public:
glm::ivec2 size() const glm::ivec2 size() const
{ {
if (image != null_handle) { if (image != null_handle) {
auto &tex = GfxRenderer->Texture(image); auto const &tex = GfxRenderer->Texture(image);
return glm::ivec2(tex.get_width(), tex.get_height()); return glm::ivec2(tex.get_width(), tex.get_height());
} }
return glm::ivec2(); return glm::ivec2();

View File

@@ -87,7 +87,7 @@ public:
opengl_dlgeometrybank() = default; opengl_dlgeometrybank() = default;
// destructor: // destructor:
~opengl_dlgeometrybank() { ~opengl_dlgeometrybank() {
for( auto &chunkrecord : m_chunkrecords ) { for( auto const &chunkrecord : m_chunkrecords ) {
::glDeleteLists( chunkrecord.list, 1 ); } } ::glDeleteLists( chunkrecord.list, 1 ); } }
private: private:

View File

@@ -363,7 +363,7 @@ void python_taskqueue::exit()
// which the previous code did not do (cancel() is a no-op stub). // which the previous code did not do (cancel() is a no-op stub).
{ {
std::scoped_lock lock(m_tasks.mutex); std::scoped_lock lock(m_tasks.mutex);
for (auto &task : m_tasks.data) for (auto const &task : m_tasks.data)
{ {
task->cancel(); task->cancel();
} }
@@ -609,7 +609,7 @@ void python_taskqueue::update()
{ {
std::scoped_lock lock(m_uploadtasks.mutex); std::scoped_lock lock(m_uploadtasks.mutex);
for (auto &task : m_uploadtasks.data) for (auto const &task : m_uploadtasks.data)
task->upload(); task->upload();
m_uploadtasks.data.clear(); m_uploadtasks.data.clear();

View File

@@ -79,7 +79,7 @@ python_screen_viewer::~python_screen_viewer()
void python_screen_viewer::threadfunc() void python_screen_viewer::threadfunc()
{ {
for (auto &window : m_windows) { for (auto const &window : m_windows) {
glfwMakeContextCurrent(window->window); glfwMakeContextCurrent(window->window);
glfwSwapInterval(Global.python_vsync ? 1 : 0); glfwSwapInterval(Global.python_vsync ? 1 : 0);
@@ -115,7 +115,7 @@ void python_screen_viewer::threadfunc()
{ {
auto start_time = std::chrono::high_resolution_clock::now(); auto start_time = std::chrono::high_resolution_clock::now();
for (auto &window : m_windows) { for (auto const &window : m_windows) {
unsigned char *image = nullptr; unsigned char *image = nullptr;
int format; int format;
@@ -190,7 +190,7 @@ void python_screen_viewer::threadfunc()
void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int h) const void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int h) const
{ {
for (auto &conf : m_windows) { for (auto const &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
conf->fb_size.x = w; conf->fb_size.x = w;
conf->fb_size.y = h; conf->fb_size.y = h;
@@ -201,7 +201,7 @@ void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int
void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h) const void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h) const
{ {
for (auto &conf : m_windows) { for (auto const &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
conf->window_size.x = w; conf->window_size.x = w;
conf->window_size.y = h; conf->window_size.y = h;
@@ -212,7 +212,7 @@ void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h)
void python_screen_viewer::notify_cursor_pos(GLFWwindow *window, double x, double y) const void python_screen_viewer::notify_cursor_pos(GLFWwindow *window, double x, double y) const
{ {
for (auto &conf : m_windows) { for (auto const &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
conf->cursor_pos.x = static_cast<int>(x); conf->cursor_pos.x = static_cast<int>(x);
conf->cursor_pos.y = static_cast<int>(y); conf->cursor_pos.y = static_cast<int>(y);
@@ -226,7 +226,7 @@ void python_screen_viewer::notify_click(GLFWwindow *window, int button, int acti
if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS) if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS)
return; return;
for (auto &conf : m_windows) { for (auto const &conf : m_windows) {
if (conf->window == window) { if (conf->window == window) {
auto pos = glm::vec2(conf->cursor_pos) / glm::vec2(conf->window_size); auto pos = glm::vec2(conf->cursor_pos) / glm::vec2(conf->window_size);
pos.y = 1.0f - pos.y; pos.y = 1.0f - pos.y;

View File

@@ -2116,7 +2116,7 @@ void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data con
} }
} }
void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data const &Command) void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data const &Command)
{ {
if (Command.action == GLFW_PRESS) if (Command.action == GLFW_PRESS)
@@ -3464,7 +3464,7 @@ void TTrain::update_pantograph_valves()
OnCommand_pantographtoggleselected(Train, Command); OnCommand_pantographtoggleselected(Train, Command);
} }
} }
void TTrain::update_pantograph_valves() void TTrain::update_pantograph_valves()
{ {
using enum operation_t; using enum operation_t;
@@ -8743,7 +8743,7 @@ bool TTrain::Update(double const Deltatime)
} }
} }
else else
fConverterTimer = 0; fConverterTimer = 0;
//------------------ //------------------
auto const lowvoltagepower{mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable}; auto const lowvoltagepower{mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable};
@@ -9169,7 +9169,7 @@ bool TTrain::Update(double const Deltatime)
btLampkaDistanceCounter.Turn(false); btLampkaDistanceCounter.Turn(false);
// universal devices state indicators // universal devices state indicators
for (auto &universal : btUniversals) for (auto &universal : btUniversals)
{ {
universal.Turn(false); universal.Turn(false);
} }
} }
@@ -10120,7 +10120,7 @@ void TTrain::update_sounds_radio()
radio_message_played = false; radio_message_played = false;
if (false == m_radiomessages.empty()) if (false == m_radiomessages.empty())
{ {
// erase completed radio messages from the list // erase completed radio messages from the list
std::erase_if(m_radiomessages, [](auto const &source) { return false == source.second->is_playing(); }); std::erase_if(m_radiomessages, [](auto const &source) { return false == source.second->is_playing(); });
} }
@@ -10347,7 +10347,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
m_controlmapper.clear(); m_controlmapper.clear();
// clear python screens // clear python screens
m_screens.clear(); m_screens.clear();
// reset sound positions // reset sound positions
auto const nullvector{glm::vec3()}; auto const nullvector{glm::vec3()};
std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = { std::vector<std::reference_wrapper<std::optional<sound_source>>> sounds = {
dsbReverserKey, dsbNastawnikJazdy, dsbNastawnikBocz, dsbSwitch, dsbPneumaticSwitch, rsHiss, rsHissU, rsHissE, rsHissX, rsHissT, rsSBHiss, dsbReverserKey, dsbNastawnikJazdy, dsbNastawnikBocz, dsbSwitch, dsbPneumaticSwitch, rsHiss, rsHissU, rsHissE, rsHissX, rsHissT, rsSBHiss,
@@ -10355,7 +10355,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
m_rainsound, m_radiostop}; m_rainsound, m_radiostop};
for (auto const &sound : sounds) for (auto const &sound : sounds)
{ {
if (sound.get()) if (sound.get())
{ {
sound.get()->offset(nullvector); sound.get()->offset(nullvector);
} }
@@ -10650,7 +10650,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
{rsHuntingNoise, caboffset}, {rsHuntingNoise, caboffset},
{dsbHasler, caboffset}, {dsbHasler, caboffset},
{dsbBuzzer, btLampkaCzuwaka.model_offset()}, {dsbBuzzer, btLampkaCzuwaka.model_offset()},
{dsbBuzzerShp, btLampkaCzuwaka.model_offset()}, {dsbBuzzerShp, btLampkaCzuwaka.model_offset()},
{dsbSlipAlarm, caboffset}, {dsbSlipAlarm, caboffset},
{m_distancecounterclear, btLampkaCzuwaka.model_offset()}, {m_distancecounterclear, btLampkaCzuwaka.model_offset()},
{m_rainsound, caboffset}, {m_rainsound, caboffset},
@@ -10658,7 +10658,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
}; };
for (auto const &[soundsource, soundoffset] : soundlocations) for (auto const &[soundsource, soundoffset] : soundlocations)
{ {
if (soundsource.get() && soundsource.get()->offset() == nullvector) if (soundsource.get() && soundsource.get()->offset() == nullvector)
{ {
soundsource.get()->offset(soundoffset); soundsource.get()->offset(soundoffset);
} }
@@ -11464,7 +11464,7 @@ void TTrain::set_cab_controls(int const Cab)
ggAutoSandButton.PutValue(mvControlled->SandDoseAutoAllow ? 1.f : 0.f); ggAutoSandButton.PutValue(mvControlled->SandDoseAutoAllow ? 1.f : 0.f);
} }
// radio // radio
ggRadioVolumeSelector.PutValue(m_radiovolume); ggRadioVolumeSelector.PutValue(m_radiovolume);
// finding each inverter - not so optimal, but action ins performed only during changing cabin // finding each inverter - not so optimal, but action ins performed only during changing cabin
bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0; bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0;

View File

@@ -19,7 +19,7 @@ void perfgraph_panel::render_contents() {
ImGui::EndCombo(); ImGui::EndCombo();
} }
Timer::stopwatch *stopwatch = nullptr; Timer::stopwatch const *stopwatch = nullptr;
if (current_timer == gfx_total) if (current_timer == gfx_total)
stopwatch = &Timer::subsystem.gfx_total; stopwatch = &Timer::subsystem.gfx_total;

View File

@@ -27,7 +27,7 @@ void ui::time_panel::render_contents()
void ui::time_panel::open() void ui::time_panel::open()
{ {
auto &data = simulation::Time.data(); auto const &data = simulation::Time.data();
time = (float)data.wHour + (float)data.wMinute / 60.0f; time = (float)data.wHour + (float)data.wMinute / 60.0f;
yearday = simulation::Time.year_day(); yearday = simulation::Time.year_day();

View File

@@ -12,7 +12,7 @@ ui::vehiclelist_panel::vehiclelist_panel(ui_layer &parent)
void ui::vehiclelist_panel::render_contents() void ui::vehiclelist_panel::render_contents()
{ {
if (m_first_show && Global.gui_trainingdefault) { if (m_first_show && Global.gui_trainingdefault) {
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) for (TDynamicObject const *vehicle : simulation::Vehicles.sequence())
{ {
if (!vehicle->Mechanik || vehicle->name() != ToLower(Global.local_start_vehicle)) if (!vehicle->Mechanik || vehicle->name() != ToLower(Global.local_start_vehicle))
continue; continue;
@@ -26,7 +26,7 @@ void ui::vehiclelist_panel::render_contents()
return; return;
} }
for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) for (TDynamicObject const *vehicle : simulation::Vehicles.sequence())
{ {
if (!vehicle->Mechanik) if (!vehicle->Mechanik)
continue; continue;

View File

@@ -280,7 +280,7 @@ memory_table::InitCells() const {
void void
memory_table::log_all() const { memory_table::log_all() const {
for( auto *cell : m_items ) { for( auto const *cell : m_items ) {
cell->LogValues(); cell->LogValues();
} }
} }