Merge pull request #2975 from HeatXD/netplay_dev

Upsteam Netplay Changes
This commit is contained in:
Connor McLaughlin 2023-05-11 18:42:58 +10:00 committed by GitHub
commit 10eef64675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 115 deletions

View File

@ -1267,8 +1267,8 @@ void Netplay::UpdateResetState()
{
if (!IsValidPlayerId(i) || s_reset_players.test(i))
continue;
if (s_peers[i].peer->state == ENET_PEER_STATE_CONNECTED)
// be sure to first check whether the peer is still valid.
if (s_peers[i].peer && s_peers[i].peer->state == ENET_PEER_STATE_CONNECTED)
s_reset_players.set(i);
}
@ -1430,7 +1430,7 @@ void Netplay::SetSettings()
Settings::GetControllerTypeName(ControllerType::DigitalController));
}
//si.SetStringValue("CPU", "ExecutionMode", "Interpreter");
// si.SetStringValue("CPU", "ExecutionMode", "Interpreter");
// No runahead or rewind, that'd be a disaster.
si.SetIntValue("Main", "RunaheadFrameCount", 0);
@ -1642,13 +1642,9 @@ void Netplay::SetInputs(Netplay::Input inputs[2])
}
}
void Netplay::StartNetplaySession(s32 local_handle, u16 local_port, const std::string& remote_addr, u16 remote_port,
s32 input_delay, std::string game_path)
void Netplay::TestNetplaySession(s32 local_handle, u16 local_port, const std::string& remote_addr, u16 remote_port,
s32 input_delay, std::string game_path)
{
// dont want to start a session when theres already one going on.
if (IsActive())
return;
const bool is_hosting = (local_handle == 1);
if (!CreateSystem(std::move(game_path), is_hosting))
{
@ -1664,22 +1660,6 @@ void Netplay::StartNetplaySession(s32 local_handle, u16 local_port, const std::s
Log_ErrorPrint("Failed to Create Netplay Session!");
System::ShutdownSystem(false);
}
else if (IsHost())
{
// Load savestate if available and only when you are the host.
// the other peers will get state from the host
std::string save = EmuFolders::SaveStates + "/netplay/" + System::GetRunningSerial() + ".sav";
System::LoadState(save.c_str());
}
}
void Netplay::StopNetplaySession()
{
if (!IsActive())
return;
// This will call back to us.
System::ShutdownSystem(false);
}
bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std::string password)
@ -1693,6 +1673,13 @@ bool Netplay::CreateSession(std::string nickname, s32 port, s32 max_players, std
CloseSession();
return false;
}
else if (IsHost())
{
// Load savestate if available and only when you are the host.
// the other peers will get state from the host
auto save_path = fmt::format("{}\\netplay\\{}.sav", EmuFolders::SaveStates, System::GetRunningSerial());
System::LoadState(save_path.c_str());
}
return true;
}

View File

@ -28,10 +28,8 @@ enum : u8
NUM_ENET_CHANNELS,
};
void StartNetplaySession(s32 local_handle, u16 local_port, const std::string& remote_addr, u16 remote_port,
void TestNetplaySession(s32 local_handle, u16 local_port, const std::string& remote_addr, u16 remote_port,
s32 input_delay, std::string game_path);
void StopNetplaySession();
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);

View File

