Skip to content

Commit

Permalink
NetPlay: Properly save Hosting GUI settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Zexaron authored and Zexaron committed Oct 13, 2018
1 parent 4809726 commit 550aa93
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Source/Core/Core/Config/NetplaySettings.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,4 +35,19 @@ const ConfigInfo<bool> NETPLAY_USE_UPNP{{System::Main, "NetPlay", "UseUPNP"}, fa


const ConfigInfo<bool> NETPLAY_ENABLE_QOS{{System::Main, "NetPlay", "EnableQoS"}, true}; const ConfigInfo<bool> NETPLAY_ENABLE_QOS{{System::Main, "NetPlay", "EnableQoS"}, true};


const ConfigInfo<u32> NETPLAY_BUFFER_SIZE{{System::Main, "NetPlay", "BufferSize"}, 5};
const ConfigInfo<u32> NETPLAY_CLIENT_BUFFER_SIZE{{System::Main, "NetPlay", "BufferSizeClient"}, 1};

const ConfigInfo<bool> NETPLAY_WRITE_SAVE_SDCARD_DATA{
{System::Main, "NetPlay", "WriteSaveSDCardData"}, false};
const ConfigInfo<bool> NETPLAY_LOAD_WII_SAVE{{System::Main, "NetPlay", "LoadWiiSave"}, false};
const ConfigInfo<bool> NETPLAY_SYNC_SAVES{{System::Main, "NetPlay", "SyncSaves"}, true};
const ConfigInfo<bool> NETPLAY_RECORD_INPUTS{{System::Main, "NetPlay", "RecordInputs"}, false};
const ConfigInfo<bool> NETPLAY_REDUCE_POLLING_RATE{{System::Main, "NetPlay", "ReducePollingRate"},
false};
const ConfigInfo<bool> NETPLAY_STRICT_SETTINGS_SYNC{{System::Main, "NetPlay", "StrictSettingsSync"},
false};
const ConfigInfo<bool> NETPLAY_HOST_INPUT_AUTHORITY{{System::Main, "NetPlay", "HostInputAuthority"},
false};

} // namespace Config } // namespace Config
11 changes: 11 additions & 0 deletions Source/Core/Core/Config/NetplaySettings.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ extern const ConfigInfo<bool> NETPLAY_USE_UPNP;


extern const ConfigInfo<bool> NETPLAY_ENABLE_QOS; extern const ConfigInfo<bool> NETPLAY_ENABLE_QOS;


extern const ConfigInfo<u32> NETPLAY_BUFFER_SIZE;
extern const ConfigInfo<u32> NETPLAY_CLIENT_BUFFER_SIZE;

extern const ConfigInfo<bool> NETPLAY_WRITE_SAVE_SDCARD_DATA;
extern const ConfigInfo<bool> NETPLAY_LOAD_WII_SAVE;
extern const ConfigInfo<bool> NETPLAY_SYNC_SAVES;
extern const ConfigInfo<bool> NETPLAY_RECORD_INPUTS;
extern const ConfigInfo<bool> NETPLAY_REDUCE_POLLING_RATE;
extern const ConfigInfo<bool> NETPLAY_STRICT_SETTINGS_SYNC;
extern const ConfigInfo<bool> NETPLAY_HOST_INPUT_AUTHORITY;

} // namespace Config } // namespace Config
20 changes: 15 additions & 5 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1093,16 +1093,18 @@ bool MainWindow::NetPlayJoin()
return false; return false;
} }


auto server = Settings::Instance().GetNetPlayServer();

// Settings // Settings
const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE); const std::string traversal_choice = Config::Get(Config::NETPLAY_TRAVERSAL_CHOICE);
const bool is_traversal = traversal_choice == "traversal"; const bool is_traversal = traversal_choice == "traversal";


