From d9f87b8030b84e41bb181e9cb1f2247a4b58b345 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 21:46:46 -0500 Subject: [PATCH 1/8] NetPlayClient: Remove unnecessary includes Replace with needed ones --- Source/Core/Core/NetPlayClient.cpp | 6 ++---- Source/Core/Core/NetPlayClient.h | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 9d5992917a..d20d1b77ef 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -3,22 +3,20 @@ // Refer to the license.txt file included. #include "Common/Common.h" +#include "Common/CommonTypes.h" #include "Common/ENetUtil.h" +#include "Common/MsgHandler.h" #include "Common/Timer.h" #include "Core/ConfigManager.h" -#include "Core/Core.h" #include "Core/Movie.h" #include "Core/NetPlayClient.h" #include "Core/HW/EXI_DeviceIPL.h" #include "Core/HW/SI.h" -#include "Core/HW/SI_DeviceDanceMat.h" #include "Core/HW/SI_DeviceGCController.h" -#include "Core/HW/SI_DeviceGCSteeringWheel.h" #include "Core/HW/Sram.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/IPC_HLE/WII_IPC_HLE_Device_usb.h" -#include "Core/IPC_HLE/WII_IPC_HLE_WiiMote.h" static const char* NETPLAY_VERSION = scm_rev_git_str; static std::mutex crit_netplay_client; diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index c95aeeaf8e..cbfd765846 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -7,9 +7,9 @@ #include #include #include -#include -#include +#include #include +#include #include #include "Common/CommonTypes.h" #include "Common/FifoQueue.h" From 102672a797edef07922a11d101f26b2baabfd95b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 21:52:02 -0500 Subject: [PATCH 2/8] NetPlayClient: Make is_connected private This is only queried, there's no need to expose it for writing. Even if it was written to, a data member shouldn't be part of your public API unless its part of a dumb object or trivial struct. --- Source/Core/Core/NetPlayClient.cpp | 7 ++----- Source/Core/Core/NetPlayClient.h | 5 ++++- Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index d20d1b77ef..1956596b90 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -30,7 +30,7 @@ NetPlayClient::~NetPlayClient() if (m_is_running.load()) StopGame(); - if (is_connected) + if (m_is_connected) { m_do_loop.store(false); m_thread.join(); @@ -76,8 +76,6 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay m_target_buffer_size = 20; ClearBuffers(); - is_connected = false; - m_player_name = name; if (!traversal) @@ -235,7 +233,7 @@ bool NetPlayClient::Connect() m_dialog->Update(); - is_connected = true; + m_is_connected = true; return true; } @@ -629,7 +627,6 @@ std::vector NetPlayClient::GetPlayers() return players; } - // called from ---GUI--- thread void NetPlayClient::SendChatMessage(const std::string& msg) { diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index cbfd765846..72379701b4 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -56,7 +56,8 @@ public: void GetPlayerList(std::string& list, std::vector& pid_list); std::vector GetPlayers(); - bool is_connected; + // Called from the GUI thread. + bool IsConnected() const { return m_is_connected; } bool StartGame(const std::string &path); bool StopGame(); @@ -135,6 +136,8 @@ private: void Disconnect(); bool Connect(); + bool m_is_connected = false; + PlayerId m_pid; std::map m_players; std::string m_host_spec; diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index ae0375bd71..72042bac2b 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -291,7 +291,7 @@ void NetPlaySetupFrame::MakeNetPlayDiag(int port, const std::string &game, bool GetTraversalServer(netplay_section, ¢ralServer); netplay_client = new NetPlayClient(ip, (u16)port, npd, WxStrToStr(m_nickname_text->GetValue()), trav, centralServer, (u16) centralPort); - if (netplay_client->is_connected) + if (netplay_client->IsConnected()) { npd->Show(); Destroy(); From 1d8ff504a5f2463a007257524fa12ab1b8fc1256 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 21:58:56 -0500 Subject: [PATCH 3/8] NetPlayClient: Make m_state private Also turns it into an enum class. --- Source/Core/Core/NetPlayClient.cpp | 21 ++++++++++----------- Source/Core/Core/NetPlayClient.h | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 1956596b90..18241ecd82 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -59,8 +59,7 @@ NetPlayClient::~NetPlayClient() // called from ---GUI--- thread NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, const std::string& centralServer, u16 centralPort) - : m_state(Failure) - , m_dialog(dialog) + : m_dialog(dialog) , m_client(nullptr) , m_server(nullptr) , m_is_running(false) @@ -134,7 +133,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay m_traversal_client->ReconnectToServer(); m_traversal_client->m_Client = this; m_host_spec = address; - m_state = WaitingForTraversalClientConnection; + m_connection_state = ConnectionState::WaitingForTraversalClientConnection; OnTraversalStateChanged(); m_connecting = true; @@ -156,7 +155,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay m_server = netEvent.peer; if (Connect()) { - m_state = Connected; + m_connection_state = ConnectionState::Connected; m_thread = std::thread(&NetPlayClient::ThreadFunc, this); } return; @@ -501,7 +500,7 @@ void NetPlayClient::Disconnect() { ENetEvent netEvent; m_connecting = false; - m_state = Failure; + m_connection_state = ConnectionState::Failure; if (m_server) enet_peer_disconnect(m_server, 0); else @@ -766,13 +765,13 @@ void NetPlayClient::ClearBuffers() // called from ---NETPLAY--- thread void NetPlayClient::OnTraversalStateChanged() { - if (m_state == WaitingForTraversalClientConnection && + if (m_connection_state == ConnectionState::WaitingForTraversalClientConnection && m_traversal_client->m_State == TraversalClient::Connected) { - m_state = WaitingForTraversalClientConnectReady; + m_connection_state = ConnectionState::WaitingForTraversalClientConnectReady; m_traversal_client->ConnectToClient(m_host_spec); } - else if (m_state != Failure && + else if (m_connection_state != ConnectionState::Failure && m_traversal_client->m_State == TraversalClient::Failure) { Disconnect(); @@ -782,9 +781,9 @@ void NetPlayClient::OnTraversalStateChanged() // called from ---NETPLAY--- thread void NetPlayClient::OnConnectReady(ENetAddress addr) { - if (m_state == WaitingForTraversalClientConnectReady) + if (m_connection_state == ConnectionState::WaitingForTraversalClientConnectReady) { - m_state = Connecting; + m_connection_state = ConnectionState::Connecting; enet_host_connect(m_client, &addr, 0, 0); } } @@ -793,7 +792,7 @@ void NetPlayClient::OnConnectReady(ENetAddress addr) void NetPlayClient::OnConnectFailed(u8 reason) { m_connecting = false; - m_state = Failure; + m_connection_state = ConnectionState::Failure; switch (reason) { case TraversalConnectFailedClientDidntRespond: diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 72379701b4..d9548e177e 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -80,16 +80,6 @@ public: static void SendTimeBase(); - enum State - { - WaitingForTraversalClientConnection, - WaitingForTraversalClientConnectReady, - Connecting, - WaitingForHelloResponse, - Connected, - Failure - } m_state; - protected: void ClearBuffers(); @@ -128,6 +118,16 @@ protected: bool m_is_recording; private: + enum class ConnectionState + { + WaitingForTraversalClientConnection, + WaitingForTraversalClientConnectReady, + Connecting, + WaitingForHelloResponse, + Connected, + Failure + }; + void UpdateDevices(); void SendPadState(const PadMapping in_game_pad, const GCPadStatus& np); void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw); @@ -137,6 +137,7 @@ private: bool Connect(); bool m_is_connected = false; + ConnectionState m_connection_state = ConnectionState::Failure; PlayerId m_pid; std::map m_players; From c2deb337aa7d8c6a881564faffeca15b046ad439 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 22:06:57 -0500 Subject: [PATCH 4/8] NetPlayClient: In-class initialize variables where possible --- Source/Core/Core/NetPlayClient.cpp | 15 +-------------- Source/Core/Core/NetPlayClient.h | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 18241ecd82..2c435a5375 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -60,23 +60,10 @@ NetPlayClient::~NetPlayClient() // called from ---GUI--- thread NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, const std::string& centralServer, u16 centralPort) : m_dialog(dialog) - , m_client(nullptr) - , m_server(nullptr) - , m_is_running(false) - , m_do_loop(true) - , m_target_buffer_size() - , m_local_player(nullptr) - , m_current_game(0) - , m_is_recording(false) - , m_pid(0) - , m_connecting(false) - , m_traversal_client(nullptr) + , m_player_name(name) { - m_target_buffer_size = 20; ClearBuffers(); - m_player_name = name; - if (!traversal) { //Direct Connection diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index d9548e177e..30f7f5421b 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -96,26 +96,26 @@ protected: Common::FifoQueue m_pad_buffer[4]; Common::FifoQueue m_wiimote_buffer[4]; - NetPlayUI* m_dialog; + NetPlayUI* m_dialog = nullptr; - ENetHost* m_client; - ENetPeer* m_server; + ENetHost* m_client = nullptr; + ENetPeer* m_server = nullptr; std::thread m_thread; std::string m_selected_game; - std::atomic m_is_running; - std::atomic m_do_loop; + std::atomic m_is_running{false}; + std::atomic m_do_loop{true}; - unsigned int m_target_buffer_size; + unsigned int m_target_buffer_size = 20; - Player* m_local_player; + Player* m_local_player = nullptr; - u32 m_current_game; + u32 m_current_game = 0; PadMappingArray m_pad_map; PadMappingArray m_wiimote_map; - bool m_is_recording; + bool m_is_recording = false; private: enum class ConnectionState @@ -139,14 +139,14 @@ private: bool m_is_connected = false; ConnectionState m_connection_state = ConnectionState::Failure; - PlayerId m_pid; + PlayerId m_pid = 0; std::map m_players; std::string m_host_spec; std::string m_player_name; - bool m_connecting; - TraversalClient* m_traversal_client; + bool m_connecting = false; + TraversalClient* m_traversal_client = nullptr; - u32 m_timebase_frame; + u32 m_timebase_frame = 0; }; void NetPlay_Enable(NetPlayClient* const np); From 8588c8fd3139c3e14d8f57cc88fcdbf7a2f6fa1d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 22:10:38 -0500 Subject: [PATCH 5/8] NetPlayClient: Make SendAsync take a unique_ptr as a parameter --- Source/Core/Core/NetPlayClient.cpp | 82 +++++++++++++++++++----------- Source/Core/Core/NetPlayClient.h | 6 ++- 2 files changed, 58 insertions(+), 30 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 2c435a5375..b59845c97b 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include "Common/Common.h" #include "Common/CommonTypes.h" #include "Common/ENetUtil.h" @@ -512,11 +513,11 @@ void NetPlayClient::Disconnect() m_server = nullptr; } -void NetPlayClient::SendAsync(sf::Packet* packet) +void NetPlayClient::SendAsync(std::unique_ptr packet) { { std::lock_guard lkq(m_crit.async_queue_write); - m_async_queue.Push(std::unique_ptr(packet)); + m_async_queue.Push(std::move(packet)); } ENetUtil::WakeupThread(m_client); } @@ -616,46 +617,71 @@ std::vector NetPlayClient::GetPlayers() // called from ---GUI--- thread void NetPlayClient::SendChatMessage(const std::string& msg) { - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_CHAT_MESSAGE; + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_CHAT_MESSAGE); *spac << msg; - SendAsync(spac); + + SendAsync(std::move(spac)); } // called from ---CPU--- thread void NetPlayClient::SendPadState(const PadMapping in_game_pad, const GCPadStatus& pad) { - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_PAD_DATA; + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_PAD_DATA); *spac << in_game_pad; - *spac << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight; + *spac << pad.button + << pad.analogA + << pad.analogB + << pad.stickX + << pad.stickY + << pad.substickX + << pad.substickY + << pad.triggerLeft + << pad.triggerRight; - SendAsync(spac); + SendAsync(std::move(spac)); } // called from ---CPU--- thread void NetPlayClient::SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw) { - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_WIIMOTE_DATA; + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_WIIMOTE_DATA); *spac << in_game_pad; - *spac << (u8)nw.size(); + *spac << static_cast(nw.size()); for (auto it : nw) { *spac << it; } - SendAsync(spac); + + SendAsync(std::move(spac)); +} + +// called from ---GUI--- thread +void NetPlayClient::SendStartGamePacket() +{ + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_START_GAME); + *spac << m_current_game; + + SendAsync(std::move(spac)); +} + +// called from ---GUI--- thread +void NetPlayClient::SendStopGamePacket() +{ + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_STOP_GAME); + + SendAsync(std::move(spac)); } // called from ---GUI--- thread bool NetPlayClient::StartGame(const std::string &path) { std::lock_guard lkg(m_crit.game); - // tell server i started the game - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_START_GAME; - *spac << m_current_game; - SendAsync(spac); + SendStartGamePacket(); if (m_is_running.load()) { @@ -1006,13 +1032,10 @@ void NetPlayClient::Stop() isPadMapped = true; } } - // tell the server to stop if we have a pad mapped in game. + + // Tell the server to stop if we have a pad mapped in game. if (isPadMapped) - { - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_STOP_GAME; - SendAsync(spac); - } + SendStopGamePacket(); } u8 NetPlayClient::InGamePadToLocalPad(u8 ingame_pad) @@ -1077,12 +1100,13 @@ void NetPlayClient::SendTimeBase() u64 timebase = SystemTimers::GetFakeTimeBase(); - sf::Packet* spac = new sf::Packet; - *spac << (MessageId)NP_MSG_TIMEBASE; - *spac << (u32)timebase; - *spac << (u32)(timebase << 32); + auto spac = std::make_unique(); + *spac << static_cast(NP_MSG_TIMEBASE); + *spac << static_cast(timebase); + *spac << static_cast(timebase << 32); *spac << netplay_client->m_timebase_frame++; - netplay_client->SendAsync(spac); + + netplay_client->SendAsync(std::move(spac)); } // stuff hacked into dolphin diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 30f7f5421b..0e1c2ec70e 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -48,7 +49,7 @@ class NetPlayClient : public TraversalClientClient { public: void ThreadFunc(); - void SendAsync(sf::Packet* packet); + void SendAsync(std::unique_ptr packet); NetPlayClient(const std::string& address, const u16 port, NetPlayUI* dialog, const std::string& name, bool traversal, const std::string& centralServer, u16 centralPort); ~NetPlayClient(); @@ -128,6 +129,9 @@ private: Failure }; + void SendStartGamePacket(); + void SendStopGamePacket(); + void UpdateDevices(); void SendPadState(const PadMapping in_game_pad, const GCPadStatus& np); void SendWiimoteState(const PadMapping in_game_pad, const NetWiimote& nw); From e6ad76fa708430148213813c88ddc14880e82ad6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 22:46:37 -0500 Subject: [PATCH 6/8] NetPlayClient: Extract control mapping checking to its own function --- Source/Core/Core/NetPlayClient.cpp | 30 +++++++++++++----------------- Source/Core/Core/NetPlayClient.h | 2 ++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index b59845c97b..a498803ce2 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include #include "Common/Common.h" #include "Common/CommonTypes.h" @@ -1017,27 +1018,22 @@ void NetPlayClient::Stop() if (!m_is_running.load()) return; - bool isPadMapped = false; - for (PadMapping mapping : m_pad_map) - { - if (mapping == m_local_player->pid) - { - isPadMapped = true; - } - } - for (PadMapping mapping : m_wiimote_map) - { - if (mapping == m_local_player->pid) - { - isPadMapped = true; - } - } - // Tell the server to stop if we have a pad mapped in game. - if (isPadMapped) + if (LocalPlayerHasControllerMapped()) SendStopGamePacket(); } +// called from ---GUI--- thread +bool NetPlayClient::LocalPlayerHasControllerMapped() const +{ + const auto mapping_matches_player_id = [this](const PadMapping& mapping) { + return mapping == m_local_player->pid; + }; + + return std::any_of(m_pad_map.begin(), m_pad_map.end(), mapping_matches_player_id) || + std::any_of(m_wiimote_map.begin(), m_wiimote_map.end(), mapping_matches_player_id); +} + u8 NetPlayClient::InGamePadToLocalPad(u8 ingame_pad) { // not our pad diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 0e1c2ec70e..f55af047cd 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -129,6 +129,8 @@ private: Failure }; + bool LocalPlayerHasControllerMapped() const; + void SendStartGamePacket(); void SendStopGamePacket(); From 7304c863a6f3d8fabf0a5326bbeb83c4cf065439 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 23:06:04 -0500 Subject: [PATCH 7/8] 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(); From c434b5b3a979415f71d939135568e4c5e7aac18f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 24 Jan 2016 23:26:38 -0500 Subject: [PATCH 8/8] NetPlayClient: Use std::array instead of C arrays for buffers --- Source/Core/Core/NetPlayClient.cpp | 19 ++++++++++++++----- Source/Core/Core/NetPlayClient.h | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 35247eeef0..ff94151f2b 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -311,11 +311,20 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) { PadMapping map = 0; GCPadStatus pad; - packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight; + packet >> map + >> pad.button + >> pad.analogA + >> pad.analogB + >> pad.stickX + >> pad.stickY + >> pad.substickX + >> pad.substickY + >> pad.triggerLeft + >> pad.triggerRight; - // trusting server for good map value (>=0 && <4) + // Trusting server for good map value (>=0 && <4) // add to pad buffer - m_pad_buffer[map].Push(pad); + m_pad_buffer.at(map).Push(pad); } break; @@ -331,9 +340,9 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) for (unsigned int i = 0; i < size; ++i) packet >> nw[i]; - // trusting server for good map value (>=0 && <4) + // Trusting server for good map value (>=0 && <4) // add to Wiimote buffer - m_wiimote_buffer[(unsigned)map].Push(nw); + m_wiimote_buffer.at(map).Push(nw); } break; diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index f55af047cd..3c9222e087 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -94,8 +95,8 @@ protected: Common::FifoQueue, false> m_async_queue; - Common::FifoQueue m_pad_buffer[4]; - Common::FifoQueue m_wiimote_buffer[4]; + std::array, 4> m_pad_buffer; + std::array, 4> m_wiimote_buffer; NetPlayUI* m_dialog = nullptr;