@ -42,7 +42,6 @@
<ClCompile Include="memorycardsettingswidget.cpp" />
<ClCompile Include="memorycardeditordialog.cpp" />
<ClCompile Include="netplaydialogs.cpp" />
<ClCompile Include="netplaywidget.cpp" />
<ClCompile Include="postprocessingchainconfigwidget.cpp" />
<ClCompile Include="postprocessingshaderconfigwidget.cpp" />
<ClCompile Include="postprocessingsettingswidget.cpp" />
@ -100,7 +99,6 @@
<QtMoc Include="postprocessingshaderconfigwidget.h" />
<QtMoc Include="postprocessingsettingswidget.h" />
<QtMoc Include="mainwindow.h" />
<QtMoc Include="netplaywidget.h" />
<QtMoc Include="qthost.h" />
<QtMoc Include="foldersettingswidget.h" />
<ClInclude Include="qtutils.h" />
@ -134,9 +132,6 @@
<QtUi Include="mainwindow.ui">
<FileType>Document</FileType>
</QtUi>
<QtUi Include="netplaywidget.ui">
<FileType>Document</FileType>
</QtUi>
<QtUi Include="settingsdialog.ui">
<FileType>Document</FileType>
</QtUi>
@ -268,7 +263,6 @@
<ClCompile Include="$(IntDir)moc_inputbindingwidgets.cpp" />
<ClCompile Include="$(IntDir)moc_mainwindow.cpp" />
<ClCompile Include="$(IntDir)moc_netplaydialogs.cpp" />
<ClCompile Include="$(IntDir)moc_netplaywidget.cpp" />
<ClCompile Include="$(IntDir)moc_memorycardsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_memorycardeditordialog.cpp" />
<ClCompile Include="$(IntDir)moc_memoryviewwidget.cpp" />

View File

@ -94,10 +94,9 @@
<ClCompile Include="coverdownloaddialog.cpp" />
<ClCompile Include="$(IntDir)moc_coverdownloaddialog.cpp" />
<ClCompile Include="colorpickerbutton.cpp" />
<ClCompile Include="netplaywidget.cpp" />
<ClCompile Include="$(IntDir)moc_colorpickerbutton.cpp" />
<ClCompile Include="$(IntDir)moc_netplaywidget.cpp" />
<ClCompile Include="netplaydialogs.cpp" />
<ClCompile Include="$(IntDir)moc_netplaydialogs.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="qtutils.h" />
@ -159,7 +158,6 @@
<QtMoc Include="foldersettingswidget.h" />
<QtMoc Include="coverdownloaddialog.h" />
<QtMoc Include="colorpickerbutton.h" />
<QtMoc Include="netplaywidget.h" />
<QtMoc Include="netplaydialogs.h" />
</ItemGroup>
<ItemGroup>
@ -202,7 +200,6 @@
<QtUi Include="controllerbindingwidget_mouse.ui" />
<QtUi Include="coverdownloaddialog.ui" />
<QtUi Include="controllerledsettingsdialog.ui" />
<QtUi Include="netplaywidget.ui" />
<QtUi Include="createnetplaysessiondialog.ui" />
<QtUi Include="joinnetplaysessiondialog.ui" />
</ItemGroup>

View File

