NetPlay: Refactor game boot code path to allow passing BootSessionData through it.

This commit is contained in:
Admiral H. Curtiss 2021-11-20 19:59:14 +01:00
parent 83ad84061e
commit 7b776f3769
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 33 additions and 12 deletions

View File

@ -33,6 +33,7 @@
#include "Common/Version.h" #include "Common/Version.h"
#include "Core/ActionReplay.h" #include "Core/ActionReplay.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/Config/NetplaySettings.h" #include "Core/Config/NetplaySettings.h"
#include "Core/Config/SessionSettings.h" #include "Core/Config/SessionSettings.h"
@ -1721,7 +1722,7 @@ bool NetPlayClient::StartGame(const std::string& path)
} }
// boot game // boot game
m_dialog->BootGame(path); m_dialog->BootGame(path, nullptr);
UpdateDevices(); UpdateDevices();

View File

@ -23,6 +23,8 @@
#include "Core/SyncIdentifier.h" #include "Core/SyncIdentifier.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
class BootSessionData;
namespace UICommon namespace UICommon
{ {
class GameFile; class GameFile;
@ -34,7 +36,8 @@ class NetPlayUI
{ {
public: public:
virtual ~NetPlayUI() {} virtual ~NetPlayUI() {}
virtual void BootGame(const std::string& filename) = 0; virtual void BootGame(const std::string& filename,
std::unique_ptr<BootSessionData> boot_session_data) = 0;
virtual void StopGame() = 0; virtual void StopGame() = 0;
virtual bool IsHosting() const = 0; virtual bool IsHosting() const = 0;

View File

@ -1372,13 +1372,15 @@ void MainWindow::NetPlayInit()
{ {
const auto& game_list_model = m_game_list->GetGameListModel(); const auto& game_list_model = m_game_list->GetGameListModel();
m_netplay_setup_dialog = new NetPlaySetupDialog(game_list_model, this); m_netplay_setup_dialog = new NetPlaySetupDialog(game_list_model, this);
m_netplay_dialog = new NetPlayDialog(game_list_model); m_netplay_dialog = new NetPlayDialog(
game_list_model,
[this](const std::string& path, std::unique_ptr<BootSessionData> boot_session_data) {
StartGame(path, ScanForSecondDisc::Yes, std::move(boot_session_data));
});
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
m_netplay_discord = new DiscordHandler(this); m_netplay_discord = new DiscordHandler(this);
#endif #endif
connect(m_netplay_dialog, &NetPlayDialog::Boot, this,
[this](const QString& path) { StartGame(path, ScanForSecondDisc::Yes); });
connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::ForceStop); connect(m_netplay_dialog, &NetPlayDialog::Stop, this, &MainWindow::ForceStop);
connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit); connect(m_netplay_dialog, &NetPlayDialog::rejected, this, &MainWindow::NetPlayQuit);
connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin); connect(m_netplay_setup_dialog, &NetPlaySetupDialog::Join, this, &MainWindow::NetPlayJoin);

View File

@ -31,6 +31,7 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/TraversalClient.h" #include "Common/TraversalClient.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/GraphicsSettings.h" #include "Core/Config/GraphicsSettings.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/Config/NetplaySettings.h" #include "Core/Config/NetplaySettings.h"
@ -62,8 +63,10 @@
#include "VideoCommon/RenderBase.h" #include "VideoCommon/RenderBase.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
NetPlayDialog::NetPlayDialog(const GameListModel& game_list_model, QWidget* parent) NetPlayDialog::NetPlayDialog(const GameListModel& game_list_model,
: QDialog(parent), m_game_list_model(game_list_model) StartGameCallback start_game_callback, QWidget* parent)
: QDialog(parent), m_game_list_model(game_list_model),
m_start_game_callback(std::move(start_game_callback))
{ {
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@ -682,10 +685,11 @@ void NetPlayDialog::UpdateGUI()
// NetPlayUI methods // NetPlayUI methods
void NetPlayDialog::BootGame(const std::string& filename) void NetPlayDialog::BootGame(const std::string& filename,
std::unique_ptr<BootSessionData> boot_session_data)
{ {
m_got_stop_request = false; m_got_stop_request = false;
emit Boot(QString::fromStdString(filename)); m_start_game_callback(filename, std::move(boot_session_data));
} }
void NetPlayDialog::StopGame() void NetPlayDialog::StopGame()

View File

@ -3,6 +3,10 @@
#pragma once #pragma once
#include <functional>
#include <memory>
#include <string>
#include <QDialog> #include <QDialog>
#include <QMenuBar> #include <QMenuBar>
@ -11,6 +15,7 @@
#include "DolphinQt/GameList/GameListModel.h" #include "DolphinQt/GameList/GameListModel.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
class BootSessionData;
class ChunkedProgressDialog; class ChunkedProgressDialog;
class MD5Dialog; class MD5Dialog;
class PadMappingDialog; class PadMappingDialog;
@ -30,14 +35,19 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit NetPlayDialog(const GameListModel& game_list_model, QWidget* parent = nullptr); using StartGameCallback = std::function<void(const std::string& path,
std::unique_ptr<BootSessionData> boot_session_data)>;
explicit NetPlayDialog(const GameListModel& game_list_model,
StartGameCallback start_game_callback, QWidget* parent = nullptr);
~NetPlayDialog(); ~NetPlayDialog();
void show(std::string nickname, bool use_traversal); void show(std::string nickname, bool use_traversal);
void reject() override; void reject() override;
// NetPlayUI methods // NetPlayUI methods
void BootGame(const std::string& filename) override; void BootGame(const std::string& filename,
std::unique_ptr<BootSessionData> boot_session_data) override;
void StopGame() override; void StopGame() override;
bool IsHosting() const override; bool IsHosting() const override;
@ -85,7 +95,6 @@ public:
void HideChunkedProgressDialog() override; void HideChunkedProgressDialog() override;
void SetChunkedProgress(int pid, u64 progress) override; void SetChunkedProgress(int pid, u64 progress) override;
signals: signals:
void Boot(const QString& filename);
void Stop(); void Stop();
private: private:
@ -162,4 +171,6 @@ private:
int m_player_count = 0; int m_player_count = 0;
int m_old_player_count = 0; int m_old_player_count = 0;
bool m_host_input_authority = false; bool m_host_input_authority = false;
StartGameCallback m_start_game_callback;
}; };