std::string host_ip; std::string host_ip;
u16 host_port; u16 host_port;
if (Settings::Instance().GetNetPlayServer()) if (server)
{ {
host_ip = "127.0.0.1"; host_ip = "127.0.0.1";
host_port = Settings::Instance().GetNetPlayServer()->GetPort(); host_port = server->GetPort();
} }
else else
{ {
Expand All @@ -1114,9 +1116,17 @@ bool MainWindow::NetPlayJoin()
const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER); const std::string traversal_host = Config::Get(Config::NETPLAY_TRAVERSAL_SERVER);
const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT); const u16 traversal_port = Config::Get(Config::NETPLAY_TRAVERSAL_PORT);
const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME); const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME);
const bool host_input_authority = Config::Get(Config::NETPLAY_HOST_INPUT_AUTHORITY);

if (server)
{
server->SetHostInputAuthority(host_input_authority);
if (!host_input_authority)
server->AdjustPadBufferSize(Config::Get(Config::NETPLAY_BUFFER_SIZE));
}


// Create Client // Create Client
const bool is_hosting_netplay = Settings::Instance().GetNetPlayServer() != nullptr; const bool is_hosting_netplay = server != nullptr;
Settings::Instance().ResetNetPlayClient(new NetPlay::NetPlayClient( Settings::Instance().ResetNetPlayClient(new NetPlay::NetPlayClient(
host_ip, host_port, m_netplay_dialog, nickname, host_ip, host_port, m_netplay_dialog, nickname,
NetPlay::NetTraversalConfig{is_hosting_netplay ? false : is_traversal, traversal_host, NetPlay::NetTraversalConfig{is_hosting_netplay ? false : is_traversal, traversal_host,
Expand All @@ -1128,8 +1138,8 @@ bool MainWindow::NetPlayJoin()
return false; return false;
} }


if (Settings::Instance().GetNetPlayServer() != nullptr) if (server != nullptr)
Settings::Instance().GetNetPlayServer()->SetNetPlayUI(m_netplay_dialog); server->SetNetPlayUI(m_netplay_dialog);


m_netplay_setup_dialog->close(); m_netplay_setup_dialog->close();
m_netplay_dialog->show(nickname, is_traversal); m_netplay_dialog->show(nickname, is_traversal);
Expand Down
53 changes: 52 additions & 1 deletion Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ NetPlayDialog::NetPlayDialog(QWidget* parent)
CreateChatLayout(); CreateChatLayout();
CreatePlayersLayout(); CreatePlayersLayout();
CreateMainLayout(); CreateMainLayout();

const int buffer_size = Config::Get(Config::NETPLAY_BUFFER_SIZE);
const bool write_save_sdcard_data = Config::Get(Config::NETPLAY_WRITE_SAVE_SDCARD_DATA);
const bool load_wii_save = Config::Get(Config::NETPLAY_LOAD_WII_SAVE);
const bool sync_saves = Config::Get(Config::NETPLAY_SYNC_SAVES);
const bool record_inputs = Config::Get(Config::NETPLAY_RECORD_INPUTS);
const bool reduce_polling_rate = Config::Get(Config::NETPLAY_REDUCE_POLLING_RATE);
const bool strict_settings_sync = Config::Get(Config::NETPLAY_STRICT_SETTINGS_SYNC);
const bool host_input_authority = Config::Get(Config::NETPLAY_HOST_INPUT_AUTHORITY);

m_buffer_size_box->setValue(buffer_size);
m_save_sd_box->setChecked(write_save_sdcard_data);
m_load_wii_box->setChecked(load_wii_save);
m_sync_save_data_box->setChecked(sync_saves);
m_record_input_box->setChecked(record_inputs);
m_reduce_polling_rate_box->setChecked(reduce_polling_rate);
m_strict_settings_sync_box->setChecked(strict_settings_sync);
m_host_input_authority_box->setChecked(host_input_authority);

ConnectWidgets(); ConnectWidgets();


auto& settings = Settings::Instance().GetQSettings(); auto& settings = Settings::Instance().GetQSettings();
Expand Down Expand Up @@ -306,6 +325,18 @@ void NetPlayDialog::ConnectWidgets()
DisplayMessage(tr("Stopped game"), "red"); DisplayMessage(tr("Stopped game"), "red");
} }
}); });

