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.
This commit is contained in:
Lioncash 2018-07-09 15:52:31 -04:00
parent 68731995b5
commit f209f5f2a4
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7
4 changed files with 36 additions and 20 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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