Skip to content

Commit

Permalink
Merge pull request #2183 from RachelBryk/netplay-time
Browse files Browse the repository at this point in the history
Use system time for start time in netplay.
  • Loading branch information
skidau committed Mar 18, 2015
2 parents 4b7748f + e7d237f commit 0ac8fd0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
14 changes: 8 additions & 6 deletions Source/Core/Core/HW/EXI_DeviceIPL.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI_DeviceIPL.h
Expand Up @@ -20,7 +20,7 @@ class CEXIIPL : public IEXIDevice
void DoState(PointerWrap &p) override;

static u32 GetGCTime();
static u32 NetPlay_GetGCTime();
static u64 NetPlay_GetGCTime();

static void Descrambler(u8* data, u32 size);

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/Core/NetPlayClient.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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<std::mutex> lk(crit_netplay_client);

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/NetPlayProto.h
Expand Up @@ -32,7 +32,7 @@ typedef std::vector<u8> NetWiimote;

#define NETPLAY_VERSION "Dolphin NetPlay 2014-01-08"

extern int g_netplay_initial_gctime;
extern u64 g_netplay_initial_gctime;

// messages
enum
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/Core/NetPlayServer.cpp
Expand Up @@ -20,7 +20,7 @@
#include <arpa/inet.h>
#endif

int g_netplay_initial_gctime = 1272737767;
u64 g_netplay_initial_gctime = 1272737767;

NetPlayServer::~NetPlayServer()
{
Expand Down Expand Up @@ -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;
Expand All @@ -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<std::recursive_mutex> lkp(m_crit.players);
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
Expand Down

0 comments on commit 0ac8fd0

Please sign in to comment.