Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CLagCompensationManager::StartLagCompensation( CBasePlayer *player, CUserCmd *cmd )
- {
- // Assume no players need to be restored
- m_RestorePlayer.ClearAll();
- m_bNeedToRestore = false;
- m_pCurrentPlayer = player;
- if ( !player->m_bLagCompensation // Player not wanting lag compensation
- || (gpGlobals->maxClients <= 1) // no lag compensation in single player
- || !sv_unlag.GetBool() // disabled by server admin
- || player->IsBot() // not for bots
- || player->IsObserver() // not for spectators
- )
- return;
- // NOTE: Put this here so that it won't show up in single player mode.
- VPROF_BUDGET( "StartLagCompensation", VPROF_BUDGETGROUP_OTHER_NETWORKING );
- Q_memset( m_RestoreData, 0, sizeof( m_RestoreData ) );
- Q_memset( m_ChangeData, 0, sizeof( m_ChangeData ) );
- // Get true latency
- // correct is the amout of time we have to correct game time
- float correct = 0.0f;
- INetChannelInfo *nci = engine->GetPlayerNetInfo( player->entindex() );
- if ( nci )
- {
- // add network latency
- correct+= nci->GetLatency( FLOW_OUTGOING );
- }
- // calc number of view interpolation ticks - 1
- int lerpTicks = TIME_TO_TICKS( player->m_fLerpTime );
- // add view interpolation latency see C_BaseEntity::GetInterpolationAmount()
- correct += TICKS_TO_TIME( lerpTicks );
- // check bouns [0,sv_maxunlag]
- correct = clamp( correct, 0.0f, sv_maxunlag.GetFloat() );
- // correct tick send by player
- int targettick = cmd->tick_count - lerpTicks;
- // calc difference between tick send by player and our latency based tick
- float deltaTime = correct - TICKS_TO_TIME(gpGlobals->tickcount - targettick);
- if ( fabs( deltaTime ) > 0.2f )
- {
- // difference between cmd time and latency is too big > 200ms, use time correction based on latency
- // DevMsg("StartLagCompensation: delta too big (%.3f)\n", deltaTime );
- targettick = gpGlobals->tickcount - TIME_TO_TICKS( correct );
- }
- // Iterate all active players
- const CBitVec<MAX_EDICTS> *pEntityTransmitBits = engine->GetEntityTransmitBitsForClient( player->entindex() - 1 );
- for ( int i = 1; i <= gpGlobals->maxClients; i++ )
- {
- CBasePlayer *pPlayer = UTIL_PlayerByIndex( i );
- if ( !pPlayer )
- {
- continue;
- }
- // Don't lag compensate yourself you loser...
- if ( player == pPlayer )
- {
- continue;
- }
- // Custom checks for if things should lag compensate (based on things like what team the player is on).
- if ( !player->WantsLagCompensationOnEntity( pPlayer, cmd, pEntityTransmitBits ) )
- continue;
- // Move other player back in time
- BacktrackPlayer( pPlayer, TICKS_TO_TIME( targettick ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement