|
|
@ -133,9 +133,7 @@ plNetClientMgr::plNetClientMgr() : |
|
|
|
// fProgressBar( nil ),
|
|
|
|
// fProgressBar( nil ),
|
|
|
|
fTaskProgBar( nil ), |
|
|
|
fTaskProgBar( nil ), |
|
|
|
fMsgRecorder(nil), |
|
|
|
fMsgRecorder(nil), |
|
|
|
fServerTimeOffset(0), |
|
|
|
fLastLocalTime(),
|
|
|
|
fTimeSamples(0), |
|
|
|
|
|
|
|
fLastTimeUpdate(0), |
|
|
|
|
|
|
|
fListenListMode(kListenList_Distance), |
|
|
|
fListenListMode(kListenList_Distance), |
|
|
|
fAgeSDLObjectKey(nil), |
|
|
|
fAgeSDLObjectKey(nil), |
|
|
|
fExperimentalLevel(0), |
|
|
|
fExperimentalLevel(0), |
|
|
@ -480,34 +478,23 @@ void plNetClientMgr::StartLinkInFX() |
|
|
|
//
|
|
|
|
//
|
|
|
|
void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg) |
|
|
|
void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ((hsTimer::GetSysSeconds() - fLastTimeUpdate) > 5) |
|
|
|
if (!msg->GetHasTimeSent()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
fLastTimeUpdate = hsTimer::GetSysSeconds(); |
|
|
|
if (msg->GetTimeSent().AtEpoch()) |
|
|
|
|
|
|
|
return; |
|
|
|
const plUnifiedTime& msgSentUT = msg->GetTimeSent(); |
|
|
|
|
|
|
|
if (!msgSentUT.AtEpoch()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
double diff = plUnifiedTime::GetTimeDifference(msgSentUT, plClientUnifiedTime::GetCurrentTime()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fServerTimeOffset == 0) |
|
|
|
double localTime = hsTimer::GetSeconds(); |
|
|
|
{ |
|
|
|
if (localTime - fLastLocalTime < 1.0) |
|
|
|
fServerTimeOffset = diff; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fServerTimeOffset = fServerTimeOffset + ((diff - fServerTimeOffset) / ++fTimeSamples); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DebugMsg("Setting server time offset to %f", fServerTimeOffset); |
|
|
|
fLastServerTime = msg->GetTimeSent(); |
|
|
|
} |
|
|
|
fLastLocalTime = localTime; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void plNetClientMgr::ResetServerTimeOffset() |
|
|
|
void plNetClientMgr::ResetServerTimeOffset() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fServerTimeOffset = 0; |
|
|
|
fLastServerTime.ToEpoch(); |
|
|
|
fTimeSamples = 0; |
|
|
|
fLastLocalTime = 0.0; |
|
|
|
fLastTimeUpdate = 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -515,14 +502,12 @@ void plNetClientMgr::ResetServerTimeOffset() |
|
|
|
//
|
|
|
|
//
|
|
|
|
plUnifiedTime plNetClientMgr::GetServerTime() const
|
|
|
|
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(); |
|
|
|
return plUnifiedTime::GetCurrentTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
plUnifiedTime serverUT; |
|
|
|
return fLastServerTime + plUnifiedTime(hsTimer::GetSeconds() - fLastLocalTime); |
|
|
|
if (fServerTimeOffset<0) |
|
|
|
|
|
|
|
return plUnifiedTime::GetCurrentTime() - plUnifiedTime(fabs(fServerTimeOffset));
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return plUnifiedTime::GetCurrentTime() + plUnifiedTime(fServerTimeOffset);
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|