Permalink
Browse files

Core: Namespace NetPlay utilities under the NetPlay namespace

Previously there was only one function under the NetPlay namespace,
which is kind of silly considering we have all of these other types
and functions existing outside of the namespace.

This moves the rest of them into the namespace.

This gets some general names, like Player, for example, out of the global namespace.
  • Loading branch information...
lioncash committed Jul 6, 2018
1 parent 3d1a773 commit 675260b0f7b164dca59d2888ee2c58a921ca02c1
@@ -334,20 +334,21 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
if (NetPlay::IsNetPlayRunning())
{
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(g_NetPlaySettings));
StartUp.bCPUThread = g_NetPlaySettings.m_CPUthread;
StartUp.bEnableCheats = g_NetPlaySettings.m_EnableCheats;
StartUp.bDSPHLE = g_NetPlaySettings.m_DSPHLE;
StartUp.bEnableMemcardSdWriting = g_NetPlaySettings.m_WriteToMemcard;
StartUp.bCopyWiiSaveNetplay = g_NetPlaySettings.m_CopyWiiSave;
StartUp.cpu_core = g_NetPlaySettings.m_CPUcore;
StartUp.SelectedLanguage = g_NetPlaySettings.m_SelectedLanguage;
StartUp.bOverrideGCLanguage = g_NetPlaySettings.m_OverrideGCLanguage;
StartUp.m_DSPEnableJIT = g_NetPlaySettings.m_DSPEnableJIT;
StartUp.m_OCEnable = g_NetPlaySettings.m_OCEnable;
StartUp.m_OCFactor = g_NetPlaySettings.m_OCFactor;
StartUp.m_EXIDevice[0] = g_NetPlaySettings.m_EXIDevice[0];
StartUp.m_EXIDevice[1] = g_NetPlaySettings.m_EXIDevice[1];
const NetPlay::NetSettings& netplay_settings = NetPlay::g_NetPlaySettings;
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(netplay_settings));
StartUp.bCPUThread = netplay_settings.m_CPUthread;
StartUp.bEnableCheats = netplay_settings.m_EnableCheats;
StartUp.bDSPHLE = netplay_settings.m_DSPHLE;
StartUp.bEnableMemcardSdWriting = netplay_settings.m_WriteToMemcard;
StartUp.bCopyWiiSaveNetplay = netplay_settings.m_CopyWiiSave;
StartUp.cpu_core = netplay_settings.m_CPUcore;
StartUp.SelectedLanguage = netplay_settings.m_SelectedLanguage;
StartUp.bOverrideGCLanguage = netplay_settings.m_OverrideGCLanguage;
StartUp.m_DSPEnableJIT = netplay_settings.m_DSPEnableJIT;
StartUp.m_OCEnable = netplay_settings.m_OCEnable;
StartUp.m_OCFactor = netplay_settings.m_OCFactor;
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[1] = true;
}
@@ -16,7 +16,7 @@ namespace ConfigLoaders
class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader
{
public:
explicit NetPlayConfigLayerLoader(const NetSettings& settings)
explicit NetPlayConfigLayerLoader(const NetPlay::NetSettings& settings)
: ConfigLayerLoader(Config::LayerType::Netplay), m_settings(settings)
{
}
@@ -47,11 +47,12 @@ class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader
}
private:
const NetSettings m_settings;
const NetPlay::NetSettings m_settings;
};
// 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);
}
@@ -6,14 +6,18 @@
#include <memory>
struct NetSettings;
namespace Config
{
class ConfigLayerLoader;
}
namespace NetPlay
{
struct NetSettings;
}
namespace ConfigLoaders
{
std::unique_ptr<Config::ConfigLayerLoader> GenerateNetPlayConfigLoader(const NetSettings& settings);
std::unique_ptr<Config::ConfigLayerLoader>
GenerateNetPlayConfigLoader(const NetPlay::NetSettings& settings);
}
@@ -122,7 +122,7 @@ void SetIsThrottlerTempDisabled(bool disable)
void FrameUpdateOnCPUThread()
{
if (NetPlay::IsNetPlayRunning())
NetPlayClient::SendTimeBase();
NetPlay::NetPlayClient::SendTimeBase();
}
// Display messages and return values
@@ -41,6 +41,8 @@
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/VideoConfig.h"
namespace NetPlay
{
static std::mutex crit_netplay_client;
static NetPlayClient* netplay_client = nullptr;
NetSettings g_NetPlaySettings;
@@ -1306,41 +1308,59 @@ const PadMappingArray& NetPlayClient::GetWiimoteMapping() const
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
// called from ---CPU--- thread
// Actual Core function which is called on every frame
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)
return netplay_client->GetNetPads(numPAD, PadStatus);
else
return false;
if (NetPlay::netplay_client)
return NetPlay::netplay_client->GetNetPads(numPAD, PadStatus);
return false;
}
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)
return netplay_client->WiimoteUpdate(wiimote, data, size, reporting_mode);
else
return false;
if (NetPlay::netplay_client)
return NetPlay::netplay_client->WiimoteUpdate(wiimote, data, size, reporting_mode);
return false;
}
// 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)
{
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
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];
}
@@ -1357,39 +1377,22 @@ bool Wiimote::NetPlay_GetButtonPress(int wiimote, bool pressed)
// also called from ---GUI--- thread when starting input recording
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)
return g_netplay_initial_rtc;
else
return 0;
if (NetPlay::netplay_client)
return NetPlay::g_netplay_initial_rtc;
return 0;
}
// called from ---CPU--- thread
// return the local pad num that should rumble given a ingame pad num
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)
return netplay_client->InGamePadToLocalPad(numPAD);
else
return numPAD;
}
if (NetPlay::netplay_client)
return NetPlay::netplay_client->InGamePadToLocalPad(numPAD);
bool NetPlay::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;
return numPAD;
}
@@ -18,6 +18,8 @@
#include "Core/NetPlayProto.h"
#include "InputCommon/GCPadStatus.h"
namespace NetPlay
{
class NetPlayUI
{
public:
@@ -186,3 +188,4 @@ class NetPlayClient : public TraversalClientClient
void NetPlay_Enable(NetPlayClient* const np);
void NetPlay_Disable();
} // namespace NetPlay
@@ -14,6 +14,8 @@ namespace PowerPC
enum class CPUCore;
}
namespace NetPlay
{
struct NetSettings
{
bool m_CPUthread;
@@ -109,7 +111,5 @@ using FrameNum = u32;
using PadMapping = s8;
using PadMappingArray = std::array<PadMapping, 4>;
namespace NetPlay
{
bool IsNetPlayRunning();
}
} // namespace NetPlay
@@ -40,6 +40,8 @@
#include <arpa/inet.h>
#endif
namespace NetPlay
{
u64 g_netplay_initial_rtc = 1272737767;
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"));
return result;
}
} // namespace NetPlay
@@ -19,8 +19,8 @@
#include "Common/TraversalClient.h"
#include "Core/NetPlayProto.h"
enum class PlayerGameStatus;
namespace NetPlay
{
class NetPlayUI;
enum class PlayerGameStatus;
@@ -124,3 +124,4 @@ class NetPlayServer : public TraversalClientClient
TraversalClient* m_traversal_client = nullptr;
NetPlayUI* m_dialog = nullptr;
};
} // namespace NetPlay
@@ -1086,10 +1086,11 @@ bool MainWindow::NetPlayJoin()
const std::string nickname = Config::Get(Config::NETPLAY_NICKNAME);
// 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,
NetTraversalConfig{Settings::Instance().GetNetPlayServer() != nullptr ? false : is_traversal,
traversal_host, traversal_port}));
NetPlay::NetTraversalConfig{is_hosting_netplay ? false : is_traversal, traversal_host,
traversal_port}));
if (!Settings::Instance().GetNetPlayClient()->IsConnected())
{
@@ -1133,8 +1134,9 @@ bool MainWindow::NetPlayHost(const QString& game_id)
host_port = Config::Get(Config::NETPLAY_LISTEN_PORT);
// Create Server
Settings::Instance().ResetNetPlayServer(new NetPlayServer(
host_port, use_upnp, NetTraversalConfig{is_traversal, traversal_host, traversal_port}));
Settings::Instance().ResetNetPlayServer(new NetPlay::NetPlayServer(
host_port, use_upnp,
NetPlay::NetTraversalConfig{is_traversal, traversal_host, traversal_port}));
if (!Settings::Instance().GetNetPlayServer()->is_connected)
{
@@ -34,9 +34,7 @@ class JITWidget;
class LogConfigWidget;
class LogWidget;
class MemoryWidget;
class NetPlayClient;
class NetPlayDialog;
class NetPlayServer;
class NetPlaySetupDialog;
class RegisterWidget;
class SearchBar;
@@ -285,7 +285,7 @@ void NetPlayDialog::OnStart()
return;
}
NetSettings settings;
NetPlay::NetSettings settings;
// Copy all relevant settings
SConfig& instance = SConfig::GetInstance();
@@ -379,7 +379,8 @@ void NetPlayDialog::UpdateGUI()
{tr("Player"), tr("Game Status"), tr("Ping"), tr("Mapping"), tr("Revision")});
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;
for (size_t i = 0; i < array.size(); i++)
{
@@ -392,8 +393,10 @@ void NetPlayDialog::UpdateGUI()
return '|' + str + '|';
};
static const std::map<PlayerGameStatus, QString> player_status{
{PlayerGameStatus::Ok, tr("OK")}, {PlayerGameStatus::NotFound, tr("Not Found")}};
static const std::map<NetPlay::PlayerGameStatus, QString> player_status{
{NetPlay::PlayerGameStatus::Ok, tr("OK")},
{NetPlay::PlayerGameStatus::NotFound, tr("Not Found")},
};
for (int i = 0; i < player_count; i++)
{
@@ -11,7 +11,6 @@
class MD5Dialog;
class GameListModel;
class NetPlayServer;
class PadMappingDialog;
class QCheckBox;
class QComboBox;
@@ -26,7 +25,7 @@ class QTableWidget;
class QTextEdit;
class QToolButton;
class NetPlayDialog : public QDialog, public NetPlayUI
class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
{
Q_OBJECT
public:
@@ -94,12 +94,13 @@ int PadMappingDialog::exec()
return QDialog::exec();
}
PadMappingArray PadMappingDialog::GetGCPadArray()
NetPlay::PadMappingArray PadMappingDialog::GetGCPadArray()
{
return m_pad_mapping;
}
PadMappingArray PadMappingDialog::GetWiimoteArray()
NetPlay::PadMappingArray PadMappingDialog::GetWiimoteArray()
{
return m_wii_mapping;
}
Oops, something went wrong.

0 comments on commit 675260b

Please sign in to comment.