Merge pull request #7226 from lioncash/netplay

Core: Namespace NetPlay utilities under the NetPlay namespace
This commit is contained in:
Mat M 2018-07-09 00:38:12 -04:00 committed by GitHub
commit 9487892c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 119 additions and 97 deletions

View File

@ -334,20 +334,21 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
if (NetPlay::IsNetPlayRunning()) if (NetPlay::IsNetPlayRunning())
{ {
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(g_NetPlaySettings)); const NetPlay::NetSettings& netplay_settings = NetPlay::g_NetPlaySettings;
StartUp.bCPUThread = g_NetPlaySettings.m_CPUthread; Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(netplay_settings));
StartUp.bEnableCheats = g_NetPlaySettings.m_EnableCheats; StartUp.bCPUThread = netplay_settings.m_CPUthread;
StartUp.bDSPHLE = g_NetPlaySettings.m_DSPHLE; StartUp.bEnableCheats = netplay_settings.m_EnableCheats;
StartUp.bEnableMemcardSdWriting = g_NetPlaySettings.m_WriteToMemcard; StartUp.bDSPHLE = netplay_settings.m_DSPHLE;
StartUp.bCopyWiiSaveNetplay = g_NetPlaySettings.m_CopyWiiSave; StartUp.bEnableMemcardSdWriting = netplay_settings.m_WriteToMemcard;
StartUp.cpu_core = g_NetPlaySettings.m_CPUcore; StartUp.bCopyWiiSaveNetplay = netplay_settings.m_CopyWiiSave;
StartUp.SelectedLanguage = g_NetPlaySettings.m_SelectedLanguage; StartUp.cpu_core = netplay_settings.m_CPUcore;
StartUp.bOverrideGCLanguage = g_NetPlaySettings.m_OverrideGCLanguage; StartUp.SelectedLanguage = netplay_settings.m_SelectedLanguage;
StartUp.m_DSPEnableJIT = g_NetPlaySettings.m_DSPEnableJIT; StartUp.bOverrideGCLanguage = netplay_settings.m_OverrideGCLanguage;
StartUp.m_OCEnable = g_NetPlaySettings.m_OCEnable; StartUp.m_DSPEnableJIT = netplay_settings.m_DSPEnableJIT;
StartUp.m_OCFactor = g_NetPlaySettings.m_OCFactor; StartUp.m_OCEnable = netplay_settings.m_OCEnable;
StartUp.m_EXIDevice[0] = g_NetPlaySettings.m_EXIDevice[0]; StartUp.m_OCFactor = netplay_settings.m_OCFactor;
StartUp.m_EXIDevice[1] = g_NetPlaySettings.m_EXIDevice[1]; StartUp.m_EXIDevice[0] = netplay_settings.m_EXIDevice[0];
StartUp.m_EXIDevice[1] = netplay_settings.m_EXIDevice[1];
config_cache.bSetEXIDevice[0] = true; config_cache.bSetEXIDevice[0] = true;
config_cache.bSetEXIDevice[1] = true; config_cache.bSetEXIDevice[1] = true;
} }

View File

@ -16,7 +16,7 @@ namespace ConfigLoaders
class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader
{ {
public: public:
explicit NetPlayConfigLayerLoader(const NetSettings& settings) explicit NetPlayConfigLayerLoader(const NetPlay::NetSettings& settings)
: ConfigLayerLoader(Config::LayerType::Netplay), m_settings(settings) : ConfigLayerLoader(Config::LayerType::Netplay), m_settings(settings)
{ {
} }
@ -47,11 +47,12 @@ public:
} }
private: private:
const NetSettings m_settings; const NetPlay::NetSettings m_settings;
}; };
// Loader generation // Loader generation
std::unique_ptr<Config::ConfigLayerLoader> GenerateNetPlayConfigLoader(const NetSettings& settings) std::unique_ptr<Config::ConfigLayerLoader>
GenerateNetPlayConfigLoader(const NetPlay::NetSettings& settings)
{ {
return std::make_unique<NetPlayConfigLayerLoader>(settings); return std::make_unique<NetPlayConfigLayerLoader>(settings);
} }

