move LAN/netplay stuff to net-utils

This commit is contained in:
Arisotura 2024-08-07 15:13:26 +02:00
parent bdbcd9c351
commit 7b40d3f6ca
7 changed files with 21 additions and 49 deletions

View File

@ -52,8 +52,6 @@ set(SOURCES_QT_SDL
CLI.h
CLI.cpp
LAN.cpp
Netplay.cpp
LANDialog.cpp
NetplayDialog.cpp
)
@ -93,8 +91,6 @@ add_compile_definitions(ARCHIVE_SUPPORT_ENABLED)
add_executable(melonDS ${SOURCES_QT_SDL})
find_package(ENet REQUIRED)
add_subdirectory("../../net"
"${CMAKE_BINARY_DIR}/net"
)
@ -182,7 +178,6 @@ endif()
target_link_libraries(melonDS PRIVATE core)
target_link_libraries(melonDS PRIVATE PkgConfig::SDL2 PkgConfig::LibArchive PkgConfig::Zstd)
target_link_libraries(melonDS PRIVATE ${QT_LINK_LIBS} ${CMAKE_DL_LIBS})
target_link_libraries(melonDS PRIVATE ${ENET_LIBRARIES})
if (WIN32)
option(PORTABLE "Make a portable build that looks for its configuration in the current directory" ON)

View File

@ -17,37 +17,10 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#ifdef __WIN32__
#include <winsock2.h>
#include <ws2tcpip.h>
#define socket_t SOCKET
#define sockaddr_t SOCKADDR
#define sockaddr_in_t SOCKADDR_IN
#else
#include <unistd.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#define socket_t int
#define sockaddr_t struct sockaddr
#define sockaddr_in_t struct sockaddr_in
#define closesocket close
#endif
#ifndef INVALID_SOCKET
#define INVALID_SOCKET (socket_t)-1
#endif
#include <enet/enet.h>
#include <SDL2/SDL.h>
#include <QStandardItemModel>
#include <QPushButton>
#include <QInputDialog>
@ -232,7 +205,8 @@ void LANStartClientDialog::updateDiscoveryList()
void LANStartClientDialog::doUpdateDiscoveryList()
{
LAN::DiscoveryMutex.lock();
if (LAN::DiscoveryMutex)
Platform::Mutex_Lock(LAN::DiscoveryMutex);
QStandardItemModel* model = (QStandardItemModel*)ui->tvAvailableGames->model();
int curcount = model->rowCount();
@ -277,7 +251,8 @@ void LANStartClientDialog::doUpdateDiscoveryList()
i++;
}
LAN::DiscoveryMutex.unlock();
if (LAN::DiscoveryMutex)
Platform::Mutex_Unlock(LAN::DiscoveryMutex);
}

View File

@ -4,8 +4,9 @@ add_library(net-utils STATIC
Net_Slirp.cpp
PacketDispatcher.cpp
LocalMP.cpp
MPInterface.h
MPInterface.cpp
LAN.cpp
Netplay.cpp
MPInterface.cpp
)
target_include_directories(net-utils PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
@ -21,3 +22,6 @@ else()
target_include_directories(net-utils SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/libslirp/glib")
target_link_libraries(net-utils PRIVATE slirp)
endif()
find_package(ENet REQUIRED)
target_link_libraries(net-utils PRIVATE ${ENET_LIBRARIES})

View File

@ -91,7 +91,7 @@ const int kLANPort = 7064;
socket_t DiscoverySocket;
u32 DiscoveryLastTick;
std::map<u32, DiscoveryData> DiscoveryList;
QMutex DiscoveryMutex;
Platform::Mutex* DiscoveryMutex = nullptr;
bool Active;
bool IsHost;
@ -120,6 +120,8 @@ u32 FrameCount;
bool Init()
{
DiscoveryMutex = Platform::Mutex_Create();
DiscoverySocket = INVALID_SOCKET;
DiscoveryLastTick = 0;
@ -183,6 +185,9 @@ void DeInit()
Host = nullptr;
enet_deinitialize();
Platform::Mutex_Free(DiscoveryMutex);
DiscoveryMutex = nullptr;
}
@ -413,7 +418,7 @@ void ProcessDiscovery()
}
else
{
DiscoveryMutex.lock();
Platform::Mutex_Lock(DiscoveryMutex);
// listen for LAN sessions
@ -467,7 +472,7 @@ void ProcessDiscovery()
DiscoveryList.erase(key);
}
DiscoveryMutex.unlock();
Platform::Mutex_Unlock(DiscoveryMutex);
// update the list in the connect dialog if needed

View File

@ -21,9 +21,9 @@
#include <string>
#include <map>
#include <QMutex>
#include "types.h"
#include "Platform.h"
namespace LAN
{
@ -61,7 +61,7 @@ struct DiscoveryData
extern bool Active;
extern std::map<u32, DiscoveryData> DiscoveryList;
extern QMutex DiscoveryMutex; // TODO: turn into Platform::Mutex or rework this to be nicer
extern Platform::Mutex* DiscoveryMutex; // TODO: turn into Platform::Mutex or rework this to be nicer
extern Player Players[16];
extern u32 PlayerPing[16];

View File

@ -23,9 +23,6 @@
#include <enet/enet.h>
#include <QStandardItemModel>
#include <QProcess>
#include "NDS.h"
#include "NDSCart.h"
#include "main.h"
@ -33,14 +30,10 @@
#include "Netplay.h"
//#include "Input.h"
//#include "ROMManager.h"
#include "Config.h"
//#include "Config.h"
#include "Savestate.h"
#include "Platform.h"
#include "ui_NetplayStartHostDialog.h"
#include "ui_NetplayStartClientDialog.h"
#include "ui_NetplayDialog.h"
using namespace melonDS;
namespace Netplay