From 8f89dcefcd3b202741d8e5ebf24833255d9e2109 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 15:52:25 +0200 Subject: [PATCH] refactor(sonar): use auto where the type is spelled out on the right (cpp:S5827) Co-Authored-By: Claude Opus 5.5 --- McZapkie/Mover.cpp | 2 +- McZapkie/Oerlikon_ESt.cpp | 2 +- application/driveruipanels.cpp | 2 +- gl/shader.cpp | 2 +- input/command.cpp | 2 +- input/messaging.cpp | 2 +- network/backend/asio.cpp | 6 +++--- network/message.cpp | 2 +- rendering/flip-s3tc.h | 6 +++--- rendering/opengl33particles.cpp | 2 +- rendering/screenshot.cpp | 2 +- scene/sn_utils.cpp | 4 ++-- scripting/PyInt.cpp | 4 ++-- scripting/pythonscreenviewer.cpp | 8 ++++---- utilities/Timer.cpp | 2 +- utilities/color.h | 2 +- utilities/uart.cpp | 20 ++++++++++---------- widgets/cameraview_extcam.cpp | 6 +++--- widgets/vehiclelist.cpp | 2 +- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 202a3c62..b5f6ca6f 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -733,7 +733,7 @@ void TMoverParameters::BrakeLevelSet(double b) fBrakeCtrlPos = Handle->GetPos(bh_MAX); // TODO: verify whether BrakeCtrlPosR and fBrakeCtrlPos can be rolled into single variable BrakeCtrlPosR = fBrakeCtrlPos; - int x = static_cast(std::floor(fBrakeCtrlPos)); // jeśli odwołujemy się do BrakeCtrlPos w pośrednich, to musi być + auto x = static_cast(std::floor(fBrakeCtrlPos)); // jeśli odwołujemy się do BrakeCtrlPos w pośrednich, to musi być // obcięte a nie zaokrągone while (x > BrakeCtrlPos && BrakeCtrlPos < BrakeCtrlPosNo) // jeśli zwiększyło się o 1 if (!IncBrakeLevelOld()) // T_MoverParameters:: diff --git a/McZapkie/Oerlikon_ESt.cpp b/McZapkie/Oerlikon_ESt.cpp index 237eb989..cbf5ab94 100644 --- a/McZapkie/Oerlikon_ESt.cpp +++ b/McZapkie/Oerlikon_ESt.cpp @@ -211,7 +211,7 @@ double TNESt3::GetPF( double const PP, double const dt, double const Vel ) // pr double dV{ 0.0 }; double dV1{ 0.0 }; - double const nastG = static_cast(BrakeDelayFlag & bdelay_G); + auto const nastG = static_cast(BrakeDelayFlag & bdelay_G); // sprawdzanie stanu CheckState(BCP, dV1); diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 60bc0252..8edc52a9 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -588,7 +588,7 @@ debug_panel::render() { #ifdef WITH_UART if(true == render_section( "UART", m_uartlines)) { int ports_num = static_cast(UartStatus.available_ports.size()); - char **avlports = new char*[ports_num]; + auto avlports = new char*[ports_num]; for (int i=0; i < ports_num; i++) { avlports[i] = (char *) UartStatus.available_ports[i].c_str(); } diff --git a/gl/shader.cpp b/gl/shader.cpp index ed47547e..b84ba3a2 100644 --- a/gl/shader.cpp +++ b/gl/shader.cpp @@ -41,7 +41,7 @@ bool has_gl_extension(char const *name) { GLint count = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &count); for (GLint i = 0; i < count; ++i) { - char const *ext = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + auto ext = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); if (ext != nullptr && std::strcmp(ext, name) == 0) { return true; } diff --git a/input/command.cpp b/input/command.cpp index ffc77fc0..44909cd2 100644 --- a/input/command.cpp +++ b/input/command.cpp @@ -855,7 +855,7 @@ command_queue::pop( command_data &Command, uint32_t const Recipient ) { bool command_queue::is_network_target(uint32_t const Recipient) const { - if (const command_target target = (command_target)(Recipient & ~0xffff); target == command_target::entity) + if (const auto target = (command_target)(Recipient & ~0xffff); target == command_target::entity) return false; return true; diff --git a/input/messaging.cpp b/input/messaging.cpp index 6a1f8753..30ad02ec 100644 --- a/input/messaging.cpp +++ b/input/messaging.cpp @@ -76,7 +76,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz) case 3: // rozkaz dla AI if (Global.iMultiplayer) { - int i = int(pRozkaz->cString[8]); // długość pierwszego łańcucha (z przodu dwa floaty) + auto i = int(pRozkaz->cString[8]); // długość pierwszego łańcucha (z przodu dwa floaty) CommLog( Now() + " " + std::to_string(pRozkaz->iComm) + " " + std::string(pRozkaz->cString + 11 + i, (unsigned)pRozkaz->cString[10 + i]) + diff --git a/network/backend/asio.cpp b/network/backend/asio.cpp index c19ccaa9..bc7393a1 100644 --- a/network/backend/asio.cpp +++ b/network/backend/asio.cpp @@ -92,7 +92,7 @@ void network::tcp::connection::handle_data(const asio::error_code &err, size_t b void network::tcp::connection::write_message(const message &msg, std::ostream &stream) const { - size_t beg = (size_t)stream.tellp(); + auto beg = (size_t)stream.tellp(); sn_utils::ls_uint32(stream, NETWORK_MAGIC); sn_utils::ls_uint32(stream, 0); @@ -149,7 +149,7 @@ network::tcp::server::server(std::shared_ptr buf, asio::io_context void network::tcp::server::accept_conn() { - std::shared_ptr conn = std::make_shared(m_io_ctx); + auto conn = std::make_shared(m_io_ctx); conn->set_handler(std::bind(&server::handle_message, this, conn, std::placeholders::_1)); m_acceptor.async_accept(conn->m_socket, std::bind(&server::handle_accept, this, conn, std::placeholders::_1)); @@ -183,7 +183,7 @@ void network::tcp::client::connect() if (this->conn) return; - std::shared_ptr conn = std::make_shared(io_ctx, true, resume_frame_counter); + auto conn = std::make_shared(io_ctx, true, resume_frame_counter); conn->set_handler(std::bind(&client::handle_message, this, conn, std::placeholders::_1)); asio::ip::tcp::endpoint endpoint( diff --git a/network/message.cpp b/network/message.cpp index 13fac7e7..a8a222fc 100644 --- a/network/message.cpp +++ b/network/message.cpp @@ -103,7 +103,7 @@ void network::frame_info::deserialize(std::istream &stream) std::shared_ptr network::deserialize_message(std::istream &stream) { - message::type_e type = (message::type_e)sn_utils::ld_uint16(stream); + auto type = (message::type_e)sn_utils::ld_uint16(stream); std::shared_ptr msg; diff --git a/rendering/flip-s3tc.h b/rendering/flip-s3tc.h index a29fdc48..d842677a 100644 --- a/rendering/flip-s3tc.h +++ b/rendering/flip-s3tc.h @@ -131,7 +131,7 @@ void flip_dxt1_image(void *data, int width, int height) int y; struct dxt1_block temp1; struct dxt1_block temp2; - struct dxt1_block *blocks = (struct dxt1_block *)data; + auto blocks = (struct dxt1_block *)data; width = (width + 3) / 4; height = (height + 3) / 4; @@ -162,7 +162,7 @@ void flip_dxt23_image(void *data, int width, int height) int y; struct dxt23_block temp1; struct dxt23_block temp2; - struct dxt23_block *blocks = (struct dxt23_block *)data; + auto blocks = (struct dxt23_block *)data; width = (width + 3) / 4; height = (height + 3) / 4; @@ -193,7 +193,7 @@ void flip_dxt45_image(void *data, int width, int height) int y; struct dxt45_block temp1; struct dxt45_block temp2; - struct dxt45_block *blocks = (struct dxt45_block *)data; + auto blocks = (struct dxt45_block *)data; width = (width + 3) / 4; height = (height + 3) / 4; diff --git a/rendering/opengl33particles.cpp b/rendering/opengl33particles.cpp index 4ba5e6d5..84a09738 100644 --- a/rendering/opengl33particles.cpp +++ b/rendering/opengl33particles.cpp @@ -120,7 +120,7 @@ opengl33_particles::render() { if (!m_shader) { gl::shader vert("smoke.vert"); gl::shader frag("smoke.frag"); - gl::program *prog = new gl::program({vert, frag}); + auto prog = new gl::program({vert, frag}); m_shader = std::unique_ptr(prog); } diff --git a/rendering/screenshot.cpp b/rendering/screenshot.cpp index eb7e7aac..dc7005de 100644 --- a/rendering/screenshot.cpp +++ b/rendering/screenshot.cpp @@ -55,7 +55,7 @@ void screenshot_manager::screenshot_save_thread( char *img, int w, int h ) void screenshot_manager::make_screenshot() { - char *img = new char[Global.fb_size.x * Global.fb_size.y * 4]; + auto img = new char[Global.fb_size.x * Global.fb_size.y * 4]; glReadPixels(0, 0, Global.fb_size.x, Global.fb_size.y, Global.gfx_usegles ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)img); //m7t: use pbo diff --git a/scene/sn_utils.cpp b/scene/sn_utils.cpp index 0df3f8cb..fedf8244 100644 --- a/scene/sn_utils.cpp +++ b/scene/sn_utils.cpp @@ -197,7 +197,7 @@ void sn_utils::ls_int64(std::ostream &s, int64_t v) void sn_utils::ls_float32(std::ostream &s, float t) { - uint32_t v = std::bit_cast(t); + auto v = std::bit_cast(t); uint8_t buf[4]; buf[0] = static_cast(v); buf[1] = static_cast(v >> 8); @@ -208,7 +208,7 @@ void sn_utils::ls_float32(std::ostream &s, float t) void sn_utils::ls_float64(std::ostream &s, double t) { - uint64_t v = std::bit_cast(t); + auto v = std::bit_cast(t); uint8_t buf[8]; buf[0] = static_cast(v); buf[1] = static_cast(v >> 8); diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index b982bf86..e970de18 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -117,8 +117,8 @@ void render_task::run() if (outputWidth != nullptr && outputHeight != nullptr && m_target != nullptr) { - const int screenWidth = static_cast(PyLong_AsLong(outputWidth)); - const int screenHeight = static_cast(PyLong_AsLong(outputHeight)); + const auto screenWidth = static_cast(PyLong_AsLong(outputWidth)); + const auto screenHeight = static_cast(PyLong_AsLong(outputHeight)); const bool useRgb = false && !Global.gfx_usegles; diff --git a/scripting/pythonscreenviewer.cpp b/scripting/pythonscreenviewer.cpp index 1b5e696e..27a0b36f 100644 --- a/scripting/pythonscreenviewer.cpp +++ b/scripting/pythonscreenviewer.cpp @@ -7,25 +7,25 @@ void texture_window_resize(GLFWwindow *win, int w, int h) { - python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); + auto texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); texwindow->notify_window_size(win, w, h); } void texture_window_fb_resize(GLFWwindow *win, int w, int h) { - python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); + auto texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); texwindow->notify_window_fb_size(win, w, h); } void texture_window_mouse_button(GLFWwindow *win, int button, int action, int /*mods*/) { - python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); + auto texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); texwindow->notify_click(win, button, action); } void texture_window_cursor_pos(GLFWwindow *win, double x, double y) { - python_screen_viewer *texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); + auto texwindow = (python_screen_viewer*)glfwGetWindowUserPointer(win); texwindow->notify_cursor_pos(win, x, y); } diff --git a/utilities/Timer.cpp b/utilities/Timer.cpp index d9ad2032..0b877f2b 100644 --- a/utilities/Timer.cpp +++ b/utilities/Timer.cpp @@ -95,7 +95,7 @@ void UpdateTimers(bool pause) oldCount = count; // Keep track of the time lapse and frame count #if __unix__ - double fTime = (double)(count / 1000000000); + auto fTime = (double)(count / 1000000000); #elif _WIN32_WINNT >= _WIN32_WINNT_VISTA double fTime = ::GetTickCount64() * 0.001f; // Get current time in seconds #elif _WIN32 diff --git a/utilities/color.h b/utilities/color.h index dd9ade6b..be853a3d 100644 --- a/utilities/color.h +++ b/utilities/color.h @@ -82,7 +82,7 @@ HSVtoRGB( glm::vec3 const &HSV ) { float hh = HSV.x; if( hh >= 360.0 ) hh = 0.0; hh /= 60.0f; - int const i = (int)hh; + auto const i = (int)hh; float const ff = hh - static_cast(i); float const p = HSV.z * ( 1.f - HSV.y ); float const q = HSV.z * ( 1.f - HSV.y * ff ); diff --git a/utilities/uart.cpp b/utilities/uart.cpp index b5cab25a..69963bc4 100644 --- a/utilities/uart.cpp +++ b/utilities/uart.cpp @@ -496,7 +496,7 @@ void uart_input::poll() ); } if( true == conf.radiovolumeenable ) { - int8_t requested_volume = static_cast((buffer[12] & 0xF0) >> 4); + auto requested_volume = static_cast((buffer[12] & 0xF0) >> 4); relay.post( user_command::radiovolumeset, requested_volume == 0xF ? 1.0 : requested_volume * (1.0 / 15.0), @@ -534,16 +534,16 @@ void uart_input::poll() SYSTEMTIME time = simulation::Time.data(); uint16_t tacho = Global.iPause ? 0 : static_cast(trainstate.velocity * conf.tachoscale); - uint16_t tank_press = (uint16_t)std::min(conf.tankuart, trainstate.reservoir_pressure * 0.1f / conf.tankmax * conf.tankuart); - uint16_t pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart); - uint16_t brake_press = (uint16_t)std::min(conf.brakeuart, trainstate.brake_pressure * 0.1f / conf.brakemax * conf.brakeuart); - uint16_t pantograph_press = (uint16_t)std::min(conf.pantographuart, trainstate.pantograph_pressure * 0.1f / conf.pantographmax * conf.pantographuart ); - uint16_t hv_voltage = (uint16_t)std::min(conf.hvuart, trainstate.hv_voltage / conf.hvmax * conf.hvuart); - uint16_t current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0] / conf.currentmax * conf.currentuart); - uint16_t current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1] / conf.currentmax * conf.currentuart); - uint16_t current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2] / conf.currentmax * conf.currentuart); + auto tank_press = (uint16_t)std::min(conf.tankuart, trainstate.reservoir_pressure * 0.1f / conf.tankmax * conf.tankuart); + auto pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart); + auto brake_press = (uint16_t)std::min(conf.brakeuart, trainstate.brake_pressure * 0.1f / conf.brakemax * conf.brakeuart); + auto pantograph_press = (uint16_t)std::min(conf.pantographuart, trainstate.pantograph_pressure * 0.1f / conf.pantographmax * conf.pantographuart ); + auto hv_voltage = (uint16_t)std::min(conf.hvuart, trainstate.hv_voltage / conf.hvmax * conf.hvuart); + auto current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0] / conf.currentmax * conf.currentuart); + auto current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1] / conf.currentmax * conf.currentuart); + auto current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2] / conf.currentmax * conf.currentuart); uint32_t odometer = static_cast(trainstate.distance * 10000.0); - uint16_t lv_voltage = (uint16_t)std::min( conf.lvuart, trainstate.lv_voltage / conf.lvmax * conf.lvuart ); + auto lv_voltage = (uint16_t)std::min( conf.lvuart, trainstate.lv_voltage / conf.lvmax * conf.lvuart ); if( trainstate.cab > 0 ) { // NOTE: moving from a cab to engine room doesn't change cab indicator m_trainstatecab = trainstate.cab - 1; diff --git a/widgets/cameraview_extcam.cpp b/widgets/cameraview_extcam.cpp index 1da51535..608e91a2 100644 --- a/widgets/cameraview_extcam.cpp +++ b/widgets/cameraview_extcam.cpp @@ -122,8 +122,8 @@ void ui::cameraview_panel::capture_func() piped_proc proc(cmdline); size_t frame_size = Global.extcam_res.x * Global.extcam_res.y * 3; - uint8_t *read_buffer = new uint8_t[frame_size]; - uint8_t *active_buffer = new uint8_t[frame_size]; + auto read_buffer = new uint8_t[frame_size]; + auto active_buffer = new uint8_t[frame_size]; size_t bufpos = 0; @@ -172,7 +172,7 @@ void ui::cameraview_panel::record_func() piped_proc proc(cmdline, true); size_t frame_size = Global.extcam_res.x * Global.extcam_res.y * 3; - uint8_t *read_buffer = new uint8_t[frame_size]; + auto read_buffer = new uint8_t[frame_size]; uint32_t last_cnt = 0; size_t bufpos = frame_size; diff --git a/widgets/vehiclelist.cpp b/widgets/vehiclelist.cpp index e8ee1e12..92f9edf1 100644 --- a/widgets/vehiclelist.cpp +++ b/widgets/vehiclelist.cpp @@ -37,7 +37,7 @@ void ui::vehiclelist_panel::render_contents() if (vehicle->Mechanik) timetable = vehicle->Mechanik->TrainName() + ", "; - std::string label = std::string(name + ", " + timetable + std::to_string(speed) + " km/h###"); + auto label = std::string(name + ", " + timetable + std::to_string(speed) + " km/h###"); ImGui::PushID(vehicle); if (ImGui::Button(label.c_str())) {