Advertisement
Guest User

Untitled

a guest
May 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #include "Prediction.h"
  2.  
  3. // yay we can hit skeet now. Just for me to make a good resolver and we gucci. i also updated eye angle pointer so resolver works
  4. float m_flOldCurtime;
  5. float m_flOldFrametime;
  6. int* nPredictionRandomSeed = nullptr;
  7.  
  8. #define TICK_INTERVAL ( Interfaces::Globals->interval_per_tick )
  9.  
  10. #define TIME_TO_TICKS( dt ) ( (int)( 0.5f + (float)(dt) / TICK_INTERVAL ) )
  11.  
  12. #define TICKS_TO_TIME( t ) ( Interfaces::Globals->interval_per_tick * ( t ) )
  13.  
  14. void LagComp::LagCompensation(CUserCmd *cmd, IClientEntity *pLocal)
  15. {
  16. LagRecord *prevRecord = NULL;
  17. LagRecord *record = NULL;
  18.  
  19. Vector prevOrg = pLocal->GetOrigin();
  20.  
  21. Vector delta = record->m_vecOrigin - prevOrg;
  22. /*if (delta.Length2DSqr() > prevRecord->m_flTeleportDistanceSqr) 64
  23. {
  24. // lost track, too much difference
  25. return;
  26. }*/
  27.  
  28. // correct is the amout of time we have to correct game time
  29. float correct = 0.0f;
  30.  
  31. // calc number of view interpolation ticks - 1
  32. int lerpTicks = TIME_TO_TICKS(cmd->m_fLerpTime);
  33.  
  34. // add view interpolation latency see C_BaseEntity::GetInterpolationAmount()
  35. correct += TICKS_TO_TIME(lerpTicks);
  36.  
  37. // correct tick send by player
  38. int targettick = cmd->tick_count - lerpTicks;
  39.  
  40. // calc difference between tick send by player and our latency based tick
  41. float deltaTime = correct - TICKS_TO_TIME(Interfaces::Globals->tickcount - targettick);
  42.  
  43. if (fabs(deltaTime) > 0.2f)
  44. {
  45. // difference between cmd time and latency is too big > 200ms, use time correction based on latency
  46. targettick = Interfaces::Globals->tickcount - TIME_TO_TICKS(correct);
  47. }
  48. }
  49.  
  50. void Prediction::PredictionStart(CUserCmd* cmd, IClientEntity* pLocal)
  51. {
  52. BYTE bMoveData[0x200];
  53. float curtime = Interfaces::Globals->curtime;
  54. float frametime = Interfaces::Globals->frametime;
  55. int iFlags = pLocal->GetFlags();
  56.  
  57. Interfaces::Globals->curtime = (float)pLocal->GetTickBase() * Interfaces::Globals->interval_per_tick;
  58. Interfaces::Globals->frametime = Interfaces::Globals->interval_per_tick;
  59.  
  60. Interfaces::MoveHelper->SetHost(pLocal);
  61.  
  62. Interfaces::GamePrediction->SetupMove(pLocal, cmd, nullptr, bMoveData);
  63. Interfaces::GameMovement->ProcessMovement(pLocal, bMoveData);
  64. Interfaces::GamePrediction->FinishMove(pLocal, cmd, bMoveData);
  65.  
  66. Interfaces::MoveHelper->SetHost(0);
  67.  
  68. Interfaces::Globals->curtime = curtime;
  69. Interfaces::Globals->frametime = frametime;
  70. *pLocal->GetPointerFlags() = iFlags;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement