Skip to content

Commit

Permalink
Core: Namespace NetPlay utilities under the NetPlay namespace
Browse files Browse the repository at this point in the history
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 675260b
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 97 deletions.
29 changes: 15 additions & 14 deletions Source/Core/Core/BootManager.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
} }
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/ConfigLoaders/NetPlayConfigLoader.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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)
{ {
} }
Expand Down Expand Up @@ -47,11 +47,12 @@ class NetPlayConfigLayerLoader final : public Config::ConfigLayerLoader
} }


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);
} }
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/Core/ConfigLoaders/NetPlayConfigLoader.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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);
} }
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 42 additions & 39 deletions Source/Core/Core/NetPlayClient.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
} }
Expand All @@ -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;
} }
3 changes: 3 additions & 0 deletions Source/Core/Core/NetPlayClient.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -186,3 +188,4 @@ class NetPlayClient : public TraversalClientClient


void NetPlay_Enable(NetPlayClient* const np); void NetPlay_Enable(NetPlayClient* const np);
void NetPlay_Disable(); void NetPlay_Disable();
} // namespace NetPlay
6 changes: 3 additions & 3 deletions Source/Core/Core/NetPlayProto.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace PowerPC
enum class CPUCore; enum class CPUCore;
} }


namespace NetPlay
{
struct NetSettings struct NetSettings
{ {
bool m_CPUthread; bool m_CPUthread;
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions Source/Core/Core/NetPlayServer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions Source/Core/Core/NetPlayServer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -124,3 +124,4 @@ class NetPlayServer : public TraversalClientClient
TraversalClient* m_traversal_client = nullptr; TraversalClient* m_traversal_client = nullptr;
NetPlayUI* m_dialog = nullptr; NetPlayUI* m_dialog = nullptr;
}; };
} // namespace NetPlay
12 changes: 7 additions & 5 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1086,10 +1086,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())
{ {
Expand Down Expand Up @@ -1133,8 +1134,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)
{ {
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DolphinQt/MainWindow.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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++)
{ {
Expand All @@ -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++)
{ {
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/NetPlay/PadMappingDialog.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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;
} }
Expand Down
Loading

0 comments on commit 675260b

Please sign in to comment.