// Is it time to send a pure sync to every other player ? bool CPlayer::IsTimeForPuresyncFar ( void ) { long long llTime = GetModuleTickCount64 (); if ( llTime > m_llNextFarPuresyncTime ) { int iSlowSyncRate = g_pBandwidthSettings->ZoneUpdateIntervals [ ZONE3 ]; m_llNextFarPuresyncTime = llTime + iSlowSyncRate; m_llNextFarPuresyncTime += rand () % ( 1 + iSlowSyncRate / 10 ); // Extra bit to help distribute the load // No far sync if light sync is enabled if ( g_pBandwidthSettings->bLightSyncEnabled ) { // Add stats // Record all far sync bytes/packets that would have been sent/skipped as skipped int iNumPackets = m_FarPlayerList.size (); int iNumSkipped = ( iNumPackets * iSlowSyncRate - iNumPackets * 1000 ) / 1000; g_pStats->lightsync.llSyncPacketsSkipped += iNumPackets; g_pStats->lightsync.llSyncBytesSkipped += iNumPackets * GetApproxPuresyncPacketSize (); g_pStats->lightsync.llSyncPacketsSkipped += iNumSkipped; g_pStats->lightsync.llSyncBytesSkipped += iNumSkipped * GetApproxPuresyncPacketSize (); return false; // No far sync if light sync is enabled } // Add stats int iNumPackets = m_FarPlayerList.size (); int iNumSkipped = ( iNumPackets * iSlowSyncRate - iNumPackets * 1000 ) / 1000; g_pStats->puresync.llSentPacketsByZone [ ZONE3 ] += iNumPackets; g_pStats->puresync.llSentBytesByZone [ ZONE3 ] += iNumPackets * GetApproxPuresyncPacketSize (); g_pStats->puresync.llSkippedPacketsByZone [ ZONE3 ] += iNumSkipped; g_pStats->puresync.llSkippedBytesByZone [ ZONE3 ] += iNumSkipped * GetApproxPuresyncPacketSize (); return true; } return false; }
// // Dynamically increase the interval between near sync updates depending on stuffs // bool CPlayer::IsTimeToReceiveNearSyncFrom ( CPlayer* pOther, SNearInfo& nearInfo ) { int iZone = GetSyncZone ( pOther ); int iUpdateInterval = g_pBandwidthSettings->ZoneUpdateIntervals [ iZone ]; #if MTA_DEBUG if ( m_iLastZoneDebug != iZone ) { // Calc direction from our camera to the other player const CVector& vecOtherPosition = pOther->GetPosition (); CVector vecDirToOther = pOther->GetPosition () - m_vecCamPosition; // Get distance float fDistSq = vecDirToOther.LengthSquared (); // Get angle between camera direction and direction to other vecDirToOther.Normalize (); float fDot = m_vecCamFwd.DotProduct ( &vecDirToOther ); OutputDebugLine ( SString ( "Dist:%1.0f Dot:%0.3f %s SyncTo %s zone changing: %d -> %d [Interval:%d] CamPos:%1.0f,%1.0f,%1.0f CamFwd:%1.2f,%1.2f,%1.2f " ,sqrtf ( fDistSq ) ,fDot ,pOther->GetNick () ,GetNick () ,m_iLastZoneDebug ,iZone ,iUpdateInterval ,m_vecCamPosition.fX ,m_vecCamPosition.fY ,m_vecCamPosition.fZ ,m_vecCamFwd.fX ,m_vecCamFwd.fY ,m_vecCamFwd.fZ ) ); m_iLastZoneDebug = iZone; } #endif long long llTimeNow = GetModuleTickCount64 (); long long llNextUpdateTime = nearInfo.llLastUpdateTime + iUpdateInterval; if ( llNextUpdateTime > llTimeNow ) { g_pStats->puresync.llSkippedPacketsByZone[ iZone ]++; return false; } nearInfo.llLastUpdateTime = llTimeNow; g_pStats->puresync.llSentPacketsByZone[ iZone ]++; return true; }