Skip to content

Commit

Permalink
Merge pull request #2987 from HeatXD/input_delay_option
Browse files Browse the repository at this point in the history
Netplay/UI: add input delay option to netplay dialogs
  • Loading branch information
stenzek authored Jul 24, 2023
2 parents 4d262c2 + e51a8f2 commit 36fde62
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 38 deletions.
14 changes: 4 additions & 10 deletions src/core/netplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,18 +2060,15 @@ void Netplay::SetInputs(Netplay::Input inputs[2])
}
}

bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password)
bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password, int inputdelay)
{
s_local_session_password = std::move(password);

// TODO: This is going to blow away our memory cards, because for sync purposes we want all clients
// 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.

// TODO: input delay. GGPO Should support changing it on the fly.
const s32 input_delay = 1;

if (!Netplay::Start(true, std::move(nickname), std::string(), port, input_delay))
if (!Netplay::Start(true, std::move(nickname), std::string(), port, inputdelay))
{
CloseSession();
return false;
Expand All @@ -2086,15 +2083,12 @@ 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)
bool spectating, int inputdelay)
{
s_local_session_password = std::move(password);
s_local_spectating = spectating;

// TODO: input delay. GGPO Should support changing it on the fly.
const s32 input_delay = 1;

if (!Netplay::Start(false, std::move(nickname), hostname, port, input_delay))
if (!Netplay::Start(false, std::move(nickname), hostname, port, inputdelay))
{
CloseSession();
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/core/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ enum : u8
NUM_ENET_CHANNELS,
};

bool CreateSession(std::string nickname, s32 port, s32 max_players, std::string password);
bool JoinSession(std::string nickname, const std::string& hostname, s32 port, std::string password, bool spectating);
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 IsActive();

Expand Down
20 changes: 15 additions & 5 deletions src/duckstation-qt/createnetplaysessiondialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>496</width>
<height>235</height>
<height>267</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -92,14 +92,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1</number>
Expand Down Expand Up @@ -129,14 +129,14 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="maxLength">
<number>128</number>
Expand All @@ -146,6 +146,16 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Input Delay:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="inputDelay"/>
</item>
</layout>
</item>
<item>
Expand Down
24 changes: 17 additions & 7 deletions src/duckstation-qt/joinnetplaysessiondialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<x>0</x>
<y>0</y>
<width>480</width>
<height>226</height>
<height>254</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -92,14 +92,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="port">
<property name="minimum">
<number>1</number>
Expand All @@ -112,28 +112,28 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Hostname:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="hostname">
<property name="text">
<string>localhost</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="password">
<property name="maxLength">
<number>128</number>
Expand All @@ -143,6 +143,16 @@
</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>
</item>
<item>
Expand Down
15 changes: 11 additions & 4 deletions src/duckstation-qt/netplaydialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CreateNetplaySessionDialog::CreateNetplaySessionDialog(QWidget* parent) : QDialo

connect(m_ui.maxPlayers, &QSpinBox::valueChanged, this, &CreateNetplaySessionDialog::updateState);
connect(m_ui.port, &QSpinBox::valueChanged, this, &CreateNetplaySessionDialog::updateState);
connect(m_ui.inputDelay, &QSpinBox::valueChanged, this, &CreateNetplaySessionDialog::updateState);
connect(m_ui.nickname, &QLineEdit::textChanged, this, &CreateNetplaySessionDialog::updateState);
connect(m_ui.password, &QLineEdit::textChanged, this, &CreateNetplaySessionDialog::updateState);

Expand All @@ -34,19 +35,22 @@ void CreateNetplaySessionDialog::accept()

const int players = m_ui.maxPlayers->value();
const int port = m_ui.port->value();
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
const QString& password = m_ui.password->text();
QDialog::accept();

g_emu_thread->createNetplaySession(nickname.trimmed(), port, players, password);
g_emu_thread->createNetplaySession(nickname.trimmed(), port, players, password, inputdelay);
}

