Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.2 KiB

  1. //--------------------------------------------------------------------------------------------------------
  2. // Copyright (c) 2007 Turtle Rock Studios, Inc.
  3. #include "cbase.h"
  4. #include "c_basetoggle.h"
  5. // memdbgon must be the last include file in a .cpp file!!!
  6. #include "tier0/memdbgon.h"
  7. IMPLEMENT_CLIENTCLASS_DT( C_BaseToggle, DT_BaseToggle, CBaseToggle )
  8. RecvPropVector( RECVINFO( m_vecFinalDest ) ),
  9. RecvPropInt( RECVINFO( m_movementType ) ),
  10. RecvPropFloat( RECVINFO( m_flMoveTargetTime ) ),
  11. END_RECV_TABLE()
  12. BEGIN_PREDICTION_DATA( C_BaseToggle )
  13. END_PREDICTION_DATA()
  14. ConVar cl_predict_basetoggles("cl_predict_basetoggles", "1" );
  15. //--------------------------------------------------------------------------------------------------------
  16. // Returns the velocity imparted to players standing on us.
  17. void C_BaseToggle::GetGroundVelocityToApply( Vector &vecGroundVel )
  18. {
  19. vecGroundVel = GetLocalVelocity();
  20. if( !GetPredictable() )
  21. {
  22. vecGroundVel.z = 0.0f; // don't give upward velocity, or it could predict players into the air.
  23. }
  24. }
  25. bool C_BaseToggle::ShouldPredict( void )
  26. {
  27. return cl_predict_basetoggles.GetBool() && (m_movementType == MOVE_TOGGLE_LINEAR);
  28. }
  29. C_BasePlayer *C_BaseToggle::GetPredictionOwner( void )
  30. {
  31. C_BasePlayer *pPlayer = (C_BasePlayer *)m_hPredictionOwner.Get();
  32. if( pPlayer && pPlayer->IsLocalPlayer() )
  33. return pPlayer;
  34. return NULL;
  35. }
  36. bool C_BaseToggle::PredictionIsPhysicallySimulated( void )
  37. {
  38. return (m_movementType == MOVE_TOGGLE_LINEAR);
  39. }
  40. void C_BaseToggle::PostDataUpdate( DataUpdateType_t updateType )
  41. {
  42. BaseClass::PostDataUpdate( updateType );
  43. m_vLastNetworked = GetNetworkOrigin();
  44. m_fLastNetworkedTime = gpGlobals->curtime;
  45. if( GetPredictionEligible() && m_bWasPredictingMotion && (m_movementType == MOVE_TOGGLE_NONE) )
  46. {
  47. SetPredictionEligible( false );
  48. ResetLatched();
  49. }
  50. m_bWasPredictingMotion = (m_movementType != MOVE_TOGGLE_NONE);
  51. }
  52. void C_BaseToggle::PhysicsSimulate( void )
  53. {
  54. BaseClass::PhysicsSimulate();
  55. if( GetPredictable() )
  56. {
  57. Vector vOrigin = PredictPosition( GetPredictionOwner()->PredictedServerTime() );
  58. if( vOrigin == m_vecFinalDest )
  59. {
  60. SetLocalVelocity( vec3_origin );
  61. }
  62. SetLocalOrigin( vOrigin );
  63. SetNetworkOrigin( vOrigin );
  64. }
  65. }
  66. Vector C_BaseToggle::PredictPosition( float fCurTime )
  67. {
  68. if( (m_movementType != MOVE_TOGGLE_LINEAR) || m_flMoveTargetTime <= 0.0f )
  69. return GetNetworkOrigin();
  70. if( m_flMoveTargetTime > fCurTime )
  71. {
  72. float fTargetTime = m_flMoveTargetTime;
  73. float fTimeRemaining = fTargetTime - fCurTime;
  74. float fTotalTime = fTargetTime - m_fLastNetworkedTime;
  75. if( fTotalTime <= 0.0f )
  76. return m_vecFinalDest;
  77. float fInterp = fTimeRemaining / fTotalTime;
  78. return (m_vLastNetworked * fInterp) + (m_vecFinalDest * (1.0f - fInterp));
  79. }
  80. else
  81. {
  82. return m_vecFinalDest;
  83. }
  84. }
  85. //--------------------------------------------------------------------------------------------------------
  86. IMPLEMENT_CLIENTCLASS_DT( C_BaseButton, DT_BaseButton, CBaseButton )
  87. RecvPropBool( RECVINFO( m_usable ) ),
  88. END_RECV_TABLE()
  89. //--------------------------------------------------------------------------------------------------------
  90. bool C_BaseButton::IsPotentiallyUsable( void )
  91. {
  92. return true;
  93. }