Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #7226 from lioncash/netplay
Core: Namespace NetPlay utilities under the NetPlay namespace
  • Loading branch information
lioncash committed Jul 9, 2018
2 parents 8c97fb7 + 675260b commit 9487892
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
Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/ConfigLoaders/NetPlayConfigLoader.cpp
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/Core/ConfigLoaders/NetPlayConfigLoader.h
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.cpp
Expand Up @@ -122,7 +122,7 @@ void SetIsThrottlerTempDisabled(bool disable)
void FrameUpdateOnCPUThread()
{
if (NetPlay::IsNetPlayRunning())
NetPlayClient::SendTimeBase();
NetPlay::NetPlayClient::SendTimeBase();
}

// Display messages and return values
Expand Down
81 changes: 42 additions & 39 deletions Source/Core/Core/NetPlayClient.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand All @@ -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;
}
3 changes: 3 additions & 0 deletions Source/Core/Core/NetPlayClient.h
Expand Up @@ -18,6 +18,8 @@
#include "Core/NetPlayProto.h"
#include "InputCommon/GCPadStatus.h"

namespace NetPlay
{
class NetPlayUI
{
public:
Expand Down Expand Up @@ -186,3 +188,4 @@ class NetPlayClient : public TraversalClientClient

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

namespace NetPlay
{
struct NetSettings
{
bool m_CPUthread;
Expand Down Expand Up @@ -109,7 +111,5 @@ using FrameNum = u32;
using PadMapping = s8;
using PadMappingArray = std::array<PadMapping, 4>;

namespace NetPlay
{
bool IsNetPlayRunning();
}
} // namespace NetPlay
3 changes: 3 additions & 0 deletions Source/Core/Core/NetPlayServer.cpp
Expand Up @@ -40,6 +40,8 @@
#include <arpa/inet.h>
#endif

namespace NetPlay
{
u64 g_netplay_initial_rtc = 1272737767;

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"));
return result;
}
} // namespace NetPlay
5 changes: 3 additions & 2 deletions Source/Core/Core/NetPlayServer.h
Expand Up @@ -19,8 +19,8 @@
#include "Common/TraversalClient.h"
#include "Core/NetPlayProto.h"

enum class PlayerGameStatus;

namespace NetPlay
{
class NetPlayUI;
enum class PlayerGameStatus;

Expand Down Expand Up @@ -124,3 +124,4 @@ class NetPlayServer : public TraversalClientClient
TraversalClient* m_traversal_client = nullptr;
NetPlayUI* m_dialog = nullptr;
};
} // namespace NetPlay
12 changes: 7 additions & 5 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -1087,10 +1087,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())
{
Expand Down Expand Up @@ -1134,8 +1135,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)
{
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/DolphinQt/MainWindow.h
Expand Up @@ -34,9 +34,7 @@ class JITWidget;
class LogConfigWidget;
class LogWidget;
class MemoryWidget;
class NetPlayClient;
class NetPlayDialog;
class NetPlayServer;
class NetPlaySetupDialog;
class RegisterWidget;
class SearchBar;
Expand Down
11 changes: 7 additions & 4 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Expand Up @@ -285,7 +285,7 @@ void NetPlayDialog::OnStart()
return;
}

NetSettings settings;
NetPlay::NetSettings settings;

// Copy all relevant settings
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")});
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++)
{
Expand All @@ -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++)
{
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.h
Expand Up @@ -11,7 +11,6 @@

class MD5Dialog;
class GameListModel;
class NetPlayServer;
class PadMappingDialog;
class QCheckBox;
class QComboBox;
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/NetPlay/PadMappingDialog.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9487892

Please sign in to comment.