bool CreateNetplaySessionDialog::validate()
{
const int players = m_ui.maxPlayers->value();
const int port = m_ui.port->value();
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
return (!nickname.isEmpty() && players >= 2 && players <= Netplay::MAX_PLAYERS && port > 0 && port <= 65535);
return (!nickname.isEmpty() && players >= 2 && players <= Netplay::MAX_PLAYERS && port > 0 && port <= 65535 &&
inputdelay >= 0 && inputdelay <= 10);
}

void CreateNetplaySessionDialog::updateState()
Expand All @@ -59,6 +63,7 @@ JoinNetplaySessionDialog::JoinNetplaySessionDialog(QWidget* parent)
m_ui.setupUi(this);

connect(m_ui.port, &QSpinBox::valueChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.inputDelay, &QSpinBox::valueChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.nickname, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.password, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
connect(m_ui.hostname, &QLineEdit::textChanged, this, &JoinNetplaySessionDialog::updateState);
Expand All @@ -79,21 +84,23 @@ void JoinNetplaySessionDialog::accept()
return;

const int port = m_ui.port->value();
const int inputdelay = m_ui.inputDelay->value();
const QString& nickname = m_ui.nickname->text();
const QString& hostname = m_ui.hostname->text();
const QString& password = m_ui.password->text();
const bool spectating = m_ui.spectating->isChecked();
QDialog::accept();

g_emu_thread->joinNetplaySession(nickname.trimmed(), hostname.trimmed(), port, password, spectating);
g_emu_thread->joinNetplaySession(nickname.trimmed(), hostname.trimmed(), port, password, spectating, inputdelay);
}

bool JoinNetplaySessionDialog::validate()
{
const int port = m_ui.port->value();
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);
return (!nickname.isEmpty() && !hostname.isEmpty() && port > 0 && port <= 65535 && inputdelay >= 0 && inputdelay <= 10);
}

void JoinNetplaySessionDialog::updateState()
Expand Down
18 changes: 10 additions & 8 deletions src/duckstation-qt/qthost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,38 +1071,40 @@ void EmuThread::reloadPostProcessingShaders()
System::ReloadPostProcessingShaders();
}

void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password)
void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password, int inputdelay)
{
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(qint32, port), Q_ARG(qint32, max_players), Q_ARG(const QString&, password),
Q_ARG(int, inputdelay));
return;
}

// need a valid system to make a session
if (!System::IsValid())
return;

if (!Netplay::CreateSession(nickname.toStdString(), port, max_players, password.toStdString()))
if (!Netplay::CreateSession(nickname.toStdString(), port, max_players, password.toStdString(), inputdelay))
{
errorReported(tr("Netplay Error"), tr("Failed to create netplay session. The log may contain more information."));
return;
}
}

void EmuThread::joinNetplaySession(const QString& nickname, const QString& hostname, qint32 port,
const QString& password, bool spectating)
const QString& password, bool spectating, int inputdelay)
{
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(bool, spectating), Q_ARG(int, inputdelay));
return;
}

if (!Netplay::JoinSession(nickname.toStdString(), hostname.toStdString(), port, password.toStdString(), spectating))
if (!Netplay::JoinSession(nickname.toStdString(), hostname.toStdString(), port, password.toStdString(), spectating,
inputdelay))
{
errorReported(tr("Netplay Error"), tr("Failed to join netplay session. The log may contain more information."));
return;
Expand Down Expand Up @@ -2243,11 +2245,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());
g_emu_thread->createNetplaySession(nickname, port, 2, QString(), 0);
}
else
{
g_emu_thread->joinNetplaySession(nickname, remote, port, QString(), false);
g_emu_thread->joinNetplaySession(nickname, remote, port, QString(), false, 0);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/duckstation-qt/qthost.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ public Q_SLOTS:
void setCheatEnabled(quint32 index, bool enabled);
void applyCheat(quint32 index);
void reloadPostProcessingShaders();
void createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password);
void createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password,
int inputdelay);
void joinNetplaySession(const QString& nickname, const QString& hostname, qint32 port, const QString& password,
bool spectating);
bool spectating, int inputdelay);

private Q_SLOTS:
void stopInThread();
Expand Down

0 comments on commit 36fde62

Please sign in to comment.