mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
NetPlay host input authority mode
Currently, each player buffers their own inputs and sends them to the host. The host then relays those inputs to everyone else. Every player waits on inputs from all players to be buffered before continuing. What this means is all clients run in lockstep, and the total latency of inputs cannot be lower than the sum of the 2 highest client ping times in the game (in 3+ player sessions with people across the world, the latency can be very high). Host input authority mode changes it so players no longer buffer their own inputs, and only send them to the host. The host stores only the most recent input received from a player. The host then sends inputs for all pads at the SI poll interval, similar to the existing code. If a player sends inputs to slowly, their last received input is simply sent again. If they send too quickly, inputs are dropped. This means that the host has full control over what inputs are actually read by the game, hence the name of the mode. Also, because the rate at which inputs are received by SI is decoupled from the rate at which players are sending inputs, clients are no longer dependent on each other. They only care what the host is doing. This means that they can set their buffer individually based on their latency to the host, rather than the highest latency between any 2 players, allowing someone with lower ping to the host to have less latency than someone else. This is a catch to this: as a necessity of how the host's input sending works, the host has 0 latency. There isn't a good way to fix this, as input delay is now solely dependent on the real latency to the host's server. Having differing latency between players would be considered unfair for competitive play, but for casual play we don't really care. For this reason though, combined with the potential for a few inputs to be dropped on a bad connection, the old mode will remain and this new mode is entirely optional.
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QPushButton>
|
||||
#include <QSignalBlocker>
|
||||
#include <QSpinBox>
|
||||
#include <QSplitter>
|
||||
#include <QTableWidget>
|
||||
@ -99,6 +100,7 @@ void NetPlayDialog::CreateMainLayout()
|
||||
m_record_input_box = new QCheckBox(tr("Record inputs"));
|
||||
m_reduce_polling_rate_box = new QCheckBox(tr("Reduce Polling Rate"));
|
||||
m_strict_settings_sync_box = new QCheckBox(tr("Strict Settings Sync"));
|
||||
m_host_input_authority_box = new QCheckBox(tr("Host Input Authority"));
|
||||
m_buffer_label = new QLabel(tr("Buffer:"));
|
||||
m_quit_button = new QPushButton(tr("Quit"));
|
||||
m_splitter = new QSplitter(Qt::Horizontal);
|
||||
@ -142,6 +144,14 @@ void NetPlayDialog::CreateMainLayout()
|
||||
tr("This will sync additional graphics settings, and force everyone to the same internal "
|
||||
"resolution.\nMay prevent desync in some games that use EFB reads. Please ensure everyone "
|
||||
"uses the same video backend."));
|
||||
m_host_input_authority_box->setToolTip(
|
||||
tr("This gives the host control over when inputs are sent to the game, effectively "
|
||||
"decoupling players from each other in terms of buffering.\nThis allows players to have "
|
||||
"latency based solely on their connection to the host, rather than everyone's connection. "
|
||||
"Buffer works differently\nin this mode. The host always has no latency, and the buffer "
|
||||
"setting serves to prevent stutter, speeding up when the amount of buffered\ninputs "
|
||||
"exceeds the set limit. Input delay is instead based on ping to the host. This results in "
|
||||
"smoother gameplay on unstable connections."));
|
||||
|
||||
m_main_layout->addWidget(m_game_button, 0, 0);
|
||||
m_main_layout->addWidget(m_md5_button, 0, 1);
|
||||
@ -163,6 +173,7 @@ void NetPlayDialog::CreateMainLayout()
|
||||
options_boxes->addWidget(m_record_input_box);
|
||||
options_boxes->addWidget(m_reduce_polling_rate_box);
|
||||
options_boxes->addWidget(m_strict_settings_sync_box);
|
||||
options_boxes->addWidget(m_host_input_authority_box);
|
||||
|
||||
options_widget->addLayout(options_boxes, 0, 3, Qt::AlignTop);
|
||||
options_widget->setColumnStretch(3, 1000);
|
||||
@ -261,11 +272,20 @@ void NetPlayDialog::ConnectWidgets()
|
||||
if (value == m_buffer_size)
|
||||
return;
|
||||
|
||||
auto client = Settings::Instance().GetNetPlayClient();
|
||||
auto server = Settings::Instance().GetNetPlayServer();
|
||||
if (server)
|
||||
server->AdjustPadBufferSize(value);
|
||||
else
|
||||
client->AdjustPadBufferSize(value);
|
||||
});
|
||||
|
||||
connect(m_host_input_authority_box, &QCheckBox::toggled, [this](bool checked) {
|
||||
auto server = Settings::Instance().GetNetPlayServer();
|
||||
if (server)
|
||||
server->SetHostInputAuthority(checked);
|
||||
});
|
||||
|
||||
connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart);
|
||||
connect(m_quit_button, &QPushButton::clicked, this, &NetPlayDialog::reject);
|
||||
|
||||
@ -447,8 +467,7 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
||||
m_sync_save_data_box->setHidden(!is_hosting);
|
||||
m_reduce_polling_rate_box->setHidden(!is_hosting);
|
||||
m_strict_settings_sync_box->setHidden(!is_hosting);
|
||||
m_buffer_size_box->setHidden(!is_hosting);
|
||||
m_buffer_label->setHidden(!is_hosting);
|
||||
m_host_input_authority_box->setHidden(!is_hosting);
|
||||
m_kick_button->setHidden(!is_hosting);
|
||||
m_assign_ports_button->setHidden(!is_hosting);
|
||||
m_md5_button->setHidden(!is_hosting);
|
||||
@ -458,6 +477,8 @@ void NetPlayDialog::show(std::string nickname, bool use_traversal)
|
||||
m_game_button->setEnabled(is_hosting);
|
||||
m_kick_button->setEnabled(false);
|
||||
|
||||
m_buffer_label->setText(is_hosting ? tr("Buffer:") : tr("Max Buffer:"));
|
||||
|
||||
QDialog::show();
|
||||
UpdateGUI();
|
||||
}
|
||||
@ -720,6 +741,7 @@ void NetPlayDialog::SetOptionsEnabled(bool enabled)
|
||||
m_assign_ports_button->setEnabled(enabled);
|
||||
m_reduce_polling_rate_box->setEnabled(enabled);
|
||||
m_strict_settings_sync_box->setEnabled(enabled);
|
||||
m_host_input_authority_box->setEnabled(enabled);
|
||||
}
|
||||
|
||||
m_record_input_box->setEnabled(enabled);
|
||||
@ -744,12 +766,51 @@ void NetPlayDialog::OnMsgStopGame()
|
||||
|
||||
void NetPlayDialog::OnPadBufferChanged(u32 buffer)
|
||||
{
|
||||
QueueOnObject(this, [this, buffer] { m_buffer_size_box->setValue(buffer); });
|
||||
DisplayMessage(tr("Buffer size changed to %1").arg(buffer), "");
|
||||
QueueOnObject(this, [this, buffer] {
|
||||
const QSignalBlocker blocker(m_buffer_size_box);
|
||||
m_buffer_size_box->setValue(buffer);
|
||||
});
|
||||
DisplayMessage(m_host_input_authority && !IsHosting() ?
|
||||
tr("Max buffer size changed to %1").arg(buffer) :
|
||||
tr("Buffer size changed to %1").arg(buffer),
|
||||
"");
|
||||
|
||||
m_buffer_size = static_cast<int>(buffer);
|
||||
}
|
||||
|
||||
void NetPlayDialog::OnHostInputAuthorityChanged(bool enabled)
|
||||
{
|
||||
QueueOnObject(this, [this, enabled] {
|
||||
const bool is_hosting = IsHosting();
|
||||
const bool enable_buffer = is_hosting != enabled;
|
||||
|
||||
if (is_hosting)
|
||||
{
|
||||
m_buffer_size_box->setEnabled(enable_buffer);
|
||||
m_buffer_label->setEnabled(enable_buffer);
|
||||
m_buffer_size_box->setHidden(false);
|
||||
m_buffer_label->setHidden(false);
|
||||
|
||||
QSignalBlocker blocker(m_host_input_authority_box);
|
||||
m_host_input_authority_box->setChecked(enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer_size_box->setEnabled(true);
|
||||
m_buffer_label->setEnabled(true);
|
||||
m_buffer_size_box->setHidden(!enable_buffer);
|
||||
m_buffer_label->setHidden(!enable_buffer);
|
||||
|
||||
if (enabled)
|
||||
m_buffer_size_box->setValue(1);
|
||||
}
|
||||
});
|
||||
DisplayMessage(enabled ? tr("Host input authority enabled") : tr("Host input authority disabled"),
|
||||
"");
|
||||
|
||||
m_host_input_authority = enabled;
|
||||
}
|
||||
|
||||
void NetPlayDialog::OnDesync(u32 frame, const std::string& player)
|
||||
{
|
||||
DisplayMessage(tr("Possible desync detected: %1 might have desynced at frame %2")
|
||||
|
Reference in New Issue
Block a user