From e7d237f199be77141d21f11198d6d6e2ab5bae50 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Sun, 8 Mar 2015 08:21:03 -0400 Subject: [PATCH] Use system time for start time in netplay. --- Source/Core/Core/HW/EXI_DeviceIPL.cpp | 14 ++++++++------ Source/Core/Core/HW/EXI_DeviceIPL.h | 2 +- Source/Core/Core/NetPlayClient.cpp | 7 +++++-- Source/Core/Core/NetPlayProto.h | 2 +- Source/Core/Core/NetPlayServer.cpp | 7 ++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI_DeviceIPL.cpp index 7533c4f154..fbb89a20b7 100644 --- a/Source/Core/Core/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI_DeviceIPL.cpp @@ -12,6 +12,7 @@ #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/Movie.h" +#include "Core/NetPlayProto.h" #include "Core/HW/EXI_DeviceIPL.h" #include "Core/HW/SystemTimers.h" @@ -345,15 +346,16 @@ u32 CEXIIPL::GetGCTime() // let's keep time moving forward, regardless of what it starts at ltime += CoreTiming::GetTicks() / SystemTimers::GetTicksPerSecond(); } - else + else if (NetPlay::IsNetPlayRunning()) { - // hack in some netplay stuff ltime = NetPlay_GetGCTime(); - if (0 == ltime) - ltime = Common::Timer::GetLocalTimeSinceJan1970(); - else - ltime += CoreTiming::GetTicks() / SystemTimers::GetTicksPerSecond(); + // let's keep time moving forward, regardless of what it starts at + ltime += CoreTiming::GetTicks() / SystemTimers::GetTicksPerSecond(); + } + else + { + ltime = Common::Timer::GetLocalTimeSinceJan1970(); } return ((u32)ltime - cJanuary2000); diff --git a/Source/Core/Core/HW/EXI_DeviceIPL.h b/Source/Core/Core/HW/EXI_DeviceIPL.h index 87eb443d84..cb8097ea59 100644 --- a/Source/Core/Core/HW/EXI_DeviceIPL.h +++ b/Source/Core/Core/HW/EXI_DeviceIPL.h @@ -20,7 +20,7 @@ public: void DoState(PointerWrap &p) override; static u32 GetGCTime(); - static u32 NetPlay_GetGCTime(); + static u64 NetPlay_GetGCTime(); static void Descrambler(u8* data, u32 size); diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 6fcbd6c70f..d49b2babf9 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -382,7 +382,10 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) packet >> tmp; g_NetPlaySettings.m_EXIDevice[1] = (TEXIDevices)tmp; - packet >> g_netplay_initial_gctime; + u32 x, y; + packet >> x; + packet >> y; + g_netplay_initial_gctime = x | ((u64)y >> 32); } m_dialog->OnMsgStartGame(); @@ -1061,7 +1064,7 @@ bool WiimoteEmu::Wiimote::NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size) // called from ---CPU--- thread // so all players' games get the same time -u32 CEXIIPL::NetPlay_GetGCTime() +u64 CEXIIPL::NetPlay_GetGCTime() { std::lock_guard lk(crit_netplay_client); diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index 8017933149..84904082e3 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -32,7 +32,7 @@ typedef std::vector NetWiimote; #define NETPLAY_VERSION "Dolphin NetPlay 2014-01-08" -extern int g_netplay_initial_gctime; +extern u64 g_netplay_initial_gctime; // messages enum diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 79acbb6918..177d9f9d54 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -20,7 +20,7 @@ #include #endif -int g_netplay_initial_gctime = 1272737767; +u64 g_netplay_initial_gctime = 1272737767; NetPlayServer::~NetPlayServer() { @@ -648,7 +648,7 @@ bool NetPlayServer::StartGame() // no change, just update with clients AdjustPadBufferSize(m_target_buffer_size); - g_netplay_initial_gctime = CEXIIPL::GetGCTime(); + g_netplay_initial_gctime = Common::Timer::GetLocalTimeSinceJan1970(); // tell clients to start game sf::Packet spac; @@ -663,7 +663,8 @@ bool NetPlayServer::StartGame() spac << m_settings.m_OCFactor; spac << m_settings.m_EXIDevice[0]; spac << m_settings.m_EXIDevice[1]; - spac << g_netplay_initial_gctime; + spac << (u32)g_netplay_initial_gctime; + spac << (u32)g_netplay_initial_gctime << 32; std::lock_guard lkp(m_crit.players); std::lock_guard lks(m_crit.send);