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

refactor(sonar): use structured bindings for pair access (cpp:S6005)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 16:06:32 +02:00
parent 9c7043d013
commit b6349b76e3
18 changed files with 152 additions and 152 deletions

View File

@@ -796,12 +796,12 @@ std::unordered_map<std::string, user_command> 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

View File

@@ -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

View File

@@ -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 );

View File

@@ -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<int>(bindingsetup.second) ] = bindingsetup.first;
m_bindings[ std::get<int>(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;