From 7304c863a6f3d8fabf0a5326bbeb83c4cf065439 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 23:06:04 -0500 Subject: [PATCH] NetPlayClient: Deduplicate code for player list retrieval --- Source/Core/Core/NetPlayClient.cpp | 41 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index a498803ce2..35247eeef0 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -575,29 +575,26 @@ void NetPlayClient::GetPlayerList(std::string& list, std::vector& pid_list) std::ostringstream ss; - std::map::const_iterator - i = m_players.begin(), - e = m_players.end(); - for (; i != e; ++i) + const auto enumerate_player_controller_mappings = [&ss](const PadMappingArray& mappings, const Player& player) { + for (size_t i = 0; i < mappings.size(); i++) + { + if (mappings[i] == player.pid) + ss << i + 1; + else + ss << '-'; + } + }; + + for (const auto& entry : m_players) { - const Player *player = &(i->second); - ss << player->name << "[" << (int)player->pid << "] : " << player->revision << " | "; - for (unsigned int j = 0; j < 4; j++) - { - if (m_pad_map[j] == player->pid) - ss << j + 1; - else - ss << '-'; - } - for (unsigned int j = 0; j < 4; j++) - { - if (m_wiimote_map[j] == player->pid) - ss << j + 1; - else - ss << '-'; - } - ss << " |\nPing: " << player->ping << "ms\n\n"; - pid_list.push_back(player->pid); + const Player& player = entry.second; + ss << player.name << "[" << static_cast(player.pid) << "] : " << player.revision << " | "; + + enumerate_player_controller_mappings(m_pad_map, player); + enumerate_player_controller_mappings(m_wiimote_map, player); + + ss << " |\nPing: " << player.ping << "ms\n\n"; + pid_list.push_back(player.pid); } list = ss.str();