View File

@ -6,14 +6,18 @@
#include <memory> #include <memory>
struct NetSettings;
namespace Config namespace Config
{ {
class ConfigLayerLoader; class ConfigLayerLoader;
} }
namespace NetPlay
{
struct NetSettings;
}
namespace ConfigLoaders namespace ConfigLoaders
{ {
std::unique_ptr<Config::ConfigLayerLoader> GenerateNetPlayConfigLoader(const NetSettings& settings); std::unique_ptr<Config::ConfigLayerLoader>
GenerateNetPlayConfigLoader(const NetPlay::NetSettings& settings);
} }

View File

@ -122,7 +122,7 @@ void SetIsThrottlerTempDisabled(bool disable)
void FrameUpdateOnCPUThread() void FrameUpdateOnCPUThread()
{ {
if (NetPlay::IsNetPlayRunning()) if (NetPlay::IsNetPlayRunning())
NetPlayClient::SendTimeBase(); NetPlay::NetPlayClient::SendTimeBase();
} }
// Display messages and return values // Display messages and return values

View File

@ -41,6 +41,8 @@
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h" #include "VideoCommon/VideoConfig.h"
namespace NetPlay
{
static std::mutex crit_netplay_client; static std::mutex crit_netplay_client;
static NetPlayClient* netplay_client = nullptr; static NetPlayClient* netplay_client = nullptr;
NetSettings g_NetPlaySettings; NetSettings g_NetPlaySettings;
@ -1306,41 +1308,59 @@ const PadMappingArray& NetPlayClient::GetWiimoteMapping() const
return m_wiimote_map; return m_wiimote_map;
} }
bool IsNetPlayRunning()
{
return netplay_client != nullptr;
}
void NetPlay_Enable(NetPlayClient* const np)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
netplay_client = np;
}
void NetPlay_Disable()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
netplay_client = nullptr;
}
} // namespace NetPlay
// stuff hacked into dolphin // stuff hacked into dolphin
// called from ---CPU--- thread // called from ---CPU--- thread
// Actual Core function which is called on every frame // Actual Core function which is called on every frame
bool SerialInterface::CSIDevice_GCController::NetPlay_GetInput(int numPAD, GCPadStatus* PadStatus) bool SerialInterface::CSIDevice_GCController::NetPlay_GetInput(int numPAD, GCPadStatus* PadStatus)
{ {
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
if (netplay_client) if (NetPlay::netplay_client)
return netplay_client->GetNetPads(numPAD, PadStatus); return NetPlay::netplay_client->GetNetPads(numPAD, PadStatus);
else
return false; return false;
} }
bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode) bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode)
{ {
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
if (netplay_client) if (NetPlay::netplay_client)
return netplay_client->WiimoteUpdate(wiimote, data, size, reporting_mode); return NetPlay::netplay_client->WiimoteUpdate(wiimote, data, size, reporting_mode);
else
return false; return false;
} }
// Sync the info whether a button was pressed or not. Used for the reconnect on button press feature // Sync the info whether a button was pressed or not. Used for the reconnect on button press feature
bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed) bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
{ {
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
// Use the reporting mode 0 for the button pressed event, the real ones start at RT_REPORT_CORE // Use the reporting mode 0 for the button pressed event, the real ones start at RT_REPORT_CORE
u8 data[2] = {static_cast<u8>(pressed), 0}; u8 data[2] = {static_cast<u8>(pressed), 0};
if (netplay_client) if (NetPlay::netplay_client)
{ {
if (netplay_client->WiimoteUpdate(wiimote, data, 2, 0)) if (NetPlay::netplay_client->WiimoteUpdate(wiimote, data, 2, 0))
{ {
return data[0]; return data[0];
} }
@ -1357,39 +1377,22 @@ bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
// also called from ---GUI--- thread when starting input recording // also called from ---GUI--- thread when starting input recording
u64 ExpansionInterface::CEXIIPL::NetPlay_GetEmulatedTime() u64 ExpansionInterface::CEXIIPL::NetPlay_GetEmulatedTime()
{ {
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
if (netplay_client) if (NetPlay::netplay_client)
return g_netplay_initial_rtc; return NetPlay::g_netplay_initial_rtc;
else
return 0; return 0;
} }
// called from ---CPU--- thread // called from ---CPU--- thread
// return the local pad num that should rumble given a ingame pad num // return the local pad num that should rumble given a ingame pad num
int SerialInterface::CSIDevice_GCController::NetPlay_InGamePadToLocalPad(int numPAD) int SerialInterface::CSIDevice_GCController::NetPlay_InGamePadToLocalPad(int numPAD)
{ {
std::lock_guard<std::mutex> lk(crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
if (netplay_client) if (NetPlay::netplay_client)
return netplay_client->InGamePadToLocalPad(numPAD); return NetPlay::netplay_client->InGamePadToLocalPad(numPAD);
else
return numPAD;
}
bool NetPlay::IsNetPlayRunning() return numPAD;
{
return netplay_client != nullptr;
}
void NetPlay_Enable(NetPlayClient* const np)
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
netplay_client = np;
}
void NetPlay_Disable()
{
std::lock_guard<std::mutex> lk(crit_netplay_client);
netplay_client = nullptr;
} }

View File

@ -18,6 +18,8 @@
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
namespace NetPlay
{
class NetPlayUI class NetPlayUI
{ {
public: public:
@ -186,3 +188,4 @@ private:
void NetPlay_Enable(NetPlayClient* const np); void NetPlay_Enable(NetPlayClient* const np);
void NetPlay_Disable(); void NetPlay_Disable();
} // namespace NetPlay

View File

@ -14,6 +14,8 @@ namespace PowerPC
enum class CPUCore; enum class CPUCore;
} }
namespace NetPlay
{
struct NetSettings struct NetSettings
{ {
bool m_CPUthread; bool m_CPUthread;
@ -109,7 +111,5 @@ using FrameNum = u32;
using PadMapping = s8; using PadMapping = s8;
using PadMappingArray = std::array<PadMapping, 4>; using PadMappingArray = std::array<PadMapping, 4>;
namespace NetPlay
{
bool IsNetPlayRunning(); bool IsNetPlayRunning();
} } // namespace NetPlay

View File

@ -40,6 +40,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
namespace NetPlay
{
u64 g_netplay_initial_rtc = 1272737767; u64 g_netplay_initial_rtc = 1272737767;
NetPlayServer::~NetPlayServer() NetPlayServer::~NetPlayServer()
@ -951,3 +953,4 @@ std::vector<std::pair<std::string, std::string>> NetPlayServer::GetInterfaceList
result.emplace_back(std::make_pair("!local!", "127.0.0.1")); result.emplace_back(std::make_pair("!local!", "127.0.0.1"));
return result; return result;
} }
} // namespace NetPlay

View File

@ -19,8 +19,8 @@
#include "Common/TraversalClient.h" #include "Common/TraversalClient.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
enum class PlayerGameStatus; namespace NetPlay
{
class NetPlayUI; class NetPlayUI;
enum class PlayerGameStatus; enum class PlayerGameStatus;
@ -124,3 +124,4 @@ private:
TraversalClient* m_traversal_client = nullptr; TraversalClient* m_traversal_client = nullptr;
NetPlayUI* m_dialog = nullptr; NetPlayUI* m_dialog = nullptr;
}; };
} // namespace NetPlay

View File

@ -1087,10 +1087,11 @@ bool MainWindow::NetPlayJoin()
const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME); const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME);
// Create Client // Create Client
Settings::Instance().ResetNetPlayClient(new NetPlayClient( const bool is_hosting_netplay = Settings::Instance().GetNetPlayServer() != nullptr;
Settings::Instance().ResetNetPlayClient(new NetPlay::NetPlayClient(
host_ip, host_port, m_netplay_dialog, nickname, host_ip, host_port, m_netplay_dialog, nickname,
NetTraversalConfig{Settings::Instance().GetNetPlayServer() != nullptr ? false : is_traversal, NetPlay::NetTraversalConfig{is_hosting_netplay ? false : is_traversal, traversal_host,
traversal_host, traversal_port})); traversal_port}));
if (!Settings::Instance().GetNetPlayClient()->IsConnected()) if (!Settings::Instance().GetNetPlayClient()->IsConnected())
{ {
@ -1134,8 +1135,9 @@ bool MainWindow::NetPlayHost(const QString& game_id)
host_port = Config::Get(Config::NETPLAY_LISTEN_PORT); host_port = Config::Get(Config::NETPLAY_LISTEN_PORT);
// Create Server // Create Server
Settings::Instance().ResetNetPlayServer(new NetPlayServer( Settings::Instance().ResetNetPlayServer(new NetPlay::NetPlayServer(
host_port, use_upnp, NetTraversalConfig{is_traversal, traversal_host, traversal_port})); host_port, use_upnp,
NetPlay::NetTraversalConfig{is_traversal, traversal_host, traversal_port}));
if (!Settings::Instance().GetNetPlayServer()->is_connected) if (!Settings::Instance().GetNetPlayServer()->is_connected)
{ {

View File

@ -34,9 +34,7 @@ class JITWidget;
class LogConfigWidget; class LogConfigWidget;
class LogWidget; class LogWidget;
class MemoryWidget; class MemoryWidget;
class NetPlayClient;
class NetPlayDialog; class NetPlayDialog;
class NetPlayServer;
class NetPlaySetupDialog; class NetPlaySetupDialog;
class RegisterWidget; class RegisterWidget;
class SearchBar; class SearchBar;

View File

@ -285,7 +285,7 @@ void NetPlayDialog::OnStart()
return; return;
} }
NetSettings settings; NetPlay::NetSettings settings;
// Copy all relevant settings // Copy all relevant settings
SConfig& instance = SConfig::GetInstance(); SConfig& instance = SConfig::GetInstance();
@ -379,7 +379,8 @@ void NetPlayDialog::UpdateGUI()
{tr("Player"), tr("Game Status"), tr("Ping"), tr("Mapping"), tr("Revision")}); {tr("Player"), tr("Game Status"), tr("Ping"), tr("Mapping"), tr("Revision")});
m_players_list->setRowCount(player_count); m_players_list->setRowCount(player_count);
const auto get_mapping_string = [](const Player* player, const PadMappingArray& array) { const auto get_mapping_string = [](const NetPlay::Player* player,
const NetPlay::PadMappingArray& array) {
std::string str; std::string str;
for (size_t i = 0; i < array.size(); i++) for (size_t i = 0; i < array.size(); i++)
{ {
@ -392,8 +393,10 @@ void NetPlayDialog::UpdateGUI()
return '|' + str + '|'; return '|' + str + '|';
}; };
static const std::map<PlayerGameStatus, QString> player_status{ static const std::map<NetPlay::PlayerGameStatus, QString> player_status{
{PlayerGameStatus::Ok, tr("OK")}, {PlayerGameStatus::NotFound, tr("Not Found")}}; {NetPlay::PlayerGameStatus::Ok, tr("OK")},
{NetPlay::PlayerGameStatus::NotFound, tr("Not Found")},
};
for (int i = 0; i < player_count; i++) for (int i = 0; i < player_count; i++)
{ {

View File

@ -11,7 +11,6 @@
class MD5Dialog; class MD5Dialog;
class GameListModel; class GameListModel;
class NetPlayServer;
class PadMappingDialog; class PadMappingDialog;
class QCheckBox; class QCheckBox;
class QComboBox; class QComboBox;
@ -26,7 +25,7 @@ class QTableWidget;
class QTextEdit; class QTextEdit;
class QToolButton; class QToolButton;
class NetPlayDialog : public QDialog, public NetPlayUI class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -94,12 +94,13 @@ int PadMappingDialog::exec()
return QDialog::exec(); return QDialog::exec();
} }
PadMappingArray PadMappingDialog::GetGCPadArray()
NetPlay::PadMappingArray PadMappingDialog::GetGCPadArray()
{ {
return m_pad_mapping; return m_pad_mapping;
} }
PadMappingArray PadMappingDialog::GetWiimoteArray() NetPlay::PadMappingArray PadMappingDialog::GetWiimoteArray()
{ {
return m_wii_mapping; return m_wii_mapping;
} }

View File

@ -8,12 +8,15 @@
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
class NetPlayClient;
class Player;
class QGridLayout; class QGridLayout;
class QComboBox; class QComboBox;
class QDialogButtonBox; class QDialogButtonBox;
namespace NetPlay
{
class Player;
}
class PadMappingDialog : public QDialog class PadMappingDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -22,8 +25,8 @@ public:
int exec() override; int exec() override;
PadMappingArray GetGCPadArray(); NetPlay::PadMappingArray GetGCPadArray();
PadMappingArray GetWiimoteArray(); NetPlay::PadMappingArray GetWiimoteArray();
private: private:
void CreateWidgets(); void CreateWidgets();
@ -31,12 +34,12 @@ private:
void OnMappingChanged(); void OnMappingChanged();
PadMappingArray m_pad_mapping; NetPlay::PadMappingArray m_pad_mapping;
PadMappingArray m_wii_mapping; NetPlay::PadMappingArray m_wii_mapping;
QGridLayout* m_main_layout; QGridLayout* m_main_layout;
std::array<QComboBox*, 4> m_gc_boxes; std::array<QComboBox*, 4> m_gc_boxes;
std::array<QComboBox*, 4> m_wii_boxes; std::array<QComboBox*, 4> m_wii_boxes;
std::vector<const Player*> m_players; std::vector<const NetPlay::Player*> m_players;
QDialogButtonBox* m_button_box; QDialogButtonBox* m_button_box;
}; };

