Guest User

interp

a guest
Nov 20th, 2015
1,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.56 KB | None | 0 0
  1. int CBaseEntity::BaseInterpolatePart1( float &currentTime, Vector &oldOrigin, QAngle &oldAngles, int &bNoMoreChanges )
  2. {
  3.     // Don't mess with the world!!!
  4.     bNoMoreChanges = 1;
  5.    
  6.  
  7.     // These get moved to the parent position automatically
  8.     if ( IsFollowingEntity() || !IsInterpolationEnabled() )
  9.     {
  10.         // Assume current origin ( no interpolation )
  11.         MoveToLastReceivedPosition();
  12.         return INTERPOLATE_STOP;
  13.     }
  14.  
  15.  
  16.     if ( GetPredictable() || IsClientCreated() )
  17.     {
  18.         C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer();
  19.         if ( localplayer && currentTime == gpGlobals->curtime )
  20.         {
  21.             currentTime = localplayer->GetFinalPredictedTime();
  22.             currentTime -= TICK_INTERVAL;
  23.             currentTime += ( gpGlobals->interpolation_amount * TICK_INTERVAL );
  24.         }
  25.     }
  26.  
  27.     oldOrigin = m_vecOrigin;
  28.     oldAngles = m_angRotation;
  29.  
  30.     bNoMoreChanges = Interp_Interpolate( GetVarMapping(), currentTime );
  31.     if ( cl_interp_all.GetInt() || (m_EntClientFlags & ENTCLIENTFLAG_ALWAYS_INTERPOLATE) )
  32.         bNoMoreChanges = 0;
  33.  
  34.     return INTERPOLATE_CONTINUE;
  35. }
  36.  
  37. void C_BaseEntity::BaseInterpolatePart2( Vector &oldOrigin, QAngle &oldAngles, int nChangeFlags )
  38. {
  39.     if ( m_vecOrigin != oldOrigin )
  40.     {
  41.         nChangeFlags |= POSITION_CHANGED;
  42.     }
  43.  
  44.     if( m_angRotation != oldAngles )
  45.     {
  46.         nChangeFlags |= ANGLES_CHANGED;
  47.     }
  48.  
  49.     if ( nChangeFlags != 0 )
  50.     {
  51.         InvalidatePhysicsRecursive( nChangeFlags );
  52.     }
  53.  
  54. #if 0
  55.     if ( IsPlayer() &&
  56.         cl_watchplayer.GetInt() == entindex() &&
  57.         C_BasePlayer::GetLocalPlayer() &&
  58.         GetTeam() == C_BasePlayer::GetLocalPlayer()->GetTeam() )
  59.     {
  60.         // SpewInterpolatedVar( &m_iv_vecOrigin, gpGlobals->curtime, GetInterpolationAmount( LATCH_SIMULATION_VAR ), false );
  61.         Vector vel;
  62.         EstimateAbsVelocity( vel );
  63.         float spd = vel.Length();
  64.  
  65.         Msg( "estimated %f\n", spd );
  66.     }
  67. #endif
  68. }
  69.  
  70. inline int C_BaseEntity::Interp_Interpolate( VarMapping_t *map, float currentTime )
  71. {
  72.     int bNoMoreChanges = 1;
  73.     if ( currentTime < map->m_lastInterpolationTime )
  74.     {
  75.         for ( int i = 0; i < map->m_nInterpolatedEntries; i++ )
  76.         {
  77.             VarMapEntry_t *e = &map->m_Entries[ i ];
  78.  
  79.             e->m_bNeedsToInterpolate = true;
  80.         }
  81.     }
  82.     map->m_lastInterpolationTime = currentTime;
  83.  
  84.     for ( int i = 0; i < map->m_nInterpolatedEntries; i++ )
  85.     {
  86.         VarMapEntry_t *e = &map->m_Entries[ i ];
  87.  
  88.         if ( !e->m_bNeedsToInterpolate )
  89.             continue;
  90.            
  91.         IInterpolatedVar *watcher = e->watcher;
  92.         Assert( !( watcher->GetType() & EXCLUDE_AUTO_INTERPOLATE ) );
  93.  
  94.  
  95.         if ( watcher->Interpolate( currentTime ) )
  96.             e->m_bNeedsToInterpolate = false;
  97.         else
  98.             bNoMoreChanges = 0;
  99.     }
  100.  
  101.     return bNoMoreChanges;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment