Backport LAN (#2131)

backport the old LAN feature to the modern melonDS codebase.
This commit is contained in:
Arisotura
2024-08-10 23:20:50 +02:00
committed by GitHub
parent ec71b15505
commit 8d31875902
34 changed files with 4163 additions and 87 deletions

View File

@ -73,7 +73,8 @@
#include "Config.h"
#include "version.h"
#include "Savestate.h"
#include "LocalMP.h"
#include "MPInterface.h"
#include "LANDialog.h"
//#include "main_shaders.h"
@ -88,7 +89,6 @@ using namespace melonDS;
extern CameraManager* camManager[2];
extern bool camStarted[2];
extern LocalMP localMp;
QString NdsRomMimeType = "application/x-nintendo-ds-rom";
@ -432,6 +432,25 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actMPNewInstance = submenu->addAction("Launch new instance");
connect(actMPNewInstance, &QAction::triggered, this, &MainWindow::onMPNewInstance);
submenu->addSeparator();
actLANStartHost = submenu->addAction("Host LAN game");
connect(actLANStartHost, &QAction::triggered, this, &MainWindow::onLANStartHost);
actLANStartClient = submenu->addAction("Join LAN game");
connect(actLANStartClient, &QAction::triggered, this, &MainWindow::onLANStartClient);
/*submenu->addSeparator();
actNPStartHost = submenu->addAction("NETPLAY HOST");
connect(actNPStartHost, &QAction::triggered, this, &MainWindow::onNPStartHost);
actNPStartClient = submenu->addAction("NETPLAY CLIENT");
connect(actNPStartClient, &QAction::triggered, this, &MainWindow::onNPStartClient);
actNPTest = submenu->addAction("NETPLAY GO");
connect(actNPTest, &QAction::triggered, this, &MainWindow::onNPTest);*/
}
}
{
@ -737,6 +756,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
QObject::connect(qApp, &QApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged);
onUpdateInterfaceSettings();
updateMPInterface(MPInterface::GetType());
}
MainWindow::~MainWindow()
@ -756,24 +777,9 @@ void MainWindow::closeEvent(QCloseEvent* event)
QByteArray geom = saveGeometry();
QByteArray enc = geom.toBase64(QByteArray::Base64Encoding);
windowCfg.SetString("Geometry", enc.toStdString());
Config::Save();
if (hasOGL && (windowID == 0))
{
// we intentionally don't unpause here
emuThread->emuPause();
emuThread->deinitContext();
}
emuThread->detachWindow(this);
if (windowID == 0)
{
int inst = emuInstance->instanceID;
deleteEmuInstance(inst);
}
emuInstance->deleteWindow(windowID, false);
QMainWindow::closeEvent(event);
}
@ -1685,6 +1691,67 @@ void MainWindow::onMPNewInstance()
createEmuInstance();
}
void MainWindow::onLANStartHost()
{
if (!lanWarning(true)) return;
LANStartHostDialog::openDlg(this);
}
void MainWindow::onLANStartClient()
{
if (!lanWarning(false)) return;
LANStartClientDialog::openDlg(this);
}
void MainWindow::onNPStartHost()
{
//Netplay::StartHost();
//NetplayStartHostDialog::openDlg(this);
}
void MainWindow::onNPStartClient()
{
//Netplay::StartClient();
//NetplayStartClientDialog::openDlg(this);
}
void MainWindow::onNPTest()
{
// HAX
//Netplay::StartGame();
}
void MainWindow::updateMPInterface(MPInterfaceType type)
{
// MP interface was changed, reflect it in the UI
bool enable = (type == MPInterface_Local);
actMPNewInstance->setEnabled(enable);
actLANStartHost->setEnabled(enable);
actLANStartClient->setEnabled(enable);
/*actNPStartHost->setEnabled(enable);
actNPStartClient->setEnabled(enable);
actNPTest->setEnabled(enable);*/
}
bool MainWindow::lanWarning(bool host)
{
if (numEmuInstances() < 2)
return true;
QString verb = host ? "host" : "join";
QString msg = "Multiple emulator instances are currently open.\n"
"If you "+verb+" a LAN game now, all secondary instances will be closed.\n\n"
"Do you wish to continue?";
auto res = QMessageBox::warning(this, "melonDS", msg, QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
if (res == QMessageBox::No)
return false;
deleteAllEmuInstances(1);
return true;
}
void MainWindow::onOpenEmuSettings()
{
emuThread->emuPause();
@ -1840,7 +1907,7 @@ void MainWindow::onMPSettingsFinished(int res)
{
emuInstance->mpAudioMode = globalCfg.GetInt("MP.AudioMode");
emuInstance->audioMute();
localMp.SetRecvTimeout(globalCfg.GetInt("MP.RecvTimeout"));
MPInterface::Get().SetRecvTimeout(globalCfg.GetInt("MP.RecvTimeout"));
emuThread->emuUnpause();
}