NetPlayServer: Make g_initial_netplay_rtc a member variable of NetPlayClient

Behaviorally, this belongs within the netplay client. The server will
always transmit a known RTC value, so it doesn't even need a global for
this. Given the client receives the packet containing said RTC value, we can
store it as a member variable and provide an accessor for reading that
value.

This removes another global variable within the netplay code.
This commit is contained in:
Lioncash 2018-07-14 18:55:17 -04:00
parent 72d5ff54f3
commit ac1b48497e
5 changed files with 24 additions and 11 deletions

View File

@ -528,7 +528,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
packet >> m_net_settings.m_EnableGPUTextureDecoding; packet >> m_net_settings.m_EnableGPUTextureDecoding;
packet >> m_net_settings.m_StrictSettingsSync; packet >> m_net_settings.m_StrictSettingsSync;
g_netplay_initial_rtc = Common::PacketReadU64(packet); m_initial_rtc = Common::PacketReadU64(packet);
packet >> m_net_settings.m_SyncSaveData; packet >> m_net_settings.m_SyncSaveData;
packet >> m_net_settings.m_SaveDataRegion; packet >> m_net_settings.m_SaveDataRegion;
@ -1454,6 +1454,11 @@ bool NetPlayClient::GetNetPads(const int pad_nb, GCPadStatus* pad_status)
return true; return true;
} }
u64 NetPlayClient::GetInitialRTCValue() const
{
return m_initial_rtc;
}
// called from ---CPU--- thread // called from ---CPU--- thread
bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode) bool NetPlayClient::WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode)
{ {
@ -1811,7 +1816,7 @@ u64 ExpansionInterface::CEXIIPL::NetPlay_GetEmulatedTime()
std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client); std::lock_guard<std::mutex> lk(NetPlay::crit_netplay_client);
if (NetPlay::netplay_client) if (NetPlay::netplay_client)
return NetPlay::g_netplay_initial_rtc; return NetPlay::netplay_client->GetInitialRTCValue();
return 0; return 0;
} }

View File

@ -102,6 +102,8 @@ public:
bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode); bool WiimoteUpdate(int _number, u8* data, const u8 size, u8 reporting_mode);
bool GetNetPads(int pad_nb, GCPadStatus* pad_status); bool GetNetPads(int pad_nb, GCPadStatus* pad_status);
u64 GetInitialRTCValue() const;
void OnTraversalStateChanged() override; void OnTraversalStateChanged() override;
void OnConnectReady(ENetAddress addr) override; void OnConnectReady(ENetAddress addr) override;
void OnConnectFailed(u8 reason) override; void OnConnectFailed(u8 reason) override;
@ -203,6 +205,7 @@ private:
u8 m_sync_save_data_count = 0; u8 m_sync_save_data_count = 0;
u8 m_sync_save_data_success_count = 0; u8 m_sync_save_data_success_count = 0;
u64 m_initial_rtc = 0;
u32 m_timebase_frame = 0; u32 m_timebase_frame = 0;
}; };

View File

@ -94,8 +94,6 @@ struct NetTraversalConfig
u16 traversal_port = 0; u16 traversal_port = 0;
}; };
extern u64 g_netplay_initial_rtc;
struct Rpt : public std::vector<u8> struct Rpt : public std::vector<u8>
{ {
u16 channel; u16 channel;

View File

@ -56,8 +56,6 @@
namespace NetPlay namespace NetPlay
{ {
u64 g_netplay_initial_rtc = 1272737767;
NetPlayServer::~NetPlayServer() NetPlayServer::~NetPlayServer()
{ {
if (is_connected) if (is_connected)
@ -908,10 +906,7 @@ bool NetPlayServer::StartGame()
// no change, just update with clients // no change, just update with clients
AdjustPadBufferSize(m_target_buffer_size); AdjustPadBufferSize(m_target_buffer_size);
if (SConfig::GetInstance().bEnableCustomRTC) const u64 initial_rtc = GetInitialNetPlayRTC();
g_netplay_initial_rtc = SConfig::GetInstance().m_customRTCValue;
else
g_netplay_initial_rtc = Common::Timer::GetLocalTimeSinceJan1970();
const std::string region = SConfig::GetDirectoryForRegion( const std::string region = SConfig::GetDirectoryForRegion(
SConfig::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game)->GetRegion())); SConfig::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game)->GetRegion()));
@ -974,7 +969,7 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_ArbitraryMipmapDetectionThreshold; spac << m_settings.m_ArbitraryMipmapDetectionThreshold;
spac << m_settings.m_EnableGPUTextureDecoding; spac << m_settings.m_EnableGPUTextureDecoding;
spac << m_settings.m_StrictSettingsSync; spac << m_settings.m_StrictSettingsSync;
Common::PacketWriteU64(spac, g_netplay_initial_rtc); Common::PacketWriteU64(spac, initial_rtc);
spac << m_settings.m_SyncSaveData; spac << m_settings.m_SyncSaveData;
spac << region; spac << region;
@ -1289,6 +1284,16 @@ bool NetPlayServer::CompressBufferIntoPacket(const std::vector<u8>& in_buffer, s
return true; return true;
} }
u64 NetPlayServer::GetInitialNetPlayRTC() const
{
const auto& config = SConfig::GetInstance();
if (config.bEnableCustomRTC)
return config.m_customRTCValue;
return Common::Timer::GetLocalTimeSinceJan1970();
}
// called from multiple threads // called from multiple threads
void NetPlayServer::SendToClients(const sf::Packet& packet, const PlayerId skip_pid) void NetPlayServer::SendToClients(const sf::Packet& packet, const PlayerId skip_pid)
{ {

View File

@ -85,6 +85,8 @@ private:
bool CompressFileIntoPacket(const std::string& file_path, sf::Packet& packet); bool CompressFileIntoPacket(const std::string& file_path, sf::Packet& packet);
bool CompressBufferIntoPacket(const std::vector<u8>& in_buffer, sf::Packet& packet); bool CompressBufferIntoPacket(const std::vector<u8>& in_buffer, sf::Packet& packet);
u64 GetInitialNetPlayRTC() const;
void SendToClients(const sf::Packet& packet, const PlayerId skip_pid = 0); void SendToClients(const sf::Packet& packet, const PlayerId skip_pid = 0);
void Send(ENetPeer* socket, const sf::Packet& packet); void Send(ENetPeer* socket, const sf::Packet& packet);
unsigned int OnConnect(ENetPeer* socket); unsigned int OnConnect(ENetPeer* socket);