get this started

(it doesn't build, don't get hyped up)
This commit is contained in:
Arisotura 2024-07-17 20:51:52 +02:00
parent 71f4d7b222
commit cae725ffeb
12 changed files with 3503 additions and 0 deletions

48
cmake/FindENet.cmake Normal file
View File

@ -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)

View File

@ -51,6 +51,9 @@ set(SOURCES_QT_SDL
CLI.h
CLI.cpp
LAN.cpp
Netplay.cpp
)
if (APPLE)
@ -88,6 +91,8 @@ add_compile_definitions(ARCHIVE_SUPPORT_ENABLED)
add_executable(melonDS ${SOURCES_QT_SDL})
find_package(ENet REQUIRED)
add_subdirectory("../../net"
"${CMAKE_BINARY_DIR}/net"
)
@ -168,6 +173,7 @@ 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)

1408
src/frontend/qt_sdl/LAN.cpp Normal file

File diff suppressed because it is too large Load Diff

192
src/frontend/qt_sdl/LAN.h Normal file
View File

@ -0,0 +1,192 @@
/*
Copyright 2016-2022 melonDS team
This file is part of melonDS.
melonDS 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 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. If not, see http://www.gnu.org/licenses/.
*/
#ifndef LAN_H
#define LAN_H
#include <string>
#include <map>
#include <QDialog>
#include <QMutex>
#include <QItemSelection>
#include "types.h"
namespace Ui
{
class LANStartHostDialog;
class LANStartClientDialog;
class LANDialog;
}
namespace LAN
{
struct Player
{
int ID;
char Name[32];
int Status; // 0=no player 1=normal 2=host 3=connecting 4=disconnected
u32 Address;
};
struct DiscoveryData
{
u32 Magic;
u32 Version;
u32 Tick;
char SessionName[64];
u8 NumPlayers;
u8 MaxPlayers;
u8 Status; // 0=idle 1=playing
};
}
class LANStartHostDialog : public QDialog
{
Q_OBJECT
public:
explicit LANStartHostDialog(QWidget* parent);
~LANStartHostDialog();
static LANStartHostDialog* openDlg(QWidget* parent)
{
LANStartHostDialog* dlg = new LANStartHostDialog(parent);
dlg->open();
return dlg;
}
private slots:
void done(int r);
private:
Ui::LANStartHostDialog* ui;
};
class LANStartClientDialog : public QDialog
{
Q_OBJECT
public:
explicit LANStartClientDialog(QWidget* parent);
~LANStartClientDialog();
static LANStartClientDialog* openDlg(QWidget* parent)
{
LANStartClientDialog* dlg = new LANStartClientDialog(parent);
dlg->open();
return dlg;
}
void updateDiscoveryList();
signals:
void sgUpdateDiscoveryList();
private slots:
void onGameSelectionChanged(const QItemSelection& cur, const QItemSelection& prev);
void on_tvAvailableGames_doubleClicked(QModelIndex index);
void onDirectConnect();
void done(int r);
void doUpdateDiscoveryList();
private:
Ui::LANStartClientDialog* ui;
};
class LANDialog : public QDialog
{
Q_OBJECT
public:
explicit LANDialog(QWidget* parent);
~LANDialog();
static LANDialog* openDlg(QWidget* parent)
{
LANDialog* dlg = new LANDialog(parent);
dlg->show();
return dlg;
}
void updatePlayerList();
signals:
void sgUpdatePlayerList();
private slots:
void done(int r);
void doUpdatePlayerList();
private:
Ui::LANDialog* ui;
LAN::Player playerList[16];
u32 playerPing[16];
int numPlayers;
int maxPlayers;
int myPlayerID;
u32 hostAddress;
QMutex playerListMutex;
};
namespace LAN
{
extern bool Active;
extern std::map<u32, DiscoveryData> DiscoveryList;
extern QMutex DiscoveryMutex;
extern Player Players[16];
extern u32 PlayerPing[16];
extern int NumPlayers;
extern int MaxPlayers;
extern Player MyPlayer;
extern u32 HostAddress;
bool Init();
void DeInit();
bool StartDiscovery();
void EndDiscovery();
bool StartHost(const char* player, int numplayers);
bool StartClient(const char* player, const char* host);
void ProcessFrame();
void SetMPRecvTimeout(int timeout);
void MPBegin();
void MPEnd();
int SendMPPacket(u8* data, int len, u64 timestamp);
int RecvMPPacket(u8* data, u64* timestamp);
int SendMPCmd(u8* data, int len, u64 timestamp);
int SendMPReply(u8* data, int len, u64 timestamp, u16 aid);
int SendMPAck(u8* data, int len, u64 timestamp);
int RecvMPHostPacket(u8* data, u64* timestamp);
u16 RecvMPReplies(u8* data, u64 timestamp, u16 aidmask);
}
#endif // LAN_H

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LANDialog</class>
<widget class="QDialog" name="LANDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>522</width>
<height>391</height>
</rect>
</property>
<property name="windowTitle">
<string>LAN SHITO</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="lblStatus">
<property name="text">
<string>STATUS PLACEHOLDER</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvPlayerList"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LANStartClientDialog</class>
<widget class="QDialog" name="LANStartClientDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>409</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Join LAN game - melonDS</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Player name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtPlayerName">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="tvAvailableGames">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LANStartClientDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LANStartClientDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LANStartHostDialog</class>
<widget class="QDialog" name="LANStartHostDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>228</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Host LAN game - melonDS</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Player name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtPlayerName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Number of players:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="sbNumPlayers"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>LANStartHostDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>LANStartHostDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,147 @@
/*
Copyright 2016-2022 melonDS team
This file is part of melonDS.
melonDS 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 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. If not, see http://www.gnu.org/licenses/.
*/
#ifndef NETPLAY_H
#define NETPLAY_H
#include <QDialog>
#include "types.h"
namespace Ui
{
class NetplayStartHostDialog;
class NetplayStartClientDialog;
class NetplayDialog;
}
class NetplayStartHostDialog;
class NetplayStartClientDialog;
class NetplayDialog;
namespace Netplay
{
struct Player
{
int ID;
char Name[32];
int Status; // 0=no player 1=normal 2=host 3=connecting
u32 Address;
};
}
class NetplayStartHostDialog : public QDialog
{
Q_OBJECT
public:
explicit NetplayStartHostDialog(QWidget* parent);
~NetplayStartHostDialog();
static NetplayStartHostDialog* openDlg(QWidget* parent)
{
NetplayStartHostDialog* dlg = new NetplayStartHostDialog(parent);
dlg->open();
return dlg;
}
private slots:
void done(int r);
private:
Ui::NetplayStartHostDialog* ui;
};
class NetplayStartClientDialog : public QDialog
{
Q_OBJECT
public:
explicit NetplayStartClientDialog(QWidget* parent);
~NetplayStartClientDialog();
static NetplayStartClientDialog* openDlg(QWidget* parent)
{
NetplayStartClientDialog* dlg = new NetplayStartClientDialog(parent);
dlg->open();
return dlg;
}
private slots:
void done(int r);
private:
Ui::NetplayStartClientDialog* ui;
};
class NetplayDialog : public QDialog
{
Q_OBJECT
public:
explicit NetplayDialog(QWidget* parent);
~NetplayDialog();
static NetplayDialog* openDlg(QWidget* parent)
{
NetplayDialog* dlg = new NetplayDialog(parent);
dlg->show();
return dlg;
}
void updatePlayerList(Netplay::Player* players, int num);
signals:
void sgUpdatePlayerList(Netplay::Player* players, int num);
private slots:
void done(int r);
void doUpdatePlayerList(Netplay::Player* players, int num);
private:
Ui::NetplayDialog* ui;
};
namespace Netplay
{
extern bool Active;
bool Init();
void DeInit();
void StartHost(const char* player, int port);
void StartClient(const char* player, const char* host, int port);
void StartMirror(const Player* player);
u32 PlayerAddress(int id);
void StartGame();
void StartLocal();
void StartGame();
void ProcessFrame();
void ProcessInput();
}
#endif // NETPLAY_H

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NetplayDialog</class>
<widget class="QDialog" name="NetplayDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>522</width>
<height>391</height>
</rect>
</property>
<property name="windowTitle">
<string>NETPLAY SHITO</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="lblStatus">
<property name="text">
<string>STATUS PLACEHOLDER</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvPlayerList"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NetplayStartClientDialog</class>
<widget class="QDialog" name="NetplayStartClientDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>229</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>NETPLAY CLIENT</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Player name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Host port:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtPlayerName"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="txtPort"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Host address:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtIPAddress"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>NetplayStartClientDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NetplayStartClientDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NetplayStartHostDialog</class>
<widget class="QDialog" name="NetplayStartHostDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>229</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>NETPLAY HOST</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Player name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtPlayerName"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="txtPort"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>NetplayStartHostDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NetplayStartHostDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>