@ -2104,7 +2104,6 @@ void MainWindow::connectSignals()
updateMenuSelectedTheme();
// Netplay UI , TODO
connect(m_ui.actionSetupNetplaySession, &QAction::triggered, this, &MainWindow::onSetupNetplaySessionClicked);
connect(m_ui.actionCreateNetplaySession, &QAction::triggered, this, &MainWindow::onCreateNetplaySessionClicked);
connect(m_ui.actionJoinNetplaySession, &QAction::triggered, this, &MainWindow::onJoinNetplaySessionClicked);
}
@ -2771,28 +2770,6 @@ void MainWindow::onCPUDebuggerClosed()
m_debugger_window = nullptr;
}
void MainWindow::onSetupNetplaySessionClicked()
{
Assert(!m_netplay_window);
m_netplay_window = new NetplayWidget(this);
m_netplay_window->setWindowIcon(windowIcon());
m_netplay_window->setWindowTitle("Netplay Session");
m_netplay_window->setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint);
m_netplay_window->show();
m_ui.menuNetplay->setDisabled(true);
connect(m_netplay_window, &NetplayWidget::finished, [this]() {
Assert(m_netplay_window);
m_netplay_window->deleteLater();
m_netplay_window = nullptr;
m_ui.menuNetplay->setDisabled(false);
});
}
void MainWindow::onCreateNetplaySessionClicked()
{
CreateNetplaySessionDialog dlg(this);

View File

@ -16,7 +16,6 @@
#include "displaywidget.h"
#include "settingsdialog.h"
#include "ui_mainwindow.h"
#include <netplaywidget.h>
class QLabel;
class QThread;
@ -169,7 +168,6 @@ private Q_SLOTS:
void openCPUDebugger();
void onCPUDebuggerClosed();
void onSetupNetplaySessionClicked();
void onCreateNetplaySessionClicked();
void onJoinNetplaySessionClicked();
@ -278,7 +276,6 @@ private:
MemoryCardEditorDialog* m_memory_card_editor_dialog = nullptr;
CheatManagerDialog* m_cheat_manager_dialog = nullptr;
DebuggerWindow* m_debugger_window = nullptr;
NetplayWidget* m_netplay_window = nullptr;
std::string m_current_game_title;
std::string m_current_game_serial;

View File

@ -241,7 +241,6 @@
<property name="title">
<string>Netplay</string>
</property>
<addaction name="actionSetupNetplaySession"/>
<addaction name="separator"/>
<addaction name="actionCreateNetplaySession"/>
<addaction name="actionJoinNetplaySession"/>
@ -986,11 +985,6 @@
<string>Cover Downloader</string>
</property>
</action>
<action name="actionSetupNetplaySession">
<property name="text">
<string>Setup Session</string>
</property>
</action>
<action name="actionCreateNetplaySession">
<property name="text">
<string>Create Session...</string>

View File

@ -1069,36 +1069,6 @@ void EmuThread::reloadPostProcessingShaders()
System::ReloadPostProcessingShaders();
}
void EmuThread::startNetplaySession(int local_handle, quint16 local_port, const QString& remote_addr,
quint16 remote_port, int input_delay, const QString& game_path)
{
if (!isOnThread())
{
QMetaObject::invokeMethod(this, "startNetplaySession", Qt::QueuedConnection, Q_ARG(int, local_handle),
Q_ARG(quint16, local_port), Q_ARG(const QString&, remote_addr),
Q_ARG(quint16, remote_port), Q_ARG(int, input_delay), Q_ARG(const QString&, game_path));
return;
}
auto remAddr = remote_addr.trimmed().toStdString();
auto gamePath = game_path.trimmed().toStdString();
Netplay::StartNetplaySession(local_handle, local_port, remAddr, remote_port, input_delay, gamePath);
// TODO: Fix this junk.. for some reason, it stays sleeping...
g_emu_thread->wakeThread();
}
void EmuThread::sendNetplayMessage(const QString& message)
{
if (!isOnThread())
{
QMetaObject::invokeMethod(this, "sendNetplayMessage", Qt::QueuedConnection, Q_ARG(const QString&, message));
return;
}
// TODO REDO NETPLAY UI
// Netplay::SendMsg(message.toStdString().c_str());
}
void EmuThread::createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password)
{
if (!isOnThread())
@ -1138,16 +1108,6 @@ void EmuThread::joinNetplaySession(const QString& nickname, const QString& hostn
g_emu_thread->wakeThread();
}
void EmuThread::stopNetplaySession()
{
if (!isOnThread())
{
QMetaObject::invokeMethod(this, "stopNetplaySession", Qt::QueuedConnection);
return;
}
Netplay::StopNetplaySession();
}
void EmuThread::runOnEmuThread(std::function<void()> callback)
{
callback();
@ -2273,7 +2233,7 @@ int main(int argc, char* argv[])
const int port_base = 31200;
std::string remote = "127.0.0.1";
std::string game = "D:\\PSX\\chd\\padtest.chd";
Netplay::StartNetplaySession(h, port_base + h, remote, port_base + nh, 1, game);
Netplay::TestNetplaySession(h, port_base + h, remote, port_base + nh, 1, game);
// TODO: Fix this junk.. for some reason, it stays sleeping...
g_emu_thread->wakeThread();

View File

@ -187,10 +187,6 @@ public Q_SLOTS:
void setCheatEnabled(quint32 index, bool enabled);
void applyCheat(quint32 index);
void reloadPostProcessingShaders();
void startNetplaySession(int local_handle, quint16 local_port, const QString& remote_addr, quint16 remote_port,
int input_delay, const QString& game_path);
void stopNetplaySession();
void sendNetplayMessage(const QString& message);
void createNetplaySession(const QString& nickname, qint32 port, qint32 max_players, const QString& password);
void joinNetplaySession(const QString& nickname, const QString& hostname, qint32 port, const QString& password);