Netplay/UI update adding the traveral options to the ui. also added the roomcode to the onscreen overlay for now.

This commit is contained in:
Jamie Meyer 2023-07-29 05:39:20 +02:00
parent 7cedcca0e9
commit 25085ecb31
No known key found for this signature in database
GPG Key ID: BF30D71B2F1305C7
9 changed files with 252 additions and 119 deletions

View File

@ -129,7 +129,7 @@ static void SendTraversalPingRequest();
// GGPO session.
static void CreateGGPOSession();
static void DestroyGGPOSession();
static bool Start(bool is_hosting, std::string nickname, const std::string& remote_addr, s32 port, s32 ldelay, bool traversal = true);
static bool Start(bool is_hosting, std::string nickname, const std::string& remote_addr, s32 port, s32 ldelay, bool traversal);
static void CloseSession();
// Host functions.
@ -372,8 +372,6 @@ bool Netplay::Start(bool is_hosting, std::string nickname, const std::string& re
Log_ErrorPrintf("Failed to create enet host.");
return false;
}
// temp testing
s_traversal_host_code = nickname;
s_host_player_id = 0;
s_local_nickname = std::move(nickname);
@ -2359,6 +2357,11 @@ u32 Netplay::GetMaxPrediction()
return MAX_ROLLBACK_FRAMES;
}
std::string_view Netplay::GetHostCode()
{
return s_traversal_host_code;
}
void Netplay::SetInputs(Netplay::Input inputs[2])
{
for (u32 i = 0; i < 2; i++)
@ -2370,7 +2373,7 @@ void Netplay::SetInputs(Netplay::Input inputs[2])
}
}
bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password, int inputdelay)
bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password, int inputdelay, bool traversal)
{
s_local_session_password = std::move(password);
@ -2378,7 +2381,7 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std
// to have the same data, and we don't want to trash their local memcards. We should therefore load
// the memory cards for this game (based on game/global settings), and copy that to the temp card.
if (!Netplay::Start(true, std::move(nickname), std::string(), port, inputdelay))
if (!Netplay::Start(true, std::move(nickname), std::string(), port, inputdelay, traversal))
{
CloseSession();
return false;
@ -2393,12 +2396,14 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std
}
bool Netplay::JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password,
bool spectating, int inputdelay)
bool spectating, int inputdelay, bool traversal, const std::string& hostcode)
{
s_local_session_password = std::move(password);
s_local_spectating = spectating;
if (!Netplay::Start(false, std::move(nickname), hostname, port, inputdelay))
s_traversal_host_code = hostcode;
if (!Netplay::Start(false, std::move(nickname), hostname, port, inputdelay, traversal))
{
CloseSession();
return false;

View File

@ -31,8 +31,9 @@ enum : u8
NUM_ENET_CHANNELS,
};
bool CreateSession(std::string nickname, s32 port, s32 max_players, std::string password, int inputdelay);
bool JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password, bool spectating, int inputdelay);
bool CreateSession(std::string nickname, s32 port, s32 max_players, std::string password, int inputdelay, bool traversal);
bool JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password, bool spectating,
int inputdelay, bool traversal, const std::string& hostcode);
bool IsActive();
@ -49,6 +50,7 @@ void SendChatMessage(const std::string_view& msg);
s32 GetPing();
u32 GetMaxPrediction();
std::string_view GetHostCode();
/// Updates the throttle period, call when target emulation speed changes.
void UpdateThrottlePeriod();

View File

@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>496</width>
<height>267</height>
<height>302</height>
</rect>
</property>
<property name="windowTitle">
@ -53,7 +53,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Select a nickname and port to open your current game session to other players via netplay. A password may optionally be supplied to restrict who can join.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select a nickname and port to open your current game session to other players via netplay. A password may optionally be supplied to restrict who can join. The traversal mode option can be enabled to allow other players to join via a host code without needing to portforward.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -159,11 +159,22 @@
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="traversal">
<property name="text">
<string>Enable Traversal Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

View File

