From 560512bd9ed4db02601e039692df65d41eeace83 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 16:06:32 +0200 Subject: [PATCH] refactor(sonar): use structured bindings for pair access (cpp:S6005) --- McZapkie/Mover.cpp | 12 ++++----- application/driveruipanels.cpp | 22 ++++++++-------- audio/sound.cpp | 34 ++++++++++++------------ gl/shader.cpp | 20 +++++++------- input/command.cpp | 22 ++++++++-------- input/drivermouseinput.cpp | 4 +-- input/gamepadinput.cpp | 22 ++++++++-------- input/keyboardinput.cpp | 10 +++---- model/MdlMngr.cpp | 6 ++--- network/manager.cpp | 4 +-- network/message.cpp | 8 +++--- rendering/opengl33particles.cpp | 12 ++++----- rendering/openglparticles.cpp | 12 ++++----- scripting/PyInt.cpp | 46 ++++++++++++++++----------------- scripting/ladderlogic.cpp | 10 +++---- vehicle/Gauge.cpp | 16 ++++++------ vehicle/Train.cpp | 30 ++++++++++----------- world/mtable.cpp | 14 +++++----- 18 files changed, 152 insertions(+), 152 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index b635553b..67991360 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -624,11 +624,11 @@ bool TMoverParameters::Attach(int ConnectNo, int ConnectToNr, TMoverParameters * std::vector> const soundmappings = {{coupling::coupler, sound::attachcoupler}, {coupling::brakehose, sound::attachbrakehose}, {coupling::mainhose, sound::attachmainhose}, {coupling::control, sound::attachcontrol}, {coupling::gangway, sound::attachgangway}, {coupling::heating, sound::attachheating}}; - for (auto const &soundmapping : soundmappings) + for (auto const &[mappingcoupling, mappingsound] : soundmappings) { - if ((couplingchange & soundmapping.first) != 0) + if ((couplingchange & mappingcoupling) != 0) { - soundflag |= soundmapping.second; + soundflag |= mappingsound; } } SetFlag(coupler.sounds, soundflag); @@ -685,11 +685,11 @@ bool TMoverParameters::Dettach(int ConnectNo) std::vector> const soundmappings = {{coupling::coupler, sound::attachcoupler}, {coupling::brakehose, sound::attachbrakehose}, {coupling::mainhose, sound::attachmainhose}, {coupling::control, sound::attachcontrol}, {coupling::gangway, sound::attachgangway}, {coupling::heating, sound::attachheating}}; - for (auto const &soundmapping : soundmappings) + for (auto const &[mappingcoupling, mappingsound] : soundmappings) { - if ((couplingchange & soundmapping.first) != 0) + if ((couplingchange & mappingcoupling) != 0) { - soundflag |= soundmapping.second; + soundflag |= mappingsound; } } SetFlag(coupler.sounds, soundflag); diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 8edc52a9..cccd77e6 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -1021,9 +1021,9 @@ debug_panel::update_vehicle_brake() const { { bdelay_R, "R" }, { bdelay_M, "+Mg" } }; - for( auto const &delay : delays ) { - if( ( mover.BrakeDelayFlag & delay.first ) == delay.first ) { - brakedelay += delay.second; + for( auto const &[delayflag, delayname] : delays ) { + if( ( mover.BrakeDelayFlag & delayflag ) == delayflag ) { + brakedelay += delayname; } } @@ -1086,8 +1086,8 @@ debug_panel::update_section_engine( std::vector &Output ) const { { "cdesi: ", mover.dizel_engagestate }, { "cdelt: ", mover.dizel_engagedeltaomega }, { "gears: ", mover.dizel_automaticgearstatus} }; - for( auto const ¶meter : paramvalues ) { - parameterstext += "\n" + parameter.first + to_string( parameter.second, 2, 9 ); + for( auto const &[parametername, parametervalue] : paramvalues ) { + parameterstext += "\n" + parametername + to_string( parametervalue, 2, 9 ); } Output.emplace_back( parameterstext, Global.UITextColor ); @@ -1104,8 +1104,8 @@ debug_panel::update_section_engine( std::vector &Output ) const { { "hRtTq: ", mover.hydro_R_Torque } }; - for( auto const ¶meter : hydrovalues ) { - parameterstext += "\n" + parameter.first + to_string( parameter.second, 2, 9 ); + for( auto const &[parametername, parametervalue] : hydrovalues ) { + parameterstext += "\n" + parametername + to_string( parametervalue, 2, 9 ); } Output.emplace_back( parameterstext, Global.UITextColor ); } @@ -1176,14 +1176,14 @@ debug_panel::update_section_ai( std::vector &Output ) const { { mover.RunningTrack.Velmax, "track" } }; std::string restrictionstext; - for( auto const &restriction : restrictions ) { - if( restriction.first < 0.0 ) { continue; } + for( auto const &[restrictionspeed, restrictionsource] : restrictions ) { + if( restrictionspeed < 0.0 ) { continue; } if( false == restrictionstext.empty() ) { restrictionstext += ", "; } restrictionstext += - to_string( restriction.first, 0 ) - + " (" + restriction.second + ")"; + to_string( restrictionspeed, 0 ) + + " (" + restrictionsource + ")"; } if( false == restrictionstext.empty() ) { diff --git a/audio/sound.cpp b/audio/sound.cpp index 8d165d42..8848ffb8 100644 --- a/audio/sound.cpp +++ b/audio/sound.cpp @@ -85,8 +85,8 @@ sound_source::deserialize( cParser &Input, sound_type const Legacytype, int cons m_soundchunks.back().second.fadeout = static_cast(std::max( Chunkrange, m_soundchunks.back().second.threshold )); // m_soundchunks.back().second.fadeout = m_soundchunks.back().second.threshold; // test if the chunk table contains any actual samples while at it - for( auto &soundchunk : m_soundchunks ) { - if( soundchunk.first.buffer != null_handle ) { + for( auto &[chunkbuffer, chunkdata] : m_soundchunks ) { + if( chunkbuffer.buffer != null_handle ) { m_soundchunksempty = false; break; } @@ -219,9 +219,9 @@ sound_source::deserialize_mapping( cParser &Input ) { if( indexstart != std::string::npos ) { auto const index { std::stoi( key.substr( indexstart, indexend - indexstart ) ) }; auto const pitch { Input.getToken( false, "\n\r\t ,;" ) }; - for( auto &chunk : m_soundchunks ) { - if( chunk.second.threshold == index ) { - chunk.second.pitch = pitch > 0.f ? pitch : 1.f; + for( auto &[chunkbuffer, chunkdata] : m_soundchunks ) { + if( chunkdata.threshold == index ) { + chunkdata.pitch = pitch > 0.f ? pitch : 1.f; break; } } @@ -333,8 +333,8 @@ sound_source::copy_sounds( sound_source const &Source ) { for( auto &sound : m_sounds ) { sound.playing = 0; } - for( auto &sound : m_soundchunks ) { - sound.first.playing = 0; + for( auto &[chunkbuffer, chunkdata] : m_soundchunks ) { + chunkbuffer.playing = 0; } return *this; } @@ -418,14 +418,14 @@ sound_source::play_combined() { auto const soundpoint { compute_combined_point() }; for( std::uint32_t idx = 0; idx < m_soundchunks.size(); ++idx ) { - auto const &soundchunk { m_soundchunks[ idx ] }; + auto const &[chunkbuffer, chunkdata]{ m_soundchunks[ idx ] }; // a chunk covers range from fade in point, where it starts rising in volume over crossfade distance, // lasts until fadeout - crossfade distance point, past which it grows quiet until fade out point where it ends - if( soundpoint < soundchunk.second.fadein ) { break; } - if( soundpoint >= soundchunk.second.fadeout ) { continue; } + if( soundpoint < chunkdata.fadein ) { break; } + if( soundpoint >= chunkdata.fadeout ) { continue; } - if( soundchunk.first.buffer == null_handle || ( (m_flags & (sound_flags::exclusive | sound_flags::looping)) != 0 - && soundchunk.first.playing > 0 ) ) { + if( chunkbuffer.buffer == null_handle || ( (m_flags & (sound_flags::exclusive | sound_flags::looping)) != 0 + && chunkbuffer.playing > 0 ) ) { // combined sounds only play looped, single copy of each activated chunk continue; } @@ -669,9 +669,9 @@ sound_source::update_combined( audio::openal_source &Source ) { // for sound chunks, test whether the chunk should still be active given current value of the controlling variable if( ( m_flags & ( sound_flags::exclusive | sound_flags::looping ) ) != 0 ) { auto const soundpoint { compute_combined_point() }; - auto const &soundchunk { m_soundchunks[ soundhandle ^ sound_id::chunk ] }; - if( soundpoint < soundchunk.second.fadein - || soundpoint >= soundchunk.second.fadeout ) { + auto const &[chunkbuffer, chunkdata]{ m_soundchunks[ soundhandle ^ sound_id::chunk ] }; + if( soundpoint < chunkdata.fadein + || soundpoint >= chunkdata.fadeout ) { Source.stop(); update_counter( soundhandle, -1 ); return; @@ -867,8 +867,8 @@ sound_source::is_playing( bool const /*Includesoundends*/ ) const { if( false == isplaying && false == m_soundchunks.empty() ) { // for emitters with sample tables check also if any of the chunks is active - for( auto const &soundchunk : m_soundchunks ) { - if( soundchunk.first.playing > 0 ) { + for( auto const &[chunkbuffer, chunkdata] : m_soundchunks ) { + if( chunkbuffer.playing > 0 ) { isplaying = true; break; // one will do } diff --git a/gl/shader.cpp b/gl/shader.cpp index b84ba3a2..c53268b2 100644 --- a/gl/shader.cpp +++ b/gl/shader.cpp @@ -307,11 +307,11 @@ gl::shader::shader(const std::string &filename) { name = filename; - std::pair source = process_source(filename, "shaders/"); + auto [shadertype, shadersource] = process_source(filename, "shaders/"); - const GLchar *cstr = source.second.c_str(); + const GLchar *cstr = shadersource.c_str(); - **this = glCreateShader(source.first); + **this = glCreateShader(shadertype); glShaderSource(*this, 1, &cstr, nullptr); glCompileShader(*this); @@ -338,10 +338,10 @@ void gl::program::init() { bind(); - for (auto it : texture_conf) + for (auto [texturename, textureentry] : texture_conf) { - shader::texture_entry &e = it.second; - GLuint loc = glGetUniformLocation(*this, it.first.c_str()); + shader::texture_entry &e = textureentry; + GLuint loc = glGetUniformLocation(*this, texturename.c_str()); glUniform1i(loc, static_cast(e.id)); } @@ -378,10 +378,10 @@ gl::program::program(std::vector> shade void gl::program::attach(const gl::shader &s) { - for (auto it : s.texture_conf) - texture_conf.try_emplace(it.first, std::move(it.second)); - for (auto it : s.param_conf) - param_conf.try_emplace(it.first, std::move(it.second)); + for (auto [texturename, textureentry] : s.texture_conf) + texture_conf.try_emplace(texturename, std::move(textureentry)); + for (auto [paramname, paramentry] : s.param_conf) + param_conf.try_emplace(paramname, std::move(paramentry)); glAttachShader(*this, *s); } diff --git a/input/command.cpp b/input/command.cpp index 44909cd2..ca519a90 100644 --- a/input/command.cpp +++ b/input/command.cpp @@ -796,12 +796,12 @@ std::unordered_map commandMap = { void command_queue::update() { double delta = Timer::GetDeltaTime(); - for (auto c : m_active_continuous) + for (auto [activecommand, activerecipient] : m_active_continuous) { - command_data data({c.first, GLFW_REPEAT, 0.0, 0.0, delta, false, glm::vec3()}); // todo: improve - auto lookup = m_commands.try_emplace( c.second, commanddata_sequence() ); + command_data data({activecommand, GLFW_REPEAT, 0.0, 0.0, delta, false, glm::vec3()}); // todo: improve + auto [queueiterator, queueinserted] = m_commands.try_emplace( activerecipient, commanddata_sequence() ); // recipient stack was either located or created, so we can add to it quite safely - lookup.first->second.emplace_back( data ); + queueiterator->second.emplace_back( data ); } } @@ -809,8 +809,8 @@ void command_queue::update() void command_queue::push( command_data const &Command, uint32_t const Recipient ) { if (is_network_target(Recipient)) { - auto lookup = m_intercept_queue.try_emplace(Recipient, commanddata_sequence()); - lookup.first->second.emplace_back(Command); + auto [queueiterator, queueinserted] = m_intercept_queue.try_emplace(Recipient, commanddata_sequence()); + queueiterator->second.emplace_back(Command); } else { push_direct(Command, Recipient); } @@ -827,9 +827,9 @@ void command_queue::push_direct(const command_data &Command, const uint32_t Reci return; } - auto lookup = m_commands.try_emplace( Recipient, commanddata_sequence() ); + auto [queueiterator, queueinserted] = m_commands.try_emplace( Recipient, commanddata_sequence() ); // recipient stack was either located or created, so we can add to it quite safely - lookup.first->second.emplace_back( Command ); + queueiterator->second.emplace_back( Command ); } // retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve @@ -868,9 +868,9 @@ command_queue::commands_map command_queue::pop_intercept_queue() { } void command_queue::push_commands(const commands_map &commands) { - for (auto const &kv : commands) - for (command_data const &data : kv.second) - push_direct(data, kv.first); + for (auto const &[recipient, sequence] : commands) + for (command_data const &data : sequence) + push_direct(data, recipient); } void diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index ae067507..1a2c0883 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -367,9 +367,9 @@ drivermouse_input::button( int const Button, int const Action ) { control->screen_touch_list->emplace_back(pos); } - auto const controlbindings { bindings( simulation::Train->GetLabel( control ) ) }; + auto const [leftbinding, rightbinding]{ bindings( simulation::Train->GetLabel( control ) ) }; // if the recognized element under the cursor has a command associated with the pressed button, notify the recipient - mousecommand = Button == GLFW_MOUSE_BUTTON_LEFT ? controlbindings.first : controlbindings.second; + mousecommand = Button == GLFW_MOUSE_BUTTON_LEFT ? leftbinding : rightbinding; if( mousecommand == user_command::none ) { // if we don't have any recognized element under the cursor and the right button was pressed, enter view panning mode diff --git a/input/gamepadinput.cpp b/input/gamepadinput.cpp index bd78491a..3166aae1 100644 --- a/input/gamepadinput.cpp +++ b/input/gamepadinput.cpp @@ -189,16 +189,16 @@ gamepad_input::recall_bindings() { std::string bindingpoint {}; entryparser >> bindingpoint; - auto const splitbindingpoint { split_string_and_number( bindingpoint ) }; + auto const [bindingtype, bindingindex]{ split_string_and_number( bindingpoint ) }; - if( splitbindingpoint.first == "axis" ) { + if( bindingtype == "axis" ) { // one or more sets of: [modeIDX] input type, parameters // [optional] modeIDX associates the set with control mode IDX // input types: // -- range commandname IDX; axis value is passed as paramIDX of commandname // -- 3state commandname commandname; positive axis value issues first commandname, negative value issues second commandname - auto const axisindex { splitbindingpoint.second }; + auto const axisindex { bindingindex }; // sanity check, connected gamepad isn't guaranteed to have that many axes if( axisindex >= m_inputaxes.size() ) { continue; } @@ -264,9 +264,9 @@ gamepad_input::recall_bindings() { } } } - else if( splitbindingpoint.first == "button" ) { + else if( bindingtype == "button" ) { - auto const buttonindex { splitbindingpoint.second }; + auto const buttonindex { bindingindex }; // sanity check, connected gamepad isn't guaranteed to have that many buttons if( buttonindex >= m_inputbuttons.size() ) { continue; } @@ -486,17 +486,17 @@ gamepad_input::process_axes() { } } // issue remaining, assembled commands - for( auto const &command : commands ) { - auto const param1 { std::get<0>( command.second ) }; - auto const param2 { std::get<1>( command.second ) }; - auto &lastparams { m_lastcommandparams[ command.first ] }; + for( auto const &[commandid, commandparams] : commands ) { + auto const param1 { std::get<0>( commandparams ) }; + auto const param2 { std::get<1>( commandparams ) }; + auto &lastparams { m_lastcommandparams[ commandid ] }; if( param1 != 0.0 || std::get<0>(lastparams) != 0.0 || param2 != 0.0 || std::get<1>(lastparams) != 0.0 ) { m_relay.post( - command.first, + commandid, param1, param2, - std::get<2>( command.second ), + std::get<2>( commandparams ), // as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0 // TODO: pass correct entity id once the missing systems are in place 0 ); diff --git a/input/keyboardinput.cpp b/input/keyboardinput.cpp index d34dd4c6..cb3a6100 100644 --- a/input/keyboardinput.cpp +++ b/input/keyboardinput.cpp @@ -330,9 +330,9 @@ void keyboard_input::bind() { m_bindings.clear(); - for( auto const &bindingsetup : m_bindingsetups ) { + for( auto const &[setupcommand, setupbinding] : m_bindingsetups ) { - m_bindings[ std::get(bindingsetup.second) ] = bindingsetup.first; + m_bindings[ std::get(setupbinding) ] = setupcommand; } // cache movement key bindings @@ -347,9 +347,9 @@ keyboard_input::bind() { int keyboard_input::binding( user_command const Command ) const { - for( auto const &binding : m_bindings ) { - if( binding.second == Command ) { - return binding.first; + for( auto const &[bindingkey, bindingcommand] : m_bindings ) { + if( bindingcommand == Command ) { + return bindingkey; } } return -1; diff --git a/model/MdlMngr.cpp b/model/MdlMngr.cpp index 1fe429a0..680f67c4 100644 --- a/model/MdlMngr.cpp +++ b/model/MdlMngr.cpp @@ -95,9 +95,9 @@ TModelsManager::GetModel(std::string const &Name, bool const Dynamic, bool const postfix = "^^" + std::to_string(uid); // see if we have it in the databank - auto banklookup { find_in_databank( filename + postfix ) }; - TModel3d *model { banklookup.second }; - if( true == banklookup.first ) { + auto [banklookupfound, banklookupmodel]{ find_in_databank( filename + postfix ) }; + TModel3d *model { banklookupmodel }; + if( true == banklookupfound ) { Global.asCurrentTexturePath = buftp; return model; } diff --git a/network/manager.cpp b/network/manager.cpp index e4b312df..60adfd9e 100644 --- a/network/manager.cpp +++ b/network/manager.cpp @@ -59,8 +59,8 @@ network::manager::manager() = default; void network::manager::update() { - for (auto &backend : backend_list()) - backend.second->update(); + for (auto &[backendname, backendinstance] : backend_list()) + backendinstance->update(); if (client) client->update(); diff --git a/network/message.cpp b/network/message.cpp index a8a222fc..8e5c48f6 100644 --- a/network/message.cpp +++ b/network/message.cpp @@ -33,11 +33,11 @@ void network::server_hello::deserialize(std::istream &stream) void ::network::request_command::serialize(std::ostream &stream) const { sn_utils::ls_uint32(stream, static_cast(commands.size())); - for (auto const &kv : commands) + for (auto const &[recipient, sequence] : commands) { - sn_utils::ls_uint32(stream, kv.first); - sn_utils::ls_uint32(stream, static_cast(kv.second.size())); - for (command_data const &data : kv.second) + sn_utils::ls_uint32(stream, recipient); + sn_utils::ls_uint32(stream, static_cast(sequence.size())); + for (command_data const &data : sequence) { sn_utils::ls_uint32(stream, (uint32_t)data.command); sn_utils::ls_int32(stream, data.action); diff --git a/rendering/opengl33particles.cpp b/rendering/opengl33particles.cpp index 84a09738..002bf101 100644 --- a/rendering/opengl33particles.cpp +++ b/rendering/opengl33particles.cpp @@ -49,15 +49,15 @@ opengl33_particles::update( opengl_camera const &Camera ) { // build billboard data for particles from visible sources auto const camerarotation { glm::mat3( Camera.modelview() ) }; particle_vertex vertex; - for( auto const &source : sources ) { + for( auto const &[sourcekey, sourcedata] : sources ) { auto const particlecolor { glm::clamp( - source.second.color() + sourcedata.color() * ( glm::vec3 { Global.DayLight.ambient } + 0.35f * glm::vec3{ Global.DayLight.diffuse } ) * simulation::Environment.light_intensity(), glm::vec3{ 0.f }, glm::vec3{ 1.f } ) }; - auto const &particles { source.second.sequence() }; + auto const &particles { sourcedata.sequence() }; // TODO: put sanity cap on the overall amount of particles that can be drawn auto const sizestep { 256.0 * billboard_vertices.size() }; m_particlevertices.reserve( @@ -72,9 +72,9 @@ opengl33_particles::update( opengl_camera const &Camera ) { auto const offset { glm::vec3{ particle.position - Camera.position() } }; auto const rotation { glm::angleAxis( particle.rotation, glm::vec3{ 0.f, 0.f, 1.f } ) }; - for( auto const &billboardvertex : billboard_vertices ) { - vertex.position = offset + ( rotation * billboardvertex.first * particle.size ) * camerarotation; - vertex.texture = billboardvertex.second; + for( auto const &[billboardoffset, billboardtexture] : billboard_vertices ) { + vertex.position = offset + ( rotation * billboardoffset * particle.size ) * camerarotation; + vertex.texture = billboardtexture; m_particlevertices.emplace_back( vertex ); } diff --git a/rendering/openglparticles.cpp b/rendering/openglparticles.cpp index 2bee2f64..3b8de946 100644 --- a/rendering/openglparticles.cpp +++ b/rendering/openglparticles.cpp @@ -47,15 +47,15 @@ opengl_particles::update( opengl_camera const &Camera ) { // build billboard data for particles from visible sources auto const camerarotation { glm::mat3( Camera.modelview() ) }; particle_vertex vertex; - for( auto const &source : sources ) { + for( auto const &[sourcekey, sourcedata] : sources ) { auto const particlecolor { glm::clamp( - source.second.color() + sourcedata.color() * ( glm::vec3 { Global.DayLight.ambient } + 0.35f * glm::vec3{ Global.DayLight.diffuse } ) * 255.f, glm::vec3{ 0.f }, glm::vec3{ 255.f } ) }; - auto const &particles { source.second.sequence() }; + auto const &particles { sourcedata.sequence() }; // TODO: put sanity cap on the overall amount of particles that can be drawn auto const sizestep { 256.0 * billboard_vertices.size() }; m_particlevertices.reserve( @@ -70,9 +70,9 @@ opengl_particles::update( opengl_camera const &Camera ) { auto const offset { glm::vec3{ particle.position - Camera.position() } }; auto const rotation { glm::angleAxis( particle.rotation, glm::vec3{ 0.f, 0.f, 1.f } ) }; - for( auto const &billboardvertex : billboard_vertices ) { - vertex.position = offset + ( rotation * billboardvertex.first * particle.size ) * camerarotation; - vertex.texture = billboardvertex.second; + for( auto const &[billboardoffset, billboardtexture] : billboard_vertices ) { + vertex.position = offset + ( rotation * billboardoffset * particle.size ) * camerarotation; + vertex.texture = billboardtexture; m_particlevertices.emplace_back( vertex ); } diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index 4e4050c4..b40e71b9 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -30,36 +30,36 @@ void render_task::run() cancel(); return; } - for (auto const &datapair : m_input->floats) + for (auto const &[dataname, datavalue] : m_input->floats) { - auto *value{PyGetFloat(datapair.second)}; + auto *value{PyGetFloat(datavalue)}; if (value == nullptr) { PyErr_Clear(); continue; } - PyDict_SetItemString(input, datapair.first.c_str(), value); + PyDict_SetItemString(input, dataname.c_str(), value); Py_DECREF(value); } - for (auto const &datapair : m_input->integers) + for (auto const &[dataname, datavalue] : m_input->integers) { - auto *value{PyLong_FromLong(datapair.second)}; + auto *value{PyLong_FromLong(datavalue)}; if (value == nullptr) { PyErr_Clear(); continue; } - PyDict_SetItemString(input, datapair.first.c_str(), value); + PyDict_SetItemString(input, dataname.c_str(), value); Py_DECREF(value); } - for (auto const &datapair : m_input->bools) + for (auto const &[dataname, datavalue] : m_input->bools) { // Py_True / Py_False sa niesmiertelne, ale PyDict_SetItemString i tak // pobiera wlasna referencje - nie zwalniamy - auto *value{PyGetBool(datapair.second)}; - PyDict_SetItemString(input, datapair.first.c_str(), value); + auto *value{PyGetBool(datavalue)}; + PyDict_SetItemString(input, dataname.c_str(), value); } - for (auto const &datapair : m_input->strings) + for (auto const &[dataname, datavalue] : m_input->strings) { // Nazwy scenerii/wagonow (asName, SceneryFile, asCarName, cCode...) moga // byc albo w UTF-8, albo w starym kodowaniu Windows-1250. PyUnicode_FromString @@ -68,8 +68,8 @@ void render_task::run() // // Strategia: najpierw probujemy UTF-8 (strict). Jesli sie nie uda - probujemy // cp1250. Jesli oba zawioda - pomijamy klucz, ale nie wywracamy symulatora. - char const *const str{datapair.second.c_str()}; - Py_ssize_t const len{static_cast(datapair.second.size())}; + char const *const str{datavalue.c_str()}; + Py_ssize_t const len{static_cast(datavalue.size())}; auto *value{PyUnicode_DecodeUTF8(str, len, "strict")}; if (value == nullptr) @@ -82,16 +82,16 @@ void render_task::run() PyErr_Clear(); continue; } - PyDict_SetItemString(input, datapair.first.c_str(), value); + PyDict_SetItemString(input, dataname.c_str(), value); Py_DECREF(value); } - for (auto const &datapair : m_input->vec2_lists) + for (auto const &[dataname, datavalue] : m_input->vec2_lists) { - PyObject *list = PyList_New(datapair.second.size()); + PyObject *list = PyList_New(datavalue.size()); - for (size_t i = 0; i < datapair.second.size(); i++) + for (size_t i = 0; i < datavalue.size(); i++) { - auto const &vec = datapair.second[i]; + auto const &vec = datavalue[i]; WriteLog("passing " + glm::to_string(vec)); PyObject *tuple = PyTuple_New(2); @@ -101,7 +101,7 @@ void render_task::run() PyList_SetItem(list, i, tuple); // steals ref } - PyDict_SetItemString(input, datapair.first.c_str(), list); + PyDict_SetItemString(input, dataname.c_str(), list); Py_DECREF(list); } m_input = nullptr; @@ -376,9 +376,9 @@ void python_taskqueue::exit() // reclaim cached python objects while the interpreter is still alive, // so no Py_DECREF lands on a finalized interpreter during later teardown acquire_lock(); - for (auto &entry : m_renderers) + for (auto &[renderername, rendererobject] : m_renderers) { - Py_XDECREF(entry.second); + Py_XDECREF(rendererobject); } m_renderers.clear(); Py_XDECREF(m_stderr); @@ -437,13 +437,13 @@ auto python_taskqueue::insert(task_request const &Task) -> bool auto python_taskqueue::run_file(std::string const &File, std::string const &Path) -> bool { - auto const lookup{FileExists({Path + File, "python/local/" + File}, {".py"})}; - if (lookup.first.empty()) + auto const [filepath, fileextension]{FileExists({Path + File, "python/local/" + File}, {".py"})}; + if (filepath.empty()) { return false; } - std::ifstream inputfile{lookup.first + lookup.second}; + std::ifstream inputfile{filepath + fileextension}; std::string input; input.assign(std::istreambuf_iterator(inputfile), std::istreambuf_iterator()); diff --git a/scripting/ladderlogic.cpp b/scripting/ladderlogic.cpp index 9067e21c..23dbfb7e 100644 --- a/scripting/ladderlogic.cpp +++ b/scripting/ladderlogic.cpp @@ -154,8 +154,8 @@ basic_controller::deserialize_operation( cParser &Input ) -> bool { } if( false == operationparameter.empty() ) { - auto const parameter{ split_string_and_number( operationparameter ) }; - operation.parameter1 = static_cast( parameter.second ); + auto const [parametertype, parameterindex]{ split_string_and_number( operationparameter ) }; + operation.parameter1 = static_cast( parameterindex ); } m_program.emplace_back( operation ); @@ -380,12 +380,12 @@ basic_controller::log_error( std::string const &Error, int const Line ) const { auto basic_controller::guess_element_type_from_name( std::string const &Name ) const -> basic_element::type_e { - auto const name { split_string_and_number( Name ) }; + auto const [nametype, nameindex]{ split_string_and_number( Name ) }; - if( name.first == "t" || name.first == "ton" || name.first.find("timer.") == 0 ) { + if( nametype == "t" || nametype == "ton" || nametype.find("timer.") == 0 ) { return basic_element::type_e::timer; } - if( name.first == "c" || name.first.find("counter.") == 0 ) { + if( nametype == "c" || nametype.find("counter.") == 0 ) { return basic_element::type_e::counter; } diff --git a/vehicle/Gauge.cpp b/vehicle/Gauge.cpp index 7585b0dd..51389e5e 100644 --- a/vehicle/Gauge.cpp +++ b/vehicle/Gauge.cpp @@ -88,9 +88,9 @@ void TGauge::Init(TSubModel *Submodel, TSubModel *Submodelon, TGaugeAnimation Ty } } } - for( auto &soundfx : m_soundfxvalues ) { - if( soundfx.second.offset() == nulloffset ) { - soundfx.second.offset( offset ); + for( auto &[soundfxkey, soundfxsource] : m_soundfxvalues ) { + if( soundfxsource.offset() == nulloffset ) { + soundfxsource.offset( offset ); } } }; @@ -166,9 +166,9 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu if( !m_soundfxoff.soundproofing() ) { m_soundfxoff.soundproofing() = scratchpad.soundproofing; } - for( auto &soundfxrecord : m_soundfxvalues ) { - if( !soundfxrecord.second.soundproofing() ) { - soundfxrecord.second.soundproofing() = scratchpad.soundproofing; + for( auto &[soundfxkey, soundfxsource] : m_soundfxvalues ) { + if( !soundfxsource.soundproofing() ) { + soundfxsource.soundproofing() = scratchpad.soundproofing; } } } @@ -180,8 +180,8 @@ void TGauge::Load( cParser &Parser, TDynamicObject const *Owner, double const mu m_soundfxdecrease.owner( Owner ); m_soundfxon.owner( Owner ); m_soundfxoff.owner( Owner ); - for( auto &soundfxrecord : m_soundfxvalues ) { - soundfxrecord.second.owner( Owner ); + for( auto &[soundfxkey, soundfxsource] : m_soundfxvalues ) { + soundfxsource.owner( Owner ); } scale *= static_cast(mul); diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index f8a5f14c..07eea85b 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -10110,11 +10110,11 @@ void TTrain::update_sounds_radio() } // adjust audibility of remaining messages based on current radio conditions auto const radioenabled{true == mvOccupied->Radio && (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)}; - for (auto &message : m_radiomessages) + for (auto &[messagechannel, messagesound] : m_radiomessages) { - auto const volume{true == radioenabled && Dynamic()->Mechanik != nullptr && message.first == RadioChannel() ? m_radiovolume : 0.0}; - message.second->gain(static_cast(volume)); - radio_message_played |= true == radioenabled && Dynamic()->Mechanik != nullptr && message.first == RadioChannel(); + auto const volume{true == radioenabled && Dynamic()->Mechanik != nullptr && messagechannel == RadioChannel() ? m_radiovolume : 0.0}; + messagesound->gain(static_cast(volume)); + radio_message_played |= true == radioenabled && Dynamic()->Mechanik != nullptr && messagechannel == RadioChannel(); } // radiostop if (m_radiostop) @@ -10229,9 +10229,9 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName) {"huntingnoise:", {rsHuntingNoise, sound_placement::internal, EU07_SOUND_GLOBALRANGE, sound_type::single, sound_parameters::amplitude | sound_parameters::frequency, mvOccupied->Vmax}}, {"rainsound:", {m_rainsound, sound_placement::internal, -1, sound_type::single, 0, 100.0}}, }; - for (auto &soundconfig : internalsounds) + for (auto &[soundname, soundsource] : internalsounds) { - std::get &>(soundconfig.second).reset(); + std::get &>(soundsource).reset(); } // NOTE: since radiosound is an incomplete template not using std::optional it gets a special treatment m_radiosound.owner(DynamicObject); @@ -10343,11 +10343,11 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) } } m_radiosound.offset(nullvector); - for (auto &sound : CabSoundLocations) + for (auto &[soundsource, soundoffset] : CabSoundLocations) { - if (sound.first.get() && sound.first.get()->offset() == nullvector) + if (soundsource.get() && soundsource.get()->offset() == nullvector) { - sound.first.get()->offset(sound.second); + soundsource.get()->offset(soundoffset); } } // reset view angles @@ -10636,19 +10636,19 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) {m_rainsound, caboffset}, {m_radiostop, m_radiosound.offset()}, }; - for (auto &sound : soundlocations) + for (auto &[soundsource, soundoffset] : soundlocations) { - if (sound.first.get() && sound.first.get()->offset() == nullvector) + if (soundsource.get() && soundsource.get()->offset() == nullvector) { - sound.first.get()->offset(sound.second); + soundsource.get()->offset(soundoffset); } } // second pass, in case some items received no positioning due to missing submodels etc - for (auto &sound : soundlocations) + for (auto &[soundsource, soundoffset] : soundlocations) { - if (sound.first.get() && sound.first.get()->offset() == nullvector) + if (soundsource.get() && soundsource.get()->offset() == nullvector) { - sound.first.get()->offset(caboffset); + soundsource.get()->offset(caboffset); } } diff --git a/world/mtable.cpp b/world/mtable.cpp index 896454fd..b839c2fb 100644 --- a/world/mtable.cpp +++ b/world/mtable.cpp @@ -489,10 +489,10 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) if( entry.front() != 'R' ) { continue; } - auto const entrysplit { split_string_and_number( entry ) }; - if( entrysplit.first == "R" - && entrysplit.second <= 10 ) { - auto const radiochannel { entrysplit.second }; + auto const [entrytype, entrynumber]{ split_string_and_number( entry ) }; + if( entrytype == "R" + && entrynumber <= 10 ) { + auto const radiochannel { entrynumber }; if( record->radio_channel == -1 || radiochannel != activeradiochannel ) { // if the station has more than one radiochannel listed, @@ -610,17 +610,17 @@ TTrainParameters::load_sounds() { station.StationName.substr( 0, station.StationName.size() - 3 ) : station.StationName ) }; - auto const lookup { + auto const [filepath, fileextension]{ FileExists( { Global.asCurrentSceneryPath + stationname, std::string{ paths::sounds } + "sip/" + stationname }, { ".ogg", ".flac", ".wav" } ) }; - if( lookup.first.empty() ) { + if( filepath.empty() ) { continue; } // wczytanie dźwięku odjazdu w wersji radiowej (słychać tylko w kabinie) station.name_sound = sound_source{ sound_placement::engine, EU07_SOUND_CABANNOUNCEMENTCUTOFFRANGE } - .deserialize( lookup.first + lookup.second, sound_type::single ); + .deserialize( filepath + fileextension, sound_type::single ); } }