From 71c2c91bd193b66776c2343cc3322bb484b886ef Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Tue, 10 Oct 2023 21:32:53 -0400 Subject: [PATCH] Build with networking on the Switch --- src/glib-stub/sys/uio.h | 23 +++++++++++++++++ src/glib-stub/sys/un.h | 28 +++++++++++++++++++++ src/libretro/CMakeLists.txt | 7 +++++- src/libretro/config/definitions/network.hpp | 2 ++ src/libretro/platform/lan.cpp | 18 +++++++++++-- 5 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/glib-stub/sys/uio.h create mode 100644 src/glib-stub/sys/un.h diff --git a/src/glib-stub/sys/uio.h b/src/glib-stub/sys/uio.h new file mode 100644 index 00000000..0b342696 --- /dev/null +++ b/src/glib-stub/sys/uio.h @@ -0,0 +1,23 @@ +/* + Copyright 2023 Jesse Talavera-Greenberg + + melonDS DS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS DS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS DS. If not, see http://www.gnu.org/licenses/. +*/ + + +#ifndef MELONDS_DS_UIO_H +#define MELONDS_DS_UIO_H + +// Empty; exists to pacify includes of + +#endif //MELONDS_DS_UIO_H diff --git a/src/glib-stub/sys/un.h b/src/glib-stub/sys/un.h new file mode 100644 index 00000000..3b3bf383 --- /dev/null +++ b/src/glib-stub/sys/un.h @@ -0,0 +1,28 @@ +/* + Copyright 2023 Jesse Talavera-Greenberg + + melonDS DS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS DS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS DS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef MELONDS_DS_UN_H +#define MELONDS_DS_UN_H + +#include + +// Not used, but needed for compilation +struct sockaddr_un { + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[108]; /* Pathname */ +}; + +#endif //MELONDS_DS_UN_H diff --git a/src/libretro/CMakeLists.txt b/src/libretro/CMakeLists.txt index dab2a86b..a090e6a7 100644 --- a/src/libretro/CMakeLists.txt +++ b/src/libretro/CMakeLists.txt @@ -120,12 +120,17 @@ add_common_definitions(libretro) if (HAVE_NETWORKING) target_sources(libretro PRIVATE - ${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/LAN_PCap.cpp ${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/LAN_Socket.cpp platform/lan.cpp ) target_include_directories(libretro SYSTEM PRIVATE "${melonDS_SOURCE_DIR}/src/frontend/qt_sdl") + + if (HAVE_NETWORKING_DIRECT_MODE) + target_sources(libretro PRIVATE + ${melonDS_SOURCE_DIR}/src/frontend/qt_sdl/LAN_PCap.cpp + ) + endif() endif () if (HAVE_OPENGL OR HAVE_OPENGLES) diff --git a/src/libretro/config/definitions/network.hpp b/src/libretro/config/definitions/network.hpp index b74e3cce..7cd5ae67 100644 --- a/src/libretro/config/definitions/network.hpp +++ b/src/libretro/config/definitions/network.hpp @@ -22,6 +22,7 @@ #include "../constants.hpp" +#ifdef HAVE_NETWORKING namespace melonds::config::definitions { template constexpr std::initializer_list NetworkOptionDefinitions { @@ -73,5 +74,6 @@ namespace melonds::config::definitions { #endif }; } +#endif #endif //MELONDS_DS_NETWORK_HPP diff --git a/src/libretro/platform/lan.cpp b/src/libretro/platform/lan.cpp index 19f1a476..f6c699b2 100644 --- a/src/libretro/platform/lan.cpp +++ b/src/libretro/platform/lan.cpp @@ -32,18 +32,24 @@ namespace LAN_Socket extern Slirp* Ctx; } +#ifdef HAVE_NETWORKING_DIRECT_MODE namespace LAN_PCap { extern Platform::DynamicLibrary* PCapLib; } +#endif bool Platform::LAN_Init() { ZoneScopedN("Platform::LAN_Init"); using namespace melonds::config::net; retro_assert(_activeNetworkMode == melonds::NetworkMode::None); retro_assert(LAN_Socket::Ctx == nullptr); + +#ifdef HAVE_NETWORKING_DIRECT_MODE retro_assert(LAN_PCap::PCapLib == nullptr); +#endif switch (NetworkMode()) { +#ifdef HAVE_NETWORKING_DIRECT_MODE case melonds::NetworkMode::Direct: if (LAN_PCap::Init(true)) { retro::debug("Initialized direct-mode Wi-fi support"); @@ -53,6 +59,7 @@ bool Platform::LAN_Init() { retro::warn("Failed to initialize direct-mode Wi-fi support; falling back to indirect mode"); } [[fallthrough]]; +#endif case melonds::NetworkMode::Indirect: if (LAN_Socket::Init()) { retro::debug("Initialized indirect-mode Wi-fi support\n"); @@ -70,18 +77,23 @@ bool Platform::LAN_Init() { void Platform::LAN_DeInit() { ZoneScopedN("Platform::LAN_DeInit"); +#ifdef HAVE_NETWORKING_DIRECT_MODE LAN_PCap::DeInit(); + retro_assert(LAN_PCap::PCapLib == nullptr); +#endif LAN_Socket::DeInit(); - _activeNetworkMode = melonds::NetworkMode::None; retro_assert(LAN_Socket::Ctx == nullptr); - retro_assert(LAN_PCap::PCapLib == nullptr); + + _activeNetworkMode = melonds::NetworkMode::None; } int Platform::LAN_SendPacket(u8 *data, int len) { ZoneScopedN("Platform::LAN_SendPacket"); switch (_activeNetworkMode) { +#ifdef HAVE_NETWORKING_DIRECT_MODE case melonds::NetworkMode::Direct: return LAN_PCap::SendPacket(data, len); +#endif case melonds::NetworkMode::Indirect: return LAN_Socket::SendPacket(data, len); default: @@ -92,8 +104,10 @@ int Platform::LAN_SendPacket(u8 *data, int len) { int Platform::LAN_RecvPacket(u8 *data) { ZoneScopedN("Platform::LAN_RecvPacket"); switch (_activeNetworkMode) { +#ifdef HAVE_NETWORKING_DIRECT_MODE case melonds::NetworkMode::Direct: return LAN_PCap::RecvPacket(data); +#endif case melonds::NetworkMode::Indirect: return LAN_Socket::RecvPacket(data); default: