|
|
|
@ -133,9 +133,7 @@ plNetClientMgr::plNetClientMgr() :
|
|
|
|
|
// fProgressBar( nil ),
|
|
|
|
|
fTaskProgBar( nil ), |
|
|
|
|
fMsgRecorder(nil), |
|
|
|
|
fServerTimeOffset(0), |
|
|
|
|
fTimeSamples(0), |
|
|
|
|
fLastTimeUpdate(0), |
|
|
|
|
fLastLocalTime(),
|
|
|
|
|
fListenListMode(kListenList_Distance), |
|
|
|
|
fAgeSDLObjectKey(nil), |
|
|
|
|
fExperimentalLevel(0), |
|
|
|
@ -480,34 +478,23 @@ void plNetClientMgr::StartLinkInFX()
|
|
|
|
|
//
|
|
|
|
|
void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg) |
|
|
|
|
{ |
|
|
|
|
if ((hsTimer::GetSysSeconds() - fLastTimeUpdate) > 5) |
|
|
|
|
{ |
|
|
|
|
fLastTimeUpdate = hsTimer::GetSysSeconds(); |
|
|
|
|
|
|
|
|
|
const plUnifiedTime& msgSentUT = msg->GetTimeSent(); |
|
|
|
|
if (!msgSentUT.AtEpoch()) |
|
|
|
|
{ |
|
|
|
|
double diff = plUnifiedTime::GetTimeDifference(msgSentUT, plClientUnifiedTime::GetCurrentTime()); |
|
|
|
|
if (!msg->GetHasTimeSent()) |
|
|
|
|
return; |
|
|
|
|
if (msg->GetTimeSent().AtEpoch()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (fServerTimeOffset == 0) |
|
|
|
|
{ |
|
|
|
|
fServerTimeOffset = diff; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
fServerTimeOffset = fServerTimeOffset + ((diff - fServerTimeOffset) / ++fTimeSamples); |
|
|
|
|
} |
|
|
|
|
double localTime = hsTimer::GetSeconds(); |
|
|
|
|
if (localTime - fLastLocalTime < 1.0) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
DebugMsg("Setting server time offset to %f", fServerTimeOffset); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fLastServerTime = msg->GetTimeSent(); |
|
|
|
|
fLastLocalTime = localTime; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void plNetClientMgr::ResetServerTimeOffset() |
|
|
|
|
{ |
|
|
|
|
fServerTimeOffset = 0; |
|
|
|
|
fTimeSamples = 0; |
|
|
|
|
fLastTimeUpdate = 0; |
|
|
|
|
fLastServerTime.ToEpoch(); |
|
|
|
|
fLastLocalTime = 0.0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -515,14 +502,12 @@ void plNetClientMgr::ResetServerTimeOffset()
|
|
|
|
|
//
|
|
|
|
|
plUnifiedTime plNetClientMgr::GetServerTime() const
|
|
|
|
|
{
|
|
|
|
|
if ( fServerTimeOffset==0 ) // offline mode or before connecting/calibrating to a server
|
|
|
|
|
if (fLastServerTime.AtEpoch()) { |
|
|
|
|
WarningMsg("Someone asked for the server time, but we don't know it yet!"); |
|
|
|
|
return plUnifiedTime::GetCurrentTime(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
plUnifiedTime serverUT; |
|
|
|
|
if (fServerTimeOffset<0) |
|
|
|
|
return plUnifiedTime::GetCurrentTime() - plUnifiedTime(fabs(fServerTimeOffset));
|
|
|
|
|
else |
|
|
|
|
return plUnifiedTime::GetCurrentTime() + plUnifiedTime(fServerTimeOffset);
|
|
|
|
|
return fLastServerTime + plUnifiedTime(hsTimer::GetSeconds() - fLastLocalTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|