// SaveSettings() - Save Hosting-Dialog Settings

connect(m_buffer_size_box, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&NetPlayDialog::SaveSettings);
connect(m_save_sd_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_load_wii_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_sync_save_data_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_record_input_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_reduce_polling_rate_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_strict_settings_sync_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
connect(m_host_input_authority_box, &QCheckBox::stateChanged, this, &NetPlayDialog::SaveSettings);
} }


void NetPlayDialog::OnChat() void NetPlayDialog::OnChat()
Expand Down Expand Up @@ -802,7 +833,7 @@ void NetPlayDialog::OnHostInputAuthorityChanged(bool enabled)
m_buffer_label->setHidden(!enable_buffer); m_buffer_label->setHidden(!enable_buffer);


if (enabled) if (enabled)
m_buffer_size_box->setValue(1); m_buffer_size_box->setValue(Config::Get(Config::NETPLAY_CLIENT_BUFFER_SIZE));
} }
}); });
DisplayMessage(enabled ? tr("Host input authority enabled") : tr("Host input authority disabled"), DisplayMessage(enabled ? tr("Host input authority enabled") : tr("Host input authority disabled"),
Expand Down Expand Up @@ -910,6 +941,26 @@ std::shared_ptr<const UICommon::GameFile> NetPlayDialog::FindGameFile(const std:
return nullptr; return nullptr;
} }


void NetPlayDialog::SaveSettings()
{
if (m_host_input_authority)
{
if (!IsHosting())
Config::SetBase(Config::NETPLAY_CLIENT_BUFFER_SIZE, m_buffer_size_box->value());
}
else
{
Config::SetBase(Config::NETPLAY_BUFFER_SIZE, m_buffer_size_box->value());
}
Config::SetBase(Config::NETPLAY_WRITE_SAVE_SDCARD_DATA, m_save_sd_box->isChecked());
Config::SetBase(Config::NETPLAY_LOAD_WII_SAVE, m_load_wii_box->isChecked());
Config::SetBase(Config::NETPLAY_SYNC_SAVES, m_sync_save_data_box->isChecked());
Config::SetBase(Config::NETPLAY_RECORD_INPUTS, m_record_input_box->isChecked());
Config::SetBase(Config::NETPLAY_REDUCE_POLLING_RATE, m_reduce_polling_rate_box->isChecked());
Config::SetBase(Config::NETPLAY_STRICT_SETTINGS_SYNC, m_strict_settings_sync_box->isChecked());
Config::SetBase(Config::NETPLAY_HOST_INPUT_AUTHORITY, m_host_input_authority_box->isChecked());
}

void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier) void NetPlayDialog::ShowMD5Dialog(const std::string& file_identifier)
{ {
QueueOnObject(this, [this, file_identifier] { QueueOnObject(this, [this, file_identifier] {
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
bool IsRecording() override; bool IsRecording() override;
std::string FindGame(const std::string& game) override; std::string FindGame(const std::string& game) override;
std::shared_ptr<const UICommon::GameFile> FindGameFile(const std::string& game) override; std::shared_ptr<const UICommon::GameFile> FindGameFile(const std::string& game) override;

void SaveSettings();

void ShowMD5Dialog(const std::string& file_identifier) override; void ShowMD5Dialog(const std::string& file_identifier) override;
void SetMD5Progress(int pid, int progress) override; void SetMD5Progress(int pid, int progress) override;
void SetMD5Result(int pid, const std::string& result) override; void SetMD5Result(int pid, const std::string& result) override;
Expand Down

0 comments on commit 550aa93

Please sign in to comment.