diff options
| author | Lioncash <mathew1800@gmail.com> | 2018-07-09 15:52:31 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2018-07-12 13:55:41 -0400 |
| commit | f209f5f2a45cd1c8eb1fa0fa04533fd17a7b3ed8 (patch) | |
| tree | 17b076d0690ff3a0770599cdb9a9644c666c3015 /Source | |
| parent | 68731995b543e0f434de495441f3b405fca10ea1 (diff) | |
NetPlayClient: Make the NetSettings instance part of the NetPlayClient class
This is only ever read from externally, so we can expose a getter that ensures that
immutability, while making the actual instance internal. Given the
filling out of these settings depends on packets received by the client
instance, it makes more sense to make it a part of the client itself.
This trims off one lingering global.
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Core/BootManager.cpp | 2 | ||||
| -rw-r--r-- | Source/Core/Core/NetPlayClient.cpp | 47 | ||||
| -rw-r--r-- | Source/Core/Core/NetPlayClient.h | 2 | ||||
| -rw-r--r-- | Source/Core/Core/NetPlayProto.h | 5 |
4 files changed, 36 insertions, 20 deletions
diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 030674009d..80ee9f7348 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -336,7 +336,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot) if (NetPlay::IsNetPlayRunning()) { - const NetPlay::NetSettings& netplay_settings = NetPlay::g_NetPlaySettings; + const NetPlay::NetSettings& netplay_settings = NetPlay::GetNetSettings(); Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(netplay_settings)); StartUp.bCPUThread = netplay_settings.m_CPUthread; StartUp.bEnableCheats = netplay_settings.m_EnableCheats; diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 1051e48855..83a0aa0938 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -16,6 +16,7 @@ #include <mbedtls/md5.h> +#include "Common/Assert.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/ENetUtil.h" @@ -46,7 +47,6 @@ namespace NetPlay { static std::mutex crit_netplay_client; static NetPlayClient* netplay_client = nullptr; -NetSettings g_NetPlaySettings; // called from ---GUI--- thread NetPlayClient::~NetPlayClient() @@ -436,36 +436,36 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) { std::lock_guard<std::recursive_mutex> lkg(m_crit.game); packet >> m_current_game; - packet >> g_NetPlaySettings.m_CPUthread; + packet >> m_net_settings.m_CPUthread; INFO_LOG(NETPLAY, "Start of game %s", m_selected_game.c_str()); { std::underlying_type_t<PowerPC::CPUCore> core; if (packet >> core) - g_NetPlaySettings.m_CPUcore = static_cast<PowerPC::CPUCore>(core); + m_net_settings.m_CPUcore = static_cast<PowerPC::CPUCore>(core); else - g_NetPlaySettings.m_CPUcore = PowerPC::CPUCore::CachedInterpreter; + m_net_settings.m_CPUcore = PowerPC::CPUCore::CachedInterpreter; } - packet >> g_NetPlaySettings.m_EnableCheats; - packet >> g_NetPlaySettings.m_SelectedLanguage; - packet >> g_NetPlaySettings.m_OverrideGCLanguage; - packet >> g_NetPlaySettings.m_ProgressiveScan; - packet >> g_NetPlaySettings.m_PAL60; - packet >> g_NetPlaySettings.m_DSPEnableJIT; - packet >> g_NetPlaySettings.m_DSPHLE; - packet >> g_NetPlaySettings.m_WriteToMemcard; - packet >> g_NetPlaySettings.m_CopyWiiSave; - packet >> g_NetPlaySettings.m_OCEnable; - packet >> g_NetPlaySettings.m_OCFactor; - packet >> g_NetPlaySettings.m_ReducePollingRate; + packet >> m_net_settings.m_EnableCheats; + packet >> m_net_settings.m_SelectedLanguage; + packet >> m_net_settings.m_OverrideGCLanguage; + packet >> m_net_settings.m_ProgressiveScan; + packet >> m_net_settings.m_PAL60; + packet >> m_net_settings.m_DSPEnableJIT; + packet >> m_net_settings.m_DSPHLE; + packet >> m_net_settings.m_WriteToMemcard; + packet >> m_net_settings.m_CopyWiiSave; + packet >> m_net_settings.m_OCEnable; + packet >> m_net_settings.m_OCFactor; + packet >> m_net_settings.m_ReducePollingRate; int tmp; packet >> tmp; - g_NetPlaySettings.m_EXIDevice[0] = static_cast<ExpansionInterface::TEXIDevices>(tmp); + m_net_settings.m_EXIDevice[0] = static_cast<ExpansionInterface::TEXIDevices>(tmp); packet >> tmp; - g_NetPlaySettings.m_EXIDevice[1] = static_cast<ExpansionInterface::TEXIDevices>(tmp); + m_net_settings.m_EXIDevice[1] = static_cast<ExpansionInterface::TEXIDevices>(tmp); u32 time_low, time_high; packet >> time_low; @@ -791,6 +791,11 @@ std::vector<const Player*> NetPlayClient::GetPlayers() return players; } +const NetSettings& NetPlayClient::GetNetSettings() const +{ + return m_net_settings; +} + // called from ---GUI--- thread void NetPlayClient::SendChatMessage(const std::string& msg) { @@ -1347,6 +1352,12 @@ bool IsNetPlayRunning() return netplay_client != nullptr; } +const NetSettings& GetNetSettings() +{ + ASSERT(IsNetPlayRunning()); + return netplay_client->GetNetSettings(); +} + void NetPlay_Enable(NetPlayClient* const np) { std::lock_guard<std::mutex> lk(crit_netplay_client); diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 464337b9ea..5306c0f369 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -75,6 +75,7 @@ public: void GetPlayerList(std::string& list, std::vector<int>& pid_list); std::vector<const Player*> GetPlayers(); + const NetSettings& GetNetSettings() const; // Called from the GUI thread. bool IsConnected() const { return m_is_connected; } @@ -173,6 +174,7 @@ private: ConnectionState m_connection_state = ConnectionState::Failure; PlayerId m_pid = 0; + NetSettings m_net_settings{}; std::map<PlayerId, Player> m_players; std::string m_host_spec; std::string m_player_name; diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index dc582d3df8..b6eaad0dfa 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -49,7 +49,6 @@ struct NetTraversalConfig u16 traversal_port = 0; }; -extern NetSettings g_NetPlaySettings; extern u64 g_netplay_initial_rtc; struct Rpt : public std::vector<u8> @@ -112,4 +111,8 @@ using PadMapping = s8; using PadMappingArray = std::array<PadMapping, 4>; bool IsNetPlayRunning(); + +// Precondition: A netplay client instance must be present. In other words, +// IsNetPlayRunning() must be true before calling this. +const NetSettings& GetNetSettings(); } // namespace NetPlay |
