From a93f86330ec4d8fec4010074ee5a8aa2102776cd Mon Sep 17 00:00:00 2001 From: James Cowgill Date: Sun, 9 Nov 2014 22:30:06 +0000 Subject: [PATCH] Port dolphin to SFML 2.1 --- CMakeLists.txt | 11 +- Externals/SFML/CMakeLists.txt | 1 - Source/Core/Core/CMakeLists.txt | 1 + Source/Core/Core/HW/EXI_DeviceGecko.cpp | 35 ++--- Source/Core/Core/HW/EXI_DeviceGecko.h | 7 +- Source/Core/Core/HW/SI_DeviceGBA.cpp | 34 ++--- Source/Core/Core/HW/SI_DeviceGBA.h | 4 +- .../Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 10 +- Source/Core/Core/NetPlayClient.cpp | 28 ++-- Source/Core/Core/NetPlayClient.h | 4 +- Source/Core/Core/NetPlayServer.cpp | 122 +++++++++--------- Source/Core/Core/NetPlayServer.h | 29 ++++- .../Core/DolphinWX/Cheats/GeckoCodeDiag.cpp | 10 +- Source/VSProps/Base.props | 1 + 14 files changed, 157 insertions(+), 140 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 518c0b59db..f36c7f01b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -600,16 +600,15 @@ if(LIBUSB_FOUND) include_directories(${LIBUSB_INCLUDE_DIR}) endif(LIBUSB_FOUND) -set(SFML_FIND_VERSION TRUE) -set(SFML_FIND_VERSION_MAJOR 1) -set(SFML_FIND_VERSION_MINOR 5) +set(SFML_REQD_VERSION 2.1) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT ANDROID) - include(FindSFML OPTIONAL) + find_package(SFML ${SFML_REQD_VERSION} COMPONENTS network system) endif() -if(SFML_FOUND AND NOT SFML_VERSION_MAJOR) # SFML 1.x doesn't define SFML_VERSION_MAJOR +if(SFML_FOUND) message("Using shared SFML") else() - message("Using static SFML ${SFML_FIND_VERSION_MAJOR}.${SFML_FIND_VERSION_MINOR} from Externals") + message("Using static SFML ${SFML_REQD_VERSION} from Externals") + add_definitions(-DSFML_STATIC) add_subdirectory(Externals/SFML) include_directories(BEFORE Externals/SFML/include) endif() diff --git a/Externals/SFML/CMakeLists.txt b/Externals/SFML/CMakeLists.txt index e2127502a6..0e82eae1ec 100644 --- a/Externals/SFML/CMakeLists.txt +++ b/Externals/SFML/CMakeLists.txt @@ -23,6 +23,5 @@ set(SRC_SYSTEM src/SFML/System/Time.cpp ) -add_definitions(-DSFML_STATIC) add_library(sfml-network ${SRC_NETWORK}) add_library(sfml-system ${SRC_SYSTEM}) diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 52ec66d4b8..536acd73f7 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -238,6 +238,7 @@ set(LIBS inputcommon ${LZO} sfml-network + sfml-system videoogl videosoftware z diff --git a/Source/Core/Core/HW/EXI_DeviceGecko.cpp b/Source/Core/Core/HW/EXI_DeviceGecko.cpp index 365468a6d8..00bf044fc1 100644 --- a/Source/Core/Core/HW/EXI_DeviceGecko.cpp +++ b/Source/Core/Core/HW/EXI_DeviceGecko.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include "Common/StdMakeUnique.h" #include "Core/Core.h" #include "Core/HW/EXI_Device.h" #include "Core/HW/EXI_DeviceGecko.h" @@ -10,8 +11,8 @@ u16 GeckoSockServer::server_port; int GeckoSockServer::client_count; std::thread GeckoSockServer::connectionThread; volatile bool GeckoSockServer::server_running; -std::queue GeckoSockServer::waiting_socks; std::mutex GeckoSockServer::connection_lock; +std::queue> GeckoSockServer::waiting_socks; GeckoSockServer::GeckoSockServer() : client_running(false) @@ -41,11 +42,12 @@ void GeckoSockServer::GeckoConnectionWaiter() { Common::SetCurrentThreadName("Gecko Connection Waiter"); - sf::SocketTCP server; + sf::TcpListener server; server_port = 0xd6ec; // "dolphin gecko" for (int bind_tries = 0; bind_tries <= 10 && !server_running; bind_tries++) { - if (!(server_running = server.Listen(server_port))) + server_running = server.listen(server_port) == sf::Socket::Done; + if (!server_running) server_port++; } @@ -56,22 +58,23 @@ void GeckoSockServer::GeckoConnectionWaiter() StringFromFormat("USBGecko: Listening on TCP port %u", server_port), 5000); - server.SetBlocking(false); + server.setBlocking(false); - sf::SocketTCP new_client; + auto new_client = std::make_unique(); while (server_running) { - if (server.Accept(new_client) == sf::Socket::Done) + if (server.accept(*new_client) == sf::Socket::Done) { std::lock_guard lk(connection_lock); - waiting_socks.push(new_client); + waiting_socks.push(std::move(new_client)); + + new_client = std::make_unique(); } SLEEP(1); } - server.Close(); } -bool GeckoSockServer::GetAvailableSock(sf::SocketTCP &sock_to_fill) +bool GeckoSockServer::GetAvailableSock() { bool sock_filled = false; @@ -79,7 +82,7 @@ bool GeckoSockServer::GetAvailableSock(sf::SocketTCP &sock_to_fill) if (!waiting_socks.empty()) { - sock_to_fill = waiting_socks.front(); + client = std::move(waiting_socks.front()); if (clientThread.joinable()) { client_running = false; @@ -103,7 +106,7 @@ void GeckoSockServer::ClientThread() Common::SetCurrentThreadName("Gecko Client"); - client.SetBlocking(false); + client->setBlocking(false); while (client_running) { @@ -116,7 +119,7 @@ void GeckoSockServer::ClientThread() char data[128]; std::size_t got = 0; - if (client.Receive(&data[0], ArraySize(data), got) == sf::Socket::Disconnected) + if (client->receive(&data[0], ArraySize(data), got) == sf::Socket::Disconnected) client_running = false; if (got != 0) @@ -133,7 +136,7 @@ void GeckoSockServer::ClientThread() std::vector packet(send_fifo.begin(), send_fifo.end()); send_fifo.clear(); - if (client.Send(&packet[0], packet.size()) == sf::Socket::Disconnected) + if (client->send(&packet[0], packet.size()) == sf::Socket::Disconnected) client_running = false; } } // unlock transfer @@ -142,7 +145,7 @@ void GeckoSockServer::ClientThread() Common::YieldCPU(); } - client.Close(); + client->disconnect(); } void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize) @@ -150,8 +153,8 @@ void CEXIGecko::ImmReadWrite(u32 &_uData, u32 _uSize) // We don't really care about _uSize (void)_uSize; - if (!client.IsValid()) - GetAvailableSock(client); + if (!client || client->getLocalPort() == 0) + GetAvailableSock(); switch (_uData >> 28) { diff --git a/Source/Core/Core/HW/EXI_DeviceGecko.h b/Source/Core/Core/HW/EXI_DeviceGecko.h index 1b80b844ed..a0f2caea63 100644 --- a/Source/Core/Core/HW/EXI_DeviceGecko.h +++ b/Source/Core/Core/HW/EXI_DeviceGecko.h @@ -14,15 +14,14 @@ #include "Core/HW/EXI_Device.h" class GeckoSockServer - : public sf::SocketTCP { public: GeckoSockServer(); ~GeckoSockServer(); - bool GetAvailableSock(sf::SocketTCP &sock_to_fill); + bool GetAvailableSock(); // Client for this server object - sf::SocketTCP client; + std::unique_ptr client; void ClientThread(); std::thread clientThread; std::mutex transfer_lock; @@ -40,8 +39,8 @@ private: static u16 server_port; static volatile bool server_running; static std::thread connectionThread; - static std::queue waiting_socks; static std::mutex connection_lock; + static std::queue> waiting_socks; }; class CEXIGecko diff --git a/Source/Core/Core/HW/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI_DeviceGBA.cpp index 3526a210e6..7baeb0ffad 100644 --- a/Source/Core/Core/HW/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI_DeviceGBA.cpp @@ -5,6 +5,7 @@ #include #include "Common/CommonFuncs.h" +#include "Common/StdMakeUnique.h" #include "Common/Thread.h" #include "Common/Logging/Log.h" #include "Core/HW/SI_Device.h" @@ -13,7 +14,7 @@ #include "SFML/Network.hpp" static std::thread connectionThread; -static std::queue waiting_socks; +static std::queue> waiting_socks; static std::mutex cs_gba; namespace { volatile bool server_running; } @@ -25,25 +26,25 @@ static void GBAConnectionWaiter() Common::SetCurrentThreadName("GBA Connection Waiter"); - sf::SocketTCP server; + sf::TcpListener server; // "dolphin gba" - if (!server.Listen(0xd6ba)) + if (server.listen(0xd6ba) != sf::Socket::Done) return; - server.SetBlocking(false); + server.setBlocking(false); - sf::SocketTCP new_client; + auto new_client = std::make_unique(); while (server_running) { - if (server.Accept(new_client) == sf::Socket::Done) + if (server.accept(*new_client) == sf::Socket::Done) { std::lock_guard lk(cs_gba); - waiting_socks.push(new_client); + waiting_socks.push(std::move(new_client)); + + new_client = std::make_unique(); } SLEEP(1); } - server.Close(); - return; } void GBAConnectionWaiter_Shutdown() @@ -53,7 +54,7 @@ void GBAConnectionWaiter_Shutdown() connectionThread.join(); } -static bool GetAvailableSock(sf::SocketTCP& sock_to_fill) +static bool GetAvailableSock(std::unique_ptr& sock_to_fill) { bool sock_filled = false; @@ -61,7 +62,7 @@ static bool GetAvailableSock(sf::SocketTCP& sock_to_fill) if (!waiting_socks.empty()) { - sock_to_fill = waiting_socks.front(); + sock_to_fill = std::move(waiting_socks.front()); waiting_socks.pop(); sock_filled = true; } @@ -77,13 +78,12 @@ GBASockServer::GBASockServer() GBASockServer::~GBASockServer() { - client.Close(); } // Blocking, since GBA must always send lower byte of REG_JOYSTAT void GBASockServer::Transfer(char* si_buffer) { - if (!client.IsValid()) + if (!client || client->getLocalPort() == 0) if (!GetAvailableSock(client)) return; @@ -93,9 +93,9 @@ void GBASockServer::Transfer(char* si_buffer) u8 cmd = *current_data; if (cmd == CMD_WRITE) - client.Send(current_data, sizeof(current_data)); + client->send(current_data, sizeof(current_data)); else - client.Send(current_data, 1); + client->send(current_data, 1); DEBUG_LOG(SERIALINTERFACE, "> command %02x %02x%02x%02x%02x", (u8)current_data[0], (u8)current_data[1], (u8)current_data[2], @@ -103,8 +103,8 @@ void GBASockServer::Transfer(char* si_buffer) memset(current_data, 0, sizeof(current_data)); size_t num_received = 0; - if (client.Receive(current_data, sizeof(current_data), num_received) == sf::Socket::Disconnected) - client.Close(); + if (client->receive(current_data, sizeof(current_data), num_received) == sf::Socket::Disconnected) + client->disconnect(); DEBUG_LOG(SERIALINTERFACE, "< %02x%02x%02x%02x%02x", (u8)current_data[0], (u8)current_data[1], (u8)current_data[2], diff --git a/Source/Core/Core/HW/SI_DeviceGBA.h b/Source/Core/Core/HW/SI_DeviceGBA.h index 46a8dc5e9b..1669edd315 100644 --- a/Source/Core/Core/HW/SI_DeviceGBA.h +++ b/Source/Core/Core/HW/SI_DeviceGBA.h @@ -12,7 +12,7 @@ void GBAConnectionWaiter_Shutdown(); -class GBASockServer : public sf::SocketTCP +class GBASockServer { public: GBASockServer(); @@ -29,7 +29,7 @@ private: CMD_WRITE = 0x15 }; - sf::SocketTCP client; + std::unique_ptr client; char current_data[5]; }; diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index bcd4501f7b..4e8cabf25d 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -203,10 +203,10 @@ bool Wiimote::Read() if (SConfig::GetInstance().m_LocalCoreStartupParameter.iBBDumpPort > 0 && index == WIIMOTE_BALANCE_BOARD) { - static sf::SocketUDP Socket; - Socket.Send((char*)rpt.data(), + static sf::UdpSocket Socket; + Socket.send((char*)rpt.data(), rpt.size(), - sf::IPAddress::LocalHost, + sf::IpAddress::LocalHost, SConfig::GetInstance().m_LocalCoreStartupParameter.iBBDumpPort); } @@ -236,8 +236,8 @@ bool Wiimote::Write() { if (SConfig::GetInstance().m_LocalCoreStartupParameter.iBBDumpPort > 0 && index == WIIMOTE_BALANCE_BOARD) { - static sf::SocketUDP Socket; - Socket.Send((char*)rpt.data(), rpt.size(), sf::IPAddress::LocalHost, SConfig::GetInstance().m_LocalCoreStartupParameter.iBBDumpPort); + static sf::UdpSocket Socket; + Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, SConfig::GetInstance().m_LocalCoreStartupParameter.iBBDumpPort); } IOWrite(rpt.data(), rpt.size()); diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 5fffcd2197..1f664f0ccd 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -43,18 +43,18 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay is_connected = false; - if (m_socket.Connect(port, address, 5) == sf::Socket::Done) + if (m_socket.connect(address, port, sf::seconds(5)) == sf::Socket::Done) { // send connect message sf::Packet spac; spac << NETPLAY_VERSION; spac << netplay_dolphin_ver; spac << name; - m_socket.Send(spac); + m_socket.send(spac); sf::Packet rpac; // TODO: make this not hang - m_socket.Receive(rpac); + m_socket.receive(rpac); MessageId error; rpac >> error; @@ -76,7 +76,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay PanicAlertT("The server sent an unknown error message!"); break; } - m_socket.Close(); + m_socket.disconnect(); } else { @@ -96,7 +96,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay //PanicAlertT("Connection successful: assigned player id: %d", m_pid); is_connected = true; - m_selector.Add(m_socket); + m_selector.add(m_socket); m_thread = std::thread(&NetPlayClient::ThreadFunc, this); } } @@ -286,7 +286,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) spac << ping_key; std::lock_guard lks(m_crit.send); - m_socket.Send(spac); + m_socket.send(spac); } break; @@ -319,10 +319,10 @@ void NetPlayClient::ThreadFunc() { while (m_do_loop) { - if (m_selector.Wait(0.01f)) + if (m_selector.wait(sf::milliseconds(10))) { sf::Packet rpac; - switch (m_socket.Receive(rpac)) + switch (m_socket.receive(rpac)) { case sf::Socket::Done : OnData(rpac); @@ -340,7 +340,7 @@ void NetPlayClient::ThreadFunc() } } - m_socket.Close(); + m_socket.disconnect(); return; } @@ -403,7 +403,7 @@ void NetPlayClient::SendChatMessage(const std::string& msg) spac << msg; std::lock_guard lks(m_crit.send); - m_socket.Send(spac); + m_socket.send(spac); } // called from ---CPU--- thread @@ -416,7 +416,7 @@ void NetPlayClient::SendPadState(const PadMapping in_game_pad, const GCPadStatus spac << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight; std::lock_guard lks(m_crit.send); - m_socket.Send(spac); + m_socket.send(spac); } // called from ---CPU--- thread @@ -433,7 +433,7 @@ void NetPlayClient::SendWiimoteState(const PadMapping in_game_pad, const NetWiim } std::lock_guard lks(m_crit.send); - m_socket.Send(spac); + m_socket.send(spac); } // called from ---GUI--- thread @@ -448,7 +448,7 @@ bool NetPlayClient::StartGame(const std::string &path) spac << (char *)&g_NetPlaySettings; std::lock_guard lks(m_crit.send); - m_socket.Send(spac); + m_socket.send(spac); if (m_is_running) { @@ -751,7 +751,7 @@ void NetPlayClient::Stop() { sf::Packet spac; spac << (MessageId)NP_MSG_STOP_GAME; - m_socket.Send(spac); + m_socket.send(spac); } } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 478fa2695e..521b0bb63c 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -87,9 +87,9 @@ protected: Common::FifoQueue m_wiimote_buffer[4]; NetPlayUI* m_dialog; - sf::SocketTCP m_socket; + sf::TcpSocket m_socket; std::thread m_thread; - sf::Selector m_selector; + sf::SocketSelector m_selector; std::string m_selected_game; volatile bool m_is_running; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 1edc6c064d..d484b97f26 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -5,6 +5,7 @@ #include #include +#include "Common/StdMakeUnique.h" #include "Common/StringUtil.h" #include "Core/NetPlayServer.h" #include "InputCommon/GCPadStatus.h" @@ -15,7 +16,7 @@ NetPlayServer::~NetPlayServer() { m_do_loop = false; m_thread.join(); - m_socket.Close(); + m_socket.close(); } #ifdef USE_UPNP @@ -31,11 +32,11 @@ NetPlayServer::NetPlayServer(const u16 port) : is_connected(false), m_is_running { memset(m_pad_map, -1, sizeof(m_pad_map)); memset(m_wiimote_map, -1, sizeof(m_wiimote_map)); - if (m_socket.Listen(port)) + if (m_socket.listen(port) == sf::Socket::Done) { is_connected = true; m_do_loop = true; - m_selector.Add(m_socket); + m_selector.add(m_socket); m_thread = std::thread(&NetPlayServer::ThreadFunc, this); m_target_buffer_size = 5; } @@ -64,17 +65,14 @@ void NetPlayServer::ThreadFunc() m_update_pings = false; } - // check which sockets need attention - const unsigned int num = m_selector.Wait(0.01f); - for (unsigned int i=0; i(); + m_socket.accept(*accept_socket); unsigned int error; { @@ -87,29 +85,34 @@ void NetPlayServer::ThreadFunc() sf::Packet spac; spac << (MessageId)error; // don't need to lock, this client isn't in the client map - accept_socket.Send(spac); - - // TODO: not sure if client gets the message if i close right away - accept_socket.Close(); + accept_socket->send(spac); + accept_socket->disconnect(); } } - // client socket - else + // client sockets + for (auto it = m_players.begin(); it != m_players.end();) { - sf::Packet rpac; - switch (ready_socket.Receive(rpac)) - { - case sf::Socket::Done : - // if a bad packet is received, disconnect the client - if (0 == OnData(rpac, ready_socket)) - break; + // move iterator on immediately so client can be removed + Client& client = *it; + it++; - //case sf::Socket::Disconnected : - default : + if (m_selector.isReady(*client.socket)) + { + sf::Packet rpac; + switch (client.socket->receive(rpac)) { - std::lock_guard lkg(m_crit.game); - OnDisconnect(ready_socket); - break; + case sf::Socket::Done : + // if a bad packet is received, disconnect the client + if (0 == OnData(rpac, client)) + break; + + //case sf::Socket::Disconnected : + default : + { + std::lock_guard lkg(m_crit.game); + OnDisconnect(client); + break; + } } } } @@ -118,15 +121,15 @@ void NetPlayServer::ThreadFunc() // close listening socket and client sockets for (auto& player_entry : m_players) - player_entry.second.socket.Close(); + player_entry.socket->disconnect(); } // called from ---NETPLAY--- thread -unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket) +unsigned int NetPlayServer::OnConnect(std::unique_ptr& socket) { sf::Packet rpac; // TODO: make this not hang / check if good packet - socket.Receive(rpac); + socket->receive(rpac); std::string npver; rpac >> npver; @@ -146,7 +149,7 @@ unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket) m_update_pings = true; Client player; - player.socket = socket; + player.socket = std::move(socket); rpac >> player.revision; rpac >> player.name; @@ -154,7 +157,7 @@ unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket) PlayerId pid = 1; for (auto i = m_players.begin(); i != m_players.end(); ++i) { - if (i->second.pid == pid) + if (i->pid == pid) { pid++; i = m_players.begin(); @@ -182,57 +185,56 @@ unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket) SendToClients(spac); // send new client success message with their id - spac.Clear(); + spac.clear(); spac << (MessageId)0; spac << player.pid; - socket.Send(spac); + player.socket->send(spac); // send new client the selected game if (m_selected_game != "") { - spac.Clear(); + spac.clear(); spac << (MessageId)NP_MSG_CHANGE_GAME; spac << m_selected_game; - socket.Send(spac); + player.socket->send(spac); } // send the pad buffer value - spac.Clear(); + spac.clear(); spac << (MessageId)NP_MSG_PAD_BUFFER; spac << (u32)m_target_buffer_size; - socket.Send(spac); + player.socket->send(spac); // sync values with new client for (const auto& p : m_players) { - spac.Clear(); + spac.clear(); spac << (MessageId)NP_MSG_PLAYER_JOIN; - spac << p.second.pid << p.second.name << p.second.revision; - socket.Send(spac); + spac << p.pid << p.name << p.revision; + player.socket->send(spac); } } // unlock send + // add client to selector/ used for receiving + m_selector.add(*player.socket); + // add client to the player list { std::lock_guard lkp(m_crit.players); - m_players[socket] = player; + m_players.push_back(std::move(player)); std::lock_guard lks(m_crit.send); UpdatePadMapping(); // sync pad mappings with everyone UpdateWiimoteMapping(); } - - // add client to selector/ used for receiving - m_selector.Add(socket); - return 0; } // called from ---NETPLAY--- thread -unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket) +unsigned int NetPlayServer::OnDisconnect(Client& player) { - PlayerId pid = m_players[socket].pid; + PlayerId pid = player.pid; if (m_is_running) { @@ -258,10 +260,10 @@ unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket) spac << (MessageId)NP_MSG_PLAYER_LEAVE; spac << pid; - m_selector.Remove(socket); + m_selector.remove(*player.socket); std::lock_guard lkp(m_crit.players); - m_players.erase(m_players.find(socket)); + m_players.remove(player); // alert other players of disconnect std::lock_guard lks(m_crit.send); @@ -359,14 +361,13 @@ void NetPlayServer::AdjustPadBufferSize(unsigned int size) } // called from ---NETPLAY--- thread -unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket) +unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player) { MessageId mid; packet >> mid; // don't need lock because this is the only thread that modifies the players // only need locks for writes to m_players in this thread - Client& player = m_players[socket]; switch (mid) { @@ -568,12 +569,11 @@ bool NetPlayServer::StartGame() // called from multiple threads void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid) { - for (std::pair& p : m_players) + for (auto& p : m_players) { - if (p.second.pid && - p.second.pid != skip_pid) + if (p.pid && p.pid != skip_pid) { - p.second.socket.Send(packet); + p.socket->send(packet); } } } @@ -582,9 +582,9 @@ void NetPlayServer::KickPlayer(u8 player) { for (auto& current_player : m_players) { - if (current_player.second.pid == player) + if (current_player.pid == player) { - current_player.second.socket.Close(); + current_player.socket->disconnect(); return; } } @@ -613,7 +613,7 @@ void NetPlayServer::TryPortmapping(u16 port) // UPnP thread: try to map a port void NetPlayServer::mapPortThread(const u16 port) { - std::string ourIP = sf::IPAddress::GetLocalAddress().ToString(); + std::string ourIP = sf::IpAddress::getLocalAddress().toString(); if (!m_upnp_inited) if (!initUPnP()) diff --git a/Source/Core/Core/NetPlayServer.h b/Source/Core/Core/NetPlayServer.h index 09c9e33f6b..9f51f760eb 100644 --- a/Source/Core/Core/NetPlayServer.h +++ b/Source/Core/Core/NetPlayServer.h @@ -56,15 +56,30 @@ private: std::string name; std::string revision; - sf::SocketTCP socket; + std::unique_ptr socket; u32 ping; u32 current_game; + + // VS2013 does not generate the right constructors here automatically + // like GCC does, so we implement them manually + Client() = default; + Client(const Client& other) = delete; + Client(Client&& other) + : pid(other.pid), name(std::move(other.name)), revision(std::move(other.revision)), + socket(std::move(other.socket)), ping(other.ping), current_game(other.current_game) + { + } + + bool operator==(const Client& other) const + { + return this == &other; + } }; void SendToClients(sf::Packet& packet, const PlayerId skip_pid = 0); - unsigned int OnConnect(sf::SocketTCP& socket); - unsigned int OnDisconnect(sf::SocketTCP& socket); - unsigned int OnData(sf::Packet& packet, sf::SocketTCP& socket); + unsigned int OnConnect(std::unique_ptr& socket); + unsigned int OnDisconnect(Client& player); + unsigned int OnData(sf::Packet& packet, Client& player); void UpdatePadMapping(); void UpdateWiimoteMapping(); @@ -80,7 +95,7 @@ private: PadMapping m_pad_map[4]; PadMapping m_wiimote_map[4]; - std::map m_players; + std::list m_players; struct { @@ -91,9 +106,9 @@ private: std::string m_selected_game; - sf::SocketTCP m_socket; + sf::TcpListener m_socket; std::thread m_thread; - sf::Selector m_selector; + sf::SocketSelector m_selector; #ifdef USE_UPNP static void mapPortThread(const u16 port); diff --git a/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp b/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp index 30e722af1d..097f22ea56 100644 --- a/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp +++ b/Source/Core/DolphinWX/Cheats/GeckoCodeDiag.cpp @@ -172,20 +172,20 @@ void CodeConfigPanel::DownloadCodes(wxCommandEvent&) } sf::Http::Request req; - req.SetURI("/txt.php?txt=" + gameid); + req.setUri("/txt.php?txt=" + gameid); sf::Http http; - http.SetHost("geckocodes.org"); + http.setHost("geckocodes.org"); - const sf::Http::Response resp = http.SendRequest(req, 5.0f); + const sf::Http::Response resp = http.sendRequest(req, sf::seconds(5)); - if (sf::Http::Response::Ok == resp.GetStatus()) + if (sf::Http::Response::Ok == resp.getStatus()) { // temp vector containing parsed codes std::vector gcodes; // parse the codes - std::istringstream ss(resp.GetBody()); + std::istringstream ss(resp.getBody()); std::string line; diff --git a/Source/VSProps/Base.props b/Source/VSProps/Base.props index 3fe3bbcba1..4a361b0cb7 100644 --- a/Source/VSProps/Base.props +++ b/Source/VSProps/Base.props @@ -50,6 +50,7 @@ _CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions) USE_UPNP;%(PreprocessorDefinitions) PSAPI_VERSION=1;_M_X86=1;%(PreprocessorDefinitions) + SFML_STATIC;%(PreprocessorDefinitions) _ARCH_64=1;_M_X86_64=1;%(PreprocessorDefinitions) Level3 true