Skip to content

Commit

Permalink
Backport LAN (#2131)
Browse files Browse the repository at this point in the history
backport the old LAN feature to the modern melonDS codebase.
  • Loading branch information
Arisotura authored Aug 10, 2024
1 parent ec71b15 commit 8d31875
Show file tree
Hide file tree
Showing 34 changed files with 4,163 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
sudo rm -f /etc/apt/sources.list.d/dotnetdev.list /etc/apt/sources.list.d/microsoft-prod.list
sudo apt update
sudo apt install --allow-downgrades cmake ninja-build extra-cmake-modules libpcap0.8-dev libsdl2-dev \
sudo apt install --allow-downgrades cmake ninja-build extra-cmake-modules libpcap0.8-dev libsdl2-dev libenet-dev \
qt6-{base,base-private,multimedia}-dev libarchive-dev libzstd-dev libfuse2
- name: Configure
run: cmake -B build -G Ninja -DUSE_QT6=ON -DCMAKE_INSTALL_PREFIX=/usr
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
apt update
apt -y full-upgrade
apt -y install git {gcc-12,g++-12}-aarch64-linux-gnu cmake ninja-build extra-cmake-modules \
{libsdl2,qt6-{base,base-private,multimedia},libarchive,libzstd}-dev:arm64 \
{libsdl2,qt6-{base,base-private,multimedia},libarchive,libzstd,libenet}-dev:arm64 \
pkg-config dpkg-dev
- name: Check out source
uses: actions/checkout@v4
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindENet.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# - Try to find enet
# Once done this will define
#
# ENET_FOUND - system has enet
# ENET_INCLUDE_DIRS - the enet include directory
# ENET_LIBRARIES - the libraries needed to use enet
#
# $ENETDIR is an environment variable used for finding enet.
#
# Borrowed from The Mana World
# http://themanaworld.org/
#
# Several changes and additions by Fabian 'x3n' Landau
# Lots of simplifications by Adrian Friedli
# > www.orxonox.net <

FIND_PATH(ENET_INCLUDE_DIRS enet/enet.h
PATHS
$ENV{ENETDIR}
/usr/local
/usr
PATH_SUFFIXES include
)

FIND_LIBRARY(ENET_LIBRARY
NAMES enet
PATHS
$ENV{ENETDIR}
/usr/local
/usr
PATH_SUFFIXES lib
)

# handle the QUIETLY and REQUIRED arguments and set ENET_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ENet DEFAULT_MSG ENET_LIBRARY ENET_INCLUDE_DIRS)

IF (ENET_FOUND)
IF(WIN32)
SET(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm")
SET(ENET_LIBRARIES ${ENET_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES})
ELSE(WIN32)
SET(ENET_LIBRARIES ${ENET_LIBRARY})
ENDIF(WIN32)
ENDIF (ENET_FOUND)

MARK_AS_ADVANCED(ENET_LIBRARY ENET_LIBRARIES ENET_INCLUDE_DIRS)
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
libarchive
libGL
libslirp
enet
]) ++ optionals isLinux [
pkgs.wayland
pkgs.kdePackages.qtwayland
Expand Down
3 changes: 3 additions & 0 deletions src/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ bool Mutex_TryLock(Mutex* mutex);

void Sleep(u64 usecs);

u64 GetMSCount();
u64 GetUSCount();


// functions called when the NDS or GBA save files need to be written back to storage
// savedata and savelen are always the entire save memory buffer and its full length
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/qt_sdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ set(SOURCES_QT_SDL

CLI.h
CLI.cpp

LANDialog.cpp
NetplayDialog.cpp
)

if (APPLE)
Expand Down
50 changes: 45 additions & 5 deletions src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "Config.h"
#include "Platform.h"
#include "Net.h"
#include "LocalMP.h"
#include "MPInterface.h"

#include "NDS.h"
#include "DSi.h"
Expand All @@ -62,11 +62,11 @@ using namespace melonDS::Platform;
MainWindow* topWindow = nullptr;

const string kWifiSettingsPath = "wfcsettings.bin";
extern LocalMP localMp;
extern Net net;


EmuInstance::EmuInstance(int inst) : instanceID(inst),
EmuInstance::EmuInstance(int inst) : deleting(false),
instanceID(inst),
globalCfg(Config::GetGlobalTable()),
localCfg(Config::GetLocalTable(inst))
{
Expand Down Expand Up @@ -117,8 +117,10 @@ EmuInstance::EmuInstance(int inst) : instanceID(inst),

EmuInstance::~EmuInstance()
{
// TODO window cleanup and shit?
localMp.End(instanceID);
deleting = true;
deleteAllWindows();

MPInterface::Get().End(instanceID);

emuThread->emuExit();
emuThread->wait();
Expand Down Expand Up @@ -168,6 +170,44 @@ void EmuInstance::createWindow()
emuThread->attachWindow(win);
}

void EmuInstance::deleteWindow(int id, bool close)
{
if (id >= kMaxWindows) return;

MainWindow* win = windowList[id];
if (!win) return;

if (win->hasOpenGL() && win == mainWindow)
{
// we intentionally don't unpause here
emuThread->emuPause();
emuThread->deinitContext();
}

emuThread->detachWindow(win);

windowList[id] = nullptr;
numWindows--;

if (topWindow == win) topWindow = nullptr;
if (mainWindow == win) mainWindow = nullptr;

if (close)
win->close();

if ((!mainWindow) && (!deleting))
{
// if we closed this instance's main window, delete the instance
deleteEmuInstance(instanceID);
}
}

void EmuInstance::deleteAllWindows()
{
for (int i = kMaxWindows-1; i >= 0; i--)
deleteWindow(i, true);
}


void EmuInstance::osdAddMessage(unsigned int color, const char* fmt, ...)
{
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/qt_sdl/EmuInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class EmuInstance
std::string instanceFileSuffix();

void createWindow();
void deleteWindow(int id, bool close);
void deleteAllWindows();

void osdAddMessage(unsigned int color, const char* fmt, ...);

Expand Down Expand Up @@ -217,6 +219,8 @@ class EmuInstance
bool hotkeyPressed(int id) { return hotkeyPress & (1<<id); }
bool hotkeyReleased(int id) { return hotkeyRelease & (1<<id); }

bool deleting;

int instanceID;

EmuThread* emuThread;
Expand Down
1 change: 1 addition & 0 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void EmuThread::run()

while (emuStatus != emuStatus_Exit)
{
MPInterface::Get().Process();
emuInstance->inputProcess();

if (emuInstance->hotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
Expand Down
Loading

0 comments on commit 8d31875

Please sign in to comment.