View File

@ -268,22 +268,22 @@ GameListModel* Settings::GetGameListModel() const
return model; return model;
} }
NetPlayClient* Settings::GetNetPlayClient() NetPlay::NetPlayClient* Settings::GetNetPlayClient()
{ {
return m_client.get(); return m_client.get();
} }
void Settings::ResetNetPlayClient(NetPlayClient* client) void Settings::ResetNetPlayClient(NetPlay::NetPlayClient* client)
{ {
m_client.reset(client); m_client.reset(client);
} }
NetPlayServer* Settings::GetNetPlayServer() NetPlay::NetPlayServer* Settings::GetNetPlayServer()
{ {
return m_server.get(); return m_server.get();
} }
void Settings::ResetNetPlayServer(NetPlayServer* server) void Settings::ResetNetPlayServer(NetPlay::NetPlayServer* server)
{ {
m_server.reset(server); m_server.reset(server);
} }

View File

@ -93,10 +93,10 @@ public:
void DecreaseVolume(int volume); void DecreaseVolume(int volume);
// NetPlay // NetPlay
NetPlayClient* GetNetPlayClient(); NetPlay::NetPlayClient* GetNetPlayClient();
void ResetNetPlayClient(NetPlayClient* client = nullptr); void ResetNetPlayClient(NetPlay::NetPlayClient* client = nullptr);
NetPlayServer* GetNetPlayServer(); NetPlay::NetPlayServer* GetNetPlayServer();
void ResetNetPlayServer(NetPlayServer* server = nullptr); void ResetNetPlayServer(NetPlay::NetPlayServer* server = nullptr);
// Cheats // Cheats
bool GetCheatsEnabled() const; bool GetCheatsEnabled() const;
@ -163,8 +163,8 @@ signals:
private: private:
bool m_batch = false; bool m_batch = false;
bool m_controller_state_needed = false; bool m_controller_state_needed = false;
std::unique_ptr<NetPlayClient> m_client; std::unique_ptr<NetPlay::NetPlayClient> m_client;
std::unique_ptr<NetPlayServer> m_server; std::unique_ptr<NetPlay::NetPlayServer> m_server;
Settings(); Settings();
}; };