Skip to content

Commit

Permalink
Build with networking on the Switch
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Oct 11, 2023
1 parent d056183 commit 71c2c91
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/glib-stub/sys/uio.h
Original file line number Diff line number Diff line change
@@ -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 <sys/uio.h>

#endif //MELONDS_DS_UIO_H
28 changes: 28 additions & 0 deletions src/glib-stub/sys/un.h
Original file line number Diff line number Diff line change
@@ -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 <sys/socket.h>

// 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
7 changes: 6 additions & 1 deletion src/libretro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/libretro/config/definitions/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "../constants.hpp"

#ifdef HAVE_NETWORKING
namespace melonds::config::definitions {
template<retro_language L>
constexpr std::initializer_list<retro_core_option_v2_definition> NetworkOptionDefinitions {
Expand Down Expand Up @@ -73,5 +74,6 @@ namespace melonds::config::definitions {
#endif
};
}
#endif

#endif //MELONDS_DS_NETWORK_HPP
18 changes: 16 additions & 2 deletions src/libretro/platform/lan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 71c2c91

Please sign in to comment.