@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>480</width>
<height>254</height>
<height>308</height>
</rect>
</property>
<property name="windowTitle">
@ -65,95 +65,183 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Nickname:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nickname">
<property name="text">
<string>Netplay Peer</string>
</property>
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>31200</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="hostname">
<property name="text">
<string>localhost</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="maxLength">
<number>128</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Input Delay:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="inputDelay"/>
</item>
</layout>
<widget class="QTabWidget" name="tabConnectMode">
<property name="minimumSize">
<size>
<width>0</width>
<height>190</height>
</size>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabDirect">
<attribute name="title">
<string>Direct Mode</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Nickname:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nickname">
<property name="text">
<string>Netplay Peer</string>
</property>
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Input Delay:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="inputDelay"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="hostname">
<property name="text">
<string>localhost</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>31200</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="maxLength">
<number>128</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabTraversal">
<attribute name="title">
<string>Traversal Mode</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Nickname:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nicknameTraversal">
<property name="text">
<string>Netplay Peer</string>
</property>
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="inputDelayTraversal"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="passwordTraversal">
<property name="maxLength">
<number>128</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Host Code:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="hostCode"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Input Delay:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">

View File

@ -38,9 +38,10 @@ void CreateNetplaySessionDialog::accept()
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
const QString& password = m_ui.password->text();
const bool traversal = m_ui.traversal->isChecked();
QDialog::accept();
g_emu_thread->createNetplaySession(nickname.trimmed(), port, players, password, inputdelay);
g_emu_thread->createNetplaySession(nickname.trimmed(), port, players, password, inputdelay, traversal);
}
bool CreateNetplaySessionDialog::validate()
@ -64,9 +65,14 @@ JoinNetplaySessionDialog::JoinNetplaySessionDialog(QWidget* parent)
connect(m_ui.port, &QSpinBox::valueChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.inputDelay, &QSpinBox::valueChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.inputDelayTraversal, &QSpinBox::valueChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.nickname, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.nicknameTraversal, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.password, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.passwordTraversal, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.hostname, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.hostCode, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.tabConnectMode, &QTabWidget::currentChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this,
&JoinNetplaySessionDialog::accept);
@ -80,18 +86,22 @@ JoinNetplaySessionDialog::~JoinNetplaySessionDialog() = default;
void JoinNetplaySessionDialog::accept()
{
if (!validate())
const bool direct_mode = !m_ui.tabDirect->isHidden();
const bool valid = direct_mode ? validate() : validateTraversal();
if (!valid)
return;
const int port = m_ui.port->value();
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
int port = m_ui.port->value();
int inputdelay = direct_mode ? m_ui.inputDelay->value() : m_ui.inputDelayTraversal->value();
const QString& nickname = direct_mode ? m_ui.nickname->text() : m_ui.nicknameTraversal->text();
const QString& password = direct_mode ? m_ui.password->text() : m_ui.passwordTraversal->text();
const QString& hostname = m_ui.hostname->text();
const QString& password = m_ui.password->text();
const QString& hostcode = m_ui.hostCode->text();
const bool spectating = m_ui.spectating->isChecked();
QDialog::accept();
g_emu_thread->joinNetplaySession(nickname.trimmed(), hostname.trimmed(), port, password, spectating, inputdelay);
g_emu_thread->joinNetplaySession(nickname.trimmed(), hostname.trimmed(), port, password, spectating, inputdelay,
!direct_mode, hostcode.trimmed());
}
bool JoinNetplaySessionDialog::validate()
@ -100,10 +110,20 @@ bool JoinNetplaySessionDialog::validate()
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
const QString& hostname = m_ui.hostname->text();
return (!nickname.isEmpty() && !hostname.isEmpty() && port > 0 && port <= 65535 && inputdelay >= 0 && inputdelay <= 10);
return (!nickname.isEmpty() && !hostname.isEmpty() && port > 0 && port <= 65535 && inputdelay >= 0 &&
inputdelay <= 10);
}
bool JoinNetplaySessionDialog::validateTraversal()
{
const int inputdelay = m_ui.inputDelayTraversal->value();
const QString& nickname = m_ui.nicknameTraversal->text();
const QString& hostcode = m_ui.hostCode->text();
return (!nickname.isEmpty() && !hostcode.isEmpty() && inputdelay >= 0 && inputdelay <= 10);
}
void JoinNetplaySessionDialog::updateState()
{
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(validate());
m_ui.buttonBox->button(QDialogButtonBox::Ok)
->setEnabled(!m_ui.tabDirect->isHidden() ? validate() : validateTraversal());
}

View File

@ -44,6 +44,7 @@ private Q_SLOTS:
private:
bool validate();
bool validateTraversal();
private:
Ui::JoinNetplaySessionDialog m_ui;

View File

@ -1071,13 +1071,13 @@ void EmuThread::reloadPostProcessingShaders()
System::ReloadPostProcessingShaders();
}
void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password, int inputdelay)
void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password, int inputdelay, bool traversal)
{
if (!isOnThread())
{
QMetaObject::invokeMethod(this, "createNetplaySession", Qt::QueuedConnection, Q_ARG(const QString&, nickname),
Q_ARG(qint32, port), Q_ARG(qint32, max_players), Q_ARG(const QString&, password),
Q_ARG(int, inputdelay));
Q_ARG(int, inputdelay), Q_ARG(bool, traversal));
return;
}
@ -1085,7 +1085,7 @@ void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint3
if (!System::IsValid())
return;
if (!Netplay::CreateSession(nickname.toStdString(), port, max_players, password.toStdString(), inputdelay))
if (!Netplay::CreateSession(nickname.toStdString(), port, max_players, password.toStdString(), inputdelay, traversal))
{
errorReported(tr("Netplay Error"), tr("Failed to create netplay session. The log may contain more information."));
return;
@ -1093,18 +1093,19 @@ void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint3
}
void EmuThread::joinNetplaySession(const QString& nickname, const QString& hostname, qint32 port,
const QString& password, bool spectating, int inputdelay)
const QString& password, bool spectating, int inputdelay, bool traversal,
const QString& hostcode)
{
if (!isOnThread())
{
QMetaObject::invokeMethod(this, "joinNetplaySession", Qt::QueuedConnection, Q_ARG(const QString&, nickname),
Q_ARG(const QString&, hostname), Q_ARG(qint32, port), Q_ARG(const QString&, password),
Q_ARG(bool, spectating), Q_ARG(int, inputdelay));
Q_ARG(bool, spectating), Q_ARG(int, inputdelay), Q_ARG(bool, traversal),
Q_ARG(const QString&, hostcode));
return;
}
if (!Netplay::JoinSession(nickname.toStdString(), hostname.toStdString(), port, password.toStdString(), spectating,
inputdelay))
if (!Netplay::JoinSession(nickname.toStdString(), hostname.toStdString(), port, password.toStdString(), spectating, inputdelay, traversal, hostcode.toStdString()))
{
errorReported(tr("Netplay Error"), tr("Failed to join netplay session. The log may contain more information."));
return;
@ -2256,11 +2257,11 @@ int main(int argc, char* argv[])
params->override_fast_boot = true;
params->fast_forward_to_first_frame = true;
g_emu_thread->bootSystem(std::move(params));
g_emu_thread->createNetplaySession(nickname, port, 2, QString(), 0);
g_emu_thread->createNetplaySession(nickname, port, 2, QString(), 0, false);
}
else
{
g_emu_thread->joinNetplaySession(nickname, remote, port, QString(), false, 0);
g_emu_thread->joinNetplaySession(nickname, remote, port, QString(), false, 0, false, "");
}
});
}

View File

@ -188,9 +188,9 @@ public Q_SLOTS:
void applyCheat(quint32 index);
void reloadPostProcessingShaders();
void createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password,
int inputdelay);
int inputdelay, bool traversal);
void joinNetplaySession(const QString& nickname, const QString& hostname, qint32 port, const QString& password,
bool spectating, int inputdelay);
bool spectating, int inputdelay, bool traversal, const QString& hostcode);
void clearInputBindStateFromSource(InputBindingKey key);
private Q_SLOTS:

View File

@ -141,7 +141,12 @@ void ImGuiManager::DrawNetplayStats()
// We'll probably want to draw a graph too..
LargeString text;
text.AppendFmtString("Ping: {}", Netplay::GetPing());
text.AppendFmtString("Ping: {}\n", Netplay::GetPing());
// temporary show the hostcode here for now
auto hostcode = Netplay::GetHostCode();
if (!hostcode.empty())
text.AppendFmtString("Host Code: {}", hostcode);
const float scale = ImGuiManager::GetGlobalScale();
const float shadow_offset = 1.0f * scale;