SHARE
TWEET

Untitled

a guest Jan 24th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool Game::FindSpanningContexts(cl_entity_t* ent, float targettime, position_history_t** newer, position_history_t** older)
  2. {
  3.     assert(newer);
  4.     assert(older);
  5.  
  6.     bool extrapolate = true;
  7.  
  8.     int imod = ent->current_position;
  9.     int i0 = (imod - 0) & HISTORY_MASK; // curpos (lerp end)
  10.     int i1 = (imod - 1) & HISTORY_MASK; // oldpos (lerp start)
  11.  
  12.     for (int i = 1; i < HISTORY_MAX - 1; i++)
  13.     {
  14.         position_history_t c1 = ent->ph[((imod - i) + 0) & HISTORY_MASK];
  15.         position_history_t c2 = ent->ph[((imod - i) + 1) & HISTORY_MASK];
  16.  
  17.         if (c1.animtime == 0.f)
  18.             break;
  19.  
  20.         if (c2.animtime >= targettime && c1.animtime <= targettime)
  21.         {
  22.             i0 = ((imod - i) + 1) & HISTORY_MASK;
  23.             i1 = ((imod - i) + 0) & HISTORY_MASK;
  24.             extrapolate = false;
  25.             break;
  26.         }
  27.     }
  28.  
  29.     if (newer) *newer = &ent->ph[i0];
  30.     if (older) *older = &ent->ph[i1];
  31.  
  32.     return extrapolate;
  33. }
  34.  
  35. bool Game::BacktrackPlayer(cl_entity_s* pGameEntity, int lerp_msec, Vector& origin)
  36. {
  37.     static cvar_t* sv_unlag = g_ClientCvarsMap["sv_unlag"];
  38.     static cvar_t* cl_lw = g_ClientCvarsMap["cl_lw"];
  39.     static cvar_t* cl_lc = g_ClientCvarsMap["cl_lc"];
  40.     static cvar_t* cl_updaterate = g_ClientCvarsMap["cl_updaterate"];
  41.     static cvar_t* sv_maxunlag = g_ClientCvarsMap["sv_maxunlag"];
  42.     static cvar_t* ex_interp = g_ClientCvarsMap["ex_interp"];
  43.     static cvar_t* sv_unlagpush = g_ClientCvarsMap["sv_unlagpush"];
  44.  
  45.     // Player not wanting lag compensation
  46.     if (!sv_unlag->value || !cl_lw->value || !cl_lc->value)
  47.         return false;
  48.  
  49.     // Get true latency
  50.     const double fakelatency = g_pMiscellaneous->m_bFakeLatencyActive ? cvars::misc.fakelatency_amount / 1000.0 : 0.0;
  51.  
  52.     double latency = /*client_state->frames[client_state->parsecountmod].latency + */fakelatency;
  53.  
  54.     if (latency > 1.5)
  55.         latency = 1.5;
  56.    
  57.     double update_interval = 0.1;
  58.  
  59.     if (cl_updaterate->value > 10.f)
  60.         update_interval = 1.0 / double(cl_updaterate->value);
  61.  
  62.     // Fixup delay based on message interval (cl_updaterate, default 20 so 50 msec)
  63.     //latency -= update_interval;
  64.  
  65.     // Further fixup due to client side delay because packets arrive 1/2 through the frame loop, on average
  66.     //latency -= (g_Local->m_flFrameTime/* * 0.5*/);
  67.  
  68.     // Absolute bounds on lag compensation
  69.     double correct = min(LAG_COMPENSATION_DATA_TIME, latency);
  70.  
  71.     // See if server is applying a lower cap
  72.     if (sv_maxunlag->value)
  73.     {
  74.         // Make sure it's not negative
  75.         if (sv_maxunlag->value < 0.f)
  76.             sv_maxunlag->value = 0.f;
  77.  
  78.         // Apply server cap
  79.         correct = min(correct, sv_maxunlag->value);
  80.     }
  81.  
  82.     // Get true timestamp
  83.     const double realtime = client_state->time;
  84.  
  85.     // Figure out timestamp for which we are looking for data
  86.     double targettime = realtime - correct;
  87.  
  88.     // Remove lag based on player interpolation, as well
  89.     double interptime = (lerp_msec == -1) ? ex_interp->value : (lerp_msec / 1000.0);
  90.  
  91.     if (interptime > 0.1)
  92.         interptime = 0.1;
  93.  
  94.     if (update_interval > interptime)
  95.         interptime = update_interval;
  96.  
  97.     targettime -= interptime;
  98.  
  99.     // Server can apply a fudge, probably not needed, defaults to 0.0f
  100.     targettime += sv_unlagpush->value;
  101.  
  102.     // Cap target to present time, of course
  103.     targettime = min(realtime, targettime);
  104.  
  105.     position_history_t *newer, *older;
  106.  
  107.     FindSpanningContexts(pGameEntity, float(targettime), &newer, &older);
  108.  
  109.     if (!newer || !older)
  110.         return false;
  111.  
  112.     float frac = 0.f;
  113.  
  114.     if (newer->animtime != older->animtime)
  115.     {
  116.         frac = float(targettime - older->animtime) / (newer->animtime - older->animtime);
  117.         frac = std::clamp(frac, 0.f, 1.f);
  118.     }
  119.  
  120.     Vector delta = newer->origin - older->origin;
  121.  
  122.     if (delta.LengthSqr() > LAG_COMPENSATION_TELEPORTED_DISTANCE_SQR)
  123.         return false;
  124.  
  125.     origin = older->origin + delta * frac;
  126.  
  127.     return